@@ -345,15 +345,16 @@ func (t *clusterNormalizationTransformer) resolveDefinitions4Component(transCtx
345345 compSpec .ServiceVersion = serviceVersion
346346
347347 for i , tpl := range compSpec .Instances {
348- if len (tpl .ServiceVersion ) == 0 {
348+ if len (tpl .ServiceVersion ) == 0 && len ( tpl . CompDef ) == 0 {
349349 continue
350350 }
351351 compDef , serviceVersion , err = t .resolveCompDefinitionNServiceVersionWithTemplate (transCtx , compSpec , comp , & tpl )
352352 if err != nil {
353353 return nil , err
354354 }
355355 compDefs = append (compDefs , compDef )
356- // set the serviceVersion as resolved
356+ // set the componentDef and serviceVersion as resolved
357+ compSpec .Instances [i ].CompDef = compDef .Name
357358 compSpec .Instances [i ].ServiceVersion = serviceVersion
358359 }
359360 return compDefs , nil
@@ -386,19 +387,27 @@ func (t *clusterNormalizationTransformer) resolveCompDefinitionNServiceVersionWi
386387 }
387388 }
388389 }
389- if comp == nil || runningTpl == nil || t .checkTemplateUpgrade (compSpec , comp , protoTpl , runningTpl ) {
390- return resolveCompDefinitionNServiceVersion (ctx , cli , compSpec .ComponentDef , protoTpl .ServiceVersion )
390+
391+ serviceVersion := compSpec .ServiceVersion
392+ if len (protoTpl .ServiceVersion ) > 0 {
393+ serviceVersion = protoTpl .ServiceVersion
394+ }
395+ compDefName := compSpec .ComponentDef
396+ if len (protoTpl .CompDef ) > 0 {
397+ compDefName = protoTpl .CompDef
398+ }
399+ if comp == nil || runningTpl == nil || t .checkTemplateUpgrade (serviceVersion , compDefName , runningTpl ) {
400+ return resolveCompDefinitionNServiceVersion (ctx , cli , compDefName , serviceVersion )
391401 }
392- return resolveCompDefinitionNServiceVersion (ctx , cli , comp . Spec .CompDef , runningTpl .ServiceVersion )
402+ return resolveCompDefinitionNServiceVersion (ctx , cli , runningTpl .CompDef , runningTpl .ServiceVersion )
393403}
394404
395405func (t * clusterNormalizationTransformer ) checkCompUpgrade (compSpec * appsv1.ClusterComponentSpec , comp * appsv1.Component ) bool {
396406 return compSpec .ServiceVersion != comp .Spec .ServiceVersion || compSpec .ComponentDef != comp .Spec .CompDef
397407}
398408
399- func (t * clusterNormalizationTransformer ) checkTemplateUpgrade (compSpec * appsv1.ClusterComponentSpec ,
400- comp * appsv1.Component , protoTpl , runningTpl * appsv1.InstanceTemplate ) bool {
401- return protoTpl .ServiceVersion != runningTpl .ServiceVersion || compSpec .ComponentDef != comp .Spec .CompDef
409+ func (t * clusterNormalizationTransformer ) checkTemplateUpgrade (serviceVersion , compDefName string , runningTpl * appsv1.InstanceTemplate ) bool {
410+ return serviceVersion != runningTpl .ServiceVersion || compDefName != runningTpl .CompDef
402411}
403412
404413func (t * clusterNormalizationTransformer ) buildShardingComps (transCtx * clusterTransformContext ) (map [string ][]* appsv1.ClusterComponentSpec , error ) {
0 commit comments