Java Code Examples for io.fabric8.kubernetes.api.model.KubernetesListBuilder#accept()
The following examples show how to use
io.fabric8.kubernetes.api.model.KubernetesListBuilder#accept() .
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: ImageEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
private void updateContainers(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<PodTemplateSpecBuilder>() { @Override public void visit(PodTemplateSpecBuilder templateBuilder) { PodTemplateSpecFluent.SpecNested<PodTemplateSpecBuilder> podSpec = templateBuilder.buildSpec() == null ? templateBuilder.withNewSpec() : templateBuilder.editSpec(); List<Container> containers = podSpec.buildContainers(); if (containers == null) { containers = new ArrayList<>(); } mergeImageConfigurationWithContainerSpec(containers); podSpec.withContainers(containers).endSpec(); } }); }
Example 2
Source File: FileDataSecretEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
private void addAnnotations(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<SecretBuilder>() { @Override public void visit(SecretBuilder element) { final Map<String, String> annotations = element.buildMetadata().getAnnotations(); try { if (annotations != null && !annotations.isEmpty()) { final Map<String, String> secretAnnotations = createSecretFromAnnotations(annotations); element.addToData(secretAnnotations); } } catch (IOException e) { throw new IllegalArgumentException(e); } } }); }
Example 3
Source File: GroupKindsDecorator.java From dekorate with Apache License 2.0 | 6 votes |
public void visit(KubernetesListBuilder kubernetesList) { List<GroupKind> groupKinds = new ArrayList<>(); for (HasMetadata h : kubernetesList.getItems()) { groupKinds.add(new GroupKindBuilder() .withKind(h.getKind()) .withGroup(apiVersionGroup(h.getApiVersion())) .build()); } kubernetesList.accept(new Decorator<ApplicationSpecBuilder>() { @Override public void visit(ApplicationSpecBuilder applicationSpec) { applicationSpec.withComponentKinds(groupKinds); } }); }
Example 4
Source File: RouteEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Override public void create(PlatformMode platformMode, final KubernetesListBuilder listBuilder) { ResourceConfig resourceConfig = getConfiguration().getResource(); if (resourceConfig != null && resourceConfig.getRouteDomain() != null) { routeDomainPostfix = resourceConfig.getRouteDomain(); } if(platformMode == PlatformMode.openshift && generateRoute.equals(Boolean.TRUE)) { final List<Route> routes = new ArrayList<>(); listBuilder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { addRoute(listBuilder, serviceBuilder, routes); } }); if (!routes.isEmpty()) { Route[] routeArray = new Route[routes.size()]; routes.toArray(routeArray); listBuilder.addToItems(routeArray); } } }
Example 5
Source File: PrometheusEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { String prometheusPort = findPrometheusPort(); if (StringUtils.isNotBlank(prometheusPort)) { Map<String, String> annotations = new HashMap<>(); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_PORT, prometheusPort); MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_SCRAPE, "true"); String prometheusPath = getConfig(Config.prometheusPath); if (StringUtils.isNotBlank(prometheusPath)) { MapUtil.putIfAbsent(annotations, ANNOTATION_PROMETHEUS_PATH, prometheusPath); } log.verbose("Adding prometheus.io annotations: %s", annotations.entrySet() .stream() .map(Object::toString) .collect(Collectors.joining(", "))); serviceBuilder.editMetadata().addToAnnotations(annotations).endMetadata(); } } }); }
Example 6
Source File: ConfigMapEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
private void addAnnotations(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ConfigMapBuilder>() { @Override public void visit(ConfigMapBuilder element) { final Map<String, String> annotations = element.buildMetadata().getAnnotations(); if (annotations != null) { try { addConfigMapFromAnnotations(annotations, element); } catch (IOException e) { throw new IllegalArgumentException(e); } } } }); }
Example 7
Source File: IngressEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Override public void create(PlatformMode platformMode, final KubernetesListBuilder listBuilder) { ResourceConfig resourceConfig = getConfiguration().getResource(); Boolean shouldCreateIngress = getValueFromConfig(CREATE_EXTERNAL_URLS, false); if (shouldCreateIngress.equals(Boolean.FALSE)) { return; } if (platformMode == PlatformMode.kubernetes) { listBuilder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder serviceBuilder) { Ingress ingress = addIngress(listBuilder, serviceBuilder, getRouteDomain(resourceConfig), log); if (ingress != null) { listBuilder.addToItems(ingress); } } }); } }
Example 8
Source File: ImageEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void ensureTemplateSpecsInReplicationControllers(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ReplicationControllerBuilder>() { @Override public void visit(ReplicationControllerBuilder item) { ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder> spec = item.buildSpec() == null ? item.withNewSpec() : item.editSpec(); ReplicationControllerSpecFluent.TemplateNested<ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder>> template = spec.buildTemplate() == null ? spec.withNewTemplate() : spec.editTemplate(); template.endTemplate().endSpec(); } }); }
Example 9
Source File: DefaultServiceEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private boolean hasServices(KubernetesListBuilder builder) { final AtomicBoolean hasService = new AtomicBoolean(false); builder.accept(new TypedVisitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder element) { hasService.set(true); } }); return hasService.get(); }
Example 10
Source File: DefaultServiceEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void normalizeServicePorts(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ServicePortBuilder>() { @Override public void visit(ServicePortBuilder portBuilder) { PORT_NORMALIZATION_MAPPING.keySet().forEach(key -> { if (key.intValue() == portBuilder.buildTargetPort().getIntVal()) { portBuilder.withPort(PORT_NORMALIZATION_MAPPING.get(key)); } }); } }); }
Example 11
Source File: DefaultMetadataEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void visit(ProcessorConfig config, KubernetesListBuilder builder, MetadataVisitor<?>[] visitors) { MetadataVisitor.setProcessorConfig(config); try { for (MetadataVisitor<?> visitor : visitors) { builder.accept(visitor); } } finally { MetadataVisitor.clearProcessorConfig(); } }
Example 12
Source File: IngressEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
/** * Returns true if we already have a route created for the given name */ private static boolean hasIngress(final KubernetesListBuilder listBuilder, final String name) { final AtomicBoolean answer = new AtomicBoolean(false); listBuilder.accept(new TypedVisitor<IngressBuilder>() { @Override public void visit(IngressBuilder builder) { ObjectMeta metadata = builder.buildMetadata(); if (metadata != null && name.equals(metadata.getName())) { answer.set(true); } } }); return answer.get(); }
Example 13
Source File: ImageEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void ensureTemplateSpecsInStatefulSet(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<StatefulSetBuilder>() { @Override public void visit(StatefulSetBuilder item) { StatefulSetFluent.SpecNested<StatefulSetBuilder> spec = item.buildSpec() == null ? item.withNewSpec() : item.editSpec(); StatefulSetSpecFluent.TemplateNested<StatefulSetFluent.SpecNested<StatefulSetBuilder>> template = spec.buildTemplate() == null ? spec.withNewTemplate() : spec.editTemplate(); template.endTemplate().endSpec(); } }); }
Example 14
Source File: ImageEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void ensureTemplateSpecsInDeployments(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<DeploymentBuilder>() { @Override public void visit(DeploymentBuilder item) { DeploymentFluent.SpecNested<DeploymentBuilder> spec = item.buildSpec() == null ? item.withNewSpec() : item.editSpec(); DeploymentSpecFluent.TemplateNested<DeploymentFluent.SpecNested<DeploymentBuilder>> template = spec.buildTemplate() == null ? spec.withNewTemplate() : spec.editTemplate(); template.endTemplate().endSpec(); } }); }
Example 15
Source File: PortNameEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
@Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ContainerPortBuilder>() { @Override public void visit(ContainerPortBuilder portBuilder) { Integer port = portBuilder.getContainerPort(); // If port is given but no name, then try to detect the name if (port != null && StringUtils.isBlank(portBuilder.getName())) { addPortName(portBuilder, port); } } }); }
Example 16
Source File: AbstractHealthCheckEnricherTest.java From jkube with Eclipse Public License 2.0 | 5 votes |
@Test public void enrichContainerWithSidecar() { KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder() .withNewSpec() .withNewTemplate() .withNewSpec() .addNewContainer() .withName("app") .withImage("app:latest") .endContainer() .addNewContainer() .withName("sidecar") .withImage("sidecar:latest") .endContainer() .endSpec() .endTemplate() .endSpec() .build()); createEnricher(new Properties(), Collections.singletonMap("FABRIC8_GENERATED_CONTAINERS", "app")).create(PlatformMode.kubernetes, list); final AtomicInteger containerFound = new AtomicInteger(0); list.accept(new TypedVisitor<ContainerBuilder>() { @Override public void visit(ContainerBuilder container) { if (container.getName().equals("app")) { assertNotNull(container.build().getLivenessProbe()); assertNotNull(container.build().getReadinessProbe()); containerFound.incrementAndGet(); } else if (container.getName().equals("sidecar")) { assertNull(container.build().getLivenessProbe()); assertNull(container.build().getReadinessProbe()); containerFound.incrementAndGet(); } } }); assertEquals(2, containerFound.get()); }
Example 17
Source File: AbstractHealthCheckEnricherTest.java From jkube with Eclipse Public License 2.0 | 5 votes |
@Test public void enrichSingleContainer() { KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder() .withNewSpec() .withNewTemplate() .withNewSpec() .addNewContainer() .withName("app") .withImage("app:latest") .endContainer() .endSpec() .endTemplate() .endSpec() .build()); createEnricher(new Properties(), Collections.emptyMap()).create(PlatformMode.kubernetes, list); final AtomicInteger containerFound = new AtomicInteger(0); list.accept(new TypedVisitor<ContainerBuilder>() { @Override public void visit(ContainerBuilder container) { assertNotNull(container.build().getLivenessProbe()); assertNotNull(container.build().getReadinessProbe()); containerFound.incrementAndGet(); } }); assertEquals(1, containerFound.get()); }
Example 18
Source File: ServiceAccountEnricher.java From jkube with Eclipse Public License 2.0 | 4 votes |
@Override public void create(PlatformMode mode, KubernetesListBuilder builder) { Map<String, String> deploymentToSaPair = new HashMap<>(); List<ServiceAccount> serviceAccounts = new ArrayList<>(); // Check XML config and see if there are any service accounts specified ResourceConfig xmlResourceConfig = getConfiguration().getResource(); if(xmlResourceConfig != null && xmlResourceConfig.getServiceAccounts() != null) { for(ServiceAccountConfig serviceAccountConfig : xmlResourceConfig.getServiceAccounts()) { if(serviceAccountConfig.getName() != null) { serviceAccounts.add(createServiceAccount(builder, serviceAccountConfig.getName())); } if(serviceAccountConfig.getDeploymentRef() != null) { deploymentToSaPair.put(serviceAccountConfig.getDeploymentRef(), serviceAccountConfig.getName()); } } } // If any service account is referenced in deployment spec, then // create sa on fly. builder.accept(new TypedVisitor<DeploymentBuilder>() { @Override public void visit(DeploymentBuilder deploymentBuilder) { String serviceAccountName = getServiceAccountNameFromSpec(deploymentBuilder); if(serviceAccountName != null && getServiceAccountFromList(builder, serviceAccountName) == null) { serviceAccounts.add(createServiceAccount(builder, serviceAccountName)); } if(deploymentToSaPair.containsKey(deploymentBuilder.buildMetadata().getName())) { deploymentBuilder.editSpec() .editTemplate() .editSpec() .withServiceAccountName(deploymentToSaPair.get(deploymentBuilder.buildMetadata().getName())) .endSpec() .endTemplate() .endSpec(); } } }); builder.addAllToServiceAccountItems(serviceAccounts); }
Example 19
Source File: AbstractHealthCheckEnricherTest.java From jkube with Eclipse Public License 2.0 | 4 votes |
@Test public void enrichAllContainers() { final Properties properties = new Properties(); properties.put(AbstractHealthCheckEnricher.ENRICH_ALL_CONTAINERS, "true"); KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder() .withNewSpec() .withNewTemplate() .withNewSpec() .addNewContainer() .withName("app") .withImage("app:latest") .endContainer() .addNewContainer() .withName("app2") .withImage("app2:latest") .endContainer() .endSpec() .endTemplate() .endSpec() .build()); createEnricher(properties, Collections.emptyMap()).create(PlatformMode.kubernetes,list); final AtomicInteger containerFound = new AtomicInteger(0); list.accept(new TypedVisitor<ContainerBuilder>() { @Override public void visit(ContainerBuilder container) { if (container.getName().equals("app")) { assertNotNull(container.build().getLivenessProbe()); assertNotNull(container.build().getReadinessProbe()); containerFound.incrementAndGet(); } else if (container.getName().equals("app2")) { assertNotNull(container.build().getLivenessProbe()); assertNotNull(container.build().getReadinessProbe()); containerFound.incrementAndGet(); } } }); assertEquals(2, containerFound.get()); }
Example 20
Source File: AbstractHealthCheckEnricherTest.java From jkube with Eclipse Public License 2.0 | 4 votes |
@Test public void enrichSpecificContainers() { final Properties properties = new Properties(); properties.put(AbstractHealthCheckEnricher.ENRICH_CONTAINERS, "app2,app3"); KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder() .withNewSpec() .withNewTemplate() .withNewSpec() .addNewContainer() .withName("app") .withImage("app:latest") .endContainer() .addNewContainer() .withName("app2") .withImage("app2:latest") .endContainer() .addNewContainer() .withName("app3") .withImage("app3:latest") .endContainer() .endSpec() .endTemplate() .endSpec() .build()); createEnricher(properties, Collections.emptyMap()).create(PlatformMode.kubernetes,list); final AtomicInteger containerFound = new AtomicInteger(0); list.accept(new TypedVisitor<ContainerBuilder>() { @Override public void visit(ContainerBuilder container) { switch (container.getName()) { case "app": assertNull(container.build().getLivenessProbe()); assertNull(container.build().getReadinessProbe()); containerFound.incrementAndGet(); break; case "app2": case "app3": assertNotNull(container.build().getLivenessProbe()); assertNotNull(container.build().getReadinessProbe()); containerFound.incrementAndGet(); break; } } }); assertEquals(3, containerFound.get()); }