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

refactor to support multiple providers #150

Merged
merged 6 commits into from
Nov 3, 2023
Merged

Conversation

jacobsalmela
Copy link
Collaborator

@jacobsalmela jacobsalmela commented Sep 26, 2023

Summary and Scope

Overview

  • moves csm-specific things out of cmd, domain, and provider packages and into csm
  • passes cmd *cobra.Command, args []string from the cmd layer down each provider (allowing them to define the logic and flags)
  • removes provider.ConfigOptions since these can now be gathered direct from the cobra command or by reading the config file
  • creates a validation object in the csm package called ToBeValidated, as a result of the above (also to prevent import cycle errors)
  • converts validate functions to methods of *CSM
  • changes the cani.yml to be a map of providers and their respective options
  • creates a CsmOpts type in the csm package, which holds all the cray things
  • adjusts variable names as needed along the way

Risks and Mitigations

internal/provider/csm

  • added a new NewSessionInitCommand() function, which each provider will do to set their own options in their own package
  • removed ConfigOptions{} in favor of csm.CsmOpts{}
  • adds a GetProviderOptions() function for the upper layers to use (i.e. writing options to config file)
  • ToBeValidated{} object is created for anything needing validation (k8s CIDRS, roles/subroles, etc)
  • adjusted variables/names/paths as needed with above changes
  • conforms to the Provider interface below

internal/provider

  • removes ConfigOptions interface contstraint
  • removes SlsProvider type in favor of a provider constraint ExportJson(ctx context.Context, datastore inventory.Datastore, skipValidation bool) ([]byte, error)
  • SetProviderOptions constraint, which accepts a cmd and args (from cobra)
  • GetProviderOptions to get the options when needed

internal/inventory

  • genericized the NewDatastoreJSON() and made NewDatastoreJSONCSM() for the csm provider
  • added json/yaml tags to struct

internal/domain

  • made a generic ExportJson() function (not specific to sls)
  • moved DomainOptions into Domain since the provider can set these in their own package now
  • created SetupDomain(), which sets up the required three components for most ops: hardwaretypeLibrary, a datastore, and a provider interface object
  • uses a switch case for different providers needing different settings
  • removed ExportSls() since the provider has it as a method and is csm-specific

cmd

  • added a setupDomain(), which sets up the domain for every command to use. this is run by the root command as a PersistentPreRunE: setupDomain, and it sets a D variable (similar to the d used by each package before)
  • uses root.D in places where an unexported var was used, this should always be the active domain
  • all setup of cmds/flags, etc. are all moved to init(). an example is the BootstrapInitCmd is fairly generic, but when the NewSessionInitCmd() from the provider is called, the cmd's flags and such are replaced by that set by the provider
  • session init has the biggest makeover since all the csm-specific info was moved into the csm package. it is adjusted to use the root.D object
  • DatastoreExists() removed in favor of logic in setupDomain()

spec

  • adjusted tests as needed now that a map of providers is used instead of a single one
  • one blade test is commented out because it gives inconsistent results since we are dynamically getting all blade types from the cani command and each have their own ordinals that change (this can be addressed later)
  • the show summary code does not run, and I still need to figure out why, but the tavern tests still yield good results

Medium. A few tests needed modifications since we use a map of providers now instead of a singular one. The code is shuffled quite a bit, but I kept the test changes to a minimum for more confidence in the changes.

@jacobsalmela jacobsalmela self-assigned this Sep 26, 2023
@jacobsalmela jacobsalmela force-pushed the modest-star-brand branch 2 times, most recently from 35d3bac to e015222 Compare October 16, 2023 19:47
@jacobsalmela jacobsalmela force-pushed the modest-star-brand branch 2 times, most recently from c6e37f8 to 0948b7e Compare October 30, 2023 20:18
@jacobsalmela jacobsalmela changed the title begin refactor to support multiple providers refactor to support multiple providers Oct 30, 2023
@jacobsalmela jacobsalmela changed the base branch from main to develop November 1, 2023 15:51
@jacobsalmela jacobsalmela force-pushed the modest-star-brand branch 4 times, most recently from ecba98d to 5d2ffab Compare November 3, 2023 00:49
Signed-off-by: Jacob Salmela <jacob.salmela@hpe.com>
Signed-off-by: Jacob Salmela <jacob.salmela@hpe.com>
Signed-off-by: Jacob Salmela <jacob.salmela@hpe.com>
Signed-off-by: Jacob Salmela <jacob.salmela@hpe.com>
Signed-off-by: Jacob Salmela <jacob.salmela@hpe.com>
Signed-off-by: Jacob Salmela <jacob.salmela@hpe.com>
@jacobsalmela jacobsalmela marked this pull request as ready for review November 3, 2023 01:08
@jacobsalmela
Copy link
Collaborator Author

@shunr-hpe @rsjostrand-hpe

Since I changed very little in the tests--only some verbiage and adding new fixtures--this can safely merge with your approval.

There are still CSM-specific things to adjust and remove from cmd/domain packages, but this gives us a nice starting point.

@jacobsalmela jacobsalmela merged commit d8295a4 into develop Nov 3, 2023
5 checks passed
@jacobsalmela jacobsalmela deleted the modest-star-brand branch November 3, 2023 16:39
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.

2 participants