Java Code Examples for io.fabric8.kubernetes.api.model.HasMetadata#getMetadata()

The following examples show how to use io.fabric8.kubernetes.api.model.HasMetadata#getMetadata() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidationUtil.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
public static String createValidationMessage(Set<ConstraintViolation<?>> constraintViolations) {
    if (constraintViolations.isEmpty()) {
        return "No Constraint Validations!";
    }
    StringBuilder builder = new StringBuilder("Constraint Validations: ");
    for (ConstraintViolation<?> violation : constraintViolations) {
        if (builder.length() > 0) {
            builder.append(", ");
        }
        Object leafBean = violation.getLeafBean();
        if (leafBean instanceof HasMetadata) {
            HasMetadata hasMetadata = (HasMetadata) leafBean;
            ObjectMeta metadata = hasMetadata.getMetadata();
            if (metadata != null) {
                leafBean = "" + hasMetadata.getKind() + ": " + metadata;
            }
        }
        builder.append(violation.getPropertyPath() + " " + violation.getMessage() + " on bean: " + leafBean);
    }
    return builder.toString();
}
 
Example 2
Source File: KubernetesResourceUtil.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
protected static void mergeMetadata(HasMetadata item1, HasMetadata item2) {
    if (item1 != null && item2 != null) {
        ObjectMeta metadata1 = item1.getMetadata();
        ObjectMeta metadata2 = item2.getMetadata();
        if (metadata1 == null) {
            item1.setMetadata(metadata2);
        } else if (metadata2 != null) {
            metadata1.setAnnotations(mergeMapsAndRemoveEmptyStrings(metadata2.getAnnotations(), metadata1.getAnnotations()));
            metadata1.setLabels(mergeMapsAndRemoveEmptyStrings(metadata2.getLabels(), metadata1.getLabels()));
        }
    }
}
 
Example 3
Source File: KubernetesResourceUtil.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public static OwnerReference getControllerUid(HasMetadata resource) {
  if (resource.getMetadata() != null) {
    List<OwnerReference> ownerReferenceList = resource.getMetadata().getOwnerReferences();
    for (OwnerReference ownerReference : ownerReferenceList) {
      if (Boolean.TRUE.equals(ownerReference.getController())) {
        return ownerReference;
      }
    }
  }
  return null;
}
 
Example 4
Source File: KubernetesResourceUtil.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the resource version for the entity or null if it does not have one
 *
 * @param entity entity provided
 * @return returns resource version of provided entity
 */
public static String getResourceVersion(HasMetadata entity) {
  if (entity != null) {
    ObjectMeta metadata = entity.getMetadata();
    if (metadata != null) {
      String resourceVersion = metadata.getResourceVersion();
      if (!Utils.isNullOrEmpty(resourceVersion)) {
        return resourceVersion;
      }
    }
  }
  return null;
}
 
Example 5
Source File: KubernetesObjectUtil.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** Adds annotation to target Kubernetes object. */
public static void putAnnotation(HasMetadata target, String key, String value) {
  ObjectMeta metadata = target.getMetadata();

  if (metadata == null) {
    target.setMetadata(metadata = new ObjectMeta());
  }

  putAnnotation(metadata, key, value);
}
 
Example 6
Source File: KubernetesObjectUtil.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** Adds label to target Kubernetes object. */
public static void putLabel(HasMetadata target, String key, String value) {
  ObjectMeta metadata = target.getMetadata();

  if (metadata == null) {
    target.setMetadata(metadata = new ObjectMeta());
  }

  putLabel(target.getMetadata(), key, value);
}
 
Example 7
Source File: KubernetesObjectUtil.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** Checks if the specified object has the specified label. */
public static boolean isLabeled(HasMetadata source, String key, String value) {
  ObjectMeta metadata = source.getMetadata();

  if (metadata == null) {
    return false;
  }

  Map<String, String> labels = metadata.getLabels();
  if (labels == null) {
    return false;
  }

  return value.equals(labels.get(key));
}
 
Example 8
Source File: Metadata.java    From dekorate with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@link Predicate} that checks that a resource builder doesn't match the name and kind.
 * @param kind The specified kind.
 * @param name The specified name.
 * @return The predicate.
 */
public static Predicate<VisitableBuilder<? extends HasMetadata, ?>> matching(String apiVersion, String kind, String name) {
  return new Predicate<VisitableBuilder<? extends HasMetadata, ?>>() {
    @Override
    public Boolean apply(VisitableBuilder<? extends HasMetadata, ?> builder) {
      HasMetadata item = builder.build();
      ObjectMeta metadata = item.getMetadata();
      return apiVersion.equals(item.getApiVersion()) &&
        kind != null && kind.equals(item.getKind()) &&
        name != null && name.equals(metadata.getName());
    }
  };
}
 
Example 9
Source File: KubernetesHelper.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static Date getCreationTimestamp(HasMetadata hasMetadata) {
    ObjectMeta metadata = hasMetadata.getMetadata();
    if (metadata != null) {
        return parseTimestamp(metadata.getCreationTimestamp());
    }
    return null;
}
 
Example 10
Source File: KubernetesHelper.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the resource version for the entity or null if it does not have one
 *
 * @param entity entity as HasMetadata object
 * @return resource version as string value
 */
public static String getResourceVersion(HasMetadata entity) {
    if (entity != null) {
        ObjectMeta metadata = entity.getMetadata();
        if (metadata != null) {
            String resourceVersion = metadata.getResourceVersion();
            if (StringUtils.isNotBlank(resourceVersion)) {
                return resourceVersion;
            }
        }
    }
    return null;
}
 
Example 11
Source File: RemoveBuildAnnotationsEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private void removeBuildAnnotations(HasMetadata item) {
    if (item != null) {
        ObjectMeta metadata = item.getMetadata();
        if (metadata != null) {
            Map<String, String> annotations = metadata.getAnnotations();
            if (annotations != null) {
                annotations.remove(RESOURCE_SOURCE_URL_ANNOTATION);
            }
        }
    }
}
 
Example 12
Source File: KubernetesResourceUtil.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static Date getCreationTimestamp(HasMetadata hasMetadata) {
    ObjectMeta metadata = hasMetadata.getMetadata();
    if (metadata != null) {
        return parseTimestamp(metadata.getCreationTimestamp());
    }
    return null;
}
 
Example 13
Source File: Annotations.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static boolean booleanAnnotation(HasMetadata resource, String annotation, boolean defaultValue, String... deprecatedAnnotations) {
    ObjectMeta metadata = resource.getMetadata();
    String str = annotation(annotation, null, metadata, deprecatedAnnotations);
    return str != null ? parseBoolean(str) : defaultValue;
}
 
Example 14
Source File: Annotations.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static int intAnnotation(HasMetadata resource, String annotation, int defaultValue, String... deprecatedAnnotations) {
    ObjectMeta metadata = resource.getMetadata();
    String str = annotation(annotation, null, metadata, deprecatedAnnotations);
    return str != null ? parseInt(str) : defaultValue;
}
 
Example 15
Source File: Annotations.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static String stringAnnotation(HasMetadata resource, String annotation, String defaultValue, String... deprecatedAnnotations) {
    ObjectMeta metadata = resource.getMetadata();
    String str = annotation(annotation, null, metadata, deprecatedAnnotations);
    return str != null ? str : defaultValue;
}
 
Example 16
Source File: Annotations.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static boolean hasAnnotation(HasMetadata resource, String annotation) {
    ObjectMeta metadata = resource.getMetadata();
    String str = annotation(annotation, null, metadata, null);
    return str != null;
}
 
Example 17
Source File: Annotations.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static int incrementIntAnnotation(HasMetadata podSpec, String annotation, int defaultValue, String... deprecatedAnnotations) {
    ObjectMeta metadata = podSpec.getMetadata();
    return incrementIntAnnotation(annotation, defaultValue, metadata, deprecatedAnnotations);
}
 
Example 18
Source File: ContainerSearch.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private boolean matchMetadata(HasMetadata object) {
  ObjectMeta metaData = object.getMetadata();
  return matchesByName(metaData, parentName)
      && (parentSelector == null || SelectorFilter.test(metaData, parentSelector));
}
 
Example 19
Source File: TriggersAnnotationEnricher.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean canWriteTriggers(HasMetadata res) {
    return res.getMetadata() == null ||
            res.getMetadata().getAnnotations() == null ||
            !res.getMetadata().getAnnotations().containsKey(TRIGGERS_ANNOTATION);
}