-
Notifications
You must be signed in to change notification settings - Fork 265
Add namespaces managed by CNO to related objects field #199
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 namespaces managed by CNO to related objects field #199
Conversation
| related := []configv1.ObjectReference{ | ||
| { | ||
| Resource: "namespaces", | ||
| Name: "openshift-sdn", |
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.
(Aside: is "namespaces" correct? I would have expected it to want the singular.)
This should be computed dynamically based on the actual Namespaces we created. The same way that ReconcileOperConfig figures out the set of active DaemonSets and Deployments and then tells the StatusManager about them, it should do the same with Namespaces. (Except it should add the controller's namespace to the list too.)
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.
Plural seems fine, I found it in other spots of the code:
https://github.com/openshift/machine-api-operator/blob/6066765d8ff090fd081c7a20e59955d00004b0ad/pkg/operator/status.go#L165
https://github.com/openshift/cluster-samples-operator/blob/df3dbf4d8a119058f80067eca568c6f78ff8d725/pkg/operatorstatus/operatorstatus.go#L169
https://github.com/openshift/cluster-autoscaler-operator/blob/62768a6ba48010d12c4d86b8b06689a6970a7841/pkg/operator/operator.go#L110
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.
Plural is correct, because this is a Resource, not a Kind. However, dan is right, this should be computed automatically.
| log.Printf("Failed to get ClusterOperator %q: %v", status.name, err) | ||
| return | ||
| } | ||
| co.Status.RelatedObjects = objects |
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.
This is just modifying the copy that you just fetched, which will be GC'ed as soon as this function returns.
You can just store the objects in a field on status here, and then set them on the object in Set
f5678bd to
6d0e4bb
Compare
|
@rcarrillocruz good except now you're never copying Also, please squash your commits rather than doing fixups. It's generally easier to deal with if the PR is always in a ready-to-be-merged form. |
6d0e4bb to
ef1141d
Compare
|
/retest |
|
Doh. Sorry, I guess I wasn't clear. |
ef1141d to
16dd37f
Compare
| } | ||
| relatedObjects = append(relatedObjects, configv1.ObjectReference{ | ||
| Group: obj.GetObjectKind().GroupVersionKind().Group, | ||
| Resource: obj.GetKind(), |
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.
This isn't right - the object kind is "Namespace", whereas the API resource is "namespaces". You need to actually look up the conversion between the Kind and the Resource using the the RESTMapper.
It's a bit awkward, yes. It looks like a few other operators do it. See if they hard-code the mapping or do something cleverer.
16dd37f to
e306aa9
Compare
|
/retest |
| } | ||
| objs = append([]*uns.Unstructured{app}, objs...) | ||
|
|
||
| config, err := rest.InClusterConfig() |
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.
No need to create your own RestMapper - just get it from the manager.
| } | ||
| restMapping, err := mapper.RESTMapping(obj.GroupVersionKind().GroupKind()) | ||
| if err != nil { | ||
| log.Printf("Failed to get REST mapping:%v", err) |
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.
needs a continue here, and maybe a bit more useful error message.
|
Two small comments, then this should be good to go. |
1af0bae to
efa160e
Compare
|
/approve This adds all objects to the Related field. I think that's fine - thoughts, @danwinship? |
This allows must-gather tool to give information about CNO objects for free.
efa160e to
79ee4fc
Compare
That was the plan, wasn't it? Then we can use that to figure out what we need to clean up? The API documentation is not detailed enough to either confirm or deny that this is OK. |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rcarrillocruz, squeed 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 |
This allows must-gather tool to give information about CNO objects
for free.