Skip to content

Commit

Permalink
chore: fix create cluster with cd/cv failed when existing 0.9 kb (#8755)
Browse files Browse the repository at this point in the history
(cherry picked from commit 87efae1)
  • Loading branch information
wangyelei committed Jan 8, 2025
1 parent 34962e1 commit bee70f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions apis/apps/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ func incrementConvertFrom(converter incrementConverter, source metav1.Object, ic
return nil
}

func GetClusterDefFromIncrementConverter(obj client.Object) (string, error) {
func GetV1Alpha1ClusterFromIncrementConverter(obj client.Object) (*Cluster, error) {
incrementConverterStr := obj.GetAnnotations()[kbIncrementConverterAK]
if len(incrementConverterStr) == 0 {
return "", nil
return nil, nil
}
var alpha1Cluster Cluster
if err := json.Unmarshal([]byte(incrementConverterStr), &alpha1Cluster); err != nil {
return "", err
return nil, err
}
return alpha1Cluster.Spec.ClusterDefRef, nil
return &alpha1Cluster, nil
}
16 changes: 10 additions & 6 deletions controllers/apps/transformer_cluster_normalization.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,17 @@ func (t *clusterNormalizationTransformer) writeBackCompNShardingSpecs(transCtx *
}

func (t *clusterNormalizationTransformer) checkNPatchCRDAPIVersionKey(transCtx *clusterTransformContext) error {
// get the v1Alpha1Cluster from the annotations
v1Alpha1Cluster, err := appsv1alpha1.GetV1Alpha1ClusterFromIncrementConverter(transCtx.Cluster)
if err != nil {
return err
}
getCRDAPIVersion := func() (string, error) {
apiVersion := transCtx.Cluster.Annotations[constant.CRDAPIVersionAnnotationKey]
if len(apiVersion) > 0 {
return apiVersion, nil
}
// check if the cluster is the alpha1 version
clusterDefRef, err := appsv1alpha1.GetClusterDefFromIncrementConverter(transCtx.Cluster)
if err != nil {
return "", err
}
if len(clusterDefRef) > 0 {
if v1Alpha1Cluster != nil && len(v1Alpha1Cluster.Spec.ClusterDefRef) > 0 {
return appsv1alpha1.GroupVersion.String(), nil
}

Expand Down Expand Up @@ -469,5 +469,9 @@ func (t *clusterNormalizationTransformer) checkNPatchCRDAPIVersionKey(transCtx *
if controllerutil.IsAPIVersionSupported(apiVersion) {
return nil
}
if v1Alpha1Cluster != nil && len(v1Alpha1Cluster.Spec.ClusterVersionRef) > 0 {
// revert the topology to empty
transCtx.Cluster.Spec.Topology = ""
}
return graph.ErrPrematureStop // un-supported CRD API version, stop the transformation
}
2 changes: 2 additions & 0 deletions deploy/helm/templates/conversion-patch-hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ spec:
# 3. start KubeBlocks
kubectl patch deployment {{ include "kubeblocks.fullname" . }} -n {{ .Release.Namespace }} -p '{"spec":{"replicas":{{ .Values.replicaCount }}}}'
{{- if .Values.dataProtection.enabled }}
kubectl patch deployment {{ include "kubeblocks.fullname" . }}-dataprotection -n {{ .Release.Namespace }} -p '{"spec":{"replicas":{{ .Values.replicaCount }}}}'
{{- end }}
volumeMounts:
- mountPath: /opt
name: crd-multi-version-conversion
Expand Down

0 comments on commit bee70f4

Please sign in to comment.