Java Code Examples for io.fabric8.kubernetes.api.model.KubernetesListBuilder#addToSecretItems()

The following examples show how to use io.fabric8.kubernetes.api.model.KubernetesListBuilder#addToSecretItems() . 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: DockerRegistrySecretEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDockerRegistryWithBadKind() {
    setupExpectations();
    DockerRegistrySecretEnricher enricher = new DockerRegistrySecretEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    Secret secret = createBaseSecret(true);
    secret.setKind("Secrets");
    builder.addToSecretItems(createBaseSecret(true));
    KubernetesList expected = builder.build();

    enricher.create(PlatformMode.kubernetes, builder);
    assertEquals(expected, builder.build());
}
 
Example 2
Source File: DockerRegistrySecretEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDockerRegistryWithBadAnnotation() {
    DockerRegistrySecretEnricher enricher = new DockerRegistrySecretEnricher(context);
    setupExpectations();
    KubernetesListBuilder builder = new KubernetesListBuilder();
    Secret secret = createBaseSecret(true);
    secret.getMetadata().getAnnotations().put(annotation, "docker1.io");
    builder.addToSecretItems(createBaseSecret(true));

    KubernetesList expected = builder.build();

    enricher.create(PlatformMode.kubernetes, builder);
    assertEquals(expected, builder.build());
}
 
Example 3
Source File: AddDockerConfigJsonSecretDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(KubernetesListBuilder list) {
  String name = Strings.isNotNullOrEmpty(this.name) ? this.name : getMandatoryDeploymentMetadata(list).getName();
  Secret secret = new SecretBuilder()
    .withNewMetadata()
      .withName(name)
      .withAnnotations(this.annotations)
    .endMetadata()
    .withType(TYPE)
    .addToData(DOT_DOCKER_CONFIG_JSON, this.content)
    .build();

  list.addToSecretItems(secret);
}
 
Example 4
Source File: SecretEnricher.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
private void addSecretsFromXmlConfiguration(KubernetesListBuilder builder) {
    log.verbose("Adding secrets resources from plugin configuration");
    List<SecretConfig> secrets = getSecretsFromXmlConfig();
    Map<String, Integer> secretToIndexMap = new HashMap<>();
    if (secrets == null || secrets.isEmpty()) {
        return;
    }

    for(Integer index = 0; index < builder.buildItems().size(); index++) {
        if(builder.buildItems().get(index) instanceof Secret) {
            secretToIndexMap.put(builder.buildItems().get(index).getMetadata().getName(), index);
        }
    }

    for (int i = 0; i < secrets.size(); i++) {
        SecretConfig secretConfig = secrets.get(i);
        if (StringUtils.isBlank(secretConfig.getName())) {
            log.warn("Secret name is empty. You should provide a proper name for the secret");
            continue;
        }

        Map<String, String> data = new HashMap<>();
        String type = "";
        ObjectMeta metadata = new ObjectMetaBuilder()
                .withNamespace(secretConfig.getNamespace())
                .withName(secretConfig.getName())
                .build();

        // docker-registry
        if (secretConfig.getDockerServerId() != null) {
            JKubeEnricherContext mavenContext = ((JKubeEnricherContext)getContext());
            String dockerSecret = (mavenContext).getDockerJsonConfigString(mavenContext.getSettings(), secretConfig.getDockerServerId());
            if (StringUtils.isBlank(dockerSecret)) {
                log.warn("Docker secret with id "
                        + secretConfig.getDockerServerId()
                        + " cannot be found in maven settings");
                continue;
            }
            data.put(SecretConstants.DOCKER_DATA_KEY, Base64Util.encodeToString(dockerSecret));
            type = SecretConstants.DOCKER_CONFIG_TYPE;
        }
        // TODO: generic secret (not supported for now)

        if (StringUtils.isBlank(type) || data.isEmpty()) {
            log.warn("No data can be found for docker secret with id " + secretConfig.getDockerServerId());
            continue;
        }

        Secret secret = new SecretBuilder().withData(data).withMetadata(metadata).withType(type).build();
        if(!secretToIndexMap.containsKey(secretConfig.getName())) {
            builder.addToSecretItems(i, secret);
        }
    }
}