mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Bugfix] Fix core initContainers check (#863)
This commit is contained in:
parent
8a4f38f61f
commit
57334c2b0c
3 changed files with 102 additions and 28 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
||||
- Add Plan BackOff functionality
|
||||
- Fix Core InitContainers check
|
||||
|
||||
## [1.2.6](https://github.com/arangodb/kube-arangodb/tree/1.2.6) (2021-12-15)
|
||||
- Add ArangoBackup backoff functionality
|
||||
|
|
|
@ -97,47 +97,55 @@ func containersCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *co
|
|||
}
|
||||
|
||||
func initContainersCompare(deploymentSpec api.DeploymentSpec, group api.ServerGroup, spec, status *core.PodSpec) compareFunc {
|
||||
return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, err error) {
|
||||
return func(builder api.ActionBuilder) (Mode, api.Plan, error) {
|
||||
gs := deploymentSpec.GetServerGroupSpec(group)
|
||||
|
||||
equal, err := util.CompareJSON(spec.InitContainers, status.InitContainers)
|
||||
if err != nil {
|
||||
return SkippedRotation, nil, err
|
||||
}
|
||||
|
||||
// if equal nothing to do
|
||||
if equal {
|
||||
return SkippedRotation, nil, nil
|
||||
}
|
||||
|
||||
switch gs.InitContainers.GetMode().Get() {
|
||||
case api.ServerGroupInitContainerIgnoreMode:
|
||||
// Just copy spec to status if different
|
||||
if equal, err := util.CompareJSON(spec.InitContainers, status.InitContainers); err != nil {
|
||||
return 0, nil, err
|
||||
} else if !equal {
|
||||
if !equal {
|
||||
status.InitContainers = spec.InitContainers
|
||||
mode = mode.And(SilentRotation)
|
||||
return SilentRotation, nil, err
|
||||
} else {
|
||||
return 0, nil, err
|
||||
return SkippedRotation, nil, err
|
||||
}
|
||||
default:
|
||||
if len(status.InitContainers) != len(spec.InitContainers) {
|
||||
// Nothing to do, count is different
|
||||
return
|
||||
}
|
||||
|
||||
for id := range status.InitContainers {
|
||||
if status.InitContainers[id].Name != spec.InitContainers[id].Name {
|
||||
// Nothing to do, order is different
|
||||
return
|
||||
statusInitContainers, specInitContainers := filterReservedInitContainers(status.InitContainers), filterReservedInitContainers(spec.InitContainers)
|
||||
if equal, err := util.CompareJSON(specInitContainers, statusInitContainers); err != nil {
|
||||
return SkippedRotation, nil, err
|
||||
} else if equal {
|
||||
status.InitContainers = spec.InitContainers
|
||||
return SilentRotation, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
for id := range status.InitContainers {
|
||||
if api.IsReservedServerGroupInitContainerName(status.InitContainers[id].Name) {
|
||||
if equal, err := util.CompareJSON(spec.InitContainers[id], status.InitContainers[id]); err != nil {
|
||||
return 0, nil, err
|
||||
} else if !equal {
|
||||
status.InitContainers[id] = spec.InitContainers[id]
|
||||
mode = mode.And(SilentRotation)
|
||||
}
|
||||
}
|
||||
return SkippedRotation, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
// filterReservedInitContainers filters out reserved container names (which does not enforce restarts)
|
||||
func filterReservedInitContainers(c []core.Container) []core.Container {
|
||||
r := make([]core.Container, 0, len(c))
|
||||
|
||||
for id := range c {
|
||||
if api.IsReservedServerGroupInitContainerName(c[id].Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
r = append(r, c[id])
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// isOnlyLogLevelChanged returns true when status and spec log level arguments are different.
|
||||
|
|
|
@ -136,6 +136,71 @@ func Test_InitContainers(t *testing.T) {
|
|||
|
||||
expectedMode: SilentRotation,
|
||||
|
||||
deploymentSpec: buildDeployment(func(depl *api.DeploymentSpec) {
|
||||
depl.Agents.InitContainers = &api.ServerGroupInitContainers{
|
||||
Mode: api.ServerGroupInitContainerUpdateMode.New(),
|
||||
}
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "Only core container change",
|
||||
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
})),
|
||||
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
|
||||
c.Image = "local:2.0"
|
||||
})),
|
||||
|
||||
expectedMode: SilentRotation,
|
||||
|
||||
deploymentSpec: buildDeployment(func(depl *api.DeploymentSpec) {
|
||||
depl.Agents.InitContainers = &api.ServerGroupInitContainers{
|
||||
Mode: api.ServerGroupInitContainerUpdateMode.New(),
|
||||
}
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "Only core container change with sidecar",
|
||||
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
}), addInitContainer("sidecar", func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
})),
|
||||
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
|
||||
c.Image = "local:2.0"
|
||||
}), addInitContainer("sidecar", func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
})),
|
||||
|
||||
expectedMode: SilentRotation,
|
||||
|
||||
deploymentSpec: buildDeployment(func(depl *api.DeploymentSpec) {
|
||||
depl.Agents.InitContainers = &api.ServerGroupInitContainers{
|
||||
Mode: api.ServerGroupInitContainerUpdateMode.New(),
|
||||
}
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "Only core container change with sidecar change",
|
||||
spec: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
}), addInitContainer(api.ServerGroupReservedInitContainerNameUpgrade, func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
}), addInitContainer("sidecar", func(c *v1.Container) {
|
||||
c.Image = "local:1.0"
|
||||
})),
|
||||
status: buildPodSpec(addInitContainer(api.ServerGroupReservedInitContainerNameUUID, func(c *v1.Container) {
|
||||
c.Image = "local:2.0"
|
||||
}), addInitContainer("sidecar", func(c *v1.Container) {
|
||||
c.Image = "local:2.0"
|
||||
})),
|
||||
|
||||
expectedMode: GracefulRotation,
|
||||
|
||||
deploymentSpec: buildDeployment(func(depl *api.DeploymentSpec) {
|
||||
depl.Agents.InitContainers = &api.ServerGroupInitContainers{
|
||||
Mode: api.ServerGroupInitContainerUpdateMode.New(),
|
||||
|
|
Loading…
Reference in a new issue