use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class TopicControllerTest method testGenerateDeployment.
@Test
public void testGenerateDeployment() {
Deployment dep = tc.generateDeployment();
assertEquals(tc.topicControllerName(cluster), dep.getMetadata().getName());
assertEquals(namespace, dep.getMetadata().getNamespace());
assertEquals(new Integer(TopicController.DEFAULT_REPLICAS), dep.getSpec().getReplicas());
assertEquals(1, dep.getSpec().getTemplate().getSpec().getContainers().size());
assertEquals(tc.topicControllerName(cluster), dep.getSpec().getTemplate().getSpec().getContainers().get(0).getName());
assertEquals(tc.image, dep.getSpec().getTemplate().getSpec().getContainers().get(0).getImage());
assertEquals(getExpectedEnvVars(), dep.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv());
assertEquals(new Integer(TopicController.DEFAULT_HEALTHCHECK_DELAY), dep.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getInitialDelaySeconds());
assertEquals(new Integer(TopicController.DEFAULT_HEALTHCHECK_TIMEOUT), dep.getSpec().getTemplate().getSpec().getContainers().get(0).getLivenessProbe().getTimeoutSeconds());
assertEquals(new Integer(TopicController.DEFAULT_HEALTHCHECK_DELAY), dep.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getInitialDelaySeconds());
assertEquals(new Integer(TopicController.DEFAULT_HEALTHCHECK_TIMEOUT), dep.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getTimeoutSeconds());
assertEquals(1, dep.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts().size());
assertEquals(new Integer(TopicController.HEALTHCHECK_PORT), dep.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts().get(0).getContainerPort());
assertEquals(TopicController.HEALTHCHECK_PORT_NAME, dep.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts().get(0).getName());
assertEquals("TCP", dep.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts().get(0).getProtocol());
assertEquals("Recreate", dep.getSpec().getStrategy().getType());
}
use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class AbstractResourceOperatorTest method deleteWhenResourceExistsStillDeletes.
@Test
public void deleteWhenResourceExistsStillDeletes(TestContext context) {
T resource = resource();
Resource mockResource = mock(resourceType());
when(mockResource.get()).thenReturn(resource);
NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockResource);
MixedOperation mockCms = mock(MixedOperation.class);
when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
C mockClient = mock(clientType());
mocker(mockClient, mockCms);
AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
Async async = context.async();
op.reconcile(resource.getMetadata().getNamespace(), resource.getMetadata().getName(), null).setHandler(ar -> {
assertTrue(ar.succeeded());
verify(mockResource).delete();
async.complete();
});
}
use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class AbstractModel method createDeployment.
protected Deployment createDeployment(List<ContainerPort> ports, Probe livenessProbe, Probe readinessProbe, DeploymentStrategy updateStrategy, Map<String, String> deploymentAnnotations, Map<String, String> podAnnotations) {
Container container = new ContainerBuilder().withName(name).withImage(getImage()).withEnv(getEnvVars()).withPorts(ports).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
Deployment dep = new DeploymentBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).withAnnotations(deploymentAnnotations).endMetadata().withNewSpec().withStrategy(updateStrategy).withReplicas(replicas).withNewTemplate().withNewMetadata().withLabels(getLabelsWithName()).withAnnotations(podAnnotations).endMetadata().withNewSpec().withServiceAccountName(getServiceAccountName()).withContainers(container).endSpec().endTemplate().endSpec().build();
return dep;
}
use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class AbstractModel method createHeadlessService.
protected Service createHeadlessService(String name, List<ServicePort> ports, Map<String, String> annotations) {
Service service = new ServiceBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName(name)).withNamespace(namespace).withAnnotations(annotations).endMetadata().withNewSpec().withType("ClusterIP").withClusterIP("None").withSelector(getLabelsWithName()).withPorts(ports).endSpec().build();
log.trace("Created headless service {}", service);
return service;
}
use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class KafkaCluster method fromAssembly.
/**
* Create a Kafka cluster from the deployed StatefulSet resource
*
* @param ss The StatefulSet from which the cluster state should be recovered.
* @param namespace Kubernetes/OpenShift namespace where cluster resources belong to
* @param cluster overall cluster name
* @return Kafka cluster instance
*/
public static KafkaCluster fromAssembly(StatefulSet ss, String namespace, String cluster) {
KafkaCluster kafka = new KafkaCluster(namespace, cluster, Labels.fromResource(ss));
kafka.setReplicas(ss.getSpec().getReplicas());
Container container = ss.getSpec().getTemplate().getSpec().getContainers().get(0);
kafka.setImage(container.getImage());
kafka.setHealthCheckInitialDelay(container.getReadinessProbe().getInitialDelaySeconds());
kafka.setHealthCheckTimeout(container.getReadinessProbe().getTimeoutSeconds());
Map<String, String> vars = containerEnvVars(container);
kafka.setZookeeperConnect(vars.getOrDefault(KEY_KAFKA_ZOOKEEPER_CONNECT, ss.getMetadata().getName() + "-zookeeper:2181"));
kafka.setDefaultReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_KAFKA_DEFAULT_REPLICATION_FACTOR, String.valueOf(DEFAULT_KAFKA_DEFAULT_REPLICATION_FACTOR))));
kafka.setOffsetsTopicReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR, String.valueOf(DEFAULT_KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR))));
kafka.setTransactionStateLogReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR, String.valueOf(DEFAULT_KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR))));
kafka.setMetricsEnabled(Boolean.parseBoolean(vars.getOrDefault(KEY_KAFKA_METRICS_ENABLED, String.valueOf(DEFAULT_KAFKA_METRICS_ENABLED))));
if (kafka.isMetricsEnabled()) {
kafka.setMetricsConfigName(metricConfigsName(cluster));
}
if (!ss.getSpec().getVolumeClaimTemplates().isEmpty()) {
Storage storage = Storage.fromPersistentVolumeClaim(ss.getSpec().getVolumeClaimTemplates().get(0));
if (ss.getMetadata().getAnnotations() != null) {
String deleteClaimAnnotation = String.format("%s/%s", ClusterController.STRIMZI_CLUSTER_CONTROLLER_DOMAIN, Storage.DELETE_CLAIM_FIELD);
storage.withDeleteClaim(Boolean.valueOf(ss.getMetadata().getAnnotations().computeIfAbsent(deleteClaimAnnotation, s -> "false")));
}
kafka.setStorage(storage);
} else {
Storage storage = new Storage(Storage.StorageType.EPHEMERAL);
kafka.setStorage(storage);
}
return kafka;
}
Aggregations