File tree Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ bundle.Dockerfile for your latest operator version without building the image:
108
108
}
109
109
110
110
if err = c .validate (args ); err != nil {
111
- return fmt .Errorf ("error validating args: %v" , err )
111
+ return fmt .Errorf ("invalid command args: %v" , err )
112
112
}
113
113
114
114
if c .generateOnly {
@@ -172,7 +172,7 @@ func (c *bundleCreateCmd) setDefaults() (err error) {
172
172
c .directory = dir
173
173
}
174
174
175
- // Ensure a default channel is present if there only one channel. Don't infer
175
+ // A default channel can be inferred if there is only one channel. Don't infer
176
176
// default otherwise; the user must set this value.
177
177
if c .defaultChannel == "" && strings .Count (c .channels , "," ) == 0 {
178
178
c .defaultChannel = c .channels
@@ -199,11 +199,18 @@ func (c bundleCreateCmd) validate(args []string) error {
199
199
if c .packageName == "" {
200
200
return fmt .Errorf ("--package must be set" )
201
201
}
202
+
203
+ // Ensure a default channel is present.
204
+ if c .defaultChannel == "" {
205
+ return fmt .Errorf ("--default-channel must be set" )
206
+ }
207
+
202
208
// Bundle commands only work with bundle directory formats, not package
203
209
// manifests formats.
204
210
if isPackageManifestsDir (c .directory , c .packageName ) {
205
211
return fmt .Errorf ("bundle commands can only be used on bundle directory formats" )
206
212
}
213
+
207
214
if c .generateOnly {
208
215
if len (args ) != 0 {
209
216
return errors .New ("the command does not accept any arguments if --generate-only=true" )
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
"os"
21
21
"path/filepath"
22
+ "strings"
22
23
23
24
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
24
25
"sigs.k8s.io/kubebuilder/pkg/model/config"
@@ -33,6 +34,11 @@ func (c *bundleCmd) setCommonDefaults(cfg *config.Config) {
33
34
if c .operatorName == "" {
34
35
c .operatorName = filepath .Base (cfg .Repo )
35
36
}
37
+ // A default channel can be inferred if there is only one channel. Don't infer
38
+ // default otherwise; the user must set this value.
39
+ if c .defaultChannel == "" && strings .Count (c .channels , "," ) == 0 {
40
+ c .defaultChannel = c .channels
41
+ }
36
42
}
37
43
38
44
// runKustomize generates kustomize bundle bases.
@@ -189,6 +195,16 @@ func (c bundleCmd) runManifests(cfg *config.Config) (err error) {
189
195
return nil
190
196
}
191
197
198
+ // validateMetadata validates c for bundle metadata generation.
199
+ func (c bundleCmd ) validateMetadata (* config.Config ) (err error ) {
200
+ // Ensure a default channel is present.
201
+ if c .defaultChannel == "" {
202
+ return fmt .Errorf ("--default-channel must be set if setting multiple channels" )
203
+ }
204
+
205
+ return nil
206
+ }
207
+
192
208
// runMetadata generates a bundle.Dockerfile and bundle metadata.
193
209
func (c bundleCmd ) runMetadata () error {
194
210
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package bundle
17
17
import (
18
18
"fmt"
19
19
"path/filepath"
20
+ "strings"
20
21
21
22
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
22
23
log "github.com/sirupsen/logrus"
@@ -32,6 +33,11 @@ func (c *bundleCmd) setCommonDefaultsLegacy() {
32
33
if c .operatorName == "" {
33
34
c .operatorName = filepath .Base (projutil .MustGetwd ())
34
35
}
36
+ // A default channel can be inferred if there is only one channel. Don't infer
37
+ // default otherwise; the user must set this value.
38
+ if c .defaultChannel == "" && strings .Count (c .channels , "," ) == 0 {
39
+ c .defaultChannel = c .channels
40
+ }
35
41
}
36
42
37
43
// validateManifestsLegacy validates c for bundle manifests generation for
@@ -112,6 +118,17 @@ func (c bundleCmd) runManifestsLegacy() (err error) {
112
118
return nil
113
119
}
114
120
121
+ // validateMetadataLegacy validates c for bundle metadata generation for
122
+ // legacy project layouts.
123
+ func (c bundleCmd ) validateMetadataLegacy () (err error ) {
124
+ // Ensure a default channel is present.
125
+ if c .defaultChannel == "" {
126
+ return fmt .Errorf ("--default-channel must be set if setting multiple channels" )
127
+ }
128
+
129
+ return nil
130
+ }
131
+
115
132
// runMetadataLegacy generates a bundle.Dockerfile and bundle metadata for
116
133
// legacy project layouts.
117
134
func (c bundleCmd ) runMetadataLegacy () error {
Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ func NewCmd() *cobra.Command {
104
104
}
105
105
}
106
106
if c .metadata {
107
+ if err = c .validateMetadata (cfg ); err != nil {
108
+ return fmt .Errorf ("invalid command options: %v" , err )
109
+ }
107
110
if err = c .runMetadata (); err != nil {
108
111
log .Fatalf ("Error generating bundle metadata: %v" , err )
109
112
}
@@ -164,6 +167,9 @@ func NewCmdLegacy() *cobra.Command {
164
167
}
165
168
}
166
169
if c .metadata {
170
+ if err = c .validateMetadataLegacy (); err != nil {
171
+ return fmt .Errorf ("invalid command options: %v" , err )
172
+ }
167
173
if err = c .runMetadataLegacy (); err != nil {
168
174
log .Fatalf ("Error generating bundle metadata: %v" , err )
169
175
}
You can’t perform that action at this time.
0 commit comments