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

Initial rancher-api implementation #10144

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

Conversation

jordojordo
Copy link
Member

@jordojordo jordojordo commented Dec 12, 2023

Summary

Fixes #12705

This is the initial proposal for the rancher-api spec with a few methods on the cluster and rancher classes to interact with cluster based resources.

Note: Only the $shell hook will implemented with this PR, in further iterations we can initialize the other hooks.

Initialized by adding each plugin into the pluginDefinitions array within the installInjectedPlugins method in the shell/initialize/install-plugin.js file.

Hooks:

  • $cluster
    • fetching/managing cluster level resources
  • $rancher
    • when interacting with the management/local or Rancher cluster
  • $shell
    • to interact with @rancher/shell components/methods
  • $extension
    • for extension product related methods

This allows for Intellisense on all methods within each class for proper definitions and arguments of each method. Also adds some basic types.


Methods added to the $shell hook:

  • growl: Dispatches a growl notification with a config to determine the:
    • title, message, type, and timeout
  • modal: Opens a modal with a given config that supplies:
    • component, componentProps, resources, modalWidth, and closeOnClickOutside
  • slideInPanel: Opens a Slide-In Panel from the right of the screen with a given config that supplies:
    • component, componentProps

Notable Changes

  • Removed vue-shim template file used only in typegen script
  • Removed outdated Vue 2 typing within the vue-shim.d.ts
  • Added global-vue.d.ts to include typing for .vue files
  • Added references to both the vue-shim.d.ts and global-vue.d.ts files within typegen.sh
    • Instead of adding the contents of vue-shim.d.ts to the types/shell/index.d.ts file, we now will add a reference to that file. Adding the full contents would cause build/typing errors.

Screenshots

Growl hook

growl-test

Modal hook

modal-test.mp4

Slide-In Panel hook

slide-in-test.mp4

@jordojordo jordojordo added this to the v2.8.next1 milestone Dec 12, 2023
@jordojordo jordojordo self-assigned this Dec 12, 2023
Copy link
Contributor

@codyrancher codyrancher left a comment

Choose a reason for hiding this comment

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

I like the groups you split the api into.

It looks like all of these will be available in components. Do you intend to expose any of these to the bootstraping methods of extensions?

Comment on lines 127 to 130
Vue.use(rancherApiPlugin, { store });
Vue.use(clusterApiPlugin, { store });
Vue.use(shellApiPlugin, { store });
Vue.use(extensionApiPlugin, { store });
Copy link
Contributor

Choose a reason for hiding this comment

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

Will these make the API available in the bootstraping methods of the extensions? If so, isn't there a possibility that some of the stores won't be loaded yet? We might have to make that clear or error out gracefully if that's the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't make the API available to extensions after some initial testing, I don't think the types are being properly referenced in an extension.

Perhaps creating a helper function to check for the existence of the store before running any commands wouldn't be a bad idea, but I believe the plugins (extensions) are initialized on line 324 which is after both the store and prototypes are created:

  if (process.client && typeof plugin === 'function') {
    await plugin(app.context, inject);
  }

* @returns `Promise<any>` A promise that resolves with the fetched resource(s).
*/
async get(type: string, options?: ResourceFetchOptions): Promise<any> {
if ( this.getSchema(type) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want to inform the consumer if the schema doesn't exist instead of failing silently. I notice this pattern in other parts of this pr as well.

*
* @returns `Promise<any>` A promise that resolves with the fetched resource(s).
*/
async get(type: string, options?: ResourceFetchOptions): Promise<any> {
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 obvious to me by looking at this signature how I should retrieve all items of a resource (from looking at the code it's obvious) which I think is problematic. Maybe changing options to filter instead would make that clear but I suspect we'll want to leave it as options to support pagination in the future.

I think I'd be in favor of splitting the functionality of findAll and findMatching/find into two different methods. If there's a better idea for making the usage obvious I'd be fine with something else.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to emulate how running a kubectl get <resource> would return all of a resource (sans the namespace), maybe this isn't the best approach. I figured having Intellisense that explains the design of the function and options in detail would provide clear instructions on how to use the method.

I'm open to splitting the functionality as well, this may help limit confusion with further implementation.

import { SteveResource, ResourceManageOptions } from '@shell/types/rancher-api/cluster';
import BaseClusterApi from './base-cluster-class';

export default class ClusterApi extends BaseClusterApi {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a suspicion we'll want to expose more of the methods from shell/store.index.js.

A few examples:
getCluster
getClusterId
isRancher

Copy link
Member Author

@jordojordo jordojordo Dec 14, 2023

Choose a reason for hiding this comment

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

I decided not to dive too far into the weeds with implementation before we agreed on a proper plan of this API.

@nwmac nwmac modified the milestones: v2.9.0, v2.10.0 May 22, 2024
@nwmac nwmac modified the milestones: v2.10.0, v2.11.0 Oct 25, 2024
@nwmac nwmac modified the milestones: v2.12.0, v2.11.0 Nov 1, 2024
@jordojordo jordojordo force-pushed the rancher-api branch 3 times, most recently from a5cfc9d to e4a9bc9 Compare December 5, 2024 20:44
@jordojordo jordojordo marked this pull request as ready for review December 6, 2024 14:16
@jordojordo jordojordo force-pushed the rancher-api branch 2 times, most recently from 63ac60b to 864b06d Compare December 11, 2024 13:44
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.

Create API layer to interact with modals, growls and other interactive pieces of UI
3 participants