From c05d93b435ba7816d57a09c5aa6e590350f11097 Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Tue, 17 Oct 2023 13:53:40 +0800 Subject: [PATCH] feat: add component label for subscription Signed-off-by: Abirdcfly --- api/v1alpha1/subscription.go | 4 +++- api/v1alpha1/subscription_webhook.go | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/subscription.go b/api/v1alpha1/subscription.go index b1751047..ef79725f 100644 --- a/api/v1alpha1/subscription.go +++ b/api/v1alpha1/subscription.go @@ -27,7 +27,9 @@ import ( ) const ( - SubscriptionNameLabel = Group + "/subscription-name" + SubscriptionNameLabel = Group + "/subscription-name" + ComponentNameLabel = Group + "/component-name" + ComponentNamespaceLabel = Group + "/component-namespace" ) // IsAuto returns true if InstallMethod is Auto, case-insensitivity. diff --git a/api/v1alpha1/subscription_webhook.go b/api/v1alpha1/subscription_webhook.go index e49b92a2..445bfe1e 100644 --- a/api/v1alpha1/subscription_webhook.go +++ b/api/v1alpha1/subscription_webhook.go @@ -58,6 +58,11 @@ func (r *Subscription) Default(ctx context.Context, obj runtime.Object) error { if !isSuperUser(user) { p.Spec.Creator = user.Username } + if p.Labels == nil { + p.Labels = make(map[string]string, 1) + } + p.Labels[ComponentNameLabel] = p.Spec.ComponentRef.Name + p.Labels[ComponentNamespaceLabel] = p.Spec.ComponentRef.Namespace log.Info("set default value done") return nil }