1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

OAS-9763 Operator restarts member if log-level arg order is changed (#1676)

This commit is contained in:
jwierzbo 2024-07-02 12:21:27 +02:00 committed by GitHub
parent b67b93d3a4
commit c430fdbbe7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 65 additions and 2183 deletions

2169
go.sum

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -210,20 +210,50 @@ func filterReservedInitContainers(c []core.Container) []core.Container {
// isOnlyLogLevelChanged returns true when status and spec log level arguments are different.
// If any other argument than --log.level is different false is returned.
func isOnlyLogLevelChanged(specArgs, statusArgs []string) bool {
diff := arangoStrings.DiffStrings(specArgs, statusArgs)
nonLogSpecArgs, logSpecArgs := splitLogLevelPrefixItems(specArgs)
nonLogStatusArgs, logStatusArgs := splitLogLevelPrefixItems(statusArgs)
diff := arangoStrings.DiffStrings(nonLogSpecArgs, nonLogStatusArgs)
if len(diff) == 0 {
return false
}
for _, arg := range diff {
if !strings.HasPrefix(strings.TrimLeft(arg, " "), "--log.level") {
// ensure that the order of arguments is the same, besides log level one
for i, v := range nonLogSpecArgs {
if v != nonLogStatusArgs[i] {
return false
}
}
} else if len(diff) > 0 {
return false
}
if len(logSpecArgs) != len(logStatusArgs) {
return true
}
// check if log level arguments order is the same
for i, v := range logSpecArgs {
if v != logStatusArgs[i] {
return true
}
}
return false
}
func splitLogLevelPrefixItems(args []string) ([]string, []string) {
var nonLogLevel []string
var logLevel []string
for _, arg := range args {
if !strings.HasPrefix(arg, "--log.level") {
nonLogLevel = append(nonLogLevel, arg)
} else {
logLevel = append(logLevel, arg)
}
}
return nonLogLevel, logLevel
}
func internalContainerLifecycleCompare(spec, status *core.Container) compare.Mode {
if spec.Lifecycle == nil && status.Lifecycle == nil {
return compare.SkippedRotation

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -247,10 +247,6 @@ func logLevelTestCaseGen(name string, mode compare.Mode, spec, status []string)
func Test_Container_LogArgs(t *testing.T) {
testCases := []TestCase{
logLevelTestCaseGen("Only log level arguments of the ArangoDB server have been changed",
compare.InPlaceRotation,
[]string{"--log.level=INFO", "--log.level=requests=error"},
[]string{"--log.level=INFO"}),
logLevelTestCaseGen("ArangoDB server arguments have not been changed",
compare.SkippedRotation,
[]string{"--log.level=INFO"},
@ -259,6 +255,10 @@ func Test_Container_LogArgs(t *testing.T) {
compare.SkippedRotation,
[]string{"--log.level=INFO", "--log.level=requests=debug"},
[]string{"--log.level=INFO", "--log.level=requests=debug"}),
logLevelTestCaseGen("Multi ArangoDB server arguments have not been changed - extended",
compare.SkippedRotation,
[]string{"--foo=true", "--log.level=INFO", "--foo=false", "--log.level=requests=error", "--log.level=agency=trace", "--log.level=agencycomm=INFO"},
[]string{"--foo=true", "--log.level=INFO", "--foo=false", "--log.level=requests=error", "--log.level=agency=trace", "--log.level=agencycomm=INFO"}),
logLevelTestCaseGen("Not only log argument changed",
compare.GracefulRotation,
[]string{"--log.level=INFO", "--server.endpoint=localhost"},
@ -271,6 +271,26 @@ func Test_Container_LogArgs(t *testing.T) {
compare.InPlaceRotation,
[]string{"--foo", "--log.level=INFO"},
[]string{"--foo"}),
logLevelTestCaseGen("Only log level arguments of the ArangoDB server have been changed",
compare.InPlaceRotation,
[]string{"--log.level=INFO", "--log.level=requests=error"},
[]string{"--log.level=INFO"}),
logLevelTestCaseGen("Only order of log level arguments have been changed (checksum doesn't match)",
compare.InPlaceRotation,
[]string{"--log.level=INFO", "--log.level=requests=error", "--log.level=agency=trace", "--log.level=agencycomm=INFO", "--log.level=heartbeat=INFO"},
[]string{"--log.level=INFO", "--log.level=requests=error", "--log.level=heartbeat=INFO", "--log.level=agency=trace", "--log.level=agencycomm=INFO"}),
logLevelTestCaseGen("Change order of other args",
compare.GracefulRotation,
[]string{"--foo=true", "--log.level=INFO", "--foo=false"},
[]string{"--foo=false", "--log.level=INFO", "--foo=true"}),
logLevelTestCaseGen("Change order of the main args and main args",
compare.GracefulRotation,
[]string{"--foo=true", "--log.level=INFO", "--bar=false", "--log.level=requests=error", "--log.level=agency=trace", "--log.level=agencycomm=INFO", "--log.level=heartbeat=INFO"},
[]string{"--bar=false", "--log.level=INFO", "--foo=true", "--log.level=requests=error", "--log.level=heartbeat=INFO", "--log.level=agency=trace", "--log.level=agencycomm=INFO"}),
logLevelTestCaseGen("Change order of the logs and add log level",
compare.GracefulRotation,
[]string{"--foo=true", "--log.level=INFO", "--bar=false", "--log.level=requests=error", "--log.level=agency=trace", "--log.level=agencycomm=INFO", "--log.level=heartbeat=INFO"},
[]string{"--bar=false", "--log.level=INFO", "--foo=true", "--log.level=requests=error", "--log.level=agency=trace", "--log.level=agencycomm=INFO"}),
}
runTestCases(t)(testCases...)

View file

@ -27,10 +27,11 @@ import (
type Mode int
const (
// SkippedRotation Skips the rotation. Returned plan is ignored
SkippedRotation Mode = iota
// SilentRotation Propagates changes without restart. Returned plan is executed in High actions
// SilentRotation Propagates changes without a restart. Returned plan is executed in High actions
SilentRotation
// InPlaceRotation Silently accept changes. Returned plan is executed in Normal actions
// InPlaceRotation Silently accept changes without a restart. Returned plan is executed in Normal actions
InPlaceRotation
// GracefulRotation Schedule pod restart. Returned plan is ignored
GracefulRotation