Skip to content

Commit

Permalink
Merge pull request #375 from Abirdcfly/main
Browse files Browse the repository at this point in the history
feat: add component label for subscription
  • Loading branch information
bjwswang authored Oct 17, 2023
2 parents 798efeb + c05d93b commit 0c39546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/v1alpha1/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/subscription_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0c39546

Please sign in to comment.