Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apis/apps/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ type InstanceTemplate struct {
// +optional
ServiceVersion string `json:"serviceVersion,omitempty"`

// Specifies the name of the referenced ComponentDefinition.
//
// +kubebuilder:validation:MaxLength=64
CompDef string `json:"compDef,omitempty"`

// Indicate whether the instances belonging to this template are canary instances.
//
// +optional
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/apps.kubeblocks.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,10 @@ spec:
description: Indicate whether the instances belonging
to this template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down Expand Up @@ -8489,6 +8493,11 @@ spec:
description: Indicate whether the instances belonging
to this template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced
ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/apps.kubeblocks.io_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ spec:
description: Indicate whether the instances belonging to this
template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/operations.kubeblocks.io_opsrequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ spec:
description: Indicate whether the instances belonging
to this template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced
ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down Expand Up @@ -3487,6 +3492,11 @@ spec:
description: Indicate whether the instances belonging
to this template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced
ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down
25 changes: 17 additions & 8 deletions controllers/apps/cluster/transformer_cluster_normalization.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,16 @@ func (t *clusterNormalizationTransformer) resolveDefinitions4Component(transCtx
compSpec.ServiceVersion = serviceVersion

for i, tpl := range compSpec.Instances {
if len(tpl.ServiceVersion) == 0 {
if len(tpl.ServiceVersion) == 0 && len(tpl.CompDef) == 0 {
continue
}
compDef, serviceVersion, err = t.resolveCompDefinitionNServiceVersionWithTemplate(transCtx, compSpec, comp, &tpl)
if err != nil {
return nil, err
}
compDefs = append(compDefs, compDef)
// set the serviceVersion as resolved
// set the componentDef and serviceVersion as resolved
compSpec.Instances[i].CompDef = compDef.Name
compSpec.Instances[i].ServiceVersion = serviceVersion
}
return compDefs, nil
Expand Down Expand Up @@ -386,19 +387,27 @@ func (t *clusterNormalizationTransformer) resolveCompDefinitionNServiceVersionWi
}
}
}
if comp == nil || runningTpl == nil || t.checkTemplateUpgrade(compSpec, comp, protoTpl, runningTpl) {
return resolveCompDefinitionNServiceVersion(ctx, cli, compSpec.ComponentDef, protoTpl.ServiceVersion)

serviceVersion := compSpec.ServiceVersion
if len(protoTpl.ServiceVersion) > 0 {
serviceVersion = protoTpl.ServiceVersion
}
compDefName := compSpec.ComponentDef
if len(protoTpl.CompDef) > 0 {
compDefName = protoTpl.CompDef
}
if comp == nil || runningTpl == nil || t.checkTemplateUpgrade(serviceVersion, compDefName, runningTpl) {
return resolveCompDefinitionNServiceVersion(ctx, cli, compDefName, serviceVersion)
}
return resolveCompDefinitionNServiceVersion(ctx, cli, comp.Spec.CompDef, runningTpl.ServiceVersion)
return resolveCompDefinitionNServiceVersion(ctx, cli, runningTpl.CompDef, runningTpl.ServiceVersion)
}

func (t *clusterNormalizationTransformer) checkCompUpgrade(compSpec *appsv1.ClusterComponentSpec, comp *appsv1.Component) bool {
return compSpec.ServiceVersion != comp.Spec.ServiceVersion || compSpec.ComponentDef != comp.Spec.CompDef
}

func (t *clusterNormalizationTransformer) checkTemplateUpgrade(compSpec *appsv1.ClusterComponentSpec,
comp *appsv1.Component, protoTpl, runningTpl *appsv1.InstanceTemplate) bool {
return protoTpl.ServiceVersion != runningTpl.ServiceVersion || compSpec.ComponentDef != comp.Spec.CompDef
func (t *clusterNormalizationTransformer) checkTemplateUpgrade(serviceVersion, compDefName string, runningTpl *appsv1.InstanceTemplate) bool {
return serviceVersion != runningTpl.ServiceVersion || compDefName != runningTpl.CompDef
}

func (t *clusterNormalizationTransformer) buildShardingComps(transCtx *clusterTransformContext) (map[string][]*appsv1.ClusterComponentSpec, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (t *componentLoadResourcesTransformer) transformForNativeComponent(transCtx
if err != nil {
return intctrlutil.NewRequeueError(appsutil.RequeueDuration, err.Error())
}
compDefCopy := compDef.DeepCopy()

if err = component.UpdateCompDefinitionImages4ServiceVersion(ctx, cli, compDef, comp.Spec.ServiceVersion); err != nil {
return intctrlutil.NewRequeueError(appsutil.RequeueDuration, err.Error())
Expand All @@ -76,7 +75,12 @@ func (t *componentLoadResourcesTransformer) transformForNativeComponent(transCtx
}
for _, tpl := range comp.Spec.Instances {
if len(tpl.ServiceVersion) > 0 {
images, err := component.ResolveInstanceTemplateImages4ServiceVersion(ctx, cli, compDefCopy, tpl.ServiceVersion)
// TODO: comp defs?
compDef, err = getNCheckCompDefinition(ctx, cli, tpl.CompDef)
if err != nil {
return intctrlutil.NewRequeueError(appsutil.RequeueDuration, err.Error())
}
images, err := component.ResolveInstanceTemplateImages4ServiceVersion(ctx, cli, compDef, tpl.ServiceVersion)
if err != nil {
return intctrlutil.NewRequeueError(appsutil.RequeueDuration, err.Error())
}
Expand Down
9 changes: 9 additions & 0 deletions deploy/helm/crds/apps.kubeblocks.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,10 @@ spec:
description: Indicate whether the instances belonging
to this template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down Expand Up @@ -8489,6 +8493,11 @@ spec:
description: Indicate whether the instances belonging
to this template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced
ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/crds/apps.kubeblocks.io_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ spec:
description: Indicate whether the instances belonging to this
template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down
10 changes: 10 additions & 0 deletions deploy/helm/crds/operations.kubeblocks.io_opsrequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ spec:
description: Indicate whether the instances belonging
to this template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced
ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down Expand Up @@ -3487,6 +3492,11 @@ spec:
description: Indicate whether the instances belonging
to this template are canary instances.
type: boolean
compDef:
description: Specifies the name of the referenced
ComponentDefinition.
maxLength: 64
type: string
env:
description: |-
Defines Env to override.
Expand Down
11 changes: 11 additions & 0 deletions docs/developer_docs/api-reference/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -7929,6 +7929,17 @@ The version should follow the syntax and semantics of the “Semantic Versio
</tr>
<tr>
<td>
<code>compDef</code><br/>
<em>
string
</em>
</td>
<td>
<p>Specifies the name of the referenced ComponentDefinition.</p>
</td>
</tr>
<tr>
<td>
<code>canary</code><br/>
<em>
bool
Expand Down
8 changes: 6 additions & 2 deletions pkg/controller/component/component_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,12 @@ func resolveImagesWithCompVersions4Template(compDef *appsv1.ComponentDefinition,
if app.err != nil {
return app.err
}
images[kbagent.ContainerName] = app.image
images[kbagent.ContainerName4Worker] = app.image
if image, ok := images[kbagent.ContainerName]; !ok || len(image) == 0 {
images[kbagent.ContainerName] = app.image
}
if image, ok := images[kbagent.ContainerName4Worker]; !ok || len(image) == 0 {
images[kbagent.ContainerName4Worker] = app.image
}
}
}
}
Expand Down