From f2a49acfb38abd5c3b2bce4e754bf937a0f8e2bf Mon Sep 17 00:00:00 2001 From: lamai93 Date: Mon, 5 Aug 2019 15:06:16 +0200 Subject: [PATCH 1/3] Moved status update to pod creation. Used deepEquals for pointers. --- pkg/apis/deployment/v1alpha/member_status.go | 2 +- pkg/deployment/reconcile/action_rotate_member.go | 10 ---------- pkg/deployment/reconcile/plan_builder.go | 8 ++++---- pkg/deployment/resources/pod_creator.go | 6 ++++++ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pkg/apis/deployment/v1alpha/member_status.go b/pkg/apis/deployment/v1alpha/member_status.go index 0e102a7a5..8d5110d5e 100644 --- a/pkg/apis/deployment/v1alpha/member_status.go +++ b/pkg/apis/deployment/v1alpha/member_status.go @@ -56,7 +56,7 @@ type MemberStatus struct { // CleanoutJobID holds the ID of the agency job for cleaning out this server CleanoutJobID string `json:"cleanout-job-id,omitempty"` // SideCarSpecs contains list of specifications specified for side cars - SideCarSpecs map[string]v1.Container + SideCarSpecs map[string]v1.Container `json:"sidecars-specs,omitempty"` // ArangoVersion holds the ArangoDB version in member ArangoVersion driver.Version `json:"arango-version,omitempty"` //ImageId holds the members ArangoDB image ID diff --git a/pkg/deployment/reconcile/action_rotate_member.go b/pkg/deployment/reconcile/action_rotate_member.go index 3ad14469e..e6cbe7a07 100644 --- a/pkg/deployment/reconcile/action_rotate_member.go +++ b/pkg/deployment/reconcile/action_rotate_member.go @@ -26,7 +26,6 @@ import ( "context" "time" - "k8s.io/api/core/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha" "github.com/rs/zerolog" ) @@ -119,15 +118,6 @@ func (a *actionRotateMember) CheckProgress(ctx context.Context) (bool, bool, err m.Phase = api.MemberPhaseNone m.RecentTerminations = nil // Since we're rotating, we do not care about old terminations. m.CleanoutJobID = "" - - group := a.action.Group - var groupSpec = a.actionCtx.GetSpec().GetServerGroupSpec(group) - // Check for missing side cars in - m.SideCarSpecs = make(map[string]v1.Container) - for _, specSidecar := range groupSpec.GetSidecars() { - m.SideCarSpecs[specSidecar.Name] = *specSidecar.DeepCopy() - } - if err := a.actionCtx.UpdateMember(m); err != nil { return false, false, maskAny(err) } diff --git a/pkg/deployment/reconcile/plan_builder.go b/pkg/deployment/reconcile/plan_builder.go index 8399f1d62..f923c5ac9 100644 --- a/pkg/deployment/reconcile/plan_builder.go +++ b/pkg/deployment/reconcile/plan_builder.go @@ -449,22 +449,22 @@ func sideCarRequireRotation(wanted, given *v1.Container) bool { return true } } - if wanted.Lifecycle != given.Lifecycle { + if !reflect.DeepEqual(wanted.Lifecycle, given.Lifecycle) { return true } - if wanted.LivenessProbe != given.LivenessProbe { + if !reflect.DeepEqual(wanted.LivenessProbe, given.LivenessProbe) { return true } if !reflect.DeepEqual(wanted.Ports, given.Ports) { return true } - if wanted.ReadinessProbe != given.ReadinessProbe { + if !reflect.DeepEqual(wanted.ReadinessProbe, given.ReadinessProbe) { return true } if !reflect.DeepEqual(wanted.Resources, given.Resources) { return true } - if wanted.SecurityContext != given.SecurityContext { + if !reflect.DeepEqual(wanted.SecurityContext, given.SecurityContext) { return true } if wanted.Stdin != given.Stdin { diff --git a/pkg/deployment/resources/pod_creator.go b/pkg/deployment/resources/pod_creator.go index 4d129d763..b2ca0fb82 100644 --- a/pkg/deployment/resources/pod_creator.go +++ b/pkg/deployment/resources/pod_creator.go @@ -671,6 +671,12 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string, m.ArangoVersion = status.CurrentImage.ArangoDBVersion m.ImageID = status.CurrentImage.ImageID + // Check for missing side cars in + m.SideCarSpecs = make(map[string]v1.Container) + for _, specSidecar := range groupSpec.GetSidecars() { + m.SideCarSpecs[specSidecar.Name] = *specSidecar.DeepCopy() + } + log.Debug().Str("pod-name", m.PodName).Msg("Created pod") } else if group.IsArangosync() { // Check image From 2705ef10af9b8cbd7f6db7c6d10e9f4fc86fabd4 Mon Sep 17 00:00:00 2001 From: lamai93 Date: Mon, 5 Aug 2019 15:28:51 +0200 Subject: [PATCH 2/3] Simplified code. --- pkg/deployment/reconcile/plan_builder.go | 124 ++++++++++++----------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/pkg/deployment/reconcile/plan_builder.go b/pkg/deployment/reconcile/plan_builder.go index f923c5ac9..3be80b8f7 100644 --- a/pkg/deployment/reconcile/plan_builder.go +++ b/pkg/deployment/reconcile/plan_builder.go @@ -429,70 +429,72 @@ func podNeedsRotation(log zerolog.Logger, p v1.Pod, apiObject metav1.Object, spe // sideCarRequireRotation checks if side car requires rotation including default parameters func sideCarRequireRotation(wanted, given *v1.Container) bool { - if !reflect.DeepEqual(wanted.Args, given.Args) { - return true - } - if !reflect.DeepEqual(wanted.Command, given.Command) { - return true - } - if !reflect.DeepEqual(wanted.Env, given.Env) { - return true - } - if !reflect.DeepEqual(wanted.EnvFrom, given.EnvFrom) { - return true - } - if wanted.Image != given.Image { - return true - } - if wanted.ImagePullPolicy != given.ImagePullPolicy { - if wanted.ImagePullPolicy != "Always" || !strings.HasSuffix(given.Image, ":latest") { + return !reflect.DeepEqual(wanted, given) + /* + if !reflect.DeepEqual(wanted.Args, given.Args) { + return true + } + if !reflect.DeepEqual(wanted.Command, given.Command) { + return true + } + if !reflect.DeepEqual(wanted.Env, given.Env) { + return true + } + if !reflect.DeepEqual(wanted.EnvFrom, given.EnvFrom) { + return true + } + if wanted.Image != given.Image { + return true + } + if wanted.ImagePullPolicy != given.ImagePullPolicy { + if wanted.ImagePullPolicy != "Always" || !strings.HasSuffix(given.Image, ":latest") { + return true + } + } + if !reflect.DeepEqual(wanted.Lifecycle, given.Lifecycle) { + return true + } + if !reflect.DeepEqual(wanted.LivenessProbe, given.LivenessProbe) { + return true + } + if !reflect.DeepEqual(wanted.Ports, given.Ports) { + return true + } + if !reflect.DeepEqual(wanted.ReadinessProbe, given.ReadinessProbe) { + return true + } + if !reflect.DeepEqual(wanted.Resources, given.Resources) { + return true + } + if !reflect.DeepEqual(wanted.SecurityContext, given.SecurityContext) { + return true + } + if wanted.Stdin != given.Stdin { + return true + } + if wanted.StdinOnce != given.StdinOnce { + return true + } + if wanted.TerminationMessagePath != given.TerminationMessagePath { + return true + } + if wanted.TerminationMessagePolicy != given.TerminationMessagePolicy { + return true + } + if wanted.TTY != given.TTY { + return true + } + if !reflect.DeepEqual(wanted.VolumeDevices, given.VolumeDevices) { + return true + } + if !reflect.DeepEqual(wanted.VolumeMounts, given.VolumeMounts) { + return true + } + if wanted.WorkingDir != given.WorkingDir { return true } - } - if !reflect.DeepEqual(wanted.Lifecycle, given.Lifecycle) { - return true - } - if !reflect.DeepEqual(wanted.LivenessProbe, given.LivenessProbe) { - return true - } - if !reflect.DeepEqual(wanted.Ports, given.Ports) { - return true - } - if !reflect.DeepEqual(wanted.ReadinessProbe, given.ReadinessProbe) { - return true - } - if !reflect.DeepEqual(wanted.Resources, given.Resources) { - return true - } - if !reflect.DeepEqual(wanted.SecurityContext, given.SecurityContext) { - return true - } - if wanted.Stdin != given.Stdin { - return true - } - if wanted.StdinOnce != given.StdinOnce { - return true - } - if wanted.TerminationMessagePath != given.TerminationMessagePath { - return true - } - if wanted.TerminationMessagePolicy != given.TerminationMessagePolicy { - return true - } - if wanted.TTY != given.TTY { - return true - } - if !reflect.DeepEqual(wanted.VolumeDevices, given.VolumeDevices) { - return true - } - if !reflect.DeepEqual(wanted.VolumeMounts, given.VolumeMounts) { - return true - } - if wanted.WorkingDir != given.WorkingDir { - return true - } - return false + return false*/ } // resourcesRequireRotation returns true if the resource requirements have changed such that a rotation is required From 7e9514d224ffb8be07b1800b26fb7118ffda948e Mon Sep 17 00:00:00 2001 From: lamai93 Date: Mon, 5 Aug 2019 16:05:42 +0200 Subject: [PATCH 3/3] Deleted comment nobody needs. --- pkg/deployment/reconcile/plan_builder.go | 65 ------------------------ 1 file changed, 65 deletions(-) diff --git a/pkg/deployment/reconcile/plan_builder.go b/pkg/deployment/reconcile/plan_builder.go index 3be80b8f7..80e96575f 100644 --- a/pkg/deployment/reconcile/plan_builder.go +++ b/pkg/deployment/reconcile/plan_builder.go @@ -430,71 +430,6 @@ func podNeedsRotation(log zerolog.Logger, p v1.Pod, apiObject metav1.Object, spe // sideCarRequireRotation checks if side car requires rotation including default parameters func sideCarRequireRotation(wanted, given *v1.Container) bool { return !reflect.DeepEqual(wanted, given) - /* - if !reflect.DeepEqual(wanted.Args, given.Args) { - return true - } - if !reflect.DeepEqual(wanted.Command, given.Command) { - return true - } - if !reflect.DeepEqual(wanted.Env, given.Env) { - return true - } - if !reflect.DeepEqual(wanted.EnvFrom, given.EnvFrom) { - return true - } - if wanted.Image != given.Image { - return true - } - if wanted.ImagePullPolicy != given.ImagePullPolicy { - if wanted.ImagePullPolicy != "Always" || !strings.HasSuffix(given.Image, ":latest") { - return true - } - } - if !reflect.DeepEqual(wanted.Lifecycle, given.Lifecycle) { - return true - } - if !reflect.DeepEqual(wanted.LivenessProbe, given.LivenessProbe) { - return true - } - if !reflect.DeepEqual(wanted.Ports, given.Ports) { - return true - } - if !reflect.DeepEqual(wanted.ReadinessProbe, given.ReadinessProbe) { - return true - } - if !reflect.DeepEqual(wanted.Resources, given.Resources) { - return true - } - if !reflect.DeepEqual(wanted.SecurityContext, given.SecurityContext) { - return true - } - if wanted.Stdin != given.Stdin { - return true - } - if wanted.StdinOnce != given.StdinOnce { - return true - } - if wanted.TerminationMessagePath != given.TerminationMessagePath { - return true - } - if wanted.TerminationMessagePolicy != given.TerminationMessagePolicy { - return true - } - if wanted.TTY != given.TTY { - return true - } - if !reflect.DeepEqual(wanted.VolumeDevices, given.VolumeDevices) { - return true - } - if !reflect.DeepEqual(wanted.VolumeMounts, given.VolumeMounts) { - return true - } - if wanted.WorkingDir != given.WorkingDir { - return true - } - - return false*/ } // resourcesRequireRotation returns true if the resource requirements have changed such that a rotation is required