Skip to content

Commit 1fecd43

Browse files
committed
internal/scaffold/olm-catalog/csv*.go: set install strategy if empty
1 parent 31846a5 commit 1fecd43

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

internal/scaffold/olm-catalog/csv_updaters.go

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

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

6072
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)
73+
strategy, err := getCSVInstallStrategy(csv)
6374
if err != nil {
6475
return err
6576
}
66-
6777
switch s := strategy.(type) {
6878
case *olminstall.StrategyDetailsDeployment:
6979
perms := []olminstall.StrategyDeploymentPermissions{}
@@ -90,12 +100,10 @@ type clusterRoles [][]byte
90100
var _ csvUpdater = clusterRoles{}
91101

92102
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)
103+
strategy, err := getCSVInstallStrategy(csv)
95104
if err != nil {
96105
return err
97106
}
98-
99107
switch s := strategy.(type) {
100108
case *olminstall.StrategyDetailsDeployment:
101109
perms := []olminstall.StrategyDeploymentPermissions{}
@@ -122,8 +130,7 @@ type deployments [][]byte
122130
var _ csvUpdater = deployments{}
123131

124132
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)
133+
strategy, err := getCSVInstallStrategy(csv)
127134
if err != nil {
128135
return err
129136
}

0 commit comments

Comments
 (0)