@@ -89,7 +89,7 @@ func (t *rolloutTearDownTransformer) compReplace(transCtx *rolloutTransformConte
8989 }
9090 newReplicas := replaceInstanceTemplateReplicas (tpls )
9191 if newReplicas == replicas && spec .Replicas == replicas && checkClusterNCompRunning (transCtx , comp .Name ) {
92- tpl := tpls ["" ] // use the default template
92+ tpl := tpls ["" ]. DeepCopy () // use the default template, use DeepCopy to avoid it been removed
9393 spec .ServiceVersion = tpl .ServiceVersion
9494 spec .ComponentDef = tpl .CompDef
9595 spec .OfflineInstances = slices .DeleteFunc (spec .OfflineInstances , func (instance string ) bool {
@@ -107,9 +107,13 @@ func (t *rolloutTearDownTransformer) compReplace(transCtx *rolloutTransformConte
107107 _ , ok := tpl .Annotations [instanceTemplateCreatedByAnnotationKey ]
108108 return ok
109109 })
110- for i := range spec .Instances {
111- spec .Instances [i ].ServiceVersion = tpl .ServiceVersion
112- spec .Instances [i ].CompDef = tpl .CompDef
110+ for i , inst := range spec .Instances {
111+ if len (inst .ServiceVersion ) > 0 {
112+ spec .Instances [i ].ServiceVersion = tpl .ServiceVersion
113+ }
114+ if len (inst .CompDef ) > 0 {
115+ spec .Instances [i ].CompDef = tpl .CompDef
116+ }
113117 }
114118 }
115119 return nil
@@ -158,7 +162,7 @@ func (t *rolloutTearDownTransformer) shardingReplace(transCtx *rolloutTransformC
158162 }
159163 newReplicas := replaceInstanceTemplateReplicas (tpls )
160164 if newReplicas == replicas && spec .Template .Replicas == replicas && checkClusterNShardingRunning (transCtx , sharding .Name ) {
161- tpl := tpls ["" ] // use the default template
165+ tpl := tpls ["" ]. DeepCopy () // use the default template, use DeepCopy to avoid it been removed
162166 spec .Template .ServiceVersion = tpl .ServiceVersion
163167 spec .Template .ComponentDef = tpl .CompDef
164168 spec .Template .OfflineInstances = slices .DeleteFunc (spec .Template .OfflineInstances , func (instance string ) bool {
@@ -176,9 +180,13 @@ func (t *rolloutTearDownTransformer) shardingReplace(transCtx *rolloutTransformC
176180 _ , ok := tpl .Annotations [instanceTemplateCreatedByAnnotationKey ]
177181 return ok
178182 })
179- for i := range spec .Template .Instances {
180- spec .Template .Instances [i ].ServiceVersion = tpl .ServiceVersion
181- spec .Template .Instances [i ].CompDef = tpl .CompDef
183+ for i , inst := range spec .Template .Instances {
184+ if len (inst .ServiceVersion ) > 0 {
185+ spec .Template .Instances [i ].ServiceVersion = tpl .ServiceVersion
186+ }
187+ if len (inst .CompDef ) > 0 {
188+ spec .Template .Instances [i ].CompDef = tpl .CompDef
189+ }
182190 }
183191 }
184192 return nil
0 commit comments