Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xingran committed Mar 23, 2023
1 parent 10a5650 commit eecb4db
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 203 deletions.
44 changes: 8 additions & 36 deletions apis/apps/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type ClusterSpec struct {
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// CustomLabelSpecs is used for user-defined label tags which you want to add to the cluster or component resources.
// CustomLabelSpecs is used for user-defined label tags which you want to add to the cluster resources.
// +optional
CustomLabelSpecs []CustomLabelSpec `json:"customLabelSpecs,omitempty"`
}
Expand Down Expand Up @@ -191,6 +191,10 @@ type ClusterComponentSpec struct {
// required when TLS enabled
// +optional
Issuer *Issuer `json:"issuer,omitempty"`

// CustomLabelSpecs is used for user-defined label tags which you want to add to the component resources.
// +optional
CustomLabelSpecs []CustomLabelSpec `json:"customLabelSpecs,omitempty"`
}

type ComponentMessageMap map[string]string
Expand Down Expand Up @@ -403,48 +407,16 @@ type CustomLabelSpec struct {
// +kubebuilder:validation:Required
Value string `json:"value"`

// scope spec of label
// +kubebuilder:validation:Required
Scope *CustomLabelScope `json:"scope"`
}

type CustomLabelScope struct {
// type of scope.
// cluster: cluster scope, label will be applied to all resource objects under the cluster.
// component: component scope, label will be applied to the resource object specified under component.
// +kubebuilder:validation:Required
Type CustomLabelScopeType `json:"type"`

// component scope spec when type is component.
// +optional
ComponentScopeSpecs []ComponentScopeSpec `json:"componentScopeSpecs,omitempty"`

// cluster scope spec when type is cluster.
// +optional
ClusterScopeSpec *ClusterScopeSpec `json:"clusterScopeSpecs,omitempty"`
}

type ComponentScopeSpec struct {
// name of component, refer to cluster.spec.componentSpecs[x].name.
// +kubebuilder:validation:Required
Name string `json:"name"`

// Resources defines the resources to be labeled.
// +kubebuilder:validation:Required
Resources []GVKResource `json:"resources,omitempty"`
}

type ClusterScopeSpec struct {
// Resources defines the resources to be labeled.
// +kubebuilder:validation:Required
Resources []GVKResource `json:"resources,omitempty"`
}

type GVKResource struct {
// The Pattern of the GVKResource is Group/Version/Kind, for example "apps/v1/StatefulSet", etc.
// When the pattern resource filtered by the selector already exists, if there is no corresponding custom label, it will be added, and if label already exists, it will be updated.
// The GVK of the GVKResource is Group/Version/Kind, for example "v1/Pod", "apps/v1/StatefulSet", etc.
// When the gvk resource filtered by the selector already exists, if there is no corresponding custom label, it will be added, and if label already exists, it will be updated.
// +kubebuilder:validation:Required
Pattern string `json:"pattern"`
GVK string `json:"gvk"`

// Selector is a label query over a set of resources.
// +optional
Expand Down
134 changes: 58 additions & 76 deletions config/crd/bases/apps.kubeblocks.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,44 @@ spec:
maxLength: 63
pattern: ^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$
type: string
customLabelSpecs:
description: CustomLabelSpecs is used for user-defined label
tags which you want to add to the component resources.
items:
properties:
key:
description: key name of label
type: string
resources:
description: Resources defines the resources to be labeled.
items:
properties:
gvk:
description: The GVK of the GVKResource is Group/Version/Kind,
for example "v1/Pod", "apps/v1/StatefulSet", etc.
When the gvk resource filtered by the selector
already exists, if there is no corresponding custom
label, it will be added, and if label already
exists, it will be updated.
type: string
selector:
additionalProperties:
type: string
description: Selector is a label query over a set
of resources.
type: object
required:
- gvk
type: object
type: array
value:
description: value of label
type: string
required:
- key
- value
type: object
type: array
enabledLogs:
description: enabledLogs indicate which log file takes effect
in database cluster element is the log type which defined
Expand Down Expand Up @@ -631,93 +669,37 @@ spec:
x-kubernetes-list-type: map
customLabelSpecs:
description: CustomLabelSpecs is used for user-defined label tags
which you want to add to the cluster or component resources.
which you want to add to the cluster resources.
items:
properties:
key:
description: key name of label
type: string
scope:
description: scope spec of label
properties:
clusterScopeSpecs:
description: cluster scope spec when type is cluster.
properties:
resources:
description: Resources defines the resources to be labeled.
items:
properties:
pattern:
description: The Pattern of the GVKResource is
Group/Version/Kind, for example "apps/v1/StatefulSet",
etc. When the pattern resource filtered by the
selector already exists, if there is no corresponding
custom label, it will be added, and if label
already exists, it will be updated.
type: string
selector:
additionalProperties:
type: string
description: Selector is a label query over a
set of resources.
type: object
required:
- pattern
type: object
type: array
type: object
componentScopeSpecs:
description: component scope spec when type is component.
items:
properties:
name:
description: name of component, refer to cluster.spec.componentSpecs[x].name.
type: string
resources:
description: Resources defines the resources to be
labeled.
items:
properties:
pattern:
description: The Pattern of the GVKResource
is Group/Version/Kind, for example "apps/v1/StatefulSet",
etc. When the pattern resource filtered by
the selector already exists, if there is no
corresponding custom label, it will be added,
and if label already exists, it will be updated.
type: string
selector:
additionalProperties:
type: string
description: Selector is a label query over
a set of resources.
type: object
required:
- pattern
type: object
type: array
required:
- name
resources:
description: Resources defines the resources to be labeled.
items:
properties:
gvk:
description: The GVK of the GVKResource is Group/Version/Kind,
for example "v1/Pod", "apps/v1/StatefulSet", etc. When
the gvk resource filtered by the selector already exists,
if there is no corresponding custom label, it will be
added, and if label already exists, it will be updated.
type: string
selector:
additionalProperties:
type: string
description: Selector is a label query over a set of resources.
type: object
type: array
type:
description: 'type of scope. cluster: cluster scope, label
will be applied to all resource objects under the cluster.
component: component scope, label will be applied to the
resource object specified under component.'
enum:
- cluster
- component
type: string
required:
- type
type: object
required:
- gvk
type: object
type: array
value:
description: value of label
type: string
required:
- key
- scope
- value
type: object
type: array
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ func (r *ClusterReconciler) removeStsInitContainerForRestore(ctx context.Context

// patchClusterResourceCustomLabels patches the custom labels to GVR(Group/Version/Resource) defined in the cluster spec.
func (r *ClusterReconciler) patchClusterResourceCustomLabels(ctx context.Context, cluster *appsv1alpha1.Cluster) error {
if cluster == nil || cluster.Spec.CustomLabelSpecs == nil {
if cluster == nil || len(cluster.Spec.CustomLabelSpecs) == 0 {
return nil
}
patchGVRCustomLabels := func(resource appsv1alpha1.GVKResource, componentName, labelKey, labelValue string) error {
Expand Down
Loading

0 comments on commit eecb4db

Please sign in to comment.