use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.
the class ImageEnricherTest method checkEnrichDeploymentConfig.
@Test
public void checkEnrichDeploymentConfig() throws Exception {
KubernetesListBuilder builder = new KubernetesListBuilder().addNewDeploymentConfigItem().endDeploymentConfigItem();
imageEnricher.addMissingResources(builder);
assertCorrectlyGeneratedResources(builder.build(), "DeploymentConfig");
}
use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.
the class MergeEnricher method adapt.
@Override
public void adapt(KubernetesListBuilder builder) {
List<HasMetadata> items = notNullList(builder.getItems());
Map<String, Map<String, HasMetadata>> kindMaps = new HashMap<>();
List<HasMetadata> removeList = new ArrayList<>();
for (HasMetadata item : items) {
String kind = getKind(item);
String name = KubernetesHelper.getName(item);
Map<String, HasMetadata> map = kindMaps.get(kind);
if (map == null) {
map = new HashMap<>();
kindMaps.put(kind, map);
}
HasMetadata old = map.get(name);
if (old != null) {
HasMetadata removeItem = mergeEntities(old, item);
if (removeItem != null) {
removeList.add(removeItem);
}
} else {
map.put(name, item);
}
}
items.removeAll(removeList);
builder.withItems(items);
}
use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8 by fabric8io.
the class SessionListener method enhance.
private KubernetesList enhance(final Session session, Configuration configuration, KubernetesList kubernetesList) {
if (configuration == null || configuration.getProperties() == null || !configuration.getProperties().containsKey(Constants.KUBERNETES_MODEL_PROCESSOR_CLASS)) {
return kubernetesList;
}
String processorClassName = configuration.getProperties().get(Constants.KUBERNETES_MODEL_PROCESSOR_CLASS);
try {
final Object instance = SessionListener.class.getClassLoader().loadClass(processorClassName).newInstance();
KubernetesListBuilder builder = new KubernetesListBuilder(kubernetesList);
((Visitable) builder).accept(new Visitor() {
@Override
public void visit(Object o) {
for (Method m : findMethods(instance, o.getClass())) {
Named named = m.getAnnotation(Named.class);
if (named != null && !Strings.isNullOrBlank(named.value())) {
String objectName = o instanceof ObjectMeta ? getName((ObjectMeta) o) : getName((HasMetadata) o);
// If a name has been explicitly specified check if there is a match
if (!named.value().equals(objectName)) {
session.getLogger().warn("Named method:" + m.getName() + " with name:" + named.value() + " doesn't match: " + objectName + ", ignoring");
return;
}
}
try {
m.invoke(instance, o);
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
session.getLogger().error("Error invoking visitor method:" + m.getName() + " on:" + instance + "with argument:" + o);
}
}
}
});
return builder.build();
} catch (Exception e) {
session.getLogger().warn("Failed to load processor class:" + processorClassName + ". Ignoring");
return kubernetesList;
}
}
use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8 by fabric8io.
the class TemplatesTest method testCombineResourcesIntoTemplate.
@Test
public void testCombineResourcesIntoTemplate() throws Exception {
Service templateService = new ServiceBuilder().withNewMetadata().withName("templateService").endMetadata().build();
KubernetesList list = new KubernetesListBuilder().addNewServiceItem().withNewMetadata().withName("service1").endMetadata().endServiceItem().addNewTemplateItem().addNewParameter().withName("PARAM1").withValue("ABC").endParameter().addToObjects(templateService).endTemplateItem().addNewServiceItem().withNewMetadata().withName("service2").endMetadata().endServiceItem().build();
Object result = Templates.combineTemplates(list);
System.out.println("Combined as " + KubernetesHelper.toJson(result));
assertThat(result).isInstanceOf(Template.class);
}
Aggregations