private Map.Entry<String, String> allocateUser(HasMetadata deployment) { Secret usernamePoolSecret = kubeClient().secrets().withName(usernamePoolSecretName).get(); Secret consumedUsersSecret = kubeClient().secrets().withName(consumedUsersSecretName).get(); Map<String, String> usernamePool = decodeMap(usernamePoolSecret.getData().get("username-pool")); Collection<String> consumedUsernames = decodeList(consumedUsersSecret.getData().get("consumed-usernames")); // How much of the pool is used userPoolAvailable = ((usernamePool.size() - consumedUsernames.size()) * 100) / usernamePool.size(); // Remove all consumed usernames consumedUsernames.forEach(k -> usernamePool.remove(k)); if (usernamePool.isEmpty()) { throw new IllegalStateException("Username pool is exhausted. Please check Secret " + usernamePoolSecretName + " and " + consumedUsersSecretName); } // Take first element Map.Entry<String, String> pair = usernamePool.entrySet().iterator().next(); consumedUsernames.add(pair.getKey()); Secret updatedSecret = new SecretBuilder() .withNewMetadata() .withAnnotations(consumedUsersSecret.getMetadata().getAnnotations()) .withLabels(consumedUsersSecret.getMetadata().getLabels()) .withName(consumedUsersSecret.getMetadata().getName()) .endMetadata() .withData(null) .withStringData(Collections.singletonMap("consumed-usernames", consumedUsernames.stream().collect(Collectors.joining("\n")))).build(); // TODO handle failure case kubeClient().secrets().createOrReplace(updatedSecret); return pair; }
.withAnnotations(annotations) .endMetadata() .withStringData(secretMap) .build();
public Secret createSecret(HasMetadata owner, Map<String, String> values) { Secret secret = new SecretBuilder().withNewMetadata() .withName(secretName(owner)) .endMetadata() .withStringData(values) .build(); setOwnership(secret, owner); return kubeClient().secrets().create(secret); }
public SecretBuilder(Secret instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withData(instance.getData()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withStringData(instance.getStringData()); this.withType(instance.getType()); this.validationEnabled = validationEnabled; }
private static void createSecret(KubernetesClient client) { Secret secret = new SecretBuilder() .withStringData(ImmutableMap.of(SECRET_KEY, CONTAINER_ENV_VAR_FROM_SECRET_VALUE)).withNewMetadata() .withName("container-secret").endMetadata().build(); client.secrets().createOrReplace(secret); secret = new SecretBuilder().withStringData(ImmutableMap.of(SECRET_KEY, POD_ENV_VAR_FROM_SECRET_VALUE)) .withNewMetadata().withName("pod-secret").endMetadata().build(); client.secrets().createOrReplace(secret); }
private static void createSecret(KubernetesClient client) { Secret secret = new SecretBuilder() .withStringData(ImmutableMap.of(SECRET_KEY, CONTAINER_ENV_VAR_FROM_SECRET_VALUE)).withNewMetadata() .withName("container-secret").endMetadata().build(); client.secrets().createOrReplace(secret); secret = new SecretBuilder().withStringData(ImmutableMap.of(SECRET_KEY, POD_ENV_VAR_FROM_SECRET_VALUE)) .withNewMetadata().withName("pod-secret").endMetadata().build(); client.secrets().createOrReplace(secret); }
.addToLabels(deploymentData.getLabels()) .endMetadata() .withStringData(deploymentData.getSecret()) .build();