23
23
import io .quarkiverse .operatorsdk .bundle .runtime .CSVMetadataHolder .RequiredCRD ;
24
24
import io .quarkiverse .operatorsdk .common .*;
25
25
import io .quarkiverse .operatorsdk .runtime .BuildTimeOperatorConfiguration ;
26
+ import io .quarkiverse .operatorsdk .runtime .QuarkusControllerConfiguration ;
26
27
27
28
public class CsvManifestsBuilder extends ManifestsBuilder {
28
29
29
30
private static final Logger log = Logger .getLogger (CsvManifestsBuilder .class );
30
31
31
- private static final String DEFAULT_INSTALL_MODE = "AllNamespaces" ;
32
+ private static final String ALL_NAMESPACES = "AllNamespaces" ;
32
33
private static final String DEPLOYMENT = "deployment" ;
33
34
private static final String SERVICE_ACCOUNT_KIND = "ServiceAccount" ;
34
35
private static final String CLUSTER_ROLE_KIND = "ClusterRole" ;
@@ -37,6 +38,9 @@ public class CsvManifestsBuilder extends ManifestsBuilder {
37
38
private static final Logger LOGGER = Logger .getLogger (CsvManifestsBuilder .class .getName ());
38
39
private static final String IMAGE_PNG = "image/png" ;
39
40
public static final String OLM_TARGET_NAMESPACES = "metadata.annotations['olm.targetNamespaces']" ;
41
+ public static final String OWN_NAMESPACE = "OwnNamespace" ;
42
+ public static final String SINGLE_NAMESPACE = "SingleNamespace" ;
43
+ public static final String MULTI_NAMESPACE = "MultiNamespace" ;
40
44
private ClusterServiceVersionBuilder csvBuilder ;
41
45
private final Set <CRDDescription > ownedCRs = new HashSet <>();
42
46
private final Set <CRDDescription > requiredCRs = new HashSet <>();
@@ -46,7 +50,7 @@ public class CsvManifestsBuilder extends ManifestsBuilder {
46
50
47
51
public CsvManifestsBuilder (CSVMetadataHolder metadata , BuildTimeOperatorConfiguration operatorConfiguration ,
48
52
List <ReconcilerAugmentedClassInfo > controllers ,
49
- Path mainSourcesRoot , String deploymentName ) {
53
+ Path mainSourcesRoot , String deploymentName , Map < String , QuarkusControllerConfiguration <?>> controllerConfigs ) {
50
54
super (metadata );
51
55
this .deploymentName = deploymentName ;
52
56
this .controllers = controllers ;
@@ -135,14 +139,6 @@ public CsvManifestsBuilder(CSVMetadataHolder metadata, BuildTimeOperatorConfigur
135
139
}
136
140
}
137
141
138
- if (metadata .installModes == null || metadata .installModes .length == 0 ) {
139
- csvSpecBuilder .addNewInstallMode (true , DEFAULT_INSTALL_MODE );
140
- } else {
141
- for (CSVMetadataHolder .InstallMode installMode : metadata .installModes ) {
142
- csvSpecBuilder .addNewInstallMode (installMode .supported , installMode .type );
143
- }
144
- }
145
-
146
142
// add owned and required CRD, also collect them
147
143
final var nativeApis = new ArrayList <GroupVersionKind >();
148
144
controllers .forEach (raci -> {
@@ -181,6 +177,29 @@ public CsvManifestsBuilder(CSVMetadataHolder metadata, BuildTimeOperatorConfigur
181
177
}
182
178
});
183
179
}
180
+
181
+ // deal with install modes
182
+ // use watched namespaces information for default install mode
183
+ // fixme: multiple, incompatible controller configurations in the same bundle will result in inconsistent runs
184
+ final var config = controllerConfigs .get (raci .nameOrFailIfUnset ());
185
+ if (config .watchAllNamespaces ()) {
186
+ csvSpecBuilder .withInstallModes (new InstallMode (true , ALL_NAMESPACES ));
187
+ } else if (config .watchCurrentNamespace ()) {
188
+ csvSpecBuilder .withInstallModes (new InstallMode (true , OWN_NAMESPACE ));
189
+ } else {
190
+ final var namespaces = config .getNamespaces ();
191
+ if (namespaces .size () == 1 ) {
192
+ csvSpecBuilder .withInstallModes (new InstallMode (true , SINGLE_NAMESPACE ));
193
+ } else {
194
+ csvSpecBuilder .withInstallModes (new InstallMode (true , MULTI_NAMESPACE ));
195
+ }
196
+ }
197
+ // then process metadata
198
+ if (metadata .installModes != null ) {
199
+ for (CSVMetadataHolder .InstallMode installMode : metadata .installModes ) {
200
+ csvSpecBuilder .addNewInstallMode (installMode .supported , installMode .type );
201
+ }
202
+ }
184
203
});
185
204
186
205
// add required CRDs from CSV metadata
0 commit comments