Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add required labels to pods #787

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions internal/common/labels.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package common

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
ssp "kubevirt.io/ssp-operator/api/v1beta2"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
Expand Down Expand Up @@ -36,18 +36,13 @@ const (
// Name will translate into the AppKubernetesNameLabel
// Component will translate into the AppKubernetesComponentLabel
// Instance wide labels will be taken from the request if available
func AddAppLabels(requestInstance *ssp.SSP, name string, component AppComponent, obj client.Object) client.Object {
func AddAppLabels(requestInstance *ssp.SSP, name string, component AppComponent, obj metav1.Object) metav1.Object {
labels := getOrCreateLabels(obj)
addInstanceLabels(requestInstance, labels)

labels[AppKubernetesNameLabel] = name
labels[AppKubernetesComponentLabel] = component.String()
labels[AppKubernetesManagedByLabel] = AppKubernetesManagedByValue

addCommonLabels(labels, requestInstance, name, component)
return obj
}

func getOrCreateLabels(obj client.Object) map[string]string {
func getOrCreateLabels(obj metav1.Object) map[string]string {
labels := obj.GetLabels()
if labels == nil {
labels = map[string]string{}
Expand All @@ -56,6 +51,14 @@ func getOrCreateLabels(obj client.Object) map[string]string {
return labels
}

func addCommonLabels(labels map[string]string, requestInstance *ssp.SSP, name string, component AppComponent) {
addInstanceLabels(requestInstance, labels)

labels[AppKubernetesNameLabel] = name
labels[AppKubernetesComponentLabel] = component.String()
labels[AppKubernetesManagedByLabel] = AppKubernetesManagedByValue
}

func addInstanceLabels(requestInstance *ssp.SSP, to map[string]string) {
if requestInstance.Labels == nil {
return
Expand Down
1 change: 1 addition & 0 deletions internal/operands/template-validator/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func reconcileDeployment(request *common.Request) (common.ReconcileResult, error
}

deployment := newDeployment(request.Namespace, numberOfReplicas, image, sspTLSOptions)
common.AddAppLabels(request.Instance, operandName, operandComponent, &deployment.Spec.Template.ObjectMeta)
injectPlacementMetadata(&deployment.Spec.Template.Spec, validatorSpec)
return common.CreateOrUpdate(request).
NamespacedResource(deployment).
Expand Down
1 change: 1 addition & 0 deletions internal/operands/vm-console-proxy/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func reconcileDeployment(deployment apps.Deployment) common.ReconcileFunc {
return func(request *common.Request) (common.ReconcileResult, error) {
deployment.Namespace = request.Instance.Namespace
deployment.Spec.Template.Spec.Containers[0].Image = getVmConsoleProxyImage()
common.AddAppLabels(request.Instance, operandName, operandComponent, &deployment.Spec.Template.ObjectMeta)
return common.CreateOrUpdate(request).
NamespacedResource(&deployment).
WithAppLabels(operandName, operandComponent).
Expand Down
Loading