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

Extensions: Add hooks to support virtual clusters #11064

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

nwmac
Copy link
Member

@nwmac nwmac commented May 21, 2024

Summary

Fixes #11065

This PR adds several hooks for virtual cluster support.

The main change is a new extension API addModelExtension - this is marked experimental for now - once we establish if we need any changes, we can remove that label.

You can register model extensions and they are stored against a model type, e.g. provisioning.cattle.io.cluster. There is a method on the Steve base class to retrieve all of the model extensions for a given model type. You can register multiple model extensions for a given model.

Beyond that, it is up to a given model to decide how to use these model extensions - i.e. a model needs to define an API for them and explicitly wire that into itself. This ensures we have a defined API for extensibility, rather than allowing a model extension to do anything it wants.

In this PR, we write a model extension into the provisioning cluster model to support the needs of virtual clusters.

Risk wise, this PR is designed to minimise impact to existing code, so the risk is small.

Areas or cases that should be tested

These hooks will be tested by extensions.

Current e2e test should validate that the hooks do not break existing functionality.

Checklist

  • The PR is linked to an issue and the linked issue has a Milestone, or no issue is needed
  • The PR has a Milestone
  • The PR template has been filled out
  • The PR has been self reviewed
  • The PR has a reviewer assigned
  • The PR has automated tests or clear instructions for manual tests and the linked issue has appropriate QA labels, or tests are not needed
  • The PR has reviewed with UX and tested in light and dark mode, or there are no UX changes

@rancher-ui-project-bot rancher-ui-project-bot bot added this to the v2.9.0 milestone May 21, 2024
@nwmac nwmac marked this pull request as ready for review May 23, 2024 10:36
@nwmac nwmac requested a review from mantis-toboggan-md May 23, 2024 10:37
@nwmac nwmac changed the title Add hooks to support virtual clusters Extensions: Add hooks to support virtual clusters May 23, 2024
@nwmac nwmac force-pushed the add-virtual-cluster-hooks branch 3 times, most recently from 3225ac2 to 82fc100 Compare June 14, 2024 17:09
@nwmac
Copy link
Member Author

nwmac commented Jun 14, 2024

@mantis-toboggan-md finally got this to pass gates - refactored as we discussed.

@nwmac nwmac modified the milestones: v2.9.0, v2.10.0 Jun 27, 2024
@nwmac nwmac force-pushed the add-virtual-cluster-hooks branch from 82fc100 to 37c7477 Compare July 10, 2024 16:53
@nwmac nwmac force-pushed the add-virtual-cluster-hooks branch from 71c0394 to 29ec9b5 Compare August 13, 2024 15:35
@nwmac nwmac modified the milestones: v2.10.0, v2.11.0 Oct 22, 2024
@nwmac nwmac modified the milestones: v2.12.0, v2.11.0 Nov 1, 2024
@nwmac nwmac force-pushed the add-virtual-cluster-hooks branch from 29ec9b5 to 06756d1 Compare January 22, 2025 13:39
@nwmac nwmac requested review from aalves08 and richard-cox January 24, 2025 11:07
Copy link
Member

@aalves08 aalves08 left a comment

Choose a reason for hiding this comment

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

Reviewing this, changes seem pretty self self-contained as it's targeting the provisioning.cattle.io.cluster. I assume that since this is experimental, we don't want to document it right now, but in the future, if we open it, we need to add it to the documentation.

One last remark would be around using modelExtensions instead of extending/reusing uiConfig 🤔

nevertheless, I would say that it LGTM

Copy link
Member

@richard-cox richard-cox left a comment

Choose a reason for hiding this comment

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

Haven't given this a functional test, just looked at code.

Only minor comments. We are limiting model extensions to be singular though. Not sure we'll ever be in a scenario where different extensions might want to update things like deployment actions?

* @param cluster The cluster model (`provisioning.cattle.io.cluster`)
* @returns Whether to use this provisioner for the given cluster.
*/
useForModel(cluster: any): boolean;
Copy link
Member

Choose a reason for hiding this comment

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

this isn't wired in anywhere

* @param type Model type
* @param clz Class for the model extension (constructor)
*/
addModelExtension(type: string, clz: Function): void;
Copy link
Member

@richard-cox richard-cox Jan 24, 2025

Choose a reason for hiding this comment

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

given clz is a known function .. here (and shell/core/plugin.ts) should be typed

@@ -88,6 +88,11 @@ export default {
},

computed: {
groupable() {
Copy link
Member

Choose a reason for hiding this comment

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

this is going to break with Cody's SSP PR. We won't have access to all provisioning clusters (filteredRows) just a single pages worth.

*/
get customProvisionerHelper() {
// Find the first model extension that says it can be used for this model
return this.modelExtensions.find((modelExt) => modelExt.useFor ? modelExt.useFor(this) : false);
Copy link
Member

Choose a reason for hiding this comment

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

should there be a type / interface for modelExtension instances? missing this fn will trip up developers

return this.customProvisionerHelper?.parentCluster?.(this);
}

get groupByLabel() {
Copy link
Member

Choose a reason for hiding this comment

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

Think this is fine now, so just a comment, but in the future the plan is to group clusters by cluster class as well

}

get groupByParent() {
// Customer helper can report if the cluster has a parent cluster
Copy link
Member

Choose a reason for hiding this comment

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

typo Customer

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.

Allow clusters list to group clusters based on parent cluster
3 participants