code: public static String getNamespace(HasMetadata entity) {
      if (entity != null) {
        return getNamespace(entity.getMetadata());
      } else {
        return null;
      }
    }
docs: Getting namespace from Kubernetes Resource
  
  @param entity Kubernetes Resource
  @return returns namespace as plain string