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

Update all call-sites to ensure ResourceRefs use cluster. #1889

Merged
merged 3 commits into from
Jul 27, 2020

Conversation

absoludity
Copy link
Contributor

Signed-off-by: Michael Nelson minelson@vmware.com

Description of the change

Follows on from #1886, updating ResourceRefs to include the cluster (in the constructor as a required arg) then updating all the call-sites to use it (mainly in tests, other than AppView and OperatorInstance (which uses fromCRD)).

It was a pain to audit because the typechecker can't find everything, as the 3rd arg is an optional string. Anyway, I think I've audited all call-sites now.

This is slightly different to how I did the change in the demo branch, and has the benefit that the resource refs just calculate multicluster URLs once created, so users of the objects don't need to care.

Benefits

Required for multicluster support.

Possible drawbacks

Danger of missing a call-site.

Applicable issues

Ref: #1762

Additional information

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

Thanks! Mostly LGTM, let me know what you think about what I propose.

// TODO: add support for cluster-scoped resources, or add a ClusterResourceRef
// class.
constructor(r: IResource, defaultNamespace?: string, defaultFilter?: any) {
constructor(r: IResource, cluster: string, defaultNamespace?: string, defaultFilter?: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

for the maintainability of this I would:

  • Make the defaultNamespace mandatory. It's easier to understand calls like new ResourceRef({}, "cluster-a", namespace). Also you would notice if you are missing the cluster in some call.
  • Remove the defaultFilter param. AFAIK, it's only used in the function fromCRD above. You can move it to a setter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the maintainability of this I would:

These are both not things I changed, but always keen to improve things...

* Make the `defaultNamespace` mandatory. It's easier to understand calls like `new ResourceRef({}, "cluster-a", namespace)`. Also you would notice if you are missing the cluster in some call.

It's not clear to me why we even have this arg... the docstring says in case an IResource doesn't have a namespace, but it's a required field on IResource. I think we are only ever showing namespaced resources? Smells either like a hack to work-around bad input, or old cruft that hasn't been removed? Let me know, but either way I'm keen to change that in a separate branch and move forward here.

* Remove the `defaultFilter` param. AFAIK, it's only used in the function `fromCRD` above. You can move it to a setter.

+1. It's a public field, so just set it in fromCRD in aa48611

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear to me why we even have this arg... the docstring says in case an IResource doesn't have a namespace, but it's a required field on IResource. I think we are only ever showing namespaced resources? Smells either like a hack to work-around bad input, or old cruft that hasn't been removed? Let me know, but either way I'm keen to change that in a separate branch and move forward here.

This parameter is needed because we parse the manifests installed by helm to retrieve the different resources. With helm, it's not necessary to set the namespace. If a resource doesn't have a namespace, it's installed in the namespace of the release. Also (I am not sure about this), if the resource is a list of resources, the namespaces may not be specified in each of those elements so we would need to pass the namespace of the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation. That being the case, it seems odd to require it as a default even if it's not necessary (rather than just leaving it as an optional default). But I'll take a closer look.

@absoludity absoludity force-pushed the 1762-resource-refs-cluster-aware branch from c4b9baf to e49019c Compare July 27, 2020 02:55
Base automatically changed from 1762-namespace-actions to master July 27, 2020 06:59
@absoludity absoludity force-pushed the 1762-resource-refs-cluster-aware branch from e49019c to aa48611 Compare July 27, 2020 07:01
@absoludity absoludity merged commit 55b916a into master Jul 27, 2020
@absoludity absoludity deleted the 1762-resource-refs-cluster-aware branch July 27, 2020 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants