Search in sources :

Example 1 with ObjectReferenceBuilder

use of io.fabric8.kubernetes.api.model.ObjectReferenceBuilder in project syndesis-qe by syndesisio.

the class ExternalDatabase method deploy.

@Override
public void deploy() {
    OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().withNewMetadata().withName(NAME).withLabels(TestUtils.map("app", NAME)).endMetadata().withNewSpec().withReplicas(1).withNewTemplate().withNewMetadata().withLabels(TestUtils.map("app", NAME)).endMetadata().withNewSpec().withContainers(new ContainerBuilder().withEnv(new EnvVar("POSTGRESQL_DATABASE", "testdb", null), new EnvVar("POSTGRESQL_PASSWORD", "testpassword", null), new EnvVar("POSTGRESQL_USER", "testuser", null)).withPorts(new ContainerPortBuilder().withContainerPort(5432).withProtocol("TCP").build()).withName(NAME).withImage(" ").build()).endSpec().endTemplate().withSelector(TestUtils.map("app", NAME)).withTriggers(new DeploymentTriggerPolicyBuilder().withNewImageChangeParams().withContainerNames(NAME).withFrom(new ObjectReferenceBuilder().withKind("ImageStreamTag").withName("postgresql:12").withNamespace("openshift").build()).withAutomatic(true).endImageChangeParams().withNewType("ImageChange").build()).endSpec().done();
    OpenShiftUtils.getInstance().services().createOrReplaceWithNew().withNewMetadata().withName(NAME).withLabels(TestUtils.map("app", NAME)).endMetadata().withNewSpec().addToPorts(new ServicePortBuilder().withNewName("5432-tcp").withNewTargetPort(5432).withNewProtocol("TCP").withPort(5432).build()).addToSelector(TestUtils.map("app", NAME)).endSpec().done();
    // create a needed secret with the password
    OpenShiftUtils.getInstance().secrets().createOrReplaceWithNew().withNewMetadata().withName("syndesis-global-config").endMetadata().withStringData(TestUtils.map("POSTGRESQL_PASSWORD", "testpassword")).withNewType("Opaque").done();
}
Also used : ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ObjectReferenceBuilder(io.fabric8.kubernetes.api.model.ObjectReferenceBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) DeploymentTriggerPolicyBuilder(io.fabric8.openshift.api.model.DeploymentTriggerPolicyBuilder)

Example 2 with ObjectReferenceBuilder

use of io.fabric8.kubernetes.api.model.ObjectReferenceBuilder in project fabric8 by fabric8io.

the class SessionListener method generateServiceAccount.

private void generateServiceAccount(KubernetesClient client, Session session, Set<Secret> secrets, String serviceAccountName) {
    List<ObjectReference> secretRefs = new ArrayList<>();
    for (Secret secret : secrets) {
        secretRefs.add(new ObjectReferenceBuilder().withNamespace(session.getNamespace()).withName(KubernetesHelper.getName(secret)).build());
    }
    SecurityContextConstraints securityContextConstraints = client.securityContextConstraints().withName(session.getNamespace()).get();
    if (securityContextConstraints == null) {
        client.securityContextConstraints().createNew().withNewMetadata().withName(session.getNamespace()).endMetadata().withAllowHostDirVolumePlugin(true).withAllowPrivilegedContainer(true).withNewRunAsUser().withType("RunAsAny").endRunAsUser().withNewSeLinuxContext().withType("RunAsAny").endSeLinuxContext().withUsers("system:serviceaccount:" + session.getNamespace() + ":" + serviceAccountName).done();
    }
    ServiceAccount serviceAccount = client.serviceAccounts().inNamespace(session.getNamespace()).withName(serviceAccountName).get();
    if (serviceAccount == null) {
        client.serviceAccounts().inNamespace(session.getNamespace()).createNew().withNewMetadata().withName(serviceAccountName).endMetadata().withSecrets(secretRefs).done();
    } else {
        client.serviceAccounts().inNamespace(session.getNamespace()).withName(serviceAccountName).replace(new ServiceAccountBuilder(serviceAccount).withNewMetadata().withName(serviceAccountName).endMetadata().addToSecrets(secretRefs.toArray(new ObjectReference[secretRefs.size()])).build());
    }
}
Also used : SecurityContextConstraints(io.fabric8.openshift.api.model.SecurityContextConstraints)

Aggregations

ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)1 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 ObjectReferenceBuilder (io.fabric8.kubernetes.api.model.ObjectReferenceBuilder)1 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)1 DeploymentTriggerPolicyBuilder (io.fabric8.openshift.api.model.DeploymentTriggerPolicyBuilder)1 SecurityContextConstraints (io.fabric8.openshift.api.model.SecurityContextConstraints)1