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,24 +38,29 @@ 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 <>();
43
47
private final Path kubernetesResources ;
44
48
private final String deploymentName ;
45
49
private final List <ReconcilerAugmentedClassInfo > controllers ;
46
50
51
+ @ SuppressWarnings ("rawtypes" )
47
52
public CsvManifestsBuilder (CSVMetadataHolder metadata , BuildTimeOperatorConfiguration operatorConfiguration ,
48
53
List <ReconcilerAugmentedClassInfo > controllers ,
49
- Path mainSourcesRoot , String deploymentName ) {
54
+ Path mainSourcesRoot , String deploymentName , Map < String , QuarkusControllerConfiguration > controllerConfigs ) {
50
55
super (metadata );
51
56
this .deploymentName = deploymentName ;
52
57
this .controllers = controllers ;
53
58
this .kubernetesResources = mainSourcesRoot != null ? mainSourcesRoot .resolve ("kubernetes" ) : null ;
54
59
55
60
csvBuilder = new ClusterServiceVersionBuilder ();
56
61
57
- final var metadataBuilder = csvBuilder .withNewMetadata ().withName (getName ());
62
+ final var name = getName ();
63
+ final var metadataBuilder = csvBuilder .withNewMetadata ().withName (name );
58
64
if (metadata .annotations != null ) {
59
65
metadataBuilder .addToAnnotations ("olm.skipRange" , metadata .annotations .skipRange );
60
66
metadataBuilder .addToAnnotations ("containerImage" , metadata .annotations .containerImage );
@@ -72,7 +78,7 @@ public CsvManifestsBuilder(CSVMetadataHolder metadata, BuildTimeOperatorConfigur
72
78
final var csvSpecBuilder = csvBuilder
73
79
.editOrNewSpec ()
74
80
.withDescription (metadata .description )
75
- .withDisplayName (defaultIfEmpty (metadata .displayName , getName () ))
81
+ .withDisplayName (defaultIfEmpty (metadata .displayName , name ))
76
82
.withKeywords (metadata .keywords )
77
83
.withReplaces (metadata .replaces )
78
84
.withVersion (metadata .version )
@@ -135,14 +141,6 @@ public CsvManifestsBuilder(CSVMetadataHolder metadata, BuildTimeOperatorConfigur
135
141
}
136
142
}
137
143
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
144
// add owned and required CRD, also collect them
147
145
final var nativeApis = new ArrayList <GroupVersionKind >();
148
146
controllers .forEach (raci -> {
@@ -181,6 +179,29 @@ public CsvManifestsBuilder(CSVMetadataHolder metadata, BuildTimeOperatorConfigur
181
179
}
182
180
});
183
181
}
182
+
183
+ // deal with install modes
184
+ // use watched namespaces information for default install mode
185
+ // fixme: multiple, incompatible controller configurations in the same bundle will result in inconsistent runs
186
+ final var config = controllerConfigs .get (raci .nameOrFailIfUnset ());
187
+ if (config .watchAllNamespaces ()) {
188
+ csvSpecBuilder .withInstallModes (new InstallMode (true , ALL_NAMESPACES ));
189
+ } else if (config .watchCurrentNamespace ()) {
190
+ csvSpecBuilder .withInstallModes (new InstallMode (true , OWN_NAMESPACE ));
191
+ } else {
192
+ final var namespaces = config .getNamespaces ();
193
+ if (namespaces .size () == 1 ) {
194
+ csvSpecBuilder .withInstallModes (new InstallMode (true , SINGLE_NAMESPACE ));
195
+ } else {
196
+ csvSpecBuilder .withInstallModes (new InstallMode (true , MULTI_NAMESPACE ));
197
+ }
198
+ }
199
+ // then process metadata
200
+ if (metadata .installModes != null ) {
201
+ for (CSVMetadataHolder .InstallMode installMode : metadata .installModes ) {
202
+ csvSpecBuilder .addNewInstallMode (installMode .supported , installMode .type );
203
+ }
204
+ }
184
205
});
185
206
186
207
// add required CRDs from CSV metadata
0 commit comments