@Test public void testTemplate() { Map<String, String> depLabels = TestUtils.map("l1", "v1", "l2", "v2", Labels.KUBERNETES_PART_OF_LABEL, "custom-part", Labels.KUBERNETES_MANAGED_BY_LABEL, "custom-managed-by"); Map<String, String> expectedDepLabels = new HashMap<>(depLabels); expectedDepLabels.remove(Labels.KUBERNETES_MANAGED_BY_LABEL); Map<String, String> depAnots = TestUtils.map("a1", "v1", "a2", "v2"); Map<String, String> podLabels = TestUtils.map("l3", "v3", "l4", "v4"); Map<String, String> podAnots = TestUtils.map("a3", "v3", "a4", "v4"); Map<String, String> svcLabels = TestUtils.map("l5", "v5", "l6", "v6"); Map<String, String> svcAnots = TestUtils.map("a5", "v5", "a6", "v6"); Map<String, String> pdbLabels = TestUtils.map("l7", "v7", "l8", "v8"); Map<String, String> pdbAnots = TestUtils.map("a7", "v7", "a8", "v8"); HostAlias hostAlias1 = new HostAliasBuilder() .withHostnames("my-host-1", "my-host-2") .withIp("192.168.1.86") .build(); HostAlias hostAlias2 = new HostAliasBuilder() .withHostnames("my-host-3") .withIp("192.168.1.87") .build(); KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource) .editSpec() .withNewTemplate() .withNewDeployment() .withNewMetadata() .withLabels(depLabels) .withAnnotations(depAnots) .endMetadata() .endDeployment() .withNewPod() .withNewMetadata() .withLabels(podLabels) .withAnnotations(podAnots) .endMetadata() .withNewPriorityClassName("top-priority") .withNewSchedulerName("my-scheduler") .withHostAliases(hostAlias1, hostAlias2) .endPod() .withNewApiService() .withNewMetadata() .withLabels(svcLabels) .withAnnotations(svcAnots) .endMetadata() .endApiService() .withNewPodDisruptionBudget() .withNewMetadata() .withLabels(pdbLabels) .withAnnotations(pdbAnots) .endMetadata() .endPodDisruptionBudget() .endTemplate() .endSpec() .build(); KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(resource, VERSIONS); Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null); assertThat(dep.getMetadata().getLabels().entrySet().containsAll(expectedDepLabels.entrySet()), is(true)); assertThat(dep.getMetadata().getAnnotations().entrySet().containsAll(depAnots.entrySet()), is(true)); assertThat(dep.getSpec().getTemplate().getSpec().getPriorityClassName(), is("top-priority")); assertThat(dep.getSpec().getTemplate().getMetadata().getLabels().entrySet().containsAll(podLabels.entrySet()), is(true)); assertThat(dep.getSpec().getTemplate().getMetadata().getAnnotations().entrySet().containsAll(podAnots.entrySet()), is(true)); assertThat(dep.getSpec().getTemplate().getSpec().getSchedulerName(), is("my-scheduler")); assertThat(dep.getSpec().getTemplate().getSpec().getHostAliases(), containsInAnyOrder(hostAlias1, hostAlias2)); Service svc = kmm2.generateService(); assertThat(svc.getMetadata().getLabels().entrySet().containsAll(svcLabels.entrySet()), is(true)); assertThat(svc.getMetadata().getAnnotations().entrySet().containsAll(svcAnots.entrySet()), is(true)); PodDisruptionBudget pdb = kmm2.generatePodDisruptionBudget(); assertThat(pdb.getMetadata().getLabels().entrySet().containsAll(pdbLabels.entrySet()), is(true)); assertThat(pdb.getMetadata().getAnnotations().entrySet().containsAll(pdbAnots.entrySet()), is(true)); }
public static KafkaMirrorMaker2Cluster fromCrd(KafkaMirrorMaker2 kafkaMirrorMaker2, KafkaVersion.Lookup versions) { KafkaMirrorMaker2Cluster cluster = new KafkaMirrorMaker2Cluster(kafkaMirrorMaker2); KafkaMirrorMaker2Spec spec = kafkaMirrorMaker2.getSpec(); cluster.setOwnerReference(kafkaMirrorMaker2); String specVersion = spec.getVersion(); if (versions.version(specVersion).compareVersion("2.4.0") < 0) { throw new InvalidResourceException("Kafka MirrorMaker 2.0 is not available in the version at spec.version (" + specVersion + "). Kafka MirrorMaker 2.0 is available in Kafka version 2.4.0 and later."); } cluster.setImage(versions.kafkaMirrorMaker2Version(spec.getImage(), specVersion)); List<KafkaMirrorMaker2ClusterSpec> clustersList = ModelUtils.asListOrEmptyList(spec.getClusters()); cluster.setClusters(clustersList); KafkaMirrorMaker2ClusterSpec connectCluster = new KafkaMirrorMaker2ClusterSpecBuilder().build(); String connectClusterAlias = spec.getConnectCluster(); if (connectClusterAlias != null) { connectCluster = clustersList.stream() .filter(clustersListItem -> spec.getConnectCluster().equals(clustersListItem.getAlias())) .findFirst() .orElseThrow(() -> new InvalidResourceException("connectCluster with alias " + connectClusterAlias + " cannot be found in the list of clusters at spec.clusters")); } cluster.setConfiguration(new KafkaMirrorMaker2Configuration(connectCluster.getConfig().entrySet())); return fromSpec(buildKafkaConnectSpec(spec, connectCluster), versions, cluster); }
KafkaMirrorMaker2Cluster extends KafkaConnectCluster { public static KafkaMirrorMaker2Cluster fromCrd(KafkaMirrorMaker2 kafkaMirrorMaker2, KafkaVersion.Lookup versions) { KafkaMirrorMaker2Cluster cluster = new KafkaMirrorMaker2Cluster(kafkaMirrorMaker2); KafkaMirrorMaker2Spec spec = kafkaMirrorMaker2.getSpec(); cluster.setOwnerReference(kafkaMirrorMaker2); String specVersion = spec.getVersion(); if (versions.version(specVersion).compareVersion("2.4.0") < 0) { throw new InvalidResourceException("Kafka MirrorMaker 2.0 is not available in the version at spec.version (" + specVersion + "). Kafka MirrorMaker 2.0 is available in Kafka version 2.4.0 and later."); } cluster.setImage(versions.kafkaMirrorMaker2Version(spec.getImage(), specVersion)); List<KafkaMirrorMaker2ClusterSpec> clustersList = ModelUtils.asListOrEmptyList(spec.getClusters()); cluster.setClusters(clustersList); KafkaMirrorMaker2ClusterSpec connectCluster = new KafkaMirrorMaker2ClusterSpecBuilder().build(); String connectClusterAlias = spec.getConnectCluster(); if (connectClusterAlias != null) { connectCluster = clustersList.stream() .filter(clustersListItem -> spec.getConnectCluster().equals(clustersListItem.getAlias())) .findFirst() .orElseThrow(() -> new InvalidResourceException("connectCluster with alias " + connectClusterAlias + " cannot be found in the list of clusters at spec.clusters")); } cluster.setConfiguration(new KafkaMirrorMaker2Configuration(connectCluster.getConfig().entrySet())); return fromSpec(buildKafkaConnectSpec(spec, connectCluster), versions, cluster); } }
KafkaMirrorMaker2Cluster extends KafkaConnectCluster { public static KafkaMirrorMaker2Cluster fromCrd(KafkaMirrorMaker2 kafkaMirrorMaker2, KafkaVersion.Lookup versions) { KafkaMirrorMaker2Cluster cluster = new KafkaMirrorMaker2Cluster(kafkaMirrorMaker2); KafkaMirrorMaker2Spec spec = kafkaMirrorMaker2.getSpec(); cluster.setOwnerReference(kafkaMirrorMaker2); String specVersion = spec.getVersion(); if (versions.version(specVersion).compareVersion("2.4.0") < 0) { throw new InvalidResourceException("Kafka MirrorMaker 2.0 is not available in the version at spec.version (" + specVersion + "). Kafka MirrorMaker 2.0 is available in Kafka version 2.4.0 and later."); } cluster.setImage(versions.kafkaMirrorMaker2Version(spec.getImage(), specVersion)); List<KafkaMirrorMaker2ClusterSpec> clustersList = ModelUtils.asListOrEmptyList(spec.getClusters()); cluster.setClusters(clustersList); KafkaMirrorMaker2ClusterSpec connectCluster = new KafkaMirrorMaker2ClusterSpecBuilder().build(); String connectClusterAlias = spec.getConnectCluster(); if (connectClusterAlias != null) { connectCluster = clustersList.stream() .filter(clustersListItem -> spec.getConnectCluster().equals(clustersListItem.getAlias())) .findFirst() .orElseThrow(() -> new InvalidResourceException("connectCluster with alias " + connectClusterAlias + " cannot be found in the list of clusters at spec.clusters")); } cluster.setConfiguration(new KafkaMirrorMaker2Configuration(connectCluster.getConfig().entrySet())); return fromSpec(buildKafkaConnectSpec(spec, connectCluster), versions, cluster); } private  KafkaMirrorMaker2Cluster(HasMetadata resource); }
KafkaMirrorMaker2Cluster extends KafkaConnectCluster { public static KafkaMirrorMaker2Cluster fromCrd(KafkaMirrorMaker2 kafkaMirrorMaker2, KafkaVersion.Lookup versions) { KafkaMirrorMaker2Cluster cluster = new KafkaMirrorMaker2Cluster(kafkaMirrorMaker2); KafkaMirrorMaker2Spec spec = kafkaMirrorMaker2.getSpec(); cluster.setOwnerReference(kafkaMirrorMaker2); String specVersion = spec.getVersion(); if (versions.version(specVersion).compareVersion("2.4.0") < 0) { throw new InvalidResourceException("Kafka MirrorMaker 2.0 is not available in the version at spec.version (" + specVersion + "). Kafka MirrorMaker 2.0 is available in Kafka version 2.4.0 and later."); } cluster.setImage(versions.kafkaMirrorMaker2Version(spec.getImage(), specVersion)); List<KafkaMirrorMaker2ClusterSpec> clustersList = ModelUtils.asListOrEmptyList(spec.getClusters()); cluster.setClusters(clustersList); KafkaMirrorMaker2ClusterSpec connectCluster = new KafkaMirrorMaker2ClusterSpecBuilder().build(); String connectClusterAlias = spec.getConnectCluster(); if (connectClusterAlias != null) { connectCluster = clustersList.stream() .filter(clustersListItem -> spec.getConnectCluster().equals(clustersListItem.getAlias())) .findFirst() .orElseThrow(() -> new InvalidResourceException("connectCluster with alias " + connectClusterAlias + " cannot be found in the list of clusters at spec.clusters")); } cluster.setConfiguration(new KafkaMirrorMaker2Configuration(connectCluster.getConfig().entrySet())); return fromSpec(buildKafkaConnectSpec(spec, connectCluster), versions, cluster); } private  KafkaMirrorMaker2Cluster(HasMetadata resource); static KafkaMirrorMaker2Cluster fromCrd(KafkaMirrorMaker2 kafkaMirrorMaker2, 
                                                   KafkaVersion.Lookup versions); @Override String getServiceAccountName(); }
KafkaMirrorMaker2Cluster extends KafkaConnectCluster { public static KafkaMirrorMaker2Cluster fromCrd(KafkaMirrorMaker2 kafkaMirrorMaker2, KafkaVersion.Lookup versions) { KafkaMirrorMaker2Cluster cluster = new KafkaMirrorMaker2Cluster(kafkaMirrorMaker2); KafkaMirrorMaker2Spec spec = kafkaMirrorMaker2.getSpec(); cluster.setOwnerReference(kafkaMirrorMaker2); String specVersion = spec.getVersion(); if (versions.version(specVersion).compareVersion("2.4.0") < 0) { throw new InvalidResourceException("Kafka MirrorMaker 2.0 is not available in the version at spec.version (" + specVersion + "). Kafka MirrorMaker 2.0 is available in Kafka version 2.4.0 and later."); } cluster.setImage(versions.kafkaMirrorMaker2Version(spec.getImage(), specVersion)); List<KafkaMirrorMaker2ClusterSpec> clustersList = ModelUtils.asListOrEmptyList(spec.getClusters()); cluster.setClusters(clustersList); KafkaMirrorMaker2ClusterSpec connectCluster = new KafkaMirrorMaker2ClusterSpecBuilder().build(); String connectClusterAlias = spec.getConnectCluster(); if (connectClusterAlias != null) { connectCluster = clustersList.stream() .filter(clustersListItem -> spec.getConnectCluster().equals(clustersListItem.getAlias())) .findFirst() .orElseThrow(() -> new InvalidResourceException("connectCluster with alias " + connectClusterAlias + " cannot be found in the list of clusters at spec.clusters")); } cluster.setConfiguration(new KafkaMirrorMaker2Configuration(connectCluster.getConfig().entrySet())); return fromSpec(buildKafkaConnectSpec(spec, connectCluster), versions, cluster); } private  KafkaMirrorMaker2Cluster(HasMetadata resource); static KafkaMirrorMaker2Cluster fromCrd(KafkaMirrorMaker2 kafkaMirrorMaker2, 
                                                   KafkaVersion.Lookup versions); @Override String getServiceAccountName();  }