Skip to content

Commit

Permalink
add log print to reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-lss committed Mar 14, 2024
1 parent 257db21 commit 58a75b5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions pkg/controllers/components.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/controllers/deployment_updater.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 58a75b5

Please sign in to comment.