@@ -56,11 +56,33 @@ func (r ResourceGenerators) ResourceGenerator() ResourceGenerator {
56
56
57
57
type UniqueNameGenerator func (string , interface {}) (string , error )
58
58
59
+ // BundleConfig represents configuration options for bundle rendering
60
+ type BundleConfig struct {
61
+ // InstallMode contains install mode specific configuration
62
+ InstallMode * InstallModeConfig
63
+ }
64
+
65
+ // InstallModeConfig is a union type for install mode specific configuration
66
+ type InstallModeConfig struct {
67
+ // InstallMode specifies the install mode for the bundle
68
+ InstallMode bundle.InstallModeType
69
+
70
+ // SingleNamespaceInstallMode is required when InstallMode == "SingleNamespace"
71
+ SingleNamespaceInstallMode * SingleNamespaceInstallModeConfig
72
+ }
73
+
74
+ // SingleNamespaceInstallModeConfig contains configuration for SingleNamespace install mode
75
+ type SingleNamespaceInstallModeConfig struct {
76
+ // WatchNamespace is the namespace to watch (required)
77
+ WatchNamespace string
78
+ }
79
+
59
80
type Options struct {
60
81
InstallNamespace string
61
82
TargetNamespaces []string
62
83
UniqueNameGenerator UniqueNameGenerator
63
84
CertificateProvider CertificateProvider
85
+ BundleConfig * BundleConfig
64
86
}
65
87
66
88
func (o * Options ) apply (opts ... Option ) * Options {
@@ -83,6 +105,14 @@ func (o *Options) validate(rv1 *bundle.RegistryV1) (*Options, []error) {
83
105
if err := validateTargetNamespaces (rv1 , o .InstallNamespace , o .TargetNamespaces ); err != nil {
84
106
errs = append (errs , fmt .Errorf ("invalid target namespaces %v: %w" , o .TargetNamespaces , err ))
85
107
}
108
+
109
+ // Validate bundle configuration
110
+ if o .BundleConfig != nil {
111
+ if configErrs := validateBundleConfig (o .BundleConfig ); len (configErrs ) > 0 {
112
+ errs = append (errs , configErrs ... )
113
+ }
114
+ }
115
+
86
116
return o , errs
87
117
}
88
118
@@ -106,6 +136,12 @@ func WithCertificateProvider(provider CertificateProvider) Option {
106
136
}
107
137
}
108
138
139
+ func WithBundleConfig (config * BundleConfig ) Option {
140
+ return func (o * Options ) {
141
+ o .BundleConfig = config
142
+ }
143
+ }
144
+
109
145
type BundleRenderer struct {
110
146
BundleValidator BundleValidator
111
147
ResourceGenerators []ResourceGenerator
@@ -118,13 +154,27 @@ func (r BundleRenderer) Render(rv1 bundle.RegistryV1, installNamespace string, o
118
154
}
119
155
120
156
// generate bundle objects
121
- genOpts , errs := (& Options {
157
+ genOpts := (& Options {
122
158
// default options
123
159
InstallNamespace : installNamespace ,
124
160
TargetNamespaces : []string {metav1 .NamespaceAll },
125
161
UniqueNameGenerator : DefaultUniqueNameGenerator ,
126
162
CertificateProvider : nil ,
127
- }).apply (opts ... ).validate (& rv1 )
163
+ }).apply (opts ... )
164
+
165
+ if genOpts .BundleConfig != nil && genOpts .BundleConfig .InstallMode != nil {
166
+ switch genOpts .BundleConfig .InstallMode .InstallMode {
167
+ case bundle .InstallModeSingleNamespace :
168
+ if genOpts .BundleConfig .InstallMode .SingleNamespaceInstallMode != nil {
169
+ genOpts .TargetNamespaces = []string {genOpts .BundleConfig .InstallMode .SingleNamespaceInstallMode .WatchNamespace }
170
+ }
171
+ case bundle .InstallModeOwnNamespace :
172
+ genOpts .TargetNamespaces = []string {installNamespace }
173
+ case bundle .InstallModeAllNamespaces :
174
+ genOpts .TargetNamespaces = []string {metav1 .NamespaceAll }
175
+ }
176
+ }
177
+ genOpts , errs := genOpts .validate (& rv1 )
128
178
129
179
if len (errs ) > 0 {
130
180
return nil , fmt .Errorf ("invalid option(s): %w" , errors .Join (errs ... ))
@@ -175,3 +225,34 @@ func validateTargetNamespaces(rv1 *bundle.RegistryV1, installNamespace string, t
175
225
}
176
226
return fmt .Errorf ("supported install modes %v do not support target namespaces %v" , sets.List [string ](supportedInstallModes ), targetNamespaces )
177
227
}
228
+
229
+ // validateBundleConfig validates that the bundle configuration is internally consistent and complete
230
+ func validateBundleConfig (config * BundleConfig ) []error {
231
+ var errs []error
232
+
233
+ if config .InstallMode == nil {
234
+ return errs
235
+ }
236
+
237
+ switch config .InstallMode .InstallMode {
238
+ case bundle .InstallModeAllNamespaces :
239
+ // AllNamespaces mode should not have SingleNamespace configuration
240
+ if config .InstallMode .SingleNamespaceInstallMode != nil {
241
+ errs = append (errs , fmt .Errorf ("invalid parameter singleNamespaceInstallMode: must not be set when installMode is %q" , bundle .InstallModeAllNamespaces ))
242
+ }
243
+ case bundle .InstallModeSingleNamespace :
244
+ // SingleNamespace mode requires SingleNamespace configuration
245
+ if config .InstallMode .SingleNamespaceInstallMode == nil {
246
+ errs = append (errs , fmt .Errorf ("missing required parameter singleNamespaceInstallMode when installMode is %q" , bundle .InstallModeSingleNamespace ))
247
+ } else if config .InstallMode .SingleNamespaceInstallMode .WatchNamespace == "" {
248
+ errs = append (errs , fmt .Errorf ("missing required parameter watchNamespace in singleNamespaceInstallMode" ))
249
+ }
250
+ case bundle .InstallModeOwnNamespace :
251
+ // OwnNamespace mode should not have SingleNamespace configuration
252
+ if config .InstallMode .SingleNamespaceInstallMode != nil {
253
+ errs = append (errs , fmt .Errorf ("invalid parameter singleNamespaceInstallMode: must not be set when installMode is %q" , bundle .InstallModeOwnNamespace ))
254
+ }
255
+ }
256
+
257
+ return errs
258
+ }
0 commit comments