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 }