io.fabric8.kubernetes.api.model.DoneableConfigMap Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.DoneableConfigMap. 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: ConfigMapSupplier.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Autowired
public ConfigMapSupplier(KubernetesClient client, @Value(TruckParkConstants.TRUCK_PARK) String name) {
  this.name = name;
  Resource<ConfigMap, DoneableConfigMap> resource = client.configMaps().withName(name);
  configMap = resource.get();
  if (configMap == null) {
    throw new RuntimeException(String.format("ConfigMap %s does not exist.", name));
  }
  watch = resource.watch(this);
}
 
Example #2
Source File: EventBasedConfigurationChangeDetectorTests.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@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 #3
Source File: ConfigMapLockTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
  kc = mock(DefaultKubernetesClient.class, Answers.RETURNS_DEEP_STUBS);
  configMaps = mock(MixedOperation.class, Answers.RETURNS_DEEP_STUBS);
  doneableConfigMap = mock(DoneableConfigMap.class, Answers.RETURNS_DEEP_STUBS);
  metadata = mock(DoneableConfigMap.MetadataNested.class, Answers.RETURNS_DEEP_STUBS);
  when(kc.inNamespace(anyString()).configMaps()).thenReturn(configMaps);
  when(configMaps.withName(anyString()).createNew()).thenReturn(doneableConfigMap);
  when(doneableConfigMap.editOrNewMetadata()).thenReturn(metadata);
}
 
Example #4
Source File: ConfigMapExample.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
  Config config = new ConfigBuilder().build();
  KubernetesClient client = new DefaultKubernetesClient(config);

  String namespace = null;
  if (args.length > 0) {
    namespace = args[0];
  }
  if (namespace == null) {
    namespace = client.getNamespace();
  }
  if (namespace == null) {
    namespace = "default";
  }

  String name = "cheese";
  try {
    Resource<ConfigMap, DoneableConfigMap> configMapResource = client.configMaps().inNamespace(namespace).withName(name);


    ConfigMap configMap = configMapResource.createOrReplace(new ConfigMapBuilder().
        withNewMetadata().withName(name).endMetadata().
        addToData("foo", "" + new Date()).
        addToData("bar", "beer").
        build());

    log("Upserted ConfigMap at " + configMap.getMetadata().getSelfLink() + " data " + configMap.getData());

  } finally {
    client.close();
  }
}
 
Example #5
Source File: AbstractWatcher.java    From abstract-operator with Apache License 2.0 4 votes vote down vote up
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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@Override
protected AbstractResourceOperator<KubernetesClient, ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> createResourceOperations(Vertx vertx, KubernetesClient mockClient) {
    return new ConfigMapOperator(vertx, mockClient);
}
 
Example #9
Source File: MockKube.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public MockKube withInitialCms(Set<ConfigMap> initialCms) {
    this.cmDb.putAll(db(initialCms, ConfigMap.class, DoneableConfigMap.class));
    return this;
}
 
Example #10
Source File: AutoAdaptableKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps() {
  return delegate.configMaps();
}
 
Example #11
Source File: DefaultKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps() {
  return new ConfigMapOperationsImpl(httpClient, getConfiguration());
}
 
Example #12
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps() {
  return delegate.configMaps();
}
 
Example #13
Source File: DefaultOpenShiftClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@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 vote down vote up
/**
 * API entrypoint for ConfigMap related operations. ConfigMap (core/v1)
 *
 * @return MixedOperation object for ConfigMap related operations.
 */
MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps();