-
Notifications
You must be signed in to change notification settings - Fork 238
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
feat: implement direct controller for MonitoringDashboard #1863
feat: implement direct controller for MonitoringDashboard #1863
Conversation
justinsb
commented
May 21, 2024
•
edited
Loading
edited
- feat: implement direct controller for MonitoringDashboard
- chore: update monitoringdashboard golden output
165c67e
to
bde11ea
Compare
I think we should merge this after we have more tests (at least #1806) - then I can also make the ref-test real |
bde11ea
to
b8be512
Compare
a5fc35d
to
25883aa
Compare
"widgets": [ | ||
{ | ||
"title": "Widget 1", | ||
"xyChart": { | ||
"dataSets": [ | ||
{ | ||
"plotType": "LINE", | ||
"plotType": 1, |
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.
Kind of annoying, but the official client uses integer enum encoding, messing up our diffs. I can try the proto form and see if it is any better.
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 missed this. Please ignore my other comment.
Content-Type: application/json | ||
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1 |
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 think the diff is confused here because we don't do a GET before DELETE. Maybe we should just do the GET!
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 added a semi-superfluous GET to delete, the diff now looks much better!
5b333d9
to
9ac8098
Compare
|
||
func newDashboardModel(config *controller.Config) directbase.Model { | ||
ctx := context.TODO() | ||
gcpClient, err := newGCPClient(ctx, config) |
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.
or we can move this to AdapterForObject
so as we can use the passed in context.Context
parameter.
The AdapterForObject will be initialized in each Reconcile loop.
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.
My one concern is that building the client may be expensive: if we have to open a new TCP connection, or if we have to get the token again. But I don't want to block this PR on it, so I'll move it!
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.
Ah, I guess we're calling the expensive call every time anyway :-)
...ture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardrefs/_http.log
Show resolved
Hide resolved
@@ -3,7 +3,6 @@ kind: MonitoringDashboard | |||
metadata: | |||
annotations: | |||
cnrm.cloud.google.com/management-conflict-prevention-policy: none | |||
cnrm.cloud.google.com/state-into-spec: merge |
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.
👍
) | ||
|
||
func GetResourceID(u *unstructured.Unstructured) (string, error) { | ||
resourceID, _, err := unstructured.NestedString(u.Object, "spec", "resourceID") |
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 recalled to see a team discussion about the camel case for projectId
rather than projectID
. Shall this be resourceId
or resourceID
?
(Not a blocker to this PR, just want to align the names here since this is a shareable function under direct/references)
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.
So ... go says "ID". KRM style guide says "ID". Google APIs use "Id" (in JSON). Most KCC fields use Id
, but I guess here we use resourceID
.
If the KCC field was called resourceId
, I don't know whether I would follow go conventions or try to match the name of the field.
In this case though, we're reading a field, and I think that field's name is resourceID
. That's correct against KRM style guide, but possibly inconsistent with most other GCP-generated fields.
I think it's your decision @yuwenma , and it's going to be interesting!
(Our best bet might be to stop adding fields that end in Id at all, maybe it's another marker that something is actually a ref ... or we could just drop ID arguing that it is the "type" of the field, and we don't say "fooString" so why do we say "fooID" or "fooURL" ? )
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func normalizeResourceName(ctx context.Context, reader client.Reader, src client.Object, ref *v1alpha1.ResourceRef) (*v1alpha1.ResourceRef, error) { |
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.
Do you want to move this to controller/direct/reference/
or something that can be sharable? I feel like this is a good piece to reuse and continue improving as we building up more resources.
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.
Yes, but my "rule of thumb" is to move it when we have two copies. For this particular one, we only have one copy (this is actually very specialized - there's a field called "resourceName" in MonitoringDashboard. Note that this method does call into shared functions for most of its logic!
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.
Actually I guess this is resolving a resource of arbitrary kind, so is more reusable than I first thought. Still, it's our first ... let's move it when we have two or three instances.
func setStatus(u *unstructured.Unstructured, typedStatus any) error { | ||
status, err := runtime.DefaultUnstructuredConverter.ToUnstructured(typedStatus) | ||
if err != nil { | ||
return fmt.Errorf("error converting status to unstructured: %w", err) | ||
} | ||
|
||
// Use existing values for conditions/observedGeneration; they are managed in k8s not the GCP API | ||
old, _, _ := unstructured.NestedMap(u.Object, "status") | ||
if old != nil { | ||
status["conditions"] = old["conditions"] | ||
status["observedGeneration"] = old["observedGeneration"] | ||
} | ||
|
||
u.Object["status"] = status | ||
|
||
return nil | ||
} | ||
|
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.
qq: do you think we shall move this to the direct_controllerReconcile
?
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.
We should move it, along with most/all of the functions in utils. I just don't think we know where to move it to yet!
3bdaf3f
to
a680eec
Compare
/lgtm I think the presubmit should be fixed in #1979. Could you rebase this PR and re-write the golden logs? It looks great! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: yuwenma The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
a680eec
to
0f25e8c
Compare
0f25e8c
to
6d3b114
Compare
6d3b114
to
81db68b
Compare
/lgtm |
27c6cbf
into
GoogleCloudPlatform:master