diff --git a/main.go b/main.go index 79160f1a..544a7956 100644 --- a/main.go +++ b/main.go @@ -103,6 +103,8 @@ func main() { controllers.InitializeMetrics() + // Done: setup controllers + setupLog.Info("setting up controllers", "mgr", mgr) if err := controllers.SetupControllers(ctx, mgr, strings.Split(stopReconcilers, ","), true); err != nil { setupLog.Error(err, "unable to setup controller with manager") os.Exit(1) diff --git a/pkg/controllers/components.go b/pkg/controllers/components.go index 597e0966..59adafa4 100644 --- a/pkg/controllers/components.go +++ b/pkg/controllers/components.go @@ -1,9 +1,11 @@ package controllers import ( + "context" "encoding/json" "fmt" "reflect" + ctrl "sigs.k8s.io/controller-runtime" "strings" appsv1 "k8s.io/api/apps/v1" @@ -380,14 +382,22 @@ func (c MilvusComponent) GetDependencies(spec v1beta1.MilvusSpec) []MilvusCompon // IsImageUpdated returns whether the image of the component is updated func (c MilvusComponent) IsImageUpdated(m *v1beta1.Milvus) bool { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + logger := ctrl.LoggerFrom(ctx) + logger.Info("IsImageUpdated", "ComponentsDeployStatus", m.Status.ComponentsDeployStatus) + if m.Status.ComponentsDeployStatus == nil { return false } deployStatus := m.Status.ComponentsDeployStatus[c.GetName()] + logger.Info("IsImageUpdated", "m.Spec.Com.Image", m.Spec.Com.Image, "deployStatus.Image", deployStatus.Image) if m.Spec.Com.Image != deployStatus.Image { return false } + logger.Info("IsImageUpdated", "deployStatus.GetState()", deployStatus.GetState()) if deployStatus.GetState() != v1beta1.DeploymentComplete { return false } diff --git a/pkg/controllers/deployment_updater.go b/pkg/controllers/deployment_updater.go index b00c53db..8a0771d0 100644 --- a/pkg/controllers/deployment_updater.go +++ b/pkg/controllers/deployment_updater.go @@ -1,6 +1,9 @@ package controllers import ( + "context" + "fmt" + ctrl "sigs.k8s.io/controller-runtime" "time" "github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1" @@ -69,6 +72,12 @@ func updatePodTemplate( appLabels map[string]string, isCreating bool, ) { + //Done: updatePodTemplate + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + logger := ctrl.LoggerFrom(ctx) + currentTemplate := template.DeepCopy() updatePodMeta(template, appLabels, updater) @@ -77,10 +86,12 @@ func updatePodTemplate( updateScheduleSpec(template, updater) updateMilvusContainer(template, updater, isCreating) updateSidecars(template, updater) + logger.Info("updatePodTemplate", "IsEqual template", IsEqual(currentTemplate, template), "image", updater.GetMergedComponentSpec().Image, "name", updater.GetMilvus().Name) // no rolling update if IsEqual(currentTemplate, template) { return } + // some defaults change will cause rolling update, so we only perform when rolling update updateSomeFieldsOnlyWhenRolling(template, updater) } @@ -170,6 +181,12 @@ func updateVolumes(template *corev1.PodTemplateSpec, updater deploymentUpdater) } func updateMilvusContainer(template *corev1.PodTemplateSpec, updater deploymentUpdater, isCreating bool) { + //Done: updateMilvusContainer + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + logger := ctrl.LoggerFrom(ctx) + mergedComSpec := updater.GetMergedComponentSpec() containerIdx := GetContainerIndex(template.Spec.Containers, updater.GetComponentName()) @@ -229,6 +246,9 @@ func updateMilvusContainer(template *corev1.PodTemplateSpec, updater deploymentU !updater.GetMilvus().IsRollingUpdateEnabled() || // rolling update is disabled updater.GetMilvus().Spec.Com.ImageUpdateMode == v1beta1.ImageUpdateModeAll || // image update mode is update all updater.RollingUpdateImageDependencyReady() { + //Done: updateMilvusContainer + logger.Info("updateMilvusContainer", "container.Image", container.Image, "mergedComSpec.Image", mergedComSpec.Image) + container.Image = mergedComSpec.Image } @@ -382,7 +402,14 @@ func (m milvusDeploymentUpdater) RollingUpdateImageDependencyReady() bool { return false } deps := m.component.GetDependencies(m.Spec) + //Done: RollingUpdateImageDependencyReady + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + logger := ctrl.LoggerFrom(ctx) + for _, dep := range deps { + logger.Info("RollingUpdateImageDependencyReady", "dep", fmt.Sprintf("%s:%s", dep.Name, dep.FieldName)) if !dep.IsImageUpdated(m.GetMilvus()) { return false } diff --git a/pkg/controllers/deployments.go b/pkg/controllers/deployments.go index 6ca61346..f2937ff2 100644 --- a/pkg/controllers/deployments.go +++ b/pkg/controllers/deployments.go @@ -79,6 +79,7 @@ func (r *MilvusReconciler) updateDeployment( return errors.Wrap(err, "check component has terminating pod") } if hasTerminatingPod { + r.logger.Info("[MilvusReconciler.updateDeployment] component has terminating pod, skip update template", "component", component.Name) return updateDeploymentWithoutPodTemplate(deployment, updater) } @@ -122,8 +123,7 @@ func (r *MilvusReconciler) ReconcileComponentDeployment( if IsEqual(old, cur) { // Done: nothing diff r.logger.Info("nothing diff context", "name", cur.Name, "namespace", cur.Namespace) - r.logger.Info("old spec", "spec", old) - r.logger.Info("cur spec", "spec", cur) + return nil }