Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROX-24494: ACSCS Addon overrides in Gitops lingers after removing from Gitops #2186

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions internal/dinosaur/pkg/services/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func (p *AddonProvisioner) Provision(cluster api.Cluster, dataplaneClusterConfig
func (p *AddonProvisioner) provisionAddon(dataplaneClusterConfig gitops.DataPlaneClusterConfig, expectedConfig gitops.AddonConfig, installedOnCluster dbapi.AddonInstallation, existOnCluster bool) (provisionError error) {
var errs []error
clusterID := dataplaneClusterConfig.ClusterID
installedInOCM, addonErr := p.ocmClient.GetAddonInstallation(clusterID, expectedConfig.ID)
status := metrics.AddonHealthy

defer func() {
Expand All @@ -119,6 +118,12 @@ func (p *AddonProvisioner) provisionAddon(dataplaneClusterConfig gitops.DataPlan
p.updateAddonStatus(expectedConfig.ID, dataplaneClusterConfig.ClusterName, clusterID, status)
}()

if err := p.augmentGitopsWithOCMDefaultValues(&expectedConfig); err != nil {
errs = append(errs, fmt.Errorf("augment addon %s with default values from OCM: %w", expectedConfig.ID, err))
return
}
installedInOCM, addonErr := p.ocmClient.GetAddonInstallation(clusterID, expectedConfig.ID)

if addonErr != nil {
if addonErr.Is404() {
// addon does not exist, install it
Expand All @@ -134,14 +139,6 @@ func (p *AddonProvisioner) provisionAddon(dataplaneClusterConfig gitops.DataPlan
status = metrics.AddonUpgrade
return
}
if expectedConfig.Version == "" {
addon, err := p.ocmClient.GetAddon(expectedConfig.ID)
if err != nil {
errs = append(errs, fmt.Errorf("get addon %s with the latest version: %w", expectedConfig.ID, err))
return
}
expectedConfig.Version = addon.Version().ID()
}
if gitOpsConfigDifferent(expectedConfig, installedInOCM) {
errs = append(errs, p.updateAddon(clusterID, expectedConfig))
status = metrics.AddonUpgrade
Expand All @@ -168,6 +165,39 @@ func (p *AddonProvisioner) provisionAddon(dataplaneClusterConfig gitops.DataPlan
return
}

func (p *AddonProvisioner) augmentGitopsWithOCMDefaultValues(expectedConfig *gitops.AddonConfig) error {
if expectedConfig.Version == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this condition about?

Copy link
Contributor Author

@kovayur kovayur Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can specify the addon version in the gitops config. If you do not do this, the latest version will be installed.

addon, err := p.ocmClient.GetAddon(expectedConfig.ID)
if err != nil {
return fmt.Errorf("get addon %s with the latest version: %w", expectedConfig.ID, err)
}
expectedConfig.Version = addon.Version().ID()
addDefaultParameters(expectedConfig, addon.Parameters())
} else {
addonInstallation, err := p.ocmClient.GetAddonVersion(expectedConfig.ID, expectedConfig.Version)
if err != nil {
return fmt.Errorf("get addon %s with the latest version: %w", expectedConfig.ID, err)
}
addDefaultParameters(expectedConfig, addonInstallation.Parameters())
}
return nil
}

func addDefaultParameters(config *gitops.AddonConfig, parameters *clustersmgmtv1.AddOnParameterList) {
if parameters == nil {
return
}
if config.Parameters == nil {
config.Parameters = make(map[string]string)
}
parameters.Each(func(parameter *clustersmgmtv1.AddOnParameter) bool {
if _, exists := config.Parameters[parameter.ID()]; !exists {
config.Parameters[parameter.ID()] = parameter.DefaultValue()
}
return true
})
}

func validateUpToDateAddon(ocmInstallation *clustersmgmtv1.AddOnInstallation, dataPlaneInstallation dbapi.AddonInstallation) error {
var errs []error
if ocmInstallation.State() == clustersmgmtv1.AddOnInstallationStateFailed {
Expand Down Expand Up @@ -217,16 +247,12 @@ func (p *AddonProvisioner) installAddon(clusterID string, config gitops.AddonCon
}

func (p *AddonProvisioner) newInstallation(config gitops.AddonConfig) (*clustersmgmtv1.AddOnInstallation, error) {
builder := clustersmgmtv1.NewAddOnInstallation().
installation, err := clustersmgmtv1.NewAddOnInstallation().
ID(config.ID).
Addon(clustersmgmtv1.NewAddOn().ID(config.ID)).
Parameters(convertParametersToOCMAPI(config.Parameters))

if config.Version != "" {
builder = builder.AddonVersion(clustersmgmtv1.NewAddOnVersion().ID(config.Version))
}

installation, err := builder.Build()
Parameters(convertParametersToOCMAPI(config.Parameters)).
AddonVersion(clustersmgmtv1.NewAddOnVersion().ID(config.Version)).
Build()

if err != nil {
return nil, fmt.Errorf("build new addon installation %s: %w", config.ID, err)
Expand Down
Loading
Loading