Skip to content

Commit

Permalink
Final refactoring of the Model and Operator classes split and import …
Browse files Browse the repository at this point in the history
…control (#9005)

Signed-off-by: Jakub Scholz <www@scholzj.com>
  • Loading branch information
scholzj authored Aug 21, 2023
1 parent 1d88a22 commit 9b7cb99
Show file tree
Hide file tree
Showing 143 changed files with 346 additions and 296 deletions.
8 changes: 5 additions & 3 deletions .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@
<module name="TypeName"/>
<module name="AvoidStarImport"/>

<!-- dependencies -->
<!--<module name="ImportControl">
<!-- dependencies and import control -->
<module name="ImportControl">
<property name="file" value="${importControlFile}"/>
</module>-->
<!-- we do not want to validate test classes -->
<property name="path" value="^.*[\\/]src[\\/]main[\\/].*$"/>
</module>

<!-- whitespace -->
<module name="GenericWhitespace"/>
Expand Down
103 changes: 103 additions & 0 deletions .checkstyle/import-control.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!DOCTYPE import-control PUBLIC
"-//Checkstyle//DTD ImportControl Configuration 1.4//EN"
"https://checkstyle.org/dtds/import_control_1_4.dtd">

<!--
The import control rules are currently configured only for 3 packages:
* io.strimzi.operator.common.model
* io.strimzi.operator.cluster.model
* io.strimzi.operator.user.model
For all other packages, there are currently no restrictions, and they can import anything. To achieve this, we have to
first configure <import-control pkg="io.strimzi" strategyOnMismatch="allowed"> which allows all imports for all classes
not matching any of the <subpackage ...> modules without any restrictions.
And then we add the <subpackage ... strategyOnMismatch="disallowed"> which allows only the selected imports for the 3
packages mentioned above. These packages should in general use only the API and other model classes plus some selected
other classes (and of course general Java classes and some other dependencies). They should especially not use any of
the operator classes (e.g. the Assembly or Resource operators). If you make any changes to these classes and need to
import something more, you should consider if it really should be used, it should not part of the Model packages and in
case it is really needed, you can add it bellow to the allowed imports.
We also control imports only in production classes and not in tests. This is controlled in the main checkstyle file.
-->

<import-control pkg="io.strimzi" strategyOnMismatch="allowed">
<subpackage name="operator.common.model" strategyOnMismatch="disallowed">
<!-- This enforces the layering between the Strimzi Model and Operator classes in the Operator Common. The Model classes are not allowed
to import from Operator classes. They should only use the API classes -->

<!-- Common libraries and Java classes -->
<allow pkg="java" />
<allow pkg="com.fasterxml.jackson" />
<allow pkg="io.fabric8.zjsonpatch" />
<allow pkg="io.fabric8.kubernetes.api.model" />
<allow class="io.fabric8.kubernetes.client.utils.Serialization" />
<allow class="io.fabric8.kubernetes.client.CustomResource" />

<!-- Strimzi Operators classes -->
<allow pkg="io.strimzi.api.annotations" />
<allow pkg="io.strimzi.api.kafka" />
<allow pkg="io.strimzi.certs" />
<allow pkg="io.strimzi.operator.common.model" />
<allow class="io.strimzi.operator.common.Reconciliation" />
<allow class="io.strimzi.operator.common.ReconciliationLogger" />
<allow class="io.strimzi.operator.common.Util" />
<allow class="io.strimzi.operator.common.Annotations" />
</subpackage>

<subpackage name="operator.cluster.model" strategyOnMismatch="disallowed">
<!-- This enforces the layering between the Strimzi Model and Operator classes in the Cluster Operator. The Model classes are not allowed
to import from Operator classes. They should only use the API classes -->

<!-- Common libraries and Java classes -->
<allow pkg="java" />
<allow pkg="org.apache.kafka" />
<allow pkg="org.apache.logging.log4j" />
<allow pkg="com.fasterxml.jackson" />
<allow pkg="io.fabric8.zjsonpatch" />
<allow pkg="io.fabric8.openshift.api.model" />
<allow pkg="io.fabric8.kubernetes.api.model" />
<allow pkg="io.vertx.core.json" />
<allow class="edu.umd.cs.findbugs.annotations.SuppressFBWarnings" />

<!-- Strimzi Operators classes -->
<allow pkg="io.strimzi.api.kafka" />
<allow pkg="io.strimzi.plugin.security.profiles" />
<allow pkg="io.strimzi.platform" />
<allow pkg="io.strimzi.certs" />
<allow pkg="io.strimzi.kafka.config.model" />
<allow pkg="io.strimzi.operator.common.model" />
<allow pkg="io.strimzi.operator.cluster.model" />
<allow class="io.strimzi.operator.common.Reconciliation" />
<allow class="io.strimzi.operator.common.ReconciliationLogger" />
<allow class="io.strimzi.operator.common.Util" />
<allow class="io.strimzi.operator.common.InvalidConfigurationException" />
<allow class="io.strimzi.operator.common.Annotations" />
<allow class="io.strimzi.operator.cluster.ClusterOperatorConfig" />
<allow class="io.strimzi.operator.cluster.PlatformFeaturesAvailability" />

<!-- Other Strimzi projects -->
<allow pkg="io.strimzi.kafka.oauth" />
</subpackage>

<subpackage name="operator.user.model" strategyOnMismatch="disallowed">
<!-- This enforces the layering between the Strimzi Model and Operator classes in the User Operator. The Model classes are not allowed
to import from Operator classes. They should only use the API classes -->

<!-- Common libraries and Java classes -->
<allow pkg="java" />
<allow pkg="javax.naming" />
<allow pkg="org.apache.kafka.common" />
<allow pkg="io.fabric8.kubernetes.api.model" />

<!-- Strimzi Operators classes -->
<allow pkg="io.strimzi.api.kafka" />
<allow pkg="io.strimzi.certs" />
<allow pkg="io.strimzi.operator.common.model" />
<allow pkg="io.strimzi.operator.user.model" />
<allow class="io.strimzi.operator.common.Reconciliation" />
<allow class="io.strimzi.operator.common.ReconciliationLogger" />
<allow class="io.strimzi.operator.common.Util" />
</subpackage>
</import-control>
3 changes: 3 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

<!-- No Javadocs warnings as errors here => we do not want to fail because of warnings -->
<javadoc.fail.on.warnings>false</javadoc.fail.on.warnings>

<!-- Points to the root directory of the Strimzi project directory and can be used for fixed location to configuration files -->
<strimziRootDirectory>${basedir}${file.separator}..</strimziRootDirectory>
</properties>

<dependencies>
Expand Down
11 changes: 11 additions & 0 deletions api/src/main/java/io/strimzi/api/kafka/model/KafkaResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,15 @@ public static String entityUserOperatorLoggingConfigMapName(String clusterName)
public static String entityUserOperatorRoleBinding(String clusterName) {
return clusterName + "-entity-user-operator-role";
}

/**
* Name of the secret with the Cluster Operator certificates for connecting to this cluster
*
* @param cluster Name of the Kafka cluster
*
* @return Name of the Cluster Operator certificate secret
*/
public static String secretName(String cluster) {
return cluster + "-cluster-operator-certs";
}
}
5 changes: 5 additions & 0 deletions certificate-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
</license>
</licenses>

<properties>
<!-- Points to the root directory of the Strimzi project directory and can be used for fixed location to configuration files -->
<strimziRootDirectory>${basedir}${file.separator}..</strimziRootDirectory>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
5 changes: 5 additions & 0 deletions cluster-operator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
</license>
</licenses>

<properties>
<!-- Points to the root directory of the Strimzi project directory and can be used for fixed location to configuration files -->
<strimziRootDirectory>${basedir}${file.separator}..</strimziRootDirectory>
</properties>

<dependencies>
<dependency>
<groupId>io.strimzi</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@
* {@link ClusterOperator}'s in Vertx.
*/
public class ClusterOperator extends AbstractVerticle {

private static final Logger LOGGER = LogManager.getLogger(ClusterOperator.class.getName());

private static final String NAME_SUFFIX = "-cluster-operator";
private static final String CERTS_SUFFIX = NAME_SUFFIX + "-certs";

private final String namespace;
private final ClusterOperatorConfig config;

Expand Down Expand Up @@ -207,15 +203,4 @@ private void reconcileAll(String trigger) {
kafkaRebalanceAssemblyOperator.reconcileAll(trigger, namespace, ignore);
}
}

/**
* Name of the secret with the Cluster Operator certificates for connecting to the cluster
*
* @param cluster Name of the Kafka cluster
*
* @return Name of the Cluster Operator certificate secret
*/
public static String secretName(String cluster) {
return cluster + CERTS_SUFFIX;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.strimzi.operator.common.MetricsProvider;
import io.strimzi.operator.common.MicrometerMetricsProvider;
import io.strimzi.operator.common.OperatorKubernetesClientBuilder;
import io.strimzi.operator.common.PasswordGenerator;
import io.strimzi.operator.common.model.PasswordGenerator;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.ShutdownHook;
import io.strimzi.operator.common.Util;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderFactory;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.ReconciliationLogger;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.model.Labels;
import io.strimzi.plugin.security.profiles.PodSecurityProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import io.strimzi.certs.CertManager;
import io.strimzi.certs.IpAndDnsValidation;
import io.strimzi.certs.Subject;
import io.strimzi.operator.cluster.ClusterOperator;
import io.strimzi.operator.common.PasswordGenerator;
import io.strimzi.operator.common.model.PasswordGenerator;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.model.Ca;

Expand Down Expand Up @@ -121,7 +120,7 @@ public void initCaSecrets(List<Secret> secrets) {
entityUserOperatorSecret = secret;
} else if (KafkaResources.zookeeperSecretName(clusterName).equals(name)) {
zkNodesSecret = secret;
} else if (ClusterOperator.secretName(clusterName).equals(name)) {
} else if (KafkaResources.secretName(clusterName).equals(name)) {
clusterOperatorSecret = secret;
} else if (KafkaExporterResources.secretName(clusterName).equals(name)) {
kafkaExporterSecret = secret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderContextImpl;
import io.strimzi.operator.common.model.cruisecontrol.CruiseControlConfigurationParameters;
import io.strimzi.operator.common.PasswordGenerator;
import io.strimzi.operator.common.model.PasswordGenerator;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Util;
import io.strimzi.operator.common.model.Labels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.strimzi.operator.cluster.operator.resource;
package io.strimzi.operator.cluster.model;

import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.EnvVarBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
import io.strimzi.api.kafka.model.template.PodTemplate;
import io.strimzi.api.kafka.model.template.ResourceTemplate;
import io.strimzi.operator.cluster.ClusterOperatorConfig;
import io.strimzi.operator.cluster.Main;
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderContextImpl;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.Util;

Expand Down Expand Up @@ -331,7 +329,7 @@ public Role generateRole(String ownerNamespace, String namespace) {

try (BufferedReader br = new BufferedReader(
new InputStreamReader(
Main.class.getResourceAsStream("/cluster-roles/031-ClusterRole-strimzi-entity-operator.yaml"),
EntityOperator.class.getResourceAsStream("/cluster-roles/031-ClusterRole-strimzi-entity-operator.yaml"),
StandardCharsets.UTF_8)
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.strimzi.operator.cluster.model.logging.SupportsLogging;
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.strimzi.operator.cluster.model.logging.SupportsLogging;
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderContextImpl;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Util;
import io.strimzi.operator.common.model.InvalidResourceException;
import io.strimzi.operator.common.model.Labels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import io.strimzi.operator.cluster.model.metrics.SupportsMetrics;
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderContextImpl;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Annotations;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.Util;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderContextImpl;
import io.strimzi.operator.common.Annotations;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Util;
import io.strimzi.operator.common.model.InvalidResourceException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderContextImpl;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Util;
import io.strimzi.operator.common.model.Labels;
import io.strimzi.operator.common.model.OrderedProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.strimzi.api.kafka.model.connect.build.ZipArtifact;
import io.strimzi.operator.cluster.ClusterOperatorConfig;
import io.strimzi.operator.common.InvalidConfigurationException;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Util;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderContextImpl;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Util;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationPlain;
import io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationScram;
import io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationTls;
import io.strimzi.operator.cluster.ClusterOperatorConfig;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Util;
import io.strimzi.operator.common.model.InvalidResourceException;

Expand All @@ -35,8 +35,6 @@
import java.util.Map.Entry;
import java.util.function.Supplier;

import static io.strimzi.operator.cluster.ClusterOperatorConfig.STRIMZI_DEFAULT_KAFKA_INIT_IMAGE;

/**
* Kafka Mirror Maker 2 model
*/
Expand Down Expand Up @@ -148,7 +146,7 @@ private static KafkaConnectSpec buildKafkaConnectSpec(KafkaMirrorMaker2Spec spec
.withJvmOptions(spec.getJvmOptions())
.withJmxOptions(spec.getJmxOptions())
.withMetricsConfig(spec.getMetricsConfig())
.withClientRackInitImage(System.getenv().getOrDefault(STRIMZI_DEFAULT_KAFKA_INIT_IMAGE, "quay.io/strimzi/operator:latest"))
.withClientRackInitImage(System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_KAFKA_INIT_IMAGE, "quay.io/strimzi/operator:latest"))
.withRack(spec.getRack())
.withTracing(spec.getTracing())
.withTemplate(spec.getTemplate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import io.strimzi.operator.cluster.model.securityprofiles.ContainerSecurityProviderContextImpl;
import io.strimzi.operator.cluster.model.securityprofiles.PodSecurityProviderContextImpl;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.Util;
import io.strimzi.operator.common.model.InvalidResourceException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.strimzi.api.kafka.model.template.ResourceTemplate;
import io.strimzi.operator.cluster.model.nodepools.NodeIdAssignment;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.cluster.operator.resource.SharedEnvironmentProvider;
import io.strimzi.operator.common.model.Labels;
import io.strimzi.operator.common.model.StatusUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.strimzi.operator.cluster;
package io.strimzi.operator.cluster.model;

import io.strimzi.operator.common.model.InvalidResourceException;

Expand Down
Loading

0 comments on commit 9b7cb99

Please sign in to comment.