io.fabric8.kubernetes.api.model.KubernetesListBuilder Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.KubernetesListBuilder.
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: IngressEnricherTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Test public void testCreate() { // Given new Expectations() {{ // Enable creation of Ingress for Service of type LoadBalancer context.getProperty(CREATE_EXTERNAL_URLS); result = "true"; }}; Service providedService = getTestService().build(); KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(providedService); IngressEnricher ingressEnricher = new IngressEnricher(context); // When ingressEnricher.create(PlatformMode.kubernetes, kubernetesListBuilder); // Then Ingress ingress = (Ingress) kubernetesListBuilder.buildLastItem(); assertEquals(2, kubernetesListBuilder.buildItems().size()); assertNotNull(ingress); assertEquals(providedService.getMetadata().getName(), ingress.getMetadata().getName()); assertNotNull(ingress.getSpec()); assertEquals(providedService.getMetadata().getName(), ingress.getSpec().getBackend().getServiceName()); assertEquals(providedService.getSpec().getPorts().get(0).getTargetPort(), ingress.getSpec().getBackend().getServicePort()); }
Example #2
Source File: MavenProjectEnricherTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Test public void testGeneratedResources() { ProjectLabelEnricher projectEnricher = new ProjectLabelEnricher(context); KubernetesListBuilder builder = createListWithDeploymentConfig(); projectEnricher.enrich(PlatformMode.kubernetes, builder); KubernetesList list = builder.build(); Map<String, String> labels = list.getItems().get(0).getMetadata().getLabels(); assertNotNull(labels); assertEquals("groupId", labels.get("group")); assertEquals("artifactId", labels.get("app")); assertEquals("version", labels.get("version")); assertNull(labels.get("project")); builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().build()); projectEnricher.create(PlatformMode.kubernetes, builder); Deployment deployment = (Deployment)builder.buildFirstItem(); Map<String, String> selectors = deployment.getSpec().getSelector().getMatchLabels(); assertEquals("groupId", selectors.get("group")); assertEquals("artifactId", selectors.get("app")); assertNull(selectors.get("version")); assertNull(selectors.get("project")); }
Example #3
Source File: ResourceMojo.java From jkube with Eclipse Public License 2.0 | 6 votes |
private void addProfiledResourcesFromSubdirectories(PlatformMode platformMode, KubernetesListBuilder builder, File resourceDir, EnricherManager enricherManager) throws IOException, MojoExecutionException { File[] profileDirs = resourceDir.listFiles(File::isDirectory); if (profileDirs != null) { for (File profileDir : profileDirs) { Profile foundProfile = ProfileUtil.findProfile(profileDir.getName(), resourceDir); ProcessorConfig enricherConfig = foundProfile.getEnricherConfig(); File[] resourceFiles = KubernetesResourceUtil.listResourceFragments(profileDir); if (resourceFiles.length > 0) { KubernetesListBuilder profileBuilder = readResourceFragments(platformMode, resourceFiles); enricherManager.createDefaultResources(platformMode, enricherConfig, profileBuilder); enricherManager.enrich(platformMode, enricherConfig, profileBuilder); KubernetesList profileItems = profileBuilder.build(); for (HasMetadata item : profileItems.getItems()) { builder.addToItems(item); } } } } }
Example #4
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 #5
Source File: WaitUntilReadyIT.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testBatchWaitUntilReady() throws InterruptedException { String namespace = session.getNamespace(); pod = client.pods().inNamespace(namespace).create(pod); secondPod = client.pods().inNamespace(namespace).create(secondPod); mySecret = client.secrets().inNamespace(namespace).create(mySecret); // For waiting for single resource use this. client.resourceList(new KubernetesListBuilder().withItems(pod, secondPod, mySecret).build()).inNamespace(namespace).waitUntilReady(60, TimeUnit.SECONDS); // Cleanup client.pods().inNamespace(namespace).withName("p2").delete(); client.pods().inNamespace(namespace).withName("p1").delete(); client.secrets().inNamespace(namespace).withName("mysecret").delete(); }
Example #6
Source File: ResourceListTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testCreateOrReplaceWithoutDeleteExisting() throws Exception { server.expect().get().withPath("/api/v1/namespaces/ns1/services/my-service").andReturn(200 , service).times(2); server.expect().get().withPath("/api/v1/namespaces/ns1/configmaps/my-configmap").andReturn(200, configMap).times(2); server.expect().put().withPath("/api/v1/namespaces/ns1/services/my-service").andReturn(200, updatedService).once(); server.expect().put().withPath("/api/v1/namespaces/ns1/configmaps/my-configmap").andReturn(200, updatedConfigMap).once(); KubernetesClient client = server.getClient(); KubernetesList list = new KubernetesListBuilder().withItems(updatedService, updatedConfigMap).build(); client.resourceList(list).inNamespace("ns1").createOrReplace(); assertEquals(6, server.getMockServer().getRequestCount()); RecordedRequest request = server.getLastRequest(); assertEquals("/api/v1/namespaces/ns1/configmaps/my-configmap", request.getPath()); assertEquals("PUT", request.getMethod()); }
Example #7
Source File: BaseEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
/** * This method just makes sure that the replica count provided in XML config * overrides the default option; and resource fragments are always given * topmost priority. * * @param builder kubernetes list builder containing objects * @param xmlResourceConfig xml resource config from plugin configuration * @param defaultValue default value * @return resolved replica count */ protected int getReplicaCount(KubernetesListBuilder builder, ResourceConfig xmlResourceConfig, int defaultValue) { if (xmlResourceConfig != null) { List<HasMetadata> items = builder.buildItems(); for (HasMetadata item : items) { if (item instanceof Deployment && ((Deployment)item).getSpec().getReplicas() != null) { return ((Deployment)item).getSpec().getReplicas(); } if (item instanceof DeploymentConfig && ((DeploymentConfig)item).getSpec().getReplicas() != null) { return ((DeploymentConfig)item).getSpec().getReplicas(); } } return xmlResourceConfig.getReplicas() > 0 ? xmlResourceConfig.getReplicas() : defaultValue; } return defaultValue; }
Example #8
Source File: ConfigMapEnricherTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Test public void should_materialize_binary_file_content_from_annotation() throws Exception { final ConfigMap baseConfigMap = createAnnotationConfigMap("test.bin", "src/test/resources/test.bin"); final KubernetesListBuilder builder = new KubernetesListBuilder() .addToConfigMapItems(baseConfigMap); new ConfigMapEnricher(context).create(PlatformMode.kubernetes, builder); final ConfigMap configMap = (ConfigMap) builder.buildFirstItem(); final Map<String, String> data = configMap.getData(); assertThat(data) .isEmpty(); final Map<String, String> binaryData = configMap.getBinaryData(); assertThat(binaryData) .containsEntry("test.bin", "wA=="); final Map<String, String> annotations = configMap.getMetadata().getAnnotations(); assertThat(annotations) .isEmpty(); }
Example #9
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 #10
Source File: DebugEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { if (debugEnabled()) { int count = 0; List<HasMetadata> items = builder.buildItems(); if (items != null) { for (HasMetadata item : items) { if (enableDebug(item)) { count++; } } } if (count > 0) { builder.withItems(items); } log.verbose("Enabled debugging on " + count + " resource(s) thanks to the " + ENABLE_DEBUG_MAVEN_PROPERTY + " property"); } else { log.verbose("Debugging not enabled. To enable try setting the " + ENABLE_DEBUG_MAVEN_PROPERTY + " maven or system property to 'true'"); } }
Example #11
Source File: DefaultServiceEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { final ResourceConfig xmlConfig = getConfiguration().getResource(); if (xmlConfig != null && xmlConfig.getServices() != null) { // Add Services configured via XML addServices(builder, xmlConfig.getServices()); } else { final Service defaultService = getDefaultService(); if (hasServices(builder)) { mergeInDefaultServiceParameters(builder, defaultService); } else { addDefaultService(builder, defaultService); } if (Configs.asBoolean(getConfig(Config.normalizePort))) { normalizeServicePorts(builder); } } }
Example #12
Source File: PropagationPolicyTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test @DisplayName("Should delete a resource list with PropagationPolicy=Background") void testDeleteResourceList() throws InterruptedException { // Given Pod testPod = new PodBuilder().withNewMetadata().withName("testpod").endMetadata().build(); server.expect().delete().withPath("/api/v1/namespaces/foo/pods/testpod") .andReturn(HttpURLConnection.HTTP_OK, testPod) .once(); KubernetesClient client = server.getClient(); // When Boolean isDeleted = client.resourceList(new KubernetesListBuilder().withItems(testPod).build()).inNamespace("foo").delete(); // Then assertTrue(isDeleted); assertDeleteOptionsInLastRecordedRequest(DeletionPropagation.BACKGROUND.toString(), server.getLastRequest()); }
Example #13
Source File: ResourceListTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testCreateOrReplaceWithDeleteExisting() throws Exception { server.expect().get().withPath("/api/v1/namespaces/ns1/services/my-service").andReturn(200, service).once(); server.expect().get().withPath("/api/v1/namespaces/ns1/configmaps/my-configmap").andReturn(200, configMap).once(); server.expect().delete().withPath("/api/v1/namespaces/ns1/services/my-service").andReturn(200 , service).once(); server.expect().delete().withPath("/api/v1/namespaces/ns1/configmaps/my-configmap").andReturn(200, configMap).once(); server.expect().post().withPath("/api/v1/namespaces/ns1/services").andReturn(200, updatedService).once(); server.expect().post().withPath("/api/v1/namespaces/ns1/configmaps").andReturn(200, updatedConfigMap).once(); KubernetesClient client = server.getClient(); KubernetesList list = new KubernetesListBuilder().withItems(updatedService, updatedConfigMap).build(); client.resourceList(list).inNamespace("ns1").deletingExisting().createOrReplace(); assertEquals(6, server.getMockServer().getRequestCount()); RecordedRequest request = server.getLastRequest(); assertEquals("/api/v1/namespaces/ns1/configmaps", request.getPath()); assertEquals("POST", request.getMethod()); }
Example #14
Source File: OpenshiftBuildService.java From jkube with Eclipse Public License 2.0 | 6 votes |
private void checkOrCreateImageStream(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, String imageStreamName) { boolean hasImageStream = client.imageStreams().withName(imageStreamName).get() != null; if (hasImageStream && config.getBuildRecreateMode().isImageStream()) { client.imageStreams().withName(imageStreamName).delete(); hasImageStream = false; } if (!hasImageStream) { log.info("Creating ImageStream %s", imageStreamName); builder.addToItems(new ImageStreamBuilder() .withNewMetadata() .withName(imageStreamName) .endMetadata() .withNewSpec() .withNewLookupPolicy() .withLocal(config.isS2iImageStreamLookupPolicyLocal()) .endLookupPolicy() .endSpec() .build() ); } else { log.info("Adding to ImageStream %s", imageStreamName); } }
Example #15
Source File: DependencyEnricher.java From jkube with Eclipse Public License 2.0 | 6 votes |
private void enrichKubernetes(final KubernetesListBuilder builder) { final List<HasMetadata> kubernetesItems = new ArrayList<>(); processArtifactSetResources(this.kubernetesDependencyArtifacts, items -> { kubernetesItems.addAll(Arrays.asList(items.toArray(new HasMetadata[items.size()]))); return null; }); processArtifactSetResources(this.kubernetesTemplateDependencyArtifacts, items -> { List<HasMetadata> templates = Arrays.asList(items.toArray(new HasMetadata[items.size()])); // lets remove all the plain resources (without any ${PARAM} expressions) which match objects // in the Templates found from the k8s-templates.yml files which still contain ${PARAM} expressions // to preserve the parameter expressions for dependent kubernetes resources for (HasMetadata resource : templates) { if (resource instanceof Template) { Template template = (Template) resource; List<HasMetadata> objects = template.getObjects(); if (objects != null) { removeTemplateObjects(kubernetesItems, objects); kubernetesItems.addAll(objects); } } } return null; }); filterAndAddItemsToBuilder(builder, kubernetesItems); }
Example #16
Source File: KubernetesEnvironmentProvisionerTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList() throws Exception { // given String yamlRecipeContent = getResource("devfile/petclinic.yaml"); List<HasMetadata> componentsObjects = toK8SList(yamlRecipeContent).getItems(); // when k8sEnvProvisioner.provision( workspaceConfig, KubernetesEnvironment.TYPE, componentsObjects, emptyMap()); // then String defaultEnv = workspaceConfig.getDefaultEnv(); assertNotNull(defaultEnv); EnvironmentImpl environment = workspaceConfig.getEnvironments().get(defaultEnv); assertNotNull(environment); RecipeImpl recipe = environment.getRecipe(); assertNotNull(recipe); assertEquals(recipe.getType(), KUBERNETES_COMPONENT_TYPE); assertEquals(recipe.getContentType(), YAML_CONTENT_TYPE); // it is expected that applier wrap original recipes objects in new Kubernetes list KubernetesList expectedKubernetesList = new KubernetesListBuilder().withItems(toK8SList(yamlRecipeContent).getItems()).build(); assertEquals(toK8SList(recipe.getContent()).getItems(), expectedKubernetesList.getItems()); }
Example #17
Source File: AddApplicationResourceDecorator.java From dekorate with Apache License 2.0 | 6 votes |
public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); list.addToItems(new ApplicationBuilder() .withNewMetadata() .withName(meta.getName()) .withLabels(meta.getLabels()) .endMetadata() .withNewSpec() .withNewSelector() .withMatchLabels(meta.getLabels()) .endSelector() .withNewDescriptor() .withVersion(meta.getLabels().getOrDefault(Labels.VERSION, "latest")) .withOwners(Arrays.stream(config.getOwners()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList())) .withLinks(Arrays.stream(config.getLinks()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList())) .withMaintainers(Arrays.stream(config.getMaintainers()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList())) .withIcons(Arrays.stream(config.getIcons()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList())) .withKeywords(config.getKeywords()) .withNotes(config.getNotes()) .endDescriptor() .endSpec()); }
Example #18
Source File: RouteEnricherTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Test public void testCreate() { // Given Service providedService = getTestService().build(); KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder().addToItems(providedService); RouteEnricher routeEnricher = new RouteEnricher(context); // When routeEnricher.create(PlatformMode.openshift, kubernetesListBuilder); // Then Route route = (Route) kubernetesListBuilder.buildLastItem(); assertEquals(2, kubernetesListBuilder.buildItems().size()); assertNotNull(route); assertEquals(providedService.getMetadata().getName(), route.getMetadata().getName()); assertNotNull(route.getSpec()); assertEquals("Service", route.getSpec().getTo().getKind()); assertEquals("test-svc", route.getSpec().getTo().getName()); assertEquals(8080, route.getSpec().getPort().getTargetPort().getIntVal().intValue()); }
Example #19
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 #20
Source File: TemplateTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testProcess() { server.expect().withPath("/apis/template.openshift.io/v1/namespaces/test/templates/tmpl1").andReturn(200, new TemplateBuilder().build()).once(); server.expect().withPath("/apis/template.openshift.io/v1/namespaces/test/processedtemplates").andReturn(201, new KubernetesListBuilder().build()).once(); OpenShiftClient client = server.getOpenshiftClient(); KubernetesList list = client.templates().withName("tmpl1").process(new ParameterValue("name1", "value1")); assertNotNull(list); }
Example #21
Source File: AddServiceInstanceResourceDecorator.java From dekorate with Apache License 2.0 | 5 votes |
public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); list.addToItems(new ServiceInstanceBuilder() .withNewMetadata() .withName(meta.getName()) .endMetadata() .withNewSpec() .withClusterServiceClassExternalName(instance.getServiceClass()) .withClusterServicePlanExternalName(instance.getServicePlan()) .withParameters(toMap(instance.getParameters())) .endSpec()); }
Example #22
Source File: ImageEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void ensureTemplateSpecsInDeploymentConfig(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<DeploymentConfigBuilder>() { @Override public void visit(DeploymentConfigBuilder item) { DeploymentConfigFluent.SpecNested<DeploymentConfigBuilder> spec = item.buildSpec() == null ? item.withNewSpec() : item.editSpec(); DeploymentConfigSpecFluent.TemplateNested<DeploymentConfigFluent.SpecNested<DeploymentConfigBuilder>> template = spec.buildTemplate() == null ? spec.withNewTemplate() : spec.editTemplate(); template.endTemplate().endSpec(); } }); }
Example #23
Source File: OpenshiftHandler.java From dekorate with Apache License 2.0 | 5 votes |
public void handle(OpenshiftConfig config) { LOGGER.info("Processing openshift configuration."); ImageConfiguration imageConfig = getImageConfiguration(getProject(), config, configurators); Optional<DeploymentConfig> existingDeploymentConfig = resources.groups().getOrDefault(OPENSHIFT, new KubernetesListBuilder()).buildItems().stream() .filter(i -> i instanceof DeploymentConfig) .map(i -> (DeploymentConfig)i) .filter(i -> i.getMetadata().getName().equals(config.getName())) .findAny(); if (!existingDeploymentConfig.isPresent()) { resources.add(OPENSHIFT, createDeploymentConfig(config, imageConfig)); } if (config.isHeadless()) { resources.decorate(OPENSHIFT, new ApplyHeadlessDecorator(config.getName())); } for (Container container : config.getInitContainers()) { resources.decorate(OPENSHIFT, new AddInitContainerDecorator(config.getName(), container)); } if (config.getPorts().length > 0) { resources.decorate(OPENSHIFT, new AddServiceResourceDecorator(config)); } addDecorators(OPENSHIFT, config, imageConfig); }
Example #24
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 #25
Source File: DefaultNamespaceEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
/** * This method will create a default Namespace or Project if a namespace property is * specified in the xml resourceConfig or as a parameter to a mojo. * @param platformMode platform mode whether it's Kubernetes or OpenShift * @param builder list of kubernetes resources */ @Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { final String name = config.getNamespace(); if (name == null || name.isEmpty()) { return; } if (!KubernetesResourceUtil.checkForKind(builder, NAMESPACE_KINDS)) { String type = getConfig(Config.type); if ("project".equalsIgnoreCase(type) || "namespace".equalsIgnoreCase(type)) { if (platformMode == PlatformMode.kubernetes) { log.info("Adding a default Namespace:" + config.getNamespace()); Namespace namespace = handlerHub.getNamespaceHandler().getNamespace(config.getNamespace()); builder.addToNamespaceItems(namespace); } else { log.info("Adding a default Project" + config.getNamespace()); Project project = handlerHub.getProjectHandler().getProject(config.getNamespace()); builder.addToItems(project); } } } }
Example #26
Source File: KubernetesEnvironmentProvisioner.java From che with Eclipse Public License 2.0 | 5 votes |
private String asYaml(List<HasMetadata> list) throws DevfileRecipeFormatException { try { return Serialization.asYaml(new KubernetesListBuilder().withItems(list).build()); } catch (KubernetesClientException e) { throw new DevfileRecipeFormatException( format( "Unable to deserialize objects to store them in workspace config. Error: %s", e.getMessage()), e); } }
Example #27
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 #28
Source File: DefaultServiceEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void addDefaultService(KubernetesListBuilder builder, Service defaultService) { if (defaultService == null) { return; } ServiceSpec spec = defaultService.getSpec(); List<ServicePort> ports = spec.getPorts(); if (!ports.isEmpty()) { log.info("Adding a default service '%s' with ports [%s]", defaultService.getMetadata().getName(), formatPortsAsList(ports)); } else { log.info("Adding headless default service '%s'", defaultService.getMetadata().getName()); } builder.addToServiceItems(defaultService); }
Example #29
Source File: KubernetesListHandler.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Override public KubernetesList reload(OkHttpClient client, Config config, String namespace, KubernetesList item) { List<HasMetadata> replacedItems = new ArrayList<>(); for (HasMetadata metadata : item.getItems()) { ResourceHandler<HasMetadata, HasMetadataVisitiableBuilder> handler = Handlers.get(item.getKind(), item.getApiVersion()); if (handler == null) { LOGGER.warn("No handler found for:" + item.getKind() + ". Ignoring"); } else { replacedItems.add(handler.reload(client, config, namespace, metadata)); } } return new KubernetesListBuilder(item).withItems(replacedItems).build(); }
Example #30
Source File: SecretEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
@Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { // update builder // use a selector to choose all secret builder in kubernetes list builders. // try to find the target annotations // use the annotation value to generate data // add generated data to this builder builder.accept(new TypedVisitor<SecretBuilder>() { @Override public void visit(SecretBuilder secretBuilder) { Map<String, String> annotation = secretBuilder.buildMetadata().getAnnotations(); if (annotation != null) { if (!annotation.containsKey(getAnnotationKey())) { return; } String dockerId = annotation.get(getAnnotationKey()); Map<String, String> data = generateData(dockerId); if (data == null) { return; } // remove the annotation key annotation.remove(getAnnotationKey()); secretBuilder.addToData(data); } } }); addSecretsFromXmlConfiguration(builder); }