Skip to content

Commit

Permalink
feat: templateLabels in ComponentSpec
Browse files Browse the repository at this point in the history
This change allow user to inject
customized label to deployment.

Signed-off-by: Shou-En Hsiao <[email protected]>
  • Loading branch information
ShouEnHsiao committed Jul 27, 2023
1 parent e8eedc5 commit 3c66442
Show file tree
Hide file tree
Showing 4 changed files with 625 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apis/meta/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ type ComponentSpec struct {
// Custom annotations to be added into the pods
TemplateAnnotations map[string]string `json:"templateAnnotations,omitempty"`

// +kubebuilder:validation:Optional
// Custom Labels to be added into the pods
TemplateLabels map[string]string `json:"templateLabels,omitempty"`

ImageSpec `json:",inline"`

// +kubebuilder:validation:Optional
Expand Down Expand Up @@ -119,6 +123,20 @@ func (c *ComponentSpec) ApplyToDeployment(deploy *appsv1.Deployment) {
deploy.Spec.Template.Spec.ImagePullSecrets = c.ImagePullSecrets
deploy.Spec.Template.Spec.NodeSelector = c.NodeSelector
deploy.Spec.Template.Spec.Tolerations = c.Tolerations
deploy.Spec.Template.Labels = mergeLabels(deploy.Spec.Template.Labels, c.TemplateLabels)
}

// mergeLabels merges all labels together and returns a new label.
func mergeLabels(allLabels ...map[string]string) map[string]string {
lb := make(map[string]string)

for _, label := range allLabels {
for k, v := range label {
lb[k] = v
}
}

return lb
}

// ComponentStatus represents the current status of the resource.
Expand Down
7 changes: 7 additions & 0 deletions apis/meta/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 3c66442

Please sign in to comment.