Skip to content

Commit 72c9e6e

Browse files
committed
internal/scaffold/olm-catalog/csv*.go: set install strategy if empty
CHANGELOG.md: add bugfix
1 parent 31846a5 commit 72c9e6e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
### Bug Fixes
2626
- 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))
2727
- 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))
28+
- 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))
2829

2930
## v0.12.0
3031

internal/scaffold/olm-catalog/csv_updaters.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ type csvUpdater interface {
4444
apply(*olmapiv1alpha1.ClusterServiceVersion) error
4545
}
4646

47+
// Get install strategy from csv.
48+
func getCSVInstallStrategy(csv *olmapiv1alpha1.ClusterServiceVersion) (strategy olminstall.Strategy, err error) {
49+
// Default to a deployment strategy if none found.
50+
if len(csv.Spec.InstallStrategy.StrategySpecRaw) == 0 || csv.Spec.InstallStrategy.StrategyName == "" {
51+
csv.Spec.InstallStrategy.StrategyName = olminstall.InstallStrategyNameDeployment
52+
return &olminstall.StrategyDetailsDeployment{}, nil
53+
}
54+
return (&olminstall.StrategyResolver{}).UnmarshalStrategy(csv.Spec.InstallStrategy)
55+
}
56+
57+
// Set csv's spec.install to strategy.
4758
func setCSVInstallStrategy(csv *olmapiv1alpha1.ClusterServiceVersion, strategy olminstall.Strategy) error {
4859
sb, err := json.Marshal(strategy)
4960
if err != nil {
@@ -58,12 +69,10 @@ type roles [][]byte
5869
var _ csvUpdater = roles{}
5970

6071
func (us roles) apply(csv *olmapiv1alpha1.ClusterServiceVersion) (err error) {
61-
// Get install strategy from csv. Default to a deployment strategy if none found.
62-
strategy, err := (&olminstall.StrategyResolver{}).UnmarshalStrategy(csv.Spec.InstallStrategy)
72+
strategy, err := getCSVInstallStrategy(csv)
6373
if err != nil {
6474
return err
6575
}
66-
6776
switch s := strategy.(type) {
6877
case *olminstall.StrategyDetailsDeployment:
6978
perms := []olminstall.StrategyDeploymentPermissions{}
@@ -90,12 +99,10 @@ type clusterRoles [][]byte
9099
var _ csvUpdater = clusterRoles{}
91100

92101
func (us clusterRoles) apply(csv *olmapiv1alpha1.ClusterServiceVersion) (err error) {
93-
// Get install strategy from csv. Default to a deployment strategy if none found.
94-
strategy, err := (&olminstall.StrategyResolver{}).UnmarshalStrategy(csv.Spec.InstallStrategy)
102+
strategy, err := getCSVInstallStrategy(csv)
95103
if err != nil {
96104
return err
97105
}
98-
99106
switch s := strategy.(type) {
100107
case *olminstall.StrategyDetailsDeployment:
101108
perms := []olminstall.StrategyDeploymentPermissions{}
@@ -122,8 +129,7 @@ type deployments [][]byte
122129
var _ csvUpdater = deployments{}
123130

124131
func (us deployments) apply(csv *olmapiv1alpha1.ClusterServiceVersion) (err error) {
125-
// Get install strategy from csv. Default to a deployment strategy if none found.
126-
strategy, err := (&olminstall.StrategyResolver{}).UnmarshalStrategy(csv.Spec.InstallStrategy)
132+
strategy, err := getCSVInstallStrategy(csv)
127133
if err != nil {
128134
return err
129135
}

0 commit comments

Comments
 (0)