Skip to content

Commit

Permalink
feat: apply unsupported config overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardomaraschini committed Oct 16, 2023
1 parent 079ca9d commit 9fc691f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
11 changes: 9 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sigs.k8s.io/yaml"

"github.com/replicatedhq/helmvm/pkg/addons"
"github.com/replicatedhq/helmvm/pkg/customization"
"github.com/replicatedhq/helmvm/pkg/defaults"
"github.com/replicatedhq/helmvm/pkg/infra"
"github.com/replicatedhq/helmvm/pkg/prompts"
Expand Down Expand Up @@ -410,9 +411,15 @@ type UnsupportedConfigOverrides struct {
}

// applyEmbeddedUnsupportedOverrides applies the custom configuration to the cluster config.
func applyEmbeddedUnsupportedOverrides(config *v1beta1.Cluster, override []byte) error {
func applyEmbeddedUnsupportedOverrides(config *v1beta1.Cluster) error {
embconfig, err := customization.AdminConsole{}.EmbeddedClusterConfig()
if err != nil {
return fmt.Errorf("unable to get embedded cluster config: %w", err)
} else if embconfig == nil {
return nil
}
var overrides UnsupportedConfigOverrides
if err := yaml.Unmarshal(override, &overrides); err != nil {
if err := yaml.Unmarshal(embconfig, &overrides); err != nil {
return fmt.Errorf("unable to parse cluster config overrides: %w", err)
}
if overrides.Spec.UnsupportedOverrides.K0s == nil {
Expand Down
27 changes: 24 additions & 3 deletions pkg/customization/customization.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
// ParsedSection holds the parsed section from the binary. We only care about the
// application object, whatever HostPreflight we can find, and the app License.
type ParsedSection struct {
Application []byte
HostPreflights [][]byte
License []byte
Application []byte
HostPreflights [][]byte
License []byte
EmbeddedClusterConfig []byte
}

// AdminConsole is a struct that contains the actions to create and update the admin
Expand Down Expand Up @@ -95,6 +96,12 @@ func (a AdminConsole) processSection(section *elf.Section) (*ParsedSection, erro
}
result.HostPreflights = append(result.HostPreflights, content.Bytes())
}
if bytes.Contains(content.Bytes(), []byte("apiVersion: embeddedcluster.replicated.com/v1beta1")) {
if bytes.Contains(content.Bytes(), []byte("kind: Config")) {
continue
}
result.EmbeddedClusterConfig = content.Bytes()
}
}
}

Expand Down Expand Up @@ -140,3 +147,17 @@ func (a AdminConsole) License() (*v1beta1.License, error) {
}
return &license, nil
}

// EmbeddedClusterConfig reads the embedded cluster config from the embedded Kots Application Release.
func (a AdminConsole) EmbeddedClusterConfig() ([]byte, error) {
if runtime.GOOS != "linux" {
return nil, nil
}
section, err := a.ExtractCustomization()
if err != nil {
return nil, err
} else if section == nil {
return nil, nil
}
return section.EmbeddedClusterConfig, nil
}

0 comments on commit 9fc691f

Please sign in to comment.