Java Code Examples for io.fabric8.kubernetes.client.dsl.Resource#createOrReplace()

The following examples show how to use io.fabric8.kubernetes.client.dsl.Resource#createOrReplace() . 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: KubernetesService.java    From vault-crd with Apache License 2.0 6 votes vote down vote up
void modifySecret(Vault resource, VaultSecret vaultSecret) {
    Resource<Secret, DoneableSecret> secretDoneableSecretResource = client.secrets().inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName());
    Secret secret;

    if (secretDoneableSecretResource.get() != null) {
        secret = secretDoneableSecretResource.get();
    } else {
        secret = newSecretInstance(resource, vaultSecret);
    }

    secret.setType(vaultSecret.getType());
    updateAnnotations(secret, vaultSecret.getCompare());
    secret.setData(vaultSecret.getData());

    secretDoneableSecretResource.createOrReplace(secret);
    log.info("Modified secret {} in namespace {}", resource.getMetadata().getName(), resource.getMetadata().getNamespace());
}
 
Example 2
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();
  }
}