/** * Getting namespace from Kubernetes Resource * * @param entity Kubernetes Resource * @return */ public static String getNamespace(HasMetadata entity) { if (entity != null) { return getNamespace(entity.getMetadata()); } else { return null; } }
/** * Returns Qualified name for the specified Kubernetes Resource * * @param entity Kubernetes resource * @return */ public static String getQualifiedName(HasMetadata entity) { if (entity != null) { return "" + getNamespace(entity) + "/" + getName(entity); } else { return null; } }
@Test public void testNullSafeOperationsForNamespace() { String namespace = KubernetesResourceUtil.getNamespace(configMap1); assertNotNull(namespace); assertEquals("ns1", namespace); assertEquals("ns1/configmap1", KubernetesResourceUtil.getQualifiedName(configMap1)); }