From c59de8cd433eedd2da2ecbb447708e169661c162 Mon Sep 17 00:00:00 2001
From: wangyelei
Date: Tue, 3 Sep 2024 15:13:41 +0800
Subject: [PATCH] fix: mongo dump backup failed with incorrect version (#8067)
---
.../v1alpha1/backuppolicytemplate_types.go | 5 ++++
...s.kubeblocks.io_backuppolicytemplates.yaml | 24 +++++++++++++++++++
.../apps/transformer_cluster_backup_policy.go | 9 +++++++
...s.kubeblocks.io_backuppolicytemplates.yaml | 24 +++++++++++++++++++
docs/developer_docs/api-reference/cluster.md | 14 +++++++++++
5 files changed, 76 insertions(+)
diff --git a/apis/apps/v1alpha1/backuppolicytemplate_types.go b/apis/apps/v1alpha1/backuppolicytemplate_types.go
index ab3869f927f..ee7d2224e14 100644
--- a/apis/apps/v1alpha1/backuppolicytemplate_types.go
+++ b/apis/apps/v1alpha1/backuppolicytemplate_types.go
@@ -146,6 +146,11 @@ type ValueFrom struct {
//
// +optional
ComponentDef []ValueMapping `json:"componentDef,omitempty"`
+
+ // Determine the appropriate version of the backup tool image from ServiceVersion.
+ //
+ // +optional
+ ServiceVersion []ValueMapping `json:"serviceVersion,omitempty"`
}
type ValueMapping struct {
diff --git a/config/crd/bases/apps.kubeblocks.io_backuppolicytemplates.yaml b/config/crd/bases/apps.kubeblocks.io_backuppolicytemplates.yaml
index 4ceec98572d..b8d7ad0d064 100644
--- a/config/crd/bases/apps.kubeblocks.io_backuppolicytemplates.yaml
+++ b/config/crd/bases/apps.kubeblocks.io_backuppolicytemplates.yaml
@@ -259,6 +259,30 @@ spec:
the appropriate version of the backup tool image.
+ This mapping allows different versions of component images to correspond to specific versions of backup tool images.
+ items:
+ type: string
+ type: array
+ required:
+ - mappingValue
+ - names
+ type: object
+ type: array
+ serviceVersion:
+ description: Determine the appropriate version
+ of the backup tool image from ServiceVersion.
+ items:
+ properties:
+ mappingValue:
+ description: Specifies the appropriate
+ version of the backup tool image.
+ type: string
+ names:
+ description: |-
+ Represents an array of names of ClusterVersion or ComponentDefinition that can be mapped to
+ the appropriate version of the backup tool image.
+
+
This mapping allows different versions of component images to correspond to specific versions of backup tool images.
items:
type: string
diff --git a/controllers/apps/transformer_cluster_backup_policy.go b/controllers/apps/transformer_cluster_backup_policy.go
index 3248f98770b..5df883c14a8 100644
--- a/controllers/apps/transformer_cluster_backup_policy.go
+++ b/controllers/apps/transformer_cluster_backup_policy.go
@@ -468,6 +468,15 @@ func (r *clusterBackupPolicyTransformer) doEnvMapping(comp *appsv1alpha1.Cluster
Value: cm.MappingValue,
})
}
+ for _, sv := range v.ValueFrom.ServiceVersion {
+ if !slices.Contains(sv.Names, comp.ServiceVersion) {
+ continue
+ }
+ env = append(env, corev1.EnvVar{
+ Name: v.Key,
+ Value: sv.MappingValue,
+ })
+ }
}
return env
}
diff --git a/deploy/helm/crds/apps.kubeblocks.io_backuppolicytemplates.yaml b/deploy/helm/crds/apps.kubeblocks.io_backuppolicytemplates.yaml
index 4ceec98572d..b8d7ad0d064 100644
--- a/deploy/helm/crds/apps.kubeblocks.io_backuppolicytemplates.yaml
+++ b/deploy/helm/crds/apps.kubeblocks.io_backuppolicytemplates.yaml
@@ -259,6 +259,30 @@ spec:
the appropriate version of the backup tool image.
+ This mapping allows different versions of component images to correspond to specific versions of backup tool images.
+ items:
+ type: string
+ type: array
+ required:
+ - mappingValue
+ - names
+ type: object
+ type: array
+ serviceVersion:
+ description: Determine the appropriate version
+ of the backup tool image from ServiceVersion.
+ items:
+ properties:
+ mappingValue:
+ description: Specifies the appropriate
+ version of the backup tool image.
+ type: string
+ names:
+ description: |-
+ Represents an array of names of ClusterVersion or ComponentDefinition that can be mapped to
+ the appropriate version of the backup tool image.
+
+
This mapping allows different versions of component images to correspond to specific versions of backup tool images.
items:
type: string
diff --git a/docs/developer_docs/api-reference/cluster.md b/docs/developer_docs/api-reference/cluster.md
index dd6f3c00c34..1d5c892d674 100644
--- a/docs/developer_docs/api-reference/cluster.md
+++ b/docs/developer_docs/api-reference/cluster.md
@@ -22074,6 +22074,20 @@ use the latest available version in ComponentVersion.
Determine the appropriate version of the backup tool image from ComponentDefinition.
+
+
+serviceVersion
+
+
+[]ValueMapping
+
+
+ |
+
+(Optional)
+ Determine the appropriate version of the backup tool image from ServiceVersion.
+ |
+
ValueMapping