protected Map<String, String> getSelectorLabels() { return labels.withName(name).strimziLabels().toMap(); }
@Test public void testStrimziLabels() { Map sourceMap = new HashMap<String, String>(5); sourceMap.put(Labels.STRIMZI_CLUSTER_LABEL, "my-cluster"); sourceMap.put("key1", "value1"); sourceMap.put(Labels.STRIMZI_KIND_LABEL, "Kafka"); sourceMap.put("key2", "value2"); sourceMap.put(Labels.STRIMZI_NAME_LABEL, "my-cluster-kafka"); Labels labels = Labels.fromMap(sourceMap); Map expected = new HashMap<String, String>(2); expected.put(Labels.STRIMZI_CLUSTER_LABEL, "my-cluster"); expected.put(Labels.STRIMZI_KIND_LABEL, "Kafka"); expected.put(Labels.STRIMZI_NAME_LABEL, "my-cluster-kafka"); assertEquals(expected, labels.strimziLabels().toMap()); }
public Labels withUserLabels(Map<String, String> userLabels) { Map<String, String> newLabels = new HashMap<>(labels.size()); newLabels.putAll(labels); newLabels.putAll(Labels.userLabels(userLabels).toMap()); return new Labels(newLabels); }
protected Map<String, String> getLabelsWithName(String name, Map<String, String> userLabels) { return labels.withName(name).withUserLabels(userLabels).toMap(); }
protected Watch watchInAnyNamespace(Labels selector, Watcher<T> watcher) { return operation().inAnyNamespace().withLabels(selector.toMap()).watch(watcher); }
public static KafkaConnectCluster fromCrd(KafkaConnect kafkaConnect, KafkaVersion.Lookup versions) { KafkaConnectCluster cluster = fromSpec(kafkaConnect.getSpec(), versions, new KafkaConnectCluster(kafkaConnect.getMetadata().getNamespace(), kafkaConnect.getMetadata().getName(), Labels.fromResource(kafkaConnect).withKind(kafkaConnect.getKind()))); cluster.setOwnerReference(kafkaConnect); return cluster; }
private final Future<CompositeFuture> deleteKafka(Reconciliation reconciliation) { String namespace = reconciliation.namespace(); String name = reconciliation.name(); String kafkaSsName = KafkaCluster.kafkaClusterName(name); Labels pvcSelector = Labels.forCluster(name).withKind(Kafka.RESOURCE_KIND).withName(kafkaSsName); return deletePersistentVolumeClaim(namespace, pvcSelector); }
Labels selectorLabels = Labels.EMPTY.withKind(reconciliation.type().toString()).withCluster(reconciliation.name()); Labels caLabels = Labels.userLabels(kafkaAssembly.getMetadata().getLabels()).withKind(reconciliation.type().toString()).withCluster(reconciliation.name()); Future<ReconciliationState> result = Future.future(); vertx.createSharedWorkerExecutor("kubernetes-ops-pool").<ReconciliationState>executeBlocking( clusterCaConfig != null ? clusterCaConfig.getCertificateExpirationPolicy() : null); clusterCa.createRenewOrReplace( reconciliation.namespace(), reconciliation.name(), caLabels.toMap(), ownerRef); clientsCaConfig != null ? clientsCaConfig.getCertificateExpirationPolicy() : null); clientsCa.createRenewOrReplace(reconciliation.namespace(), reconciliation.name(), caLabels.toMap(), ownerRef);
@Test public void testWithUserLabels() { Labels start = Labels.forCluster("my-cluster"); // null user labels Labels nullLabels = start.withUserLabels(null); assertEquals(start.toMap(), nullLabels.toMap()); // Non-null values Map userLabels = new HashMap<String, String>(2); userLabels.put("key1", "value1"); userLabels.put("key2", "value2"); Map<String, String> expected = new HashMap<String, String>(); expected.putAll(start.toMap()); expected.putAll(userLabels); Labels nonNullLabels = start.withUserLabels(userLabels); assertEquals(expected, nonNullLabels.toMap()); }
/** * Generates service for pod. This service is used for exposing it externally. * * @param pod Number of the pod for which this service should be generated * @return The generated Service */ public Service generateExternalService(int pod) { if (isExposed()) { String perPodServiceName = externalServiceName(cluster, pod); List<ServicePort> ports = new ArrayList<>(1); ports.add(createServicePort(EXTERNAL_PORT_NAME, EXTERNAL_PORT, EXTERNAL_PORT, "TCP")); Labels selector = Labels.fromMap(getSelectorLabels()).withStatefulSetPod(kafkaPodName(cluster, pod)); return createService(perPodServiceName, getExternalServiceType(), ports, getLabelsWithName(perPodServiceName, templatePerPodServiceLabels), selector.toMap(), mergeAnnotations(Collections.EMPTY_MAP, templatePerPodServiceAnnotations)); } return null; }
Future<ReconciliationState> clusterOperatorSecret() { Labels labels = Labels.userLabels(kafkaAssembly.getMetadata().getLabels()).withKind(reconciliation.type().toString()).withCluster(reconciliation.name()); OwnerReference ownerRef = new OwnerReferenceBuilder() .withApiVersion(kafkaAssembly.getApiVersion()) .withKind(kafkaAssembly.getKind()) .withName(kafkaAssembly.getMetadata().getName()) .withUid(kafkaAssembly.getMetadata().getUid()) .withBlockOwnerDeletion(false) .withController(false) .build(); Secret secret = ModelUtils.buildSecret(clusterCa, clusterCa.clusterOperatorSecret(), namespace, ClusterOperator.secretName(name), "cluster-operator", "cluster-operator", labels, ownerRef); return withVoid(secretOperations.reconcile(namespace, ClusterOperator.secretName(name), secret)); }
@Test public void testParseValidLabels() { String validLabels = "key1=value1,key2=value2"; Map sourceMap = new HashMap<String, String>(2); sourceMap.put("key1", "value1"); sourceMap.put("key2", "value2"); Labels expected = Labels.fromMap(sourceMap); Assert.assertEquals(expected, Labels.fromString(validLabels)); }
@Test(expected = IllegalArgumentException.class) public void testParseInvalidLabels2() { String invalidLabels = "key1=value1,key2="; Labels.fromString(invalidLabels); }
@Test public void testParseNullLabelsInUserLabels() { assertEquals(Labels.EMPTY, Labels.userLabels(null)); }
@Test public void testParseNullLabelsInFromMap() { assertEquals(Labels.EMPTY, Labels.fromMap(null)); }
log.debug("reconcileAll({}, {}): desired resources with labels {}: {}", RESOURCE_KIND, trigger, selector, desiredNames); Labels resourceSelector = selector.withKind(RESOURCE_KIND); List<? extends HasMetadata> resources = getResources(namespace, resourceSelector); Set<String> resourceNames = resources.stream()
@Test(expected = IllegalArgumentException.class) public void testWithInvalidUserLabels() { Map userLabelsWithStrimzi = new HashMap<String, String>(2); userLabelsWithStrimzi.put("key1", "value1"); userLabelsWithStrimzi.put("key2", "value2"); userLabelsWithStrimzi.put("strimzi.io/something", "value3"); Labels nonNullLabels = Labels.EMPTY.withUserLabels(userLabelsWithStrimzi); } }
protected Watch watchInNamespace(String namespace, Labels selector, Watcher<T> watcher) { return operation().inNamespace(namespace).withLabels(selector.toMap()).watch(watcher); }