io.fabric8.kubernetes.api.model.ConfigMapList Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.ConfigMapList.
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: ConfigMapsTest.java From spring-cloud-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testConfigMapGet() { this.server.expect().withPath("/api/v1/namespaces/ns2/configmaps") .andReturn(200, new ConfigMapBuilder().withNewMetadata() .withName("reload-example").endMetadata() .addToData("KEY", "123").build()) .once(); KubernetesClient client = this.server.getClient(); ConfigMapList configMapList = client.configMaps().inNamespace("ns2").list(); assertThat(configMapList).isNotNull(); assertThat(configMapList.getAdditionalProperties()).containsKey("data"); @SuppressWarnings("unchecked") Map<String, String> data = (Map<String, String>) configMapList .getAdditionalProperties().get("data"); assertThat(data.get("KEY")).isEqualTo("123"); }
Example #2
Source File: ConfigMapTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testLiteralConfigMap() throws InterruptedException { HashMap<String, String> data = new HashMap<>(); data.put("foo", "bar"); data.put("cheese", "gouda"); server.expect().withPath("/api/v1/namespaces/test/configmaps").andReturn(200, new ConfigMapBuilder() .withNewMetadata() .withName("cfg1") .endMetadata() .addToData(data) .build()) .once(); NamespacedKubernetesClient client = server.getClient(); ConfigMapList cfgList = client.configMaps().list(); assertNotNull(cfgList); assertEquals(1, cfgList.getAdditionalProperties().size()); Map<String, String> keys = (Map<String, String>) cfgList.getAdditionalProperties().get("data"); assertEquals("gouda",keys.get("cheese")); assertEquals("bar",keys.get("foo")); }
Example #3
Source File: EventBasedConfigurationChangeDetectorTests.java From spring-cloud-kubernetes with Apache License 2.0 | 5 votes |
@Test public void verifyConfigChangesAccountsForBootstrapPropertySources() { ConfigReloadProperties configReloadProperties = new ConfigReloadProperties(); MockEnvironment env = new MockEnvironment(); KubernetesClient k8sClient = mock(KubernetesClient.class); ConfigMap configMap = new ConfigMap(); Map<String, String> data = new HashMap(); data.put("foo", "bar"); configMap.setData(data); MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> mixedOperation = mock( MixedOperation.class); Resource<ConfigMap, DoneableConfigMap> resource = mock(Resource.class); when(resource.get()).thenReturn(configMap); when(mixedOperation.withName(eq("myconfigmap"))).thenReturn(resource); when(k8sClient.configMaps()).thenReturn(mixedOperation); ConfigMapPropertySource configMapPropertySource = new ConfigMapPropertySource( k8sClient, "myconfigmap"); env.getPropertySources() .addFirst(new BootstrapPropertySource(configMapPropertySource)); ConfigurationUpdateStrategy configurationUpdateStrategy = mock( ConfigurationUpdateStrategy.class); ConfigMapPropertySourceLocator configMapLocator = mock( ConfigMapPropertySourceLocator.class); SecretsPropertySourceLocator secretsLocator = mock( SecretsPropertySourceLocator.class); EventBasedConfigurationChangeDetector detector = new EventBasedConfigurationChangeDetector( env, configReloadProperties, k8sClient, configurationUpdateStrategy, configMapLocator, secretsLocator); List<ConfigMapPropertySource> sources = detector .findPropertySources(ConfigMapPropertySource.class); assertThat(sources.size()).isEqualTo(1); assertThat(sources.get(0).getProperty("foo")).isEqualTo("bar"); }
Example #4
Source File: ConfigMapsTest.java From spring-cloud-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testConfigMapList() { this.server.expect().withPath("/api/v1/namespaces/ns1/configmaps") .andReturn(200, new ConfigMapListBuilder().build()).once(); KubernetesClient client = this.server.getClient(); ConfigMapList configMapList = client.configMaps().inNamespace("ns1").list(); assertThat(configMapList).isNotNull(); assertThat(configMapList.getItems().size()).isEqualTo(0); }
Example #5
Source File: AbstractWatcher.java From abstract-operator with Apache License 2.0 | 4 votes |
protected CompletableFuture<Watch> createConfigMapWatch() { CompletableFuture<Watch> cf = CompletableFuture.supplyAsync(() -> { MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> aux = client.configMaps(); final boolean inAllNs = "*".equals(namespace); Watchable<Watch, Watcher<ConfigMap>> watchable = inAllNs ? aux.inAnyNamespace().withLabels(selector) : aux.inNamespace(namespace).withLabels(selector); Watch watch = watchable.watch(new Watcher<ConfigMap>() { @Override public void eventReceived(Action action, ConfigMap cm) { if (isSupported.test(cm)) { log.info("ConfigMap in namespace {} was {}\nCM:\n{}\n", namespace, action, cm); T entity = convert.apply(cm); if (entity == null) { log.error("something went wrong, unable to parse {} definition", entityName); } if (action.equals(Action.ERROR)) { log.error("Failed ConfigMap {} in namespace{} ", cm, namespace); } else { handleAction(action, entity, inAllNs ? cm.getMetadata().getNamespace() : namespace); } } else { log.error("Unknown CM kind: {}", cm.toString()); } } @Override public void onClose(KubernetesClientException e) { if (e != null) { log.error("Watcher closed with exception in namespace {}", namespace, e); recreateWatcher(); } else { log.info("Watcher closed in namespace {}", namespace); } } }); return watch; }, SDKEntrypoint.getExecutors()); cf.thenApply(w -> { log.info("ConfigMap watcher running for labels {}", selector); return w; }).exceptionally(e -> { log.error("ConfigMap watcher failed to start", e.getCause()); return null; }); return cf; }
Example #6
Source File: SupportUtilTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void createSupportZipFileTest() throws IOException { final NamespacedOpenShiftClient client = mock(NamespacedOpenShiftClient.class); final MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods = mock(mixedOperationType()); when(pods.list()).thenReturn(new PodList()); when(client.pods()).thenReturn(pods); final MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> bcs = mock( mixedOperationType()); when(bcs.list()).thenReturn(new BuildConfigList()); when(client.buildConfigs()).thenReturn(bcs); final MixedOperation<DeploymentConfig, DeploymentConfigList, DoneableDeploymentConfig, DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig>> dcs = mock( mixedOperationType()); when(dcs.list()).thenReturn(new DeploymentConfigList()); when(client.deploymentConfigs()).thenReturn(dcs); final MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> cm = mock(mixedOperationType()); when(cm.list()).thenReturn(new ConfigMapList()); when(client.configMaps()).thenReturn(cm); final MixedOperation<ImageStreamTag, ImageStreamTagList, DoneableImageStreamTag, Resource<ImageStreamTag, DoneableImageStreamTag>> ist = mock( mixedOperationType()); final ImageStreamTagList istl = new ImageStreamTagList(); final List<ImageStreamTag> istList = new ArrayList<>(); final ImageStreamTag imageStreamTag = new ImageStreamTag(); imageStreamTag.setKind("ImageStreamTag"); final ObjectMeta objectMeta = new ObjectMeta(); objectMeta.setName("ImageStreamTag1"); imageStreamTag.setMetadata(objectMeta); istList.add(imageStreamTag); istl.setItems(istList); when(ist.list()).thenReturn(istl); when(client.imageStreamTags()).thenReturn(ist); final IntegrationHandler integrationHandler = mock(IntegrationHandler.class); when(integrationHandler.list(anyInt(), anyInt())).thenReturn(new EmptyListResult<IntegrationOverview>()); final IntegrationSupportHandler integrationSupportHandler = mock(IntegrationSupportHandler.class); final Logger log = mock(Logger.class); final SupportUtil supportUtil = new SupportUtil(client, integrationHandler, integrationSupportHandler, log); final Map<String, Boolean> configurationMap = new HashMap<>(ImmutableMap.of("int1", true, "int2", true)); final File output = supportUtil.createSupportZipFile(configurationMap, 1, 20); try (final ZipFile zip = new ZipFile(output)) { final ZipEntry imageStreamTag1 = zip.getEntry("descriptors/ImageStreamTag/ImageStreamTag1.YAML"); assertThat(imageStreamTag1).isNotNull(); AssertionsForClassTypes.assertThat(zip.getInputStream(imageStreamTag1)).hasContent(SupportUtil.YAML.dump(imageStreamTag)); } verify(log).info("Created Support file: {}", output); // tests that we haven't logged any error messages verifyZeroInteractions(log); }
Example #7
Source File: ConfigMapOperator.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Override protected MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> operation() { return client.configMaps(); }
Example #8
Source File: ConfigMapOperatorTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Override protected AbstractResourceOperator<KubernetesClient, ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> createResourceOperations(Vertx vertx, KubernetesClient mockClient) { return new ConfigMapOperator(vertx, mockClient); }
Example #9
Source File: Kubernetes.java From enmasse with Apache License 2.0 | 4 votes |
public ConfigMapList getAllConfigMaps(String namespace) { return client.configMaps().inNamespace(namespace).list(); }
Example #10
Source File: ConfigMapCrudTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test public void testCrud() { KubernetesClient client = server.getClient(); ConfigMap configmap1 = new ConfigMapBuilder().withNewMetadata().withName("configmap1").endMetadata() .addToData("one", "1") .build(); ConfigMap configmap2 = new ConfigMapBuilder() .withNewMetadata() .addToLabels("foo", "bar") .withName("configmap2") .endMetadata() .addToData("two", "2") .build(); ConfigMap configmap3 = new ConfigMapBuilder() .withNewMetadata() .addToLabels("foo", "bar") .withName("configmap2") .endMetadata() .addToData("three", "3") .build(); client.configMaps().inNamespace("ns1").create(configmap1); client.configMaps().inNamespace("ns1").create(configmap2); client.configMaps().inNamespace("ns2").create(configmap3); ConfigMapList aConfigMapList = client.configMaps().list(); assertNotNull(aConfigMapList); assertEquals(0, aConfigMapList.getItems().size()); aConfigMapList = client.configMaps().inAnyNamespace().list(); assertNotNull(aConfigMapList); assertEquals(3, aConfigMapList.getItems().size()); aConfigMapList = client.configMaps().inAnyNamespace().withLabels(Collections.singletonMap("foo", "bar")).list(); assertNotNull(aConfigMapList); assertEquals(2, aConfigMapList.getItems().size()); aConfigMapList = client.configMaps().inNamespace("ns1").list(); assertNotNull(aConfigMapList); assertEquals(2, aConfigMapList.getItems().size()); client.configMaps().inNamespace("ns1").withName("configmap1").delete(); aConfigMapList = client.configMaps().inNamespace("ns1").list(); assertNotNull(aConfigMapList); assertEquals(1, aConfigMapList.getItems().size()); configmap2 = client.configMaps().inNamespace("ns1").withName("configmap2").edit().addToData("II", "TWO").done(); assertNotNull(configmap2); assertEquals("TWO", configmap2.getData().get("II")); }
Example #11
Source File: AutoAdaptableKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps() { return delegate.configMaps(); }
Example #12
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps() { return new ConfigMapOperationsImpl(httpClient, getConfiguration()); }
Example #13
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps() { return delegate.configMaps(); }
Example #14
Source File: KubernetesClient.java From kubernetes-client with Apache License 2.0 | 2 votes |
/** * API entrypoint for ConfigMap related operations. ConfigMap (core/v1) * * @return MixedOperation object for ConfigMap related operations. */ MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps();