Skip to content

🌱 Helm extension prototype #1

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

🌱 Helm extension prototype #1

wants to merge 6 commits into from

Conversation

skattoju
Copy link
Owner

Description

Building on the initial prototype that adds functionality to install helm charts as extensions, additional functionality has been added to allow for the specification of values in the form of config maps, secrets or plain text.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

Comment on lines 386 to 390
type ConfigSourceReferences struct {
ConfigMapNames []string `json:"configMapNames,omitempty"`
SecretNames []string `json:"secretNames,omitempty"`
TextConfigs []string `json:"textConfigs,omitempty"`
}

Choose a reason for hiding this comment

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

What if you did something like a discriminated union here?

I'm thinking something like:

type ConfigSourceType string

const (
  ConfigSourceTypeConfigMap = "ConfigMap"
  ConfigSourceTypeSecret = "Secret"
  ConfigSourceTypeInline = "Inline" 
)

// CEL validation here to ensure type + property correctness
type ConfigSource struct {
  // +required
  Type ConfigSourceType `json:"type"`
  // +optional
  ConfigMap *ConfigMapReference `json:"configMap,omitempty"`
  ...
}

Then line 149 could become:

ConfigSources []ConfigSource

I think something like this might fit better with the existing conventions of the ClusterExtension API

@@ -283,3 +201,98 @@ func createClientWithToken(cfg *rest.Config, token string) (*kubernetes.Clientse

return clientSet, nil
}

// Looks for the ConfigSources by name in the install namespace and gathers values
func processConfig(ctx context.Context, tokenGetter *authentication.TokenGetter, ext *ocv1alpha1.ClusterExtension, values chartutil.Values) (chartutil.Values, error) {

Choose a reason for hiding this comment

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

This function is generally pretty straightforward but I wonder if the mental model here could be simplified a bit with some logical abstractions or separate functions?

I think the discriminated union approach for the API might also make that abstraction/functional separation a bit nicer.

Maybe something like:

func processConfigSources(ctx context.Context, client *kubernetes.Clientset, configSources []ocv1alpha1.ConfigSource, values chartutil.Values) (chartutil.Values, error) {
  for _, configSource := range configSources {
    userSuppliedValues, err := loadValuesFromConfigSource(ctx, client, configSource)
    // err check
    // do something with values
  }
  // return loaded values
}

func loadValuesFromConfigSource(ctx context.Context, client *kubernetes.Clientset, configSource ocv1alpha1.ConfigSource) (chartutil.Values, error) {
  switch configSource.Type {
    case ocv1alpha1.ConfigSourceTypeConfigMap:
      // Load from configmap
    case ocv1alpha1.ConfigSourceTypeSecret:
      // Load from secret
    case ocv1alpha1.ConfigSourceTypeInline:
      // Load from inline
  }
}

What I put might not work as is, but hopefully gets the point across that I think some responsibility separation here might be useful for readability, maintenance, and testing.

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.

4 participants