Skip to content

Commit

Permalink
type check config and fix custom chart writer
Browse files Browse the repository at this point in the history
  • Loading branch information
danj-replicated committed Oct 6, 2023
1 parent 6a8fcdd commit 06d6893
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
32 changes: 7 additions & 25 deletions pkg/addons/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ func (c *Custom) GenerateHelmConfig() ([]v1beta1.Chart, error) {
chartConfig.ChartName = dstpath
chartConfig.Values = chart.Values

err = writeChartFile(chartName, chartData.Metadata.Version)
reader := chart.ChartReader()
data, err := io.ReadAll(reader)
if err != nil {
return nil, fmt.Errorf("unable to read helm chart archive: %w", err)
}

err = os.WriteFile(dstpath, data, 0644)
if err != nil {
return nil, fmt.Errorf("unable to write helm chart archive: %w", err)
}
Expand All @@ -108,30 +114,6 @@ func (c *Custom) GenerateHelmConfig() ([]v1beta1.Chart, error) {

}

func writeChartFile(name string, version string) error {

chartfile := fmt.Sprintf("%s-%s.tgz", name, version)

src, err := os.Open(chartfile)
if err != nil {
return fmt.Errorf("unable to open helm chart archive: %w", err)
}

dstpath := defaults.PathToHelmChart(name, version)

sourceFileByte, err := io.ReadAll(src)
if err != nil {
return fmt.Errorf("unable to read helm chart archive: %w", err)
}

err = os.WriteFile(dstpath, sourceFileByte, 0644)
if err != nil {
return fmt.Errorf("unable to write helm chart archive: %w", err)
}

return nil
}

func (c *Custom) chartHasBeenDisabled(chart *chart.Chart) bool {
cname := strings.ToLower(chart.Name())
_, disabledAddons := c.disabledAddons[cname]
Expand Down
12 changes: 8 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,14 @@ func UpdateHelmConfigs(cfg *v1beta1.Cluster, opts ...addons.Option) error {
Helm: newHelmExtension,
}

spec := cfg.Spec.K0s.Config["spec"].(map[string]interface{})
spec["extensions"] = newClusterExtensions

cfg.Spec.K0s.Config["spec"] = spec
if spec, ok := cfg.Spec.K0s.Config["spec"].(map[string]interface{}); ok {
spec["extensions"] = newClusterExtensions
cfg.Spec.K0s.Config["spec"] = spec
} else {
spec := cfg.Spec.K0s.Config["spec"].(dig.Mapping)
spec["extensions"] = newClusterExtensions
cfg.Spec.K0s.Config["spec"] = spec
}

return nil
}
Expand Down

0 comments on commit 06d6893

Please sign in to comment.