Skip to content

Commit

Permalink
feat: add protected helm values to release metadata (#234)
Browse files Browse the repository at this point in the history
* add protected helm values to release metadata

* correct field

* chore: cosmetic fixes

---------

Co-authored-by: Ricardo Maraschini <[email protected]>
  • Loading branch information
danj-replicated and ricardomaraschini authored Dec 28, 2023
1 parent a35c42d commit 2eb58f6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cmd/embedded-cluster/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ReleaseMetadata struct {
K0sSHA string
K0sBinaryURL string
Configs k0sconfig.HelmExtensions
Protected map[string][]string
}

var metadataCommand = &cli.Command{
Expand All @@ -69,23 +70,25 @@ var metadataCommand = &cli.Command{
K0sSHA: sha,
K0sBinaryURL: defaults.K0sBinaryURL,
}

chtconfig, repconfig, err := addons.NewApplier(opts...).GenerateHelmConfigs()
applier := addons.NewApplier(opts...)
chtconfig, repconfig, err := applier.GenerateHelmConfigs()
if err != nil {
return fmt.Errorf("unable to apply addons: %w", err)
}

meta.Configs = k0sconfig.HelmExtensions{
ConcurrencyLevel: 1,
Charts: chtconfig,
Repositories: repconfig,
}

protectedFields, err := applier.ProtectedFields()
if err != nil {
return fmt.Errorf("unable to get protected fields: %w", err)
}
meta.Protected = protectedFields
data, err := json.MarshalIndent(meta, "", "\t")
if err != nil {
return fmt.Errorf("unable to marshal versions: %w", err)
}

fmt.Println(string(data))
return nil
},
Expand Down
11 changes: 11 additions & 0 deletions pkg/addons/adminconsole/adminconsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ var (
MigrationsImageOverride = ""
)

// protectedFields are helm values that are not overwritten when upgrading the addon.
var protectedFields = []string{
"password",
"automation",
}

var helmValues = map[string]interface{}{
"minimalRBAC": false,
"isHelmManaged": false,
Expand Down Expand Up @@ -90,6 +96,11 @@ func (a *AdminConsole) Version() (map[string]string, error) {
return map[string]string{"AdminConsole": "v" + Version}, nil
}

// GetProtectedFields returns the helm values that are not overwritten when upgrading
func (a *AdminConsole) GetProtectedFields() map[string][]string {
return map[string][]string{releaseName: protectedFields}
}

// HostPreflights returns the host preflight objects found inside the adminconsole
// or as part of the embedded kots release (customization).
func (a *AdminConsole) HostPreflights() (*v1beta2.HostPreflightSpec, error) {
Expand Down
16 changes: 16 additions & 0 deletions pkg/addons/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type AddOn interface {
HostPreflights() (*v1beta2.HostPreflightSpec, error)
GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error)
Outro(context.Context, client.Client) error
GetProtectedFields() map[string][]string
}

// Applier is an entity that applies (installs and updates) addons in the cluster.
Expand Down Expand Up @@ -78,6 +79,21 @@ func (a *Applier) GenerateHelmConfigs() ([]v1beta1.Chart, []v1beta1.Repository,
return charts, repositories, nil
}

// ProtectedFields returns the protected fields for all the embedded charts.
func (a *Applier) ProtectedFields() (map[string][]string, error) {
protectedFields := map[string][]string{}
addons, err := a.load()
if err != nil {
return protectedFields, fmt.Errorf("unable to load addons: %w", err)
}
for _, addon := range addons {
for k, v := range addon.GetProtectedFields() {
protectedFields[k] = v
}
}
return protectedFields, nil
}

// HostPreflights reads all embedded host preflights from all add-ons and returns them
// merged in a single HostPreflightSpec.
func (a *Applier) HostPreflights() (*v1beta2.HostPreflightSpec, error) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ func (c *Custom) HostPreflights() (*v1beta2.HostPreflightSpec, error) {
return nil, nil
}

// GetProtectedFields returns the protected fields for the embedded charts.
// placeholder for now.
func (c *Custom) GetProtectedFields() map[string][]string {
protectedFields := []string{}
return map[string][]string{"custom": protectedFields}
}

// GenerateHelmConfig generates the helm config for all the embedded charts.
// and writes the charts to the disk.
func (c *Custom) GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/embeddedclusteroperator/embeddedclusteroperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func (e *EmbeddedClusterOperator) HostPreflights() (*v1beta2.HostPreflightSpec,
return nil, nil
}

// GetProtectedFields returns the protected fields for the embedded charts.
// placeholder for now.
func (e *EmbeddedClusterOperator) GetProtectedFields() map[string][]string {
protectedFields := []string{}
return map[string][]string{releaseName: protectedFields}
}

// GenerateHelmConfig generates the helm config for the embedded cluster operator chart.
func (e *EmbeddedClusterOperator) GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error) {
chartConfig := v1beta1.Chart{
Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/openebs/openebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func (o *OpenEBS) HostPreflights() (*v1beta2.HostPreflightSpec, error) {
return nil, nil
}

// GetProtectedFields returns the protected fields for the embedded charts.
// placeholder for now.
func (o *OpenEBS) GetProtectedFields() map[string][]string {
protectedFields := []string{}
return map[string][]string{releaseName: protectedFields}
}

// GenerateHelmConfig generates the helm config for the OpenEBS chart.
func (o *OpenEBS) GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error) {
chartConfig := v1beta1.Chart{
Expand Down

0 comments on commit 2eb58f6

Please sign in to comment.