use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method loadResources.
public static Set<HasMetadata> loadResources(File manifest) throws IOException {
Object dto = KubernetesHelper.loadYaml(manifest, KubernetesResource.class);
if (dto == null) {
throw new IllegalStateException("Cannot load kubernetes YAML: " + manifest);
}
if (dto instanceof Template) {
Template template = (Template) dto;
boolean failOnMissingParameterValue = false;
dto = Templates.processTemplatesLocally(template, failOnMissingParameterValue);
}
Set<KubernetesResource<?>> resources = new LinkedHashSet<>();
Set<HasMetadata> entities = new TreeSet<>(new HasMetadataComparator());
for (KubernetesResource<?> resource : resources) {
entities.addAll(KubernetesHelper.toItemList(resource));
}
entities.addAll(KubernetesHelper.toItemList(dto));
return entities;
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class OpenShiftDependencyResources method addOpenShiftResources.
public void addOpenShiftResources(List<HasMetadata> items, boolean isAppCatalog) {
for (HasMetadata item : items) {
if (item instanceof Template) {
Template template = (Template) item;
if (!KubernetesResourceUtil.isAppCatalogResource(template) && !isAppCatalog) {
List<HasMetadata> objects = notNullList(template.getObjects());
String sourceUrl = getSourceUrlAnnotation(template);
if (Strings.isNotBlank(sourceUrl)) {
for (HasMetadata object : objects) {
setSourceUrlAnnotationIfNotSet(object, sourceUrl);
}
}
addOpenShiftResources(objects, isAppCatalog);
mergeParametersIntoMap(templateParameters, notNullList(template.getParameters()));
continue;
}
}
KindAndName key = new KindAndName(item);
HasMetadata old = openshiftDependencyResources.get(key);
if (old != null && !isAppCatalog) {
log.warn("Duplicate OpenShift resources for %s at %s and %s", key, getSourceUrlAnnotation(old), getSourceUrlAnnotation(item));
}
openshiftDependencyResources.put(key, item);
}
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class OpenShiftDependencyResources method convertKubernetesItemToOpenShift.
/**
* Returns the OpenShift dependency for the given resource if there is one
*/
public HasMetadata convertKubernetesItemToOpenShift(HasMetadata item) {
KindAndName key = new KindAndName(item);
HasMetadata answer = openshiftDependencyResources.get(key);
if (answer == null && item instanceof Deployment) {
key = new KindAndName("DeploymentConfig", getName(item));
answer = openshiftDependencyResources.get(key);
}
return answer;
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class ValidationUtil method createValidationMessage.
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();
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class ReplicSetOpenShiftConverter method convert.
@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
ReplicaSet resource = (ReplicaSet) item;
ReplicationControllerBuilder builder = new ReplicationControllerBuilder();
builder.withMetadata(resource.getMetadata());
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder> specBuilder = builder.withNewSpec();
Integer replicas = spec.getReplicas();
if (replicas != null) {
specBuilder.withReplicas(replicas);
}
LabelSelector selector = spec.getSelector();
if (selector != null) {
Map<String, String> matchLabels = selector.getMatchLabels();
if (matchLabels != null && !matchLabels.isEmpty()) {
specBuilder.withSelector(matchLabels);
}
}
PodTemplateSpec template = spec.getTemplate();
if (template != null) {
specBuilder.withTemplate(template);
}
specBuilder.endSpec();
}
return builder.build();
}
Aggregations