From ce90d40d962a2cf1f0b569fe4d219e1b7b30b13f Mon Sep 17 00:00:00 2001 From: gnolong <2391353625@qq.com> Date: Mon, 13 Jan 2025 19:27:50 +0800 Subject: [PATCH 01/10] fix: cluster supports specifing pvc annotations and labels --- apis/apps/v1alpha1/cluster_types.go | 10 ++++ .../bases/apps.kubeblocks.io_clusters.yaml | 48 +++++++++++++++++++ .../bases/apps.kubeblocks.io_components.yaml | 23 +++++++++ .../bases/apps.kubeblocks.io_opsrequests.yaml | 24 ++++++++++ .../crds/apps.kubeblocks.io_clusters.yaml | 48 +++++++++++++++++++ .../crds/apps.kubeblocks.io_components.yaml | 23 +++++++++ .../crds/apps.kubeblocks.io_opsrequests.yaml | 24 ++++++++++ .../component/synthesize_component.go | 2 + 8 files changed, 202 insertions(+) diff --git a/apis/apps/v1alpha1/cluster_types.go b/apis/apps/v1alpha1/cluster_types.go index 9eab7918c01..355ebb36df3 100644 --- a/apis/apps/v1alpha1/cluster_types.go +++ b/apis/apps/v1alpha1/cluster_types.go @@ -988,6 +988,16 @@ type ClusterSwitchPolicy struct { } type ClusterComponentVolumeClaimTemplate struct { + // Specifies Labels to override or add for the PVC. + // + // +optional + Labels map[string]string `json:"labels,omitempty"` + + // Specifies Annotations to override or add for the PVC. + // + // +optional + Annotations map[string]string `json:"annotations,omitempty"` + // Refers to the name of a volumeMount defined in either: // // - `componentDefinition.spec.runtime.containers[*].volumeMounts` diff --git a/config/crd/bases/apps.kubeblocks.io_clusters.yaml b/config/crd/bases/apps.kubeblocks.io_clusters.yaml index 7ee4c7e8aee..a2bd86aca44 100644 --- a/config/crd/bases/apps.kubeblocks.io_clusters.yaml +++ b/config/crd/bases/apps.kubeblocks.io_clusters.yaml @@ -1917,6 +1917,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or + add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add + for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -5573,6 +5585,18 @@ spec: These templates are used to dynamically provision persistent volumes for the Component. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or add + for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add for the + PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -10524,6 +10548,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override + or add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or + add for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -14225,6 +14261,18 @@ spec: These templates are used to dynamically provision persistent volumes for the Component. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or + add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add for + the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: diff --git a/config/crd/bases/apps.kubeblocks.io_components.yaml b/config/crd/bases/apps.kubeblocks.io_components.yaml index f623183f7df..3bd7bf3b83f 100644 --- a/config/crd/bases/apps.kubeblocks.io_components.yaml +++ b/config/crd/bases/apps.kubeblocks.io_components.yaml @@ -1817,6 +1817,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or add + for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add for the + PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -5575,6 +5587,17 @@ spec: These templates are used to dynamically provision persistent volumes for the Component. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or add for the + PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: diff --git a/config/crd/bases/apps.kubeblocks.io_opsrequests.yaml b/config/crd/bases/apps.kubeblocks.io_opsrequests.yaml index 87d3cace21e..5fbff8f6968 100644 --- a/config/crd/bases/apps.kubeblocks.io_opsrequests.yaml +++ b/config/crd/bases/apps.kubeblocks.io_opsrequests.yaml @@ -1931,6 +1931,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override + or add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or + add for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -6767,6 +6779,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override + or add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or + add for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: diff --git a/deploy/helm/crds/apps.kubeblocks.io_clusters.yaml b/deploy/helm/crds/apps.kubeblocks.io_clusters.yaml index 7ee4c7e8aee..a2bd86aca44 100644 --- a/deploy/helm/crds/apps.kubeblocks.io_clusters.yaml +++ b/deploy/helm/crds/apps.kubeblocks.io_clusters.yaml @@ -1917,6 +1917,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or + add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add + for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -5573,6 +5585,18 @@ spec: These templates are used to dynamically provision persistent volumes for the Component. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or add + for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add for the + PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -10524,6 +10548,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override + or add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or + add for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -14225,6 +14261,18 @@ spec: These templates are used to dynamically provision persistent volumes for the Component. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or + add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add for + the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: diff --git a/deploy/helm/crds/apps.kubeblocks.io_components.yaml b/deploy/helm/crds/apps.kubeblocks.io_components.yaml index f623183f7df..3bd7bf3b83f 100644 --- a/deploy/helm/crds/apps.kubeblocks.io_components.yaml +++ b/deploy/helm/crds/apps.kubeblocks.io_components.yaml @@ -1817,6 +1817,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or add + for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add for the + PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -5575,6 +5587,17 @@ spec: These templates are used to dynamically provision persistent volumes for the Component. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override or add for the + PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or add for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: diff --git a/deploy/helm/crds/apps.kubeblocks.io_opsrequests.yaml b/deploy/helm/crds/apps.kubeblocks.io_opsrequests.yaml index 87d3cace21e..5fbff8f6968 100644 --- a/deploy/helm/crds/apps.kubeblocks.io_opsrequests.yaml +++ b/deploy/helm/crds/apps.kubeblocks.io_opsrequests.yaml @@ -1931,6 +1931,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override + or add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or + add for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: @@ -6767,6 +6779,18 @@ spec: Add new or override existing volume claim templates. items: properties: + annotations: + additionalProperties: + type: string + description: Specifies Annotations to override + or add for the PVC. + type: object + labels: + additionalProperties: + type: string + description: Specifies Labels to override or + add for the PVC. + type: object name: description: |- Refers to the name of a volumeMount defined in either: diff --git a/pkg/controller/component/synthesize_component.go b/pkg/controller/component/synthesize_component.go index 1bee9e023c4..50e7ec0425d 100644 --- a/pkg/controller/component/synthesize_component.go +++ b/pkg/controller/component/synthesize_component.go @@ -509,6 +509,8 @@ func toVolumeClaimTemplates(compSpec *appsv1alpha1.ComponentSpec) []corev1.Persi ts = append(ts, corev1.PersistentVolumeClaimTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: t.Name, + Annotations: t.Annotations, + Labels: t.Labels, }, Spec: t.Spec.ToV1PersistentVolumeClaimSpec(), }) From 6cf15a9dc6fd837a9543a8ca5250a3e8c84f08d6 Mon Sep 17 00:00:00 2001 From: gnolong <2391353625@qq.com> Date: Mon, 13 Jan 2025 19:39:16 +0800 Subject: [PATCH 02/10] fix doc --- apis/apps/v1alpha1/zz_generated.deepcopy.go | 14 ++++++++++++ docs/developer_docs/api-reference/cluster.md | 24 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/apis/apps/v1alpha1/zz_generated.deepcopy.go b/apis/apps/v1alpha1/zz_generated.deepcopy.go index c80761e05a3..399f1aa1b2c 100644 --- a/apis/apps/v1alpha1/zz_generated.deepcopy.go +++ b/apis/apps/v1alpha1/zz_generated.deepcopy.go @@ -825,6 +825,20 @@ func (in *ClusterComponentVersion) DeepCopy() *ClusterComponentVersion { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterComponentVolumeClaimTemplate) DeepCopyInto(out *ClusterComponentVolumeClaimTemplate) { *out = *in + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } in.Spec.DeepCopyInto(&out.Spec) } diff --git a/docs/developer_docs/api-reference/cluster.md b/docs/developer_docs/api-reference/cluster.md index a2427b52e03..1a893e96dd4 100644 --- a/docs/developer_docs/api-reference/cluster.md +++ b/docs/developer_docs/api-reference/cluster.md @@ -5888,6 +5888,30 @@ This overrides the image and env attributes defined in clusterDefinition.spec.co
labels
Specifies Labels to override or add for the PVC.
+annotations
Specifies Annotations to override or add for the PVC.
+name
Specifies Labels to override or add for the PVC.
+Specifies the labels for the PVC of the volume. These labels can be overridden +by labels defined at a higher level in the specification.
Specifies Annotations to override or add for the PVC.
+Specifies the annotations for the PVC of the volume. These annotations can be overridden +by annotations defined at a higher level in the specification.
Specifies the labels for the PVC of the volume. These labels can be overridden -by labels defined at a higher level in the specification.
+Specifies the labels for the PVC of the volume.
Specifies the annotations for the PVC of the volume. These annotations can be overridden -by annotations defined at a higher level in the specification.
+Specifies the annotations for the PVC of the volume.
labels
name
Specifies the labels for the PVC of the volume.
+Refers to the name of a volumeMount defined in either:
+componentDefinition.spec.runtime.containers[*].volumeMounts
clusterDefinition.spec.componentDefs[*].podSpec.containers[*].volumeMounts
(deprecated)The value of name
must match the name
field of a volumeMount specified in the corresponding volumeMounts
array.
annotations
labels
Specifies the annotations for the PVC of the volume.
+Specifies the labels for the PVC of the volume.
name
annotations
Refers to the name of a volumeMount defined in either:
-componentDefinition.spec.runtime.containers[*].volumeMounts
clusterDefinition.spec.componentDefs[*].podSpec.containers[*].volumeMounts
(deprecated)The value of name
must match the name
field of a volumeMount specified in the corresponding volumeMounts
array.
Specifies the annotations for the PVC of the volume.