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

Add owner-name label on resources #3608

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/Azure/azure-service-operator/v2/internal/reconcilers"
"github.com/Azure/azure-service-operator/v2/internal/reflecthelpers"
"github.com/Azure/azure-service-operator/v2/internal/resolver"
"github.com/Azure/azure-service-operator/v2/pkg/common/annotations"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/core"
Expand Down Expand Up @@ -162,6 +163,7 @@ func (r *azureDeploymentReconcilerInstance) AddInitialResourceState(ctx context.
return err
}
genruntime.SetResourceID(r.Obj, armResource.GetID())
annotations.SetOwnedByAnnotation(r.Obj)
return nil
}

Expand Down
13 changes: 12 additions & 1 deletion v2/pkg/common/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@

package annotations

const PerResourceSecret = "serviceoperator.azure.com/credential-from"
import "github.com/Azure/azure-service-operator/v2/pkg/genruntime"

const (
PerResourceSecret = "serviceoperator.azure.com/credential-from"
OwnedByAnnotation = "serviceoperator.azure.com/owned-by"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think owner-name or owner would be clearer than owned-by.

Do we also need to think about owner-group-kind or something as well, for extension resources such as roleassignment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep makes sense - Users can filter through annotations but isn't as easy as with labels.
Made the changes to add label instead of annotation and changes the name to owned-by to owner-name.

Not very sure about if adding owner-group-kind would bring much value.. since user can anyway filter based on owner-name - which is more specific rather than filtering all resources based on just group + kind?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having owner-group-kind forces the user to do another query to discover the owner type if they don't already know it. I think there's value in making it easy/obvious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! and that applies to only resources which are KubernetesReferences?

)

func SetOwnedByAnnotation(obj genruntime.ARMMetaObject) {
if obj.Owner() != nil && obj.Owner().Name != "" {
genruntime.AddAnnotation(obj, OwnedByAnnotation, obj.Owner().Name)
}
}