Skip to content

Commit a1fc629

Browse files
committed
docs: add bundle metadata details, improve tests
Signed-off-by: Chris Laprun <[email protected]>
1 parent 2a65694 commit a1fc629

File tree

7 files changed

+47
-12
lines changed

7 files changed

+47
-12
lines changed

annotations/src/main/java/io/quarkiverse/operatorsdk/annotations/CSVMetadata.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@
55
import java.lang.annotation.RetentionPolicy;
66
import java.lang.annotation.Target;
77

8+
/**
9+
* Provides more information to generate more detailed OLM bundle manifests, in particular in the ClusterServiceVersion
10+
* resource. This can be used to provide information that cannot be inferred automatically or override what is generated by
11+
* default. Many of these fields map to CSV fields. See the OLM documentation on
12+
* <a href="https://olm.operatorframework.io/docs/tasks/creating-operator-manifests/#basic-metadata-optional">operator
13+
* manifests</a> for more details.
14+
*/
815
@Retention(RetentionPolicy.RUNTIME)
916
@Target({ ElementType.TYPE })
1017
@SuppressWarnings("unused")
1118
public @interface CSVMetadata {
19+
/**
20+
* The name which should be used for the generated bundle. If not provided, the name is derived from the project's (maven or
21+
* gradle) name. This name can be used to assign reconcilers to the same bundle by creating a {@link SharedCSVMetadata}
22+
* implementation bearing a {@link CSVMetadata} annotation specifying the CSV metadata to be shared among reconcilers
23+
* assigned to that named bundle.
24+
*/
1225
String name() default "";
1326

27+
/**
28+
* Extra annotations that should be added to the CSV metadata.
29+
*/
1430
Annotations annotations() default @Annotations;
1531

1632
String description() default "";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
package io.quarkiverse.operatorsdk.annotations;
22

3+
/**
4+
* A marker interface used to identify classes bearing {@link CSVMetadata} that needs to be shared across reconcilers using the
5+
* same {@link CSVMetadata#name()} attribute. Note that sharing metadata without using {@link SharedCSVMetadata} is not allowed.
6+
*/
37
public interface SharedCSVMetadata {
48
}

bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/MultipleReconcilerWithSharedMetadataBundleTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.quarkiverse.operatorsdk.bundle;
22

33
import static io.quarkiverse.operatorsdk.bundle.Utils.checkBundleFor;
4+
import static io.quarkiverse.operatorsdk.bundle.Utils.getCSVFor;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
46

57
import java.io.IOException;
68

@@ -29,8 +31,11 @@ public class MultipleReconcilerWithSharedMetadataBundleTest {
2931
@Test
3032
public void shouldWriteBundleForTheOperators() throws IOException {
3133
final var bundle = prodModeTestResults.getBuildDir().resolve(Utils.BUNDLE);
32-
checkBundleFor(bundle, "shared", null);
34+
checkBundleFor(bundle, AReconciler.SHARED, null);
3335
// reconcilers with no csv metadata should use the application name
3436
checkBundleFor(bundle, APPLICATION_NAME, null);
37+
38+
final var csv = getCSVFor(bundle, AReconciler.SHARED);
39+
assertEquals(AReconciler.SHARED_VERSION, csv.getSpec().getVersion());
3540
}
3641
}

bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/sources/AReconciler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import io.quarkiverse.operatorsdk.annotations.CSVMetadata;
88
import io.quarkiverse.operatorsdk.annotations.SharedCSVMetadata;
99

10-
@CSVMetadata(name = "shared", version = "0.0.1")
10+
@CSVMetadata(name = AReconciler.SHARED, version = AReconciler.SHARED_VERSION)
1111
public class AReconciler implements Reconciler<ConfigMap>, SharedCSVMetadata {
1212

13+
public static final String SHARED_VERSION = "0.0.1";
14+
public static final String SHARED = "shared";
15+
1316
@Override
14-
public UpdateControl<ConfigMap> reconcile(ConfigMap configMap, Context<ConfigMap> context)
15-
throws Exception {
17+
public UpdateControl<ConfigMap> reconcile(ConfigMap configMap, Context<ConfigMap> context) {
1618
return null;
1719
}
1820
}

bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/sources/BReconciler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
77
import io.quarkiverse.operatorsdk.annotations.CSVMetadata;
88

9-
@CSVMetadata(name = "shared", version = "0.0.2")
9+
@CSVMetadata(name = AReconciler.SHARED, version = "0.0.2")
1010
public class BReconciler implements Reconciler<Service> {
1111

1212
@Override
13-
public UpdateControl<Service> reconcile(Service service, Context<Service> context)
14-
throws Exception {
13+
public UpdateControl<Service> reconcile(Service service, Context<Service> context) {
1514
return null;
1615
}
1716
}

docs/modules/ROOT/pages/deploy-with-olm.adoc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,23 @@ If, for some reason, you need that label to be added to the selectors, just set
6363

6464
While the extension attempts to infer a lot of the required information from your project itself and it is possible to generate valid bundles without providing extra information, it might still be useful or needed to specify additional metadata to help the generation process or provide data that cannot be inferred.
6565

66-
The way this is accomplished is using the `CSVMetadata` and its associated annotations.
66+
This is accomplished is using the `io.quarkiverse.operatorsdk.annotations.CSVMetadata` and its associated annotations from the `quarkus-operator-sdk-annotations` module. `CSVMetadata` is meant to annotate your reconciler instances.
6767

68-
----- TODO: add more details on CSVMetadata ------
68+
By default, manifests for all reconcilers in a given operator will be generated as part of the same bundle, using a name automatically inferred from the project's name.
69+
It is, however, possible to split the reconcilers among several bundles by assigning reconcilers to different bundle names.
70+
One bundle will be created per specified bundle name.
71+
To associate a reconciler with a bundle name, you need to put the shared metadata (in the form of `CSVMetadata` annotation) on a class implementing the `io.quarkiverse.operatorsdk.annotations.SharedCSVMetadata` marker interface, specifying the desired bundle name on the associated `CSVMetadata` annotation.
72+
All reconcilers annotated with `CSVMetadata` using the same name as one of the `SharedCSVMetadata` classes will be assigned to the same bundle and share the associated metadata. Any value specified on `CSVMetadata` annotations that designate a reconciler as sharing metadata coming from a `SharedCSVMetadata` source will be **ignored**.
73+
74+
You can see this behavior in action in the tests of the `quarkus-operator-sdk-bundle-generator-deployment` module.
75+
76+
Note:
77+
If you provide a `SharedCSVMetadata` implementation without specifying a bundle name, then the specified metadata will be shared among all reconcilers that don't specify an explicit bundle name.
6978

7079
=== Validating the generated bundle
7180

72-
It is recommended that you validate your bundle before proceeding further. The recommended way to do so is to run the following command:
81+
It is recommended that you validate your bundle before proceeding further.
82+
The recommended way to do so is to run the following command:
7383

7484
[source,shell script]
7585
----

samples/exposedapp/src/main/java/io/halkyon/ExposedAppReconciler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
@Dependent(name = "service", type = ServiceDependent.class),
2121
@Dependent(type = IngressDependent.class, readyPostcondition = IngressDependent.class)
2222
})
23-
@CSVMetadata(displayName = "ExposedApp operator", description = "A sample operator that shows how to use JOSDK's main features with the Quarkus extension",
24-
provider = @CSVMetadata.Provider(name = "Christophe Laprun", url = "https://github.com/metacosm"))
23+
@CSVMetadata(displayName = "ExposedApp operator", description = "A sample operator that shows how to use JOSDK's main features with the Quarkus extension", provider = @CSVMetadata.Provider(name = "Christophe Laprun", url = "https://github.com/metacosm"))
2524
public class ExposedAppReconciler implements Reconciler<ExposedApp>,
2625
ContextInitializer<ExposedApp> {
2726

0 commit comments

Comments
 (0)