Skip to content

Commit

Permalink
refactor: add labels and annotations for pvc
Browse files Browse the repository at this point in the history
  • Loading branch information
zyy17 committed Jan 13, 2025
1 parent 520920e commit 98bb586
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 3 deletions.
24 changes: 24 additions & 0 deletions apis/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ type FileStorage struct {
// +optional
// +kubebuilder:validation:Enum:={"Retain", "Delete"}
StorageRetainPolicy StorageRetainPolicyType `json:"storageRetainPolicy,omitempty"`

// Labels is the labels for the PVC.
// +optional
Labels map[string]string `json:"labels,omitempty"`

// Annotations is the annotations for the PVC.
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
}

// FileStorageAccessor is the interface that wraps the basic methods for the FileStorage.
Expand All @@ -341,6 +349,8 @@ type FileStorageAccessor interface {
GetSize() string
GetMountPath() string
GetPolicy() StorageRetainPolicyType
GetLabels() map[string]string
GetAnnotations() map[string]string
}

func (in *FileStorage) GetName() string {
Expand Down Expand Up @@ -378,6 +388,20 @@ func (in *FileStorage) GetPolicy() StorageRetainPolicyType {
return ""
}

func (in *FileStorage) GetLabels() map[string]string {
if in != nil {
return in.Labels
}
return nil
}

func (in *FileStorage) GetAnnotations() map[string]string {
if in != nil {
return in.Annotations
}
return nil
}

// WALProviderSpec defines the WAL provider for the cluster.
type WALProviderSpec struct {
// RaftEngineWAL is the specification for local WAL that uses raft-engine.
Expand Down
14 changes: 14 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions config/crd/resources/greptime.io_greptimedbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18355,6 +18363,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18446,6 +18462,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18586,6 +18610,14 @@ spec:
properties:
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18670,6 +18702,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18777,6 +18817,14 @@ spec:
properties:
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down
24 changes: 24 additions & 0 deletions config/crd/resources/greptime.io_greptimedbstandalones.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -3120,6 +3128,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -3260,6 +3276,14 @@ spec:
properties:
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down
21 changes: 18 additions & 3 deletions controllers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/GreptimeTeam/greptimedb-operator/apis/v1alpha1"
"github.com/GreptimeTeam/greptimedb-operator/controllers/constant"
"github.com/GreptimeTeam/greptimedb-operator/pkg/util"
)

const (
Expand Down Expand Up @@ -176,7 +177,11 @@ func GeneratePodTemplateSpec(kind v1alpha1.ComponentKind, template *v1alpha1.Pod
}

func FileStorageToPVC(fs v1alpha1.FileStorageAccessor, fsType FileStorageType) *corev1.PersistentVolumeClaim {
var labels map[string]string
var (
labels map[string]string
annotations map[string]string
)

switch fsType {
case FileStorageTypeWAL:
labels = map[string]string{
Expand All @@ -190,10 +195,20 @@ func FileStorageToPVC(fs v1alpha1.FileStorageAccessor, fsType FileStorageType) *
// For legacy datanode PVCs, we don't need to set the file storage type label because statefulset doesn't support to modify the PVC labels.
labels = nil
}

if fs.GetLabels() != nil {
labels = util.MergeStringMap(labels, fs.GetLabels())
}

if fs.GetAnnotations() != nil {
annotations = util.MergeStringMap(annotations, fs.GetAnnotations())
}

return &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: fs.GetName(),
Labels: labels,
Name: fs.GetName(),
Labels: labels,
Annotations: annotations,
},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: fs.GetStorageClassName(),
Expand Down
2 changes: 2 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ _Appears in:_
| `storageSize` _string_ | StorageSize is the size of the storage. | | Pattern: `(^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$)` <br /> |
| `mountPath` _string_ | MountPath is the path where the storage will be mounted in the container. | | |
| `storageRetainPolicy` _[StorageRetainPolicyType](#storageretainpolicytype)_ | StorageRetainPolicy is the policy of the storage. It can be `Retain` or `Delete`. | | Enum: [Retain Delete] <br /> |
| `labels` _object (keys:string, values:string)_ | Labels is the labels for the PVC. | | |
| `annotations` _object (keys:string, values:string)_ | Annotations is the annotations for the PVC. | | |



Expand Down
72 changes: 72 additions & 0 deletions manifests/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3112,6 +3112,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18361,6 +18369,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18452,6 +18468,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18592,6 +18616,14 @@ spec:
properties:
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18676,6 +18708,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -18783,6 +18823,14 @@ spec:
properties:
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -21926,6 +21974,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -22017,6 +22073,14 @@ spec:
type: string
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down Expand Up @@ -22157,6 +22221,14 @@ spec:
properties:
fs:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
mountPath:
type: string
name:
Expand Down
Loading

0 comments on commit 98bb586

Please sign in to comment.