Skip to content

internal/scaffold/olm-catalog/csv*.go: set install strategy if empty #2298

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

Merged
merged 2 commits into from
Dec 6, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Fix issue faced in the Ansible based operators when `jmespath` queries are used because it was not installed. ([#2252](https://github.com/operator-framework/operator-sdk/pull/2252))
- Fix scorecard behavior such that a CSV file is read correctly when `olm-deployed` is set to `true`. ([#2274](https://github.com/operator-framework/operator-sdk/pull/2274))
- A CSV config's `operator-name` field will be used if `--operator-name` is not set. ([#2297](https://github.com/operator-framework/operator-sdk/pull/2297))
- Populates a CSV's `spec.install` strategy if either name or strategy body are missing with a deployment-type strategy. ([#2298](https://github.com/operator-framework/operator-sdk/pull/2298))

## v0.12.0

Expand Down
22 changes: 14 additions & 8 deletions internal/scaffold/olm-catalog/csv_updaters.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ type csvUpdater interface {
apply(*olmapiv1alpha1.ClusterServiceVersion) error
}

// Get install strategy from csv.
func getCSVInstallStrategy(csv *olmapiv1alpha1.ClusterServiceVersion) (strategy olminstall.Strategy, err error) {
// Default to a deployment strategy if none found.
if len(csv.Spec.InstallStrategy.StrategySpecRaw) == 0 || csv.Spec.InstallStrategy.StrategyName == "" {
csv.Spec.InstallStrategy.StrategyName = olminstall.InstallStrategyNameDeployment
return &olminstall.StrategyDetailsDeployment{}, nil
}
return (&olminstall.StrategyResolver{}).UnmarshalStrategy(csv.Spec.InstallStrategy)
}

// Set csv's spec.install to strategy.
func setCSVInstallStrategy(csv *olmapiv1alpha1.ClusterServiceVersion, strategy olminstall.Strategy) error {
sb, err := json.Marshal(strategy)
if err != nil {
Expand All @@ -58,12 +69,10 @@ type roles [][]byte
var _ csvUpdater = roles{}

func (us roles) apply(csv *olmapiv1alpha1.ClusterServiceVersion) (err error) {
// Get install strategy from csv. Default to a deployment strategy if none found.
strategy, err := (&olminstall.StrategyResolver{}).UnmarshalStrategy(csv.Spec.InstallStrategy)
strategy, err := getCSVInstallStrategy(csv)
if err != nil {
return err
}

switch s := strategy.(type) {
case *olminstall.StrategyDetailsDeployment:
perms := []olminstall.StrategyDeploymentPermissions{}
Expand All @@ -90,12 +99,10 @@ type clusterRoles [][]byte
var _ csvUpdater = clusterRoles{}

func (us clusterRoles) apply(csv *olmapiv1alpha1.ClusterServiceVersion) (err error) {
// Get install strategy from csv. Default to a deployment strategy if none found.
strategy, err := (&olminstall.StrategyResolver{}).UnmarshalStrategy(csv.Spec.InstallStrategy)
strategy, err := getCSVInstallStrategy(csv)
if err != nil {
return err
}

switch s := strategy.(type) {
case *olminstall.StrategyDetailsDeployment:
perms := []olminstall.StrategyDeploymentPermissions{}
Expand All @@ -122,8 +129,7 @@ type deployments [][]byte
var _ csvUpdater = deployments{}

func (us deployments) apply(csv *olmapiv1alpha1.ClusterServiceVersion) (err error) {
// Get install strategy from csv. Default to a deployment strategy if none found.
strategy, err := (&olminstall.StrategyResolver{}).UnmarshalStrategy(csv.Spec.InstallStrategy)
strategy, err := getCSVInstallStrategy(csv)
if err != nil {
return err
}
Expand Down