use of io.strimzi.api.kafka.model.KafkaClusterSpec in project strimzi by strimzi.
the class DynamicConfST method updateAndVerifyDynConf.
/**
* UpdateAndVerifyDynConf, change the kafka configuration and verify that no rolling update were triggered
* @param namespaceName name of the namespace
* @param kafkaConfig specific kafka configuration, which will be changed
*/
private void updateAndVerifyDynConf(final String namespaceName, String clusterName, Map<String, Object> kafkaConfig) {
LabelSelector kafkaSelector = KafkaResource.getLabelSelector(clusterName, KafkaResources.kafkaStatefulSetName(clusterName));
Map<String, String> kafkaPods = PodUtils.podSnapshot(namespaceName, kafkaSelector);
LOGGER.info("Updating configuration of Kafka cluster");
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
KafkaClusterSpec kafkaClusterSpec = k.getSpec().getKafka();
kafkaClusterSpec.setConfig(kafkaConfig);
}, namespaceName);
PodUtils.verifyThatRunningPodsAreStable(namespaceName, KafkaResources.kafkaStatefulSetName(clusterName));
assertThat(RollingUpdateUtils.componentHasRolled(namespaceName, kafkaSelector, kafkaPods), is(false));
}
use of io.strimzi.api.kafka.model.KafkaClusterSpec in project strimzi by strimzi.
the class CruiseControl method fromCrd.
public static CruiseControl fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions, Storage storage) {
CruiseControl cruiseControl = null;
CruiseControlSpec spec = kafkaAssembly.getSpec().getCruiseControl();
KafkaClusterSpec kafkaClusterSpec = kafkaAssembly.getSpec().getKafka();
if (spec != null) {
cruiseControl = new CruiseControl(reconciliation, kafkaAssembly);
cruiseControl.isDeployed = true;
cruiseControl.setReplicas(DEFAULT_REPLICAS);
String image = spec.getImage();
if (image == null) {
image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_CRUISE_CONTROL_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version()));
}
cruiseControl.setImage(image);
TlsSidecar tlsSidecar = spec.getTlsSidecar();
if (tlsSidecar == null) {
tlsSidecar = new TlsSidecar();
}
String tlsSideCarImage = tlsSidecar.getImage();
if (tlsSideCarImage == null) {
tlsSideCarImage = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_TLS_SIDECAR_CRUISE_CONTROL_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version()));
}
tlsSidecar.setImage(tlsSideCarImage);
cruiseControl.tlsSidecarImage = tlsSideCarImage;
cruiseControl.setTlsSidecar(tlsSidecar);
cruiseControl = cruiseControl.updateConfiguration(spec);
CruiseControlConfiguration ccConfiguration = (CruiseControlConfiguration) cruiseControl.getConfiguration();
cruiseControl.sslEnabled = isApiSslEnabled(ccConfiguration);
cruiseControl.authEnabled = isApiAuthEnabled(ccConfiguration);
KafkaConfiguration configuration = new KafkaConfiguration(reconciliation, kafkaClusterSpec.getConfig().entrySet());
if (configuration.getConfigOption(MIN_INSYNC_REPLICAS) != null) {
cruiseControl.minInsyncReplicas = configuration.getConfigOption(MIN_INSYNC_REPLICAS);
}
// To avoid illegal storage configurations provided by the user,
// we rely on the storage configuration provided by the KafkaAssemblyOperator
cruiseControl.capacity = new Capacity(kafkaAssembly.getSpec(), storage);
// Parse different types of metrics configurations
ModelUtils.parseMetrics(cruiseControl, spec);
if (spec.getReadinessProbe() != null) {
cruiseControl.setReadinessProbe(spec.getReadinessProbe());
}
if (spec.getLivenessProbe() != null) {
cruiseControl.setLivenessProbe(spec.getLivenessProbe());
}
Logging logging = spec.getLogging();
cruiseControl.setLogging(logging == null ? new InlineLogging() : logging);
cruiseControl.setGcLoggingEnabled(spec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : spec.getJvmOptions().isGcLoggingEnabled());
cruiseControl.setJvmOptions(spec.getJvmOptions());
if (spec.getJvmOptions() != null) {
cruiseControl.setJavaSystemProperties(spec.getJvmOptions().getJavaSystemProperties());
}
cruiseControl.setResources(spec.getResources());
cruiseControl.setOwnerReference(kafkaAssembly);
cruiseControl = updateTemplate(spec, cruiseControl);
cruiseControl.templatePodLabels = Util.mergeLabelsOrAnnotations(cruiseControl.templatePodLabels, DEFAULT_POD_LABELS);
}
return cruiseControl;
}
use of io.strimzi.api.kafka.model.KafkaClusterSpec in project strimzi by strimzi.
the class EntityOperator method fromCrd.
/**
* Create a Entity Operator from given desired resource
*
* @param reconciliation The reconciliation
* @param kafkaAssembly desired resource with cluster configuration containing the Entity Operator one
* @param versions The versions.
* @return Entity Operator instance, null if not configured in the ConfigMap
*/
public static EntityOperator fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions) {
EntityOperator result = null;
EntityOperatorSpec entityOperatorSpec = kafkaAssembly.getSpec().getEntityOperator();
if (entityOperatorSpec != null) {
result = new EntityOperator(reconciliation, kafkaAssembly);
result.setOwnerReference(kafkaAssembly);
EntityTopicOperator topicOperator = EntityTopicOperator.fromCrd(reconciliation, kafkaAssembly);
EntityUserOperator userOperator = EntityUserOperator.fromCrd(reconciliation, kafkaAssembly);
TlsSidecar tlsSidecar = entityOperatorSpec.getTlsSidecar();
if (entityOperatorSpec.getTemplate() != null) {
EntityOperatorTemplate template = entityOperatorSpec.getTemplate();
if (template.getDeployment() != null && template.getDeployment().getMetadata() != null) {
result.templateDeploymentLabels = template.getDeployment().getMetadata().getLabels();
result.templateDeploymentAnnotations = template.getDeployment().getMetadata().getAnnotations();
}
ModelUtils.parsePodTemplate(result, template.getPod());
if (template.getTopicOperatorContainer() != null && template.getTopicOperatorContainer().getEnv() != null) {
topicOperator.setContainerEnvVars(template.getTopicOperatorContainer().getEnv());
}
if (template.getTopicOperatorContainer() != null && template.getTopicOperatorContainer().getSecurityContext() != null) {
topicOperator.setContainerSecurityContext(template.getTopicOperatorContainer().getSecurityContext());
}
if (template.getUserOperatorContainer() != null && template.getUserOperatorContainer().getEnv() != null) {
userOperator.setContainerEnvVars(template.getUserOperatorContainer().getEnv());
}
if (template.getUserOperatorContainer() != null && template.getUserOperatorContainer().getSecurityContext() != null) {
userOperator.setContainerSecurityContext(template.getUserOperatorContainer().getSecurityContext());
}
if (template.getTlsSidecarContainer() != null && template.getTlsSidecarContainer().getEnv() != null) {
result.templateTlsSidecarContainerEnvVars = template.getTlsSidecarContainer().getEnv();
}
if (template.getTlsSidecarContainer() != null && template.getTlsSidecarContainer().getSecurityContext() != null) {
result.templateTlsSidecarContainerSecurityContext = template.getTlsSidecarContainer().getSecurityContext();
}
if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
result.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
result.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
}
}
result.setTlsSidecar(tlsSidecar);
result.setTopicOperator(topicOperator);
result.setUserOperator(userOperator);
result.setDeployed(result.getTopicOperator() != null || result.getUserOperator() != null);
String tlsSideCarImage = tlsSidecar != null ? tlsSidecar.getImage() : null;
if (tlsSideCarImage == null) {
KafkaClusterSpec kafkaClusterSpec = kafkaAssembly.getSpec().getKafka();
tlsSideCarImage = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_TLS_SIDECAR_ENTITY_OPERATOR_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version()));
}
result.tlsSidecarImage = tlsSideCarImage;
result.templatePodLabels = Util.mergeLabelsOrAnnotations(result.templatePodLabels, DEFAULT_POD_LABELS);
}
return result;
}
use of io.strimzi.api.kafka.model.KafkaClusterSpec in project strimzi-kafka-operator by strimzi.
the class CruiseControl method fromCrd.
public static CruiseControl fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions, Storage storage) {
CruiseControl cruiseControl = null;
CruiseControlSpec spec = kafkaAssembly.getSpec().getCruiseControl();
KafkaClusterSpec kafkaClusterSpec = kafkaAssembly.getSpec().getKafka();
if (spec != null) {
cruiseControl = new CruiseControl(reconciliation, kafkaAssembly);
cruiseControl.isDeployed = true;
cruiseControl.setReplicas(DEFAULT_REPLICAS);
String image = spec.getImage();
if (image == null) {
image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_CRUISE_CONTROL_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version()));
}
cruiseControl.setImage(image);
TlsSidecar tlsSidecar = spec.getTlsSidecar();
if (tlsSidecar == null) {
tlsSidecar = new TlsSidecar();
}
String tlsSideCarImage = tlsSidecar.getImage();
if (tlsSideCarImage == null) {
tlsSideCarImage = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_TLS_SIDECAR_CRUISE_CONTROL_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version()));
}
tlsSidecar.setImage(tlsSideCarImage);
cruiseControl.tlsSidecarImage = tlsSideCarImage;
cruiseControl.setTlsSidecar(tlsSidecar);
cruiseControl = cruiseControl.updateConfiguration(spec);
CruiseControlConfiguration ccConfiguration = (CruiseControlConfiguration) cruiseControl.getConfiguration();
cruiseControl.sslEnabled = isApiSslEnabled(ccConfiguration);
cruiseControl.authEnabled = isApiAuthEnabled(ccConfiguration);
KafkaConfiguration configuration = new KafkaConfiguration(reconciliation, kafkaClusterSpec.getConfig().entrySet());
if (configuration.getConfigOption(MIN_INSYNC_REPLICAS) != null) {
cruiseControl.minInsyncReplicas = configuration.getConfigOption(MIN_INSYNC_REPLICAS);
}
// To avoid illegal storage configurations provided by the user,
// we rely on the storage configuration provided by the KafkaAssemblyOperator
cruiseControl.capacity = new Capacity(kafkaAssembly.getSpec(), storage);
// Parse different types of metrics configurations
ModelUtils.parseMetrics(cruiseControl, spec);
if (spec.getReadinessProbe() != null) {
cruiseControl.setReadinessProbe(spec.getReadinessProbe());
}
if (spec.getLivenessProbe() != null) {
cruiseControl.setLivenessProbe(spec.getLivenessProbe());
}
Logging logging = spec.getLogging();
cruiseControl.setLogging(logging == null ? new InlineLogging() : logging);
cruiseControl.setGcLoggingEnabled(spec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : spec.getJvmOptions().isGcLoggingEnabled());
cruiseControl.setJvmOptions(spec.getJvmOptions());
if (spec.getJvmOptions() != null) {
cruiseControl.setJavaSystemProperties(spec.getJvmOptions().getJavaSystemProperties());
}
cruiseControl.setResources(spec.getResources());
cruiseControl.setOwnerReference(kafkaAssembly);
cruiseControl = updateTemplate(spec, cruiseControl);
cruiseControl.templatePodLabels = Util.mergeLabelsOrAnnotations(cruiseControl.templatePodLabels, DEFAULT_POD_LABELS);
}
return cruiseControl;
}
use of io.strimzi.api.kafka.model.KafkaClusterSpec in project strimzi-kafka-operator by strimzi.
the class ZookeeperCluster method fromCrd.
@SuppressWarnings({ "checkstyle:MethodLength", "checkstyle:CyclomaticComplexity" })
public static ZookeeperCluster fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions, Storage oldStorage, int oldReplicas) {
ZookeeperCluster zk = new ZookeeperCluster(reconciliation, kafkaAssembly);
zk.setOwnerReference(kafkaAssembly);
ZookeeperClusterSpec zookeeperClusterSpec = kafkaAssembly.getSpec().getZookeeper();
int replicas = zookeeperClusterSpec.getReplicas();
if (replicas <= 0) {
replicas = ZookeeperClusterSpec.DEFAULT_REPLICAS;
}
if (replicas == 1 && zookeeperClusterSpec.getStorage() != null && "ephemeral".equals(zookeeperClusterSpec.getStorage().getType())) {
LOGGER.warnCr(reconciliation, "A ZooKeeper cluster with a single replica and ephemeral storage will be in a defective state after any restart or rolling update. It is recommended that a minimum of three replicas are used.");
}
zk.setReplicas(replicas);
// Get the ZK version information from either the CRD or from the default setting
KafkaClusterSpec kafkaClusterSpec = kafkaAssembly.getSpec().getKafka();
String version = versions.supportedVersion(kafkaClusterSpec != null ? kafkaClusterSpec.getVersion() : null).zookeeperVersion();
zk.setVersion(version);
String image = zookeeperClusterSpec.getImage();
if (image == null) {
image = versions.kafkaImage(kafkaClusterSpec != null ? kafkaClusterSpec.getImage() : null, kafkaClusterSpec != null ? kafkaClusterSpec.getVersion() : null);
}
zk.setImage(image);
if (zookeeperClusterSpec.getReadinessProbe() != null) {
zk.setReadinessProbe(zookeeperClusterSpec.getReadinessProbe());
}
if (zookeeperClusterSpec.getLivenessProbe() != null) {
zk.setLivenessProbe(zookeeperClusterSpec.getLivenessProbe());
}
Logging logging = zookeeperClusterSpec.getLogging();
zk.setLogging(logging == null ? new InlineLogging() : logging);
zk.setGcLoggingEnabled(zookeeperClusterSpec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : zookeeperClusterSpec.getJvmOptions().isGcLoggingEnabled());
if (zookeeperClusterSpec.getJvmOptions() != null) {
zk.setJavaSystemProperties(zookeeperClusterSpec.getJvmOptions().getJavaSystemProperties());
}
// Parse different types of metrics configurations
ModelUtils.parseMetrics(zk, zookeeperClusterSpec);
if (oldStorage != null) {
Storage newStorage = zookeeperClusterSpec.getStorage();
AbstractModel.validatePersistentStorage(newStorage);
StorageDiff diff = new StorageDiff(reconciliation, oldStorage, newStorage, oldReplicas, zookeeperClusterSpec.getReplicas());
if (!diff.isEmpty()) {
LOGGER.warnCr(reconciliation, "Only the following changes to Zookeeper storage are allowed: " + "changing the deleteClaim flag, " + "changing overrides to nodes which do not exist yet " + "and increasing size of persistent claim volumes (depending on the volume type and used storage class).");
LOGGER.warnCr(reconciliation, "The desired ZooKeeper storage configuration in the custom resource {}/{} contains changes which are not allowed. As " + "a result, all storage changes will be ignored. Use DEBUG level logging for more information " + "about the detected changes.", kafkaAssembly.getMetadata().getNamespace(), kafkaAssembly.getMetadata().getName());
Condition warning = StatusUtils.buildWarningCondition("ZooKeeperStorage", "The desired ZooKeeper storage configuration contains changes which are not allowed. As a " + "result, all storage changes will be ignored. Use DEBUG level logging for more information " + "about the detected changes.");
zk.addWarningCondition(warning);
zk.setStorage(oldStorage);
} else {
zk.setStorage(newStorage);
}
} else {
zk.setStorage(zookeeperClusterSpec.getStorage());
}
zk.setConfiguration(new ZookeeperConfiguration(reconciliation, zookeeperClusterSpec.getConfig().entrySet()));
zk.setResources(zookeeperClusterSpec.getResources());
zk.setJvmOptions(zookeeperClusterSpec.getJvmOptions());
if (zookeeperClusterSpec.getJmxOptions() != null) {
zk.setJmxEnabled(Boolean.TRUE);
AuthenticationUtils.configureZookeeperJmxOptions(zookeeperClusterSpec.getJmxOptions().getAuthentication(), zk);
}
if (zookeeperClusterSpec.getTemplate() != null) {
ZookeeperClusterTemplate template = zookeeperClusterSpec.getTemplate();
if (template.getStatefulset() != null) {
if (template.getStatefulset().getPodManagementPolicy() != null) {
zk.templatePodManagementPolicy = template.getStatefulset().getPodManagementPolicy();
}
if (template.getStatefulset().getMetadata() != null) {
zk.templateStatefulSetLabels = template.getStatefulset().getMetadata().getLabels();
zk.templateStatefulSetAnnotations = template.getStatefulset().getMetadata().getAnnotations();
}
}
if (template.getPodSet() != null && template.getPodSet().getMetadata() != null) {
zk.templatePodSetLabels = template.getPodSet().getMetadata().getLabels();
zk.templatePodSetAnnotations = template.getPodSet().getMetadata().getAnnotations();
}
ModelUtils.parsePodTemplate(zk, template.getPod());
ModelUtils.parseInternalServiceTemplate(zk, template.getClientService());
ModelUtils.parseInternalHeadlessServiceTemplate(zk, template.getNodesService());
if (template.getPersistentVolumeClaim() != null && template.getPersistentVolumeClaim().getMetadata() != null) {
zk.templatePersistentVolumeClaimLabels = Util.mergeLabelsOrAnnotations(template.getPersistentVolumeClaim().getMetadata().getLabels(), zk.templateStatefulSetLabels);
zk.templatePersistentVolumeClaimAnnotations = template.getPersistentVolumeClaim().getMetadata().getAnnotations();
}
if (template.getZookeeperContainer() != null && template.getZookeeperContainer().getEnv() != null) {
zk.templateZookeeperContainerEnvVars = template.getZookeeperContainer().getEnv();
}
if (template.getZookeeperContainer() != null && template.getZookeeperContainer().getSecurityContext() != null) {
zk.templateZookeeperContainerSecurityContext = template.getZookeeperContainer().getSecurityContext();
}
if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
zk.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
zk.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
}
if (template.getJmxSecret() != null && template.getJmxSecret().getMetadata() != null) {
zk.templateJmxSecretLabels = template.getJmxSecret().getMetadata().getLabels();
zk.templateJmxSecretAnnotations = template.getJmxSecret().getMetadata().getAnnotations();
}
ModelUtils.parsePodDisruptionBudgetTemplate(zk, template.getPodDisruptionBudget());
}
zk.templatePodLabels = Util.mergeLabelsOrAnnotations(zk.templatePodLabels, DEFAULT_POD_LABELS);
return zk;
}
Aggregations