/** * The same labels as this instance, but with the given {@code name} for the {@code strimzi.io/name} key. */ public Labels withName(String name) { return with(STRIMZI_NAME_LABEL, name); }
/** * Returns the labels from Map. */ public static Labels fromMap(Map<String, String> labels) { if (labels != null) { return new Labels(labels); } return EMPTY; }
/** * Constructor * * @param namespace Kubernetes/OpenShift namespace where cluster resources are going to be created * @param cluster overall cluster name */ protected AbstractModel(String namespace, String cluster, Labels labels) { this.cluster = cluster; this.namespace = namespace; this.labels = labels.withCluster(cluster); }
protected Map<String, String> getLabelsWithName(String name, Map<String, String> userLabels) { return labels.withName(name).withUserLabels(userLabels).toMap(); }
protected Map<String, String> getSelectorLabels() { return labels.withName(name).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); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj == null) { return false; } else if (obj instanceof NamespaceAndName) { NamespaceAndName nrn = (NamespaceAndName) obj; if ((nrn.getName() == null && name == null) || (nrn.getName().equals(name) && ((nrn.getNamespace() == null && namespace == null) || nrn.getNamespace().equals(namespace)))) { return true; } } return false; }
@Test(expected = IllegalArgumentException.class) public void testParseInvalidLabels2() { String invalidLabels = "key1=value1,key2="; Labels.fromString(invalidLabels); }
/** * The same labels as this instance, but without any {@code strimzi.io/kind} key. */ @Deprecated public Labels withoutKind() { return without(STRIMZI_KIND_LABEL); }
@Test(expected = IllegalArgumentException.class) public void testParseInvalidLabels1() { String invalidLabels = ",key1=value1,key2=value2"; Labels.fromString(invalidLabels); }
/** * A singleton instance with the given {@code kind} for the {@code strimzi.io/kind} key. */ public static Labels forKind(String kind) { return new Labels(singletonMap(STRIMZI_KIND_LABEL, kind)); }
/** * The same labels as this instance, but with the given {@code kind} for the {@code strimzi.io/kind} key. */ public Labels withKind(String kind) { return with(STRIMZI_KIND_LABEL, kind); }
@Test(expected = IllegalArgumentException.class) public void testParseInvalidLabels3() { String invalidLabels = "key2"; Labels.fromString(invalidLabels); }
/** * A singleton instance with the given {@code cluster} for the {@code strimzi.io/cluster} key. */ public static Labels forCluster(String cluster) { return new Labels(singletonMap(STRIMZI_CLUSTER_LABEL, cluster)); }
/** * The same labels as this instance, but with the given {@code name} for the {@code strimzi.io/name} key. */ public Labels withStatefulSetPod(String name) { return with(KUBERNETES_STATEFULSET_POD_LABEL, name); }
@Test public void testParseNullLabels() { String validLabels = null; assertEquals(Labels.EMPTY, Labels.fromString(validLabels)); }
private Labels without(String label) { Map<String, String> newLabels = new HashMap<>(labels); newLabels.remove(label); return new Labels(newLabels); }
/** * The same labels as this instance, but with the given {@code cluster} for the {@code strimzi.io/cluster} key. */ public Labels withCluster(String cluster) { return with(STRIMZI_CLUSTER_LABEL, cluster); }
private Labels with(String label, String value) { Map<String, String> newLabels = new HashMap<>(labels.size() + 1); newLabels.putAll(labels); newLabels.put(label, value); return new Labels(newLabels); }