Skip to content

Commit 2eb58f6

Browse files
feat: add protected helm values to release metadata (#234)
* add protected helm values to release metadata * correct field * chore: cosmetic fixes --------- Co-authored-by: Ricardo Maraschini <[email protected]>
1 parent a35c42d commit 2eb58f6

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-5
lines changed

cmd/embedded-cluster/version.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type ReleaseMetadata struct {
4646
K0sSHA string
4747
K0sBinaryURL string
4848
Configs k0sconfig.HelmExtensions
49+
Protected map[string][]string
4950
}
5051

5152
var metadataCommand = &cli.Command{
@@ -69,23 +70,25 @@ var metadataCommand = &cli.Command{
6970
K0sSHA: sha,
7071
K0sBinaryURL: defaults.K0sBinaryURL,
7172
}
72-
73-
chtconfig, repconfig, err := addons.NewApplier(opts...).GenerateHelmConfigs()
73+
applier := addons.NewApplier(opts...)
74+
chtconfig, repconfig, err := applier.GenerateHelmConfigs()
7475
if err != nil {
7576
return fmt.Errorf("unable to apply addons: %w", err)
7677
}
77-
7878
meta.Configs = k0sconfig.HelmExtensions{
7979
ConcurrencyLevel: 1,
8080
Charts: chtconfig,
8181
Repositories: repconfig,
8282
}
83-
83+
protectedFields, err := applier.ProtectedFields()
84+
if err != nil {
85+
return fmt.Errorf("unable to get protected fields: %w", err)
86+
}
87+
meta.Protected = protectedFields
8488
data, err := json.MarshalIndent(meta, "", "\t")
8589
if err != nil {
8690
return fmt.Errorf("unable to marshal versions: %w", err)
8791
}
88-
8992
fmt.Println(string(data))
9093
return nil
9194
},

pkg/addons/adminconsole/adminconsole.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ var (
3535
MigrationsImageOverride = ""
3636
)
3737

38+
// protectedFields are helm values that are not overwritten when upgrading the addon.
39+
var protectedFields = []string{
40+
"password",
41+
"automation",
42+
}
43+
3844
var helmValues = map[string]interface{}{
3945
"minimalRBAC": false,
4046
"isHelmManaged": false,
@@ -90,6 +96,11 @@ func (a *AdminConsole) Version() (map[string]string, error) {
9096
return map[string]string{"AdminConsole": "v" + Version}, nil
9197
}
9298

99+
// GetProtectedFields returns the helm values that are not overwritten when upgrading
100+
func (a *AdminConsole) GetProtectedFields() map[string][]string {
101+
return map[string][]string{releaseName: protectedFields}
102+
}
103+
93104
// HostPreflights returns the host preflight objects found inside the adminconsole
94105
// or as part of the embedded kots release (customization).
95106
func (a *AdminConsole) HostPreflights() (*v1beta2.HostPreflightSpec, error) {

pkg/addons/applier.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type AddOn interface {
3030
HostPreflights() (*v1beta2.HostPreflightSpec, error)
3131
GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error)
3232
Outro(context.Context, client.Client) error
33+
GetProtectedFields() map[string][]string
3334
}
3435

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

82+
// ProtectedFields returns the protected fields for all the embedded charts.
83+
func (a *Applier) ProtectedFields() (map[string][]string, error) {
84+
protectedFields := map[string][]string{}
85+
addons, err := a.load()
86+
if err != nil {
87+
return protectedFields, fmt.Errorf("unable to load addons: %w", err)
88+
}
89+
for _, addon := range addons {
90+
for k, v := range addon.GetProtectedFields() {
91+
protectedFields[k] = v
92+
}
93+
}
94+
return protectedFields, nil
95+
}
96+
8197
// HostPreflights reads all embedded host preflights from all add-ons and returns them
8298
// merged in a single HostPreflightSpec.
8399
func (a *Applier) HostPreflights() (*v1beta2.HostPreflightSpec, error) {

pkg/addons/custom/custom.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ func (c *Custom) HostPreflights() (*v1beta2.HostPreflightSpec, error) {
5757
return nil, nil
5858
}
5959

60+
// GetProtectedFields returns the protected fields for the embedded charts.
61+
// placeholder for now.
62+
func (c *Custom) GetProtectedFields() map[string][]string {
63+
protectedFields := []string{}
64+
return map[string][]string{"custom": protectedFields}
65+
}
66+
6067
// GenerateHelmConfig generates the helm config for all the embedded charts.
6168
// and writes the charts to the disk.
6269
func (c *Custom) GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error) {

pkg/addons/embeddedclusteroperator/embeddedclusteroperator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ func (e *EmbeddedClusterOperator) HostPreflights() (*v1beta2.HostPreflightSpec,
5959
return nil, nil
6060
}
6161

62+
// GetProtectedFields returns the protected fields for the embedded charts.
63+
// placeholder for now.
64+
func (e *EmbeddedClusterOperator) GetProtectedFields() map[string][]string {
65+
protectedFields := []string{}
66+
return map[string][]string{releaseName: protectedFields}
67+
}
68+
6269
// GenerateHelmConfig generates the helm config for the embedded cluster operator chart.
6370
func (e *EmbeddedClusterOperator) GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error) {
6471
chartConfig := v1beta1.Chart{

pkg/addons/openebs/openebs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ func (o *OpenEBS) HostPreflights() (*v1beta2.HostPreflightSpec, error) {
5151
return nil, nil
5252
}
5353

54+
// GetProtectedFields returns the protected fields for the embedded charts.
55+
// placeholder for now.
56+
func (o *OpenEBS) GetProtectedFields() map[string][]string {
57+
protectedFields := []string{}
58+
return map[string][]string{releaseName: protectedFields}
59+
}
60+
5461
// GenerateHelmConfig generates the helm config for the OpenEBS chart.
5562
func (o *OpenEBS) GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error) {
5663
chartConfig := v1beta1.Chart{

0 commit comments

Comments
 (0)