From f307f4b703e20ad7b59572a560799fa419b9bb74 Mon Sep 17 00:00:00 2001 From: shaoyue Date: Tue, 19 Nov 2024 17:04:24 +0800 Subject: [PATCH] support custom dummy image for 2 deploy mode init (#209) Signed-off-by: haorenfsa --- apis/milvus.io/v1beta1/components_types.go | 5 +++++ charts/milvus-operator/templates/crds.yaml | 4 ++++ .../crd/bases/milvus.io_milvusclusters.yaml | 2 ++ config/crd/bases/milvus.io_milvuses.yaml | 2 ++ deploy/manifests/deployment.yaml | 4 ++++ pkg/controllers/deploy_ctrl_util.go | 9 ++++++--- pkg/controllers/deploy_ctrl_util_test.go | 13 +++++++++++++ test/min-mc-feature.yaml | 1 + test/min-milvus-feature.yaml | 19 ++++++++++--------- 9 files changed, 47 insertions(+), 12 deletions(-) diff --git a/apis/milvus.io/v1beta1/components_types.go b/apis/milvus.io/v1beta1/components_types.go index e44fd29..5b49fec 100644 --- a/apis/milvus.io/v1beta1/components_types.go +++ b/apis/milvus.io/v1beta1/components_types.go @@ -156,6 +156,11 @@ type MilvusComponents struct { // +kubebuilder:validation:Optional ToolImage string `json:"toolImage,omitempty"` + // DummyImage specify dummy image to use when creating an alternative deploy for rolling update + // when rollingMode is v2 or v3 + // +kubebuilder:validation:Optional + DummyImage string `json:"dummyImage,omitempty"` + // UpdateToolImage when milvus-operator upgraded, whether milvus should restart to update the tool image, too // otherwise, the tool image will be updated when milvus deploy's podTemplate changed // +kubebuilder:validation:Optional diff --git a/charts/milvus-operator/templates/crds.yaml b/charts/milvus-operator/templates/crds.yaml index d28328b..f926e65 100644 --- a/charts/milvus-operator/templates/crds.yaml +++ b/charts/milvus-operator/templates/crds.yaml @@ -1529,6 +1529,8 @@ spec: type: boolean dnsPolicy: type: string + dummyImage: + type: string enableManualMode: type: boolean enableRollingUpdate: @@ -9156,6 +9158,8 @@ spec: type: boolean dnsPolicy: type: string + dummyImage: + type: string enableManualMode: type: boolean enableRollingUpdate: diff --git a/config/crd/bases/milvus.io_milvusclusters.yaml b/config/crd/bases/milvus.io_milvusclusters.yaml index bfdb631..b00ee84 100644 --- a/config/crd/bases/milvus.io_milvusclusters.yaml +++ b/config/crd/bases/milvus.io_milvusclusters.yaml @@ -1527,6 +1527,8 @@ spec: type: boolean dnsPolicy: type: string + dummyImage: + type: string enableManualMode: type: boolean enableRollingUpdate: diff --git a/config/crd/bases/milvus.io_milvuses.yaml b/config/crd/bases/milvus.io_milvuses.yaml index d402a93..df566da 100644 --- a/config/crd/bases/milvus.io_milvuses.yaml +++ b/config/crd/bases/milvus.io_milvuses.yaml @@ -2505,6 +2505,8 @@ spec: type: boolean dnsPolicy: type: string + dummyImage: + type: string enableManualMode: type: boolean enableRollingUpdate: diff --git a/deploy/manifests/deployment.yaml b/deploy/manifests/deployment.yaml index 4ab1346..0696376 100644 --- a/deploy/manifests/deployment.yaml +++ b/deploy/manifests/deployment.yaml @@ -1560,6 +1560,8 @@ spec: type: boolean dnsPolicy: type: string + dummyImage: + type: string enableManualMode: type: boolean enableRollingUpdate: @@ -9188,6 +9190,8 @@ spec: type: boolean dnsPolicy: type: string + dummyImage: + type: string enableManualMode: type: boolean enableRollingUpdate: diff --git a/pkg/controllers/deploy_ctrl_util.go b/pkg/controllers/deploy_ctrl_util.go index da45fca..a822ea3 100644 --- a/pkg/controllers/deploy_ctrl_util.go +++ b/pkg/controllers/deploy_ctrl_util.go @@ -165,9 +165,12 @@ func formatComponentDeployName(mc v1beta1.Milvus, component MilvusComponent, gro func (c *DeployControllerBizUtilImpl) CreateDeploy(ctx context.Context, mc v1beta1.Milvus, podTemplate *corev1.PodTemplateSpec, groupId int) error { if podTemplate == nil { podTemplate = c.RenderPodTemplateWithoutGroupID(mc, nil, c.component) - if groupId != 0 { - // is not the first deploy, set image to dummy to avoid rolling back and forth - podTemplate.Spec.Containers[0].Image = "dummy" + } + if groupId != 0 { + // is not the first deploy, set image to dummy to avoid rolling back and forth + podTemplate.Spec.Containers[0].Image = "dummy" + if mc.Spec.Com.DummyImage != "" { + podTemplate.Spec.Containers[0].Image = mc.Spec.Com.DummyImage } } diff --git a/pkg/controllers/deploy_ctrl_util_test.go b/pkg/controllers/deploy_ctrl_util_test.go index 91065d5..83d9f62 100644 --- a/pkg/controllers/deploy_ctrl_util_test.go +++ b/pkg/controllers/deploy_ctrl_util_test.go @@ -270,6 +270,19 @@ func TestDeployControllerBizUtilImpl_CreateDeploy(t *testing.T) { err := bizUtil.CreateDeploy(ctx, mc, nil, 1) assert.NoError(t, err) }) + + t.Run("groupId=1, image set to spec.componenents.dummyImage", func(t *testing.T) { + mc.Spec.Com.DummyImage = "my-registry/my-dummy-image" + mockcli.EXPECT().Scheme().Return(scheme).Times(3) + mockcli.EXPECT().Create(ctx, gomock.AssignableToTypeOf(new(appsv1.Deployment))). + DoAndReturn(func(ctx context.Context, obj client.Object, opt ...client.Options) error { + deploy := obj.(*appsv1.Deployment) + assert.Equal(t, mc.Spec.Com.DummyImage, deploy.Spec.Template.Spec.Containers[0].Image) + return nil + }) + err := bizUtil.CreateDeploy(ctx, mc, nil, 1) + assert.NoError(t, err) + }) } func TestDeployControllerBizUtilImpl_ShouldRollback(t *testing.T) { diff --git a/test/min-mc-feature.yaml b/test/min-mc-feature.yaml index 2253c4f..4971f04 100644 --- a/test/min-mc-feature.yaml +++ b/test/min-mc-feature.yaml @@ -17,6 +17,7 @@ spec: rollingMode: 3 runWithSubProcess: true runAsNonRoot: true + dummyImage: 'my-registry/my-dummy-image' proxy: ingress: hosts: ['mc-sit.milvus.io'] diff --git a/test/min-milvus-feature.yaml b/test/min-milvus-feature.yaml index d261f01..330af66 100644 --- a/test/min-milvus-feature.yaml +++ b/test/min-milvus-feature.yaml @@ -42,13 +42,14 @@ metadata: labels: app: milvus spec: - mode: "standalone" + mode: 'standalone' components: rollingMode: 3 runWithSubProcess: true + dummyImage: 'my-registry/my-dummy-image' standalone: ingress: - hosts: ["mc-sit.milvus.io"] + hosts: ['mc-sit.milvus.io'] volumes: - name: pulsar-token secret: @@ -91,18 +92,18 @@ spec: auth: authentication: enabled: true - provider: "jwt" + provider: 'jwt' jwt: usingSecretKey: true authorization: enabled: true superUsers: # broker to broker communication - broker: "milvus" + broker: 'milvus' # proxy to broker communication - proxy: "pulsar-proxy" + proxy: 'pulsar-proxy' # pulsar-admin client to broker/proxy communication - client: "" + client: '' volumes: persistence: false components: @@ -153,9 +154,9 @@ spec: configData: PULSAR_MEM: > -Xms64m -Xmx4096m -XX:MaxDirectMemorySize=8192m - managedLedgerDefaultEnsembleSize: "1" - managedLedgerDefaultWriteQuorum: "1" - managedLedgerDefaultAckQuorum: "1" + managedLedgerDefaultEnsembleSize: '1' + managedLedgerDefaultWriteQuorum: '1' + managedLedgerDefaultAckQuorum: '1' proxy: replicaCount: 1 autoscaling: