Labels { public static Labels generateDefaultLabels(HasMetadata resource, String applicationName, String managedBy) { String instanceName = resource.getMetadata().getName(); return Labels.fromResource(resource) .withStrimziKind(resource.getKind()) .withStrimziName(Labels.APPLICATION_NAME) .withStrimziCluster(instanceName) .withKubernetesName(applicationName) .withKubernetesInstance(instanceName) .withKubernetesPartOf(instanceName) .withKubernetesManagedBy(managedBy); } private  Labels(Map<String, String> labels); static String cluster(HasMetadata resource); static String name(HasMetadata resource); Labels withAdditionalLabels(Map<String, String> additionalLabels); static Labels fromResource(HasMetadata resource); static Labels fromMap(Map<String, String> labels); static Labels fromString(String stringLabels); Labels withStrimziKind(String kind); Labels withStrimziCluster(String cluster); Labels withKubernetesName(String name); Labels withKubernetesInstance(String instanceName); Labels withKubernetesPartOf(String instanceName); Labels withKubernetesManagedBy(String operatorName); Labels withStrimziName(String name); Labels withStrimziDiscovery(); Labels withStatefulSetPod(String name); Map<String, String> toMap(); String toSelectorString(); static Labels forStrimziCluster(String cluster); static Labels forStrimziKind(String kind); Labels strimziSelectorLabels(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static Labels generateDefaultLabels(HasMetadata resource, String applicationName, String managedBy); static final String STRIMZI_DOMAIN; static final String KUBERNETES_DOMAIN; static final String STRIMZI_KIND_LABEL; static final String STRIMZI_CLUSTER_LABEL; static final String STRIMZI_NAME_LABEL; static final String STRIMZI_DISCOVERY_LABEL; static final String KUBERNETES_NAME_LABEL; static final String KUBERNETES_INSTANCE_LABEL; static final String KUBERNETES_PART_OF_LABEL; static final String APPLICATION_NAME; static final String KUBERNETES_MANAGED_BY_LABEL; static final String KUBERNETES_STATEFULSET_POD_LABEL; static final Labels EMPTY; }
@Test public void testGenerateDefaultLabels() { String instance = "my-cluster"; String operatorName = "my-operator"; String appName = "an-app"; String appArchitecture = "app-architecture"; class ResourceWithMetadata implements HasMetadata { String kind; String apiVersion; ObjectMeta metadata; public ResourceWithMetadata(String kind, String apiVersion, ObjectMeta metadata) { this.kind = kind; this.apiVersion = apiVersion; this.metadata = metadata; } public ObjectMeta getMetadata() { return metadata; } public void setMetadata(ObjectMeta metadata) { this.metadata = metadata; } public String getKind() { return kind; } public String getApiVersion() { return apiVersion; } public void setApiVersion(String apiVersion) { this.apiVersion = apiVersion; } } Map<String, String> expectedLabels = new HashMap<>(); expectedLabels.put(Labels.STRIMZI_KIND_LABEL, "MyResource"); expectedLabels.put(Labels.STRIMZI_NAME_LABEL, Labels.APPLICATION_NAME); expectedLabels.put(Labels.STRIMZI_CLUSTER_LABEL, instance); expectedLabels.put(Labels.KUBERNETES_NAME_LABEL, appName); expectedLabels.put(Labels.KUBERNETES_INSTANCE_LABEL, instance); expectedLabels.put(Labels.KUBERNETES_MANAGED_BY_LABEL, operatorName); expectedLabels.put(Labels.KUBERNETES_PART_OF_LABEL, Labels.APPLICATION_NAME + "-" + instance); Labels l = Labels.generateDefaultLabels(new ResourceWithMetadata("MyResource", "strimzi.io/v0", new ObjectMetaBuilder() .withNewName(instance) .build()), appName, operatorName); assertThat(l.toMap(), is(expectedLabels)); }