-
Notifications
You must be signed in to change notification settings - Fork 160
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 suspended annotations #4131
Conversation
6be5dea
to
d56f07f
Compare
Lets add this little snipped to the makefile and run it to fix the ci lint job |
core/server/suspend_test.go
Outdated
t.Errorf("expected annotation weave.works/suspended-by to be set to the principal %s", principalID) | ||
} | ||
} else { | ||
t.Errorf("expected annotation weave.works/suspended-by not found for %s", name.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to call .String()
because...
https://pkg.go.dev/fmt
If the format (which is implicitly %v for Println etc.) is valid for a string (%s %q %v %x %X), the following two rules apply:
4. If an operand implements the error interface, the Error method will be invoked to convert the object to a string, which will then be formatted as required by the verb (if any).
5. If an operand implements method String() string, that method will be invoked to convert the object to a string, which will then be formatted as required by the verb (if any).
core/server/suspend_test.go
Outdated
outgoingCtx := metadata.NewOutgoingContext(ctx, md) | ||
_, err = c.ToggleSuspendResource(outgoingCtx, req) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
|
||
for _, tt := range tests { | ||
name := types.NamespacedName{Name: tt.obj.GetName(), Namespace: ns.Name} | ||
g.Expect(checkSpec(t, k, name, tt.obj)).To(BeFalse()) | ||
g.Expect(checkSpec(t, k, principalID, name, tt.obj, false)).To(BeFalse()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably have split this into to two expectations rather than piggy-backing on top of checkSpec
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was to avoid having to add a switch and getting the objects for each type again, but It can be split if that makes it cleaner/clearer as a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to add a switch?
You've got a client.Object
https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client#Object which embeds https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Object ?
@@ -60,6 +60,8 @@ func (cs *coreServer) ToggleSuspendResource(ctx context.Context, msg *pb.ToggleS | |||
return nil, err | |||
} | |||
|
|||
changeSuspendAnnotations(obj, msg.Suspend, msg.Comment, principal) | |||
|
|||
if msg.Suspend { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things here...
weave-gitops/core/server/suspend.go
Lines 15 to 19 in 35231b8
principal := auth.Principal(ctx) | |
respErrors := multierror.Error{} | |
for _, obj := range msg.Objects { | |
clustersClient, err := cs.clustersManager.GetImpersonatedClient(ctx, auth.Principal(ctx)) |
We could reuse the principal from the first call in the second?
Also, we could include the "principalID" in the log.Info
so that the user who does it is logged out?
We could also include the name and namespace, and maybe even Kind of the resource, so that the logs would be searchable.
"Who unlocked the GitRepository test/test"?
Bonus points for including the Cluster name :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name,namespace, and kind are already included . I'll add the principal to the logs 👍
weave-gitops/core/server/suspend.go
Lines 44 to 49 in 35231b8
log := cs.logger.WithValues( | |
"user", principal.ID, | |
"kind", obj.GroupVersionKind().Kind, | |
"name", key.Name, | |
"namespace", key.Namespace, | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, 👍🏻
Remove unused context
generate proto on linux
Remove checkSpec and add getting unstructured object Check for spec.suspend value and suspend annotations in unstructured object
a9a394b
to
72848f0
Compare
Closes BE part of weaveworks/weave-gitops-enterprise#3546
What changed?
Add suspended-by and suspended-comment annotations to objects being suspended
Remove suspended-by and suspended-comment annotations from objects being resumed
Why was this change made?
To log who/what performed the suspending action on the resource
How was this change implemented?
Adding the annotations needed indicating
suspended-by
andsuspended-comment
that could possibly include extra details regarding the suspensionHow did you validate the change?
Release notes
Documentation Changes