Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7988-added labels and annotation keys into api module #9103

Merged
merged 4 commits into from Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .checkstyle/import-control.xml
Expand Up @@ -38,6 +38,8 @@ We also control imports only in production classes and not in tests. This is con
<!-- Strimzi Operators classes -->
<allow pkg="io.strimzi.api.annotations" />
<allow pkg="io.strimzi.api.kafka" />
<allow class="io.strimzi.api.ResourceLabels" />
<allow class="io.strimzi.api.ResourceAnotations" />
<allow pkg="io.strimzi.certs" />
<allow pkg="io.strimzi.operator.common.model" />
<allow class="io.strimzi.operator.common.Reconciliation" />
Expand Down
105 changes: 105 additions & 0 deletions api/src/main/java/io/strimzi/api/ResourceAnnotations.java
@@ -0,0 +1,105 @@
/*
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.strimzi.api;

/**
* Class for holding some annotation keys.
*/
public class ResourceAnnotations {
/**
* The Strimzi domain used in all annotations
*/
public static final String STRIMZI_DOMAIN = "strimzi.io/";

/**
* Annotation used to force rebuild of the container image even if the
* dockerfile did not change
*/
public static final String STRIMZI_IO_CONNECT_FORCE_REBUILD = STRIMZI_DOMAIN + "force-rebuild";

/**
* Annotation used to pause resource reconciliation
*/
public static final String ANNO_STRIMZI_IO_PAUSE_RECONCILIATION = STRIMZI_DOMAIN + "pause-reconciliation";

/**
* Annotation to trigger manually rolling updats
*/
public static final String ANNO_STRIMZI_IO_MANUAL_ROLLING_UPDATE = STRIMZI_DOMAIN + "manual-rolling-update";

/**
* This annotation with related possible values (approve, stop, refresh) is set
* by the user for interacting
* with the rebalance operator in order to start, stop, or refresh rebalancing
* proposals and operations.
*/
public static final String ANNO_STRIMZI_IO_REBALANCE = STRIMZI_DOMAIN + "rebalance";

/**
* Use this boolean annotation to auto-approve a rebalance optimization proposal
* without the need for the
* manual approval by applying the strimzi.io/rebalance=approve annotation
*/
public static final String ANNO_STRIMZI_IO_REBALANCE_AUTOAPPROVAL = STRIMZI_DOMAIN + "rebalance-auto-approval";

/**
* Annotation for restarting Mirror Maker 2 connector
*/
public static final String ANNO_STRIMZI_IO_RESTART_CONNECTOR = STRIMZI_DOMAIN + "restart-connector";

/**
* Annotation for restarting KafkaConnector task
*/
public static final String ANNO_STRIMZI_IO_RESTART_TASK = STRIMZI_DOMAIN + "restart-task";

/**
* Annotation for restarting Mirror Maker 2 connector task
*/
public static final String ANNO_STRIMZI_IO_RESTART_CONNECTOR_TASK = STRIMZI_DOMAIN + "restart-connector-task";

/**
* Key for specifying which Mirror Maker 2 connector should be restarted
*/
public static final String ANNO_STRIMZI_IO_RESTART_CONNECTOR_TASK_PATTERN_CONNECTOR = "connector";

/**
* Key for specifying which Mirror Maker 2 connector task should be restarted
*/
public static final String ANNO_STRIMZI_IO_RESTART_CONNECTOR_TASK_PATTERN_TASK = "task";

/**
* Annotation for configuring the ranges of node IDs which should be used for
* given node pool
*/
public static final String ANNO_STRIMZI_IO_NEXT_NODE_IDS = STRIMZI_DOMAIN + "next-node-ids";

/**
* Annotation for configuring the ranges of node IDs which should be used for
* given node pool
*/
public static final String ANNO_STRIMZI_IO_REMOVE_NODE_IDS = STRIMZI_DOMAIN + "remove-node-ids";

/**
* Annotation for enabling or disabling the Node Pools. This annotation is used
* on the Kafka CR
*/
public static final String ANNO_STRIMZI_IO_NODE_POOLS = STRIMZI_DOMAIN + "node-pools";

/**
* Annotation key for deleting both a Pod and a related PVC
*/
public static final String ANNO_STRIMZI_IO_DELETE_POD_AND_PVC = STRIMZI_DOMAIN + "delete-pod-and-pvc";

/**
* Annotation for requesting a renewal of the CA and rolling it out
*/
public static final String ANNO_STRIMZI_IO_FORCE_RENEW = STRIMZI_DOMAIN + "force-renew";

/**
* Annotation for requesting a brand-new CA to be generated and rolled out
*/
public static final String ANNO_STRIMZI_IO_FORCE_REPLACE = STRIMZI_DOMAIN + "force-replace";

}
48 changes: 48 additions & 0 deletions api/src/main/java/io/strimzi/api/ResourceLabels.java
@@ -0,0 +1,48 @@
/*
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.strimzi.api;

/**
* An immutable set of labels
*/
public class ResourceLabels {
/**
* Strimzi domain used for the Strimzi labels
*/
public static final String STRIMZI_DOMAIN = "strimzi.io/";

/**
* The kind of a Kubernetes / OpenShift Resource. It contains the same value as the Kind of the corresponding
* Custom Resource. It should have on of the following values:
*
* <ul>
* <li>Kafka</li>
* <li>KafkaConnect</li>
* <li>KafkaMirrorMaker</li>
* <li>KafkaBridge</li>
* <li>KafkaUser</li>
* <li>KafkaTopic</li>
* </ul>
*/
public static final String STRIMZI_KIND_LABEL = STRIMZI_DOMAIN + "kind";

/**
* The Strimzi cluster the resource is part of. This is typically the name of the custom resource.
*/
public static final String STRIMZI_CLUSTER_LABEL = STRIMZI_DOMAIN + "cluster";

/**
* Type of the Strimzi component to which given resource belongs. E.g. Kafka or ZooKeeper. This label does not
* depend on the name of the cluster. This is useful to identify resources which belong to the same component but
* different clusters which is useful for example for scheduling (e.g. when you do not want this broker to be
* scheduled on a node where any other Kafka broker is running).
*/
public static final String STRIMZI_COMPONENT_TYPE_LABEL = STRIMZI_DOMAIN + "component-type";

/**
* Name of the component to which given resource belongs. This typically consists of the cluster name and component.
*/
public static final String STRIMZI_NAME_LABEL = STRIMZI_DOMAIN + "name";
}
Expand Up @@ -15,7 +15,6 @@
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.ReconciliationLogger;
import io.strimzi.operator.common.model.Labels;
import io.strimzi.operator.common.operator.resource.AbstractScalableNamespacedResourceOperator;
import io.strimzi.operator.common.operator.resource.PodOperator;
import io.strimzi.operator.common.operator.resource.PvcOperator;
import io.vertx.core.Future;
Expand Down Expand Up @@ -99,7 +98,7 @@ public Future<Void> maybeManualPodCleaning() {
// Only one pod per reconciliation is rolled
Pod podToClean = pods
.stream()
.filter(pod -> Annotations.booleanAnnotation(pod, AbstractScalableNamespacedResourceOperator.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, false))
.filter(pod -> Annotations.booleanAnnotation(pod, Annotations.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, false))
.findFirst()
.orElse(null);

Expand Down Expand Up @@ -205,7 +204,7 @@ private Future<Void> deletePodAndPvc(String podName, List<PersistentVolumeClaim>

for (PersistentVolumeClaim pvc : deletePvcs) {
String pvcName = pvc.getMetadata().getName();
LOGGER.debugCr(reconciliation, "Deleting PVC {} for Pod {} based on {} annotation", pvcName, podName, AbstractScalableNamespacedResourceOperator.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC);
LOGGER.debugCr(reconciliation, "Deleting PVC {} for Pod {} based on {} annotation", pvcName, podName, Annotations.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC);
deleteResults.add(pvcOperator.deleteAsync(reconciliation, reconciliation.namespace(), pvcName, true));
}
return Future.join(deleteResults);
Expand Down
Expand Up @@ -9,6 +9,7 @@
import io.strimzi.api.kafka.model.CertificateExpirationPolicy;
import io.strimzi.certs.OpenSslCertManager;
import io.strimzi.operator.common.model.PasswordGenerator;
import io.strimzi.operator.common.Annotations;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.model.Ca;
import io.strimzi.test.annotations.ParallelSuite;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void testRemoveExpiredCertificate() {
// force key replacement so certificate renewal ...
Secret caKeySecretWithReplaceAnno = new SecretBuilder(clusterCa.caKeySecret())
.editMetadata()
.addToAnnotations(Ca.ANNO_STRIMZI_IO_FORCE_REPLACE, "true")
.addToAnnotations(Annotations.ANNO_STRIMZI_IO_FORCE_REPLACE, "true")
.endMetadata()
.build();
// ... simulated at the following time, with expire at 365 days later (by default)
Expand Down Expand Up @@ -105,7 +106,7 @@ public void testRemoveOldCertificate() {
// force key replacement so certificate renewal ...
Secret caKeySecretWithReplaceAnno = new SecretBuilder(clusterCa.caKeySecret())
.editMetadata()
.addToAnnotations(Ca.ANNO_STRIMZI_IO_FORCE_REPLACE, "true")
.addToAnnotations(Annotations.ANNO_STRIMZI_IO_FORCE_REPLACE, "true")
.endMetadata()
.build();
// ... simulated at the following time, with expire at 365 days later (by default)
Expand Down
Expand Up @@ -13,9 +13,9 @@
import io.strimzi.operator.cluster.ResourceUtils;
import io.strimzi.operator.cluster.model.PodSetUtils;
import io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier;
import io.strimzi.operator.common.Annotations;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.model.Labels;
import io.strimzi.operator.common.operator.resource.AbstractScalableNamespacedResourceOperator;
import io.strimzi.operator.common.operator.resource.PodOperator;
import io.strimzi.operator.common.operator.resource.PvcOperator;
import io.strimzi.operator.common.operator.resource.StrimziPodSetOperator;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class ManualPodCleanerTest {
public void testManualPodCleanupOnePodWithPodSets(VertxTestContext context) {
List<Pod> pods = List.of(
podWithName(CONTROLLER_NAME + "-0"),
podWithNameAndAnnotations(CONTROLLER_NAME + "-1", Collections.singletonMap(AbstractScalableNamespacedResourceOperator.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, "true")),
podWithNameAndAnnotations(CONTROLLER_NAME + "-1", Collections.singletonMap(Annotations.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, "true")),
podWithName(CONTROLLER_NAME + "-2")
);

Expand All @@ -65,7 +65,7 @@ public void testManualPodCleanupOnePodWithPodSets(VertxTestContext context) {
public void testManualPodCleanupJbodWithPodSets(VertxTestContext context) {
List<Pod> pods = List.of(
podWithName(CONTROLLER_NAME + "-0"),
podWithNameAndAnnotations(CONTROLLER_NAME + "-1", Collections.singletonMap(AbstractScalableNamespacedResourceOperator.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, "true")),
podWithNameAndAnnotations(CONTROLLER_NAME + "-1", Collections.singletonMap(Annotations.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, "true")),
podWithName(CONTROLLER_NAME + "-2")
);

Expand All @@ -85,8 +85,8 @@ public void testManualPodCleanupJbodWithPodSets(VertxTestContext context) {
public void testManualPodCleanupMultiplePodsWithPodSets(VertxTestContext context) {
List<Pod> pods = List.of(
podWithName(CONTROLLER_NAME + "-0"),
podWithNameAndAnnotations(CONTROLLER_NAME + "-1", Collections.singletonMap(AbstractScalableNamespacedResourceOperator.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, "true")),
podWithNameAndAnnotations(CONTROLLER_NAME + "-2", Collections.singletonMap(AbstractScalableNamespacedResourceOperator.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, "true"))
podWithNameAndAnnotations(CONTROLLER_NAME + "-1", Collections.singletonMap(Annotations.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, "true")),
podWithNameAndAnnotations(CONTROLLER_NAME + "-2", Collections.singletonMap(Annotations.ANNO_STRIMZI_IO_DELETE_POD_AND_PVC, "true"))
);

List<PersistentVolumeClaim> pvcs = List.of(
Expand Down
Expand Up @@ -8,6 +8,7 @@
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.PodTemplateSpec;
import io.fabric8.kubernetes.client.CustomResource;
import io.strimzi.api.ResourceAnnotations;

import java.util.HashMap;
import java.util.List;
Expand All @@ -21,11 +22,7 @@
/**
* Class for holding some annotation keys and utility methods for handling annotations
*/
public class Annotations {
/**
* The Strimzi domain used in all annotations
*/
public static final String STRIMZI_DOMAIN = "strimzi.io/";
public class Annotations extends ResourceAnnotations {

/**
* Annotation for keeping Kafka and ZooKeeper servers' certificate thumbprints.
Expand Down Expand Up @@ -69,63 +66,11 @@ public class Annotations {
*/
public static final String STRIMZI_IO_CONNECT_BUILD_IMAGE = STRIMZI_DOMAIN + "connect-build-image";

/**
* Annotation used to force rebuild of the container image even if the dockerfile did not changed
*/
public static final String STRIMZI_IO_CONNECT_FORCE_REBUILD = STRIMZI_DOMAIN + "force-rebuild";

/**
* Annotation used to pause resource reconciliation
*/
public static final String ANNO_STRIMZI_IO_PAUSE_RECONCILIATION = STRIMZI_DOMAIN + "pause-reconciliation";

/**
* Annotation to trigger manually rolling updats
*/
public static final String ANNO_STRIMZI_IO_MANUAL_ROLLING_UPDATE = STRIMZI_DOMAIN + "manual-rolling-update";

/**
* This annotation with related possible values (approve, stop, refresh) is set by the user for interacting
* with the rebalance operator in order to start, stop, or refresh rebalancing proposals and operations.
*/
public static final String ANNO_STRIMZI_IO_REBALANCE = STRIMZI_DOMAIN + "rebalance";

/**
* Use this boolean annotation to auto-approve a rebalance optimization proposal without the need for the
* manual approval by applying the strimzi.io/rebalance=approve annotation
*/
public static final String ANNO_STRIMZI_IO_REBALANCE_AUTOAPPROVAL = STRIMZI_DOMAIN + "rebalance-auto-approval";

/**
* Annotation for restarting KafkaConnector
*/
public static final String ANNO_STRIMZI_IO_RESTART = STRIMZI_DOMAIN + "restart";

/**
* Annotation for restarting Mirror Maker 2 connector
*/
public static final String ANNO_STRIMZI_IO_RESTART_CONNECTOR = STRIMZI_DOMAIN + "restart-connector";

/**
* Annotation for restarting KafkaConnector task
*/
public static final String ANNO_STRIMZI_IO_RESTART_TASK = STRIMZI_DOMAIN + "restart-task";

/**
* Annotation for restarting Mirror Maker 2 connector task
*/
public static final String ANNO_STRIMZI_IO_RESTART_CONNECTOR_TASK = STRIMZI_DOMAIN + "restart-connector-task";

/**
* Key for specifying which Mirror Maker 2 connector should be restarted
*/
public static final String ANNO_STRIMZI_IO_RESTART_CONNECTOR_TASK_PATTERN_CONNECTOR = "connector";

/**
* Key for specifying which Mirror Maker 2 connector task should be restarted
*/
public static final String ANNO_STRIMZI_IO_RESTART_CONNECTOR_TASK_PATTERN_TASK = "task";

/**
* Pattern for validation of value which specifies which connector or task should be restarted
*/
Expand All @@ -145,21 +90,6 @@ public class Annotations {
*/
public static final String ANNO_STRIMZI_IO_DELETE_CLAIM = STRIMZI_DOMAIN + "delete-claim";

/**
* Annotation for configuring the ranges of node IDs which should be used for given node pool
*/
public static final String ANNO_STRIMZI_IO_NEXT_NODE_IDS = STRIMZI_DOMAIN + "next-node-ids";

/**
* Annotation for configuring the ranges of node IDs which should be used for given node pool
*/
public static final String ANNO_STRIMZI_IO_REMOVE_NODE_IDS = STRIMZI_DOMAIN + "remove-node-ids";

/**
* Annotation for enabling or disabling the Node Pools. This annotation is used on the Kafka CR
*/
public static final String ANNO_STRIMZI_IO_NODE_POOLS = STRIMZI_DOMAIN + "node-pools";

/**
* Annotation for tracking Deployment revisions
*/
Expand Down