Skip to content

Commit

Permalink
feat: setting kots app version for deployment (#233)
Browse files Browse the repository at this point in the history
stop deploying latest and inform kots which version should be deployed
based on the release version label.
  • Loading branch information
ricardomaraschini authored Dec 20, 2023
1 parent 52e0fee commit 229443b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARCH := $(shell uname -m)
APP_NAME = embedded-cluster
ADMIN_CONSOLE_CHART_URL = oci://registry.replicated.com/library
ADMIN_CONSOLE_CHART_NAME = admin-console
ADMIN_CONSOLE_CHART_VERSION = 1.104.7-build.1
ADMIN_CONSOLE_CHART_VERSION = 1.104.7-build.2
ADMIN_CONSOLE_IMAGE_OVERRIDE =
ADMIN_CONSOLE_MIGRATIONS_IMAGE_OVERRIDE =
EMBEDDED_OPERATOR_CHART_URL = oci://registry.replicated.com/library
Expand Down
16 changes: 10 additions & 6 deletions pkg/addons/adminconsole/adminconsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (a *AdminConsole) HostPreflights() (*v1beta2.HostPreflightSpec, error) {
return a.customization.HostPreflights()
}

// addLicenseToHelmValues adds the embedded license to the helm values.
func (a *AdminConsole) addLicenseToHelmValues() error {
// addLicenseAndVersionToHelmValues adds the embedded license to the helm values.
func (a *AdminConsole) addLicenseAndVersionToHelmValues() error {
license, err := a.customization.License()
if err != nil {
return fmt.Errorf("unable to get license: %w", err)
Expand All @@ -109,7 +109,14 @@ func (a *AdminConsole) addLicenseToHelmValues() error {
if err != nil {
return fmt.Errorf("unable to marshal license: %w", err)
}
var appVersion string
if release, err := a.customization.ChannelRelease(); err != nil {
return fmt.Errorf("unable to get channel release: %w", err)
} else if release != nil {
appVersion = release.VersionLabel
}
helmValues["automation"] = map[string]interface{}{
"appVersionLabel": appVersion,
"license": map[string]interface{}{
"slug": license.Spec.AppSlug,
"data": string(raw),
Expand Down Expand Up @@ -186,18 +193,15 @@ func (a *AdminConsole) addKotsApplicationToHelmValues() error {
// GenerateHelmConfig generates the helm config for the adminconsole and writes the charts to
// the disk.
func (a *AdminConsole) GenerateHelmConfig(onlyDefaults bool) ([]v1beta1.Chart, []v1beta1.Repository, error) {

if !onlyDefaults {
if err := a.addPasswordToHelmValues(); err != nil {
return nil, nil, fmt.Errorf("unable to add password to helm values: %w", err)
}

if err := a.addKotsApplicationToHelmValues(); err != nil {
return nil, nil, fmt.Errorf("unable to add kots app to helm values: %w", err)
}
}

if err := a.addLicenseToHelmValues(); err != nil {
if err := a.addLicenseAndVersionToHelmValues(); err != nil {
return nil, nil, fmt.Errorf("unable to add license to helm values: %w", err)
}
values, err := yaml.Marshal(helmValues)
Expand Down
41 changes: 37 additions & 4 deletions pkg/customization/customization.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,25 @@ import (
embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-operator/api/v1beta1"
"github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
"github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"sigs.k8s.io/yaml"
"gopkg.in/yaml.v2"
kyaml "sigs.k8s.io/yaml"

"github.com/replicatedhq/embedded-cluster/pkg/preflights"
)

// ChannelRelease contains information about a specific app release inside a channel.
type ChannelRelease struct {
VersionLabel string `yaml:"versionLabel"`
}

// 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
EmbeddedClusterConfig []byte
ChannelRelease []byte
}

// AdminConsole is a struct that contains the actions to create and update the admin
Expand Down Expand Up @@ -105,6 +112,10 @@ func (a AdminConsole) processSection(section *elf.Section) (*ParsedSection, erro
result.EmbeddedClusterConfig = content.Bytes()
continue
}
if bytes.Contains(content.Bytes(), []byte("# channel release object")) {
result.ChannelRelease = content.Bytes()
continue
}
}
}

Expand Down Expand Up @@ -145,7 +156,7 @@ func (a AdminConsole) License() (*v1beta1.License, error) {
return nil, nil
}
var license v1beta1.License
if err := yaml.Unmarshal(section.License, &license); err != nil {
if err := kyaml.Unmarshal(section.License, &license); err != nil {
return nil, fmt.Errorf("failed to unmarshal license: %w", err)
}
return &license, nil
Expand Down Expand Up @@ -178,14 +189,36 @@ func (a AdminConsole) EmbeddedClusterConfig() (*embeddedclusterv1beta1.Config, e
} else if section == nil {
return nil, nil
}

rawcfg := section.EmbeddedClusterConfig
if rawcfg == nil {
return nil, nil
}
var cfg embeddedclusterv1beta1.Config
if err := yaml.Unmarshal(rawcfg, &cfg); err != nil {
if err := kyaml.Unmarshal(rawcfg, &cfg); err != nil {
return nil, fmt.Errorf("unable to unmarshal embedded cluster config: %w", err)
}
return &cfg, nil
}

// ChannelRelease reads the embedded channel release object. If no channel release is found,
// returns nil and no error.
func (a AdminConsole) ChannelRelease() (*ChannelRelease, 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
}
raw := section.ChannelRelease
if raw == nil {
return nil, nil
}
var release ChannelRelease
if err := yaml.Unmarshal(raw, &release); err != nil {
return nil, fmt.Errorf("unable to unmarshal channel release: %w", err)
}
return &release, nil
}

0 comments on commit 229443b

Please sign in to comment.