Search in sources :

Example 1 with ObjectReference

use of io.fabric8.kubernetes.api.model.ObjectReference in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildService method logBuildBuildFailedDetails.

private void logBuildBuildFailedDetails(OpenShiftClient client, String buildName) {
    try {
        BuildConfig build = client.buildConfigs().withName(buildName).get();
        ObjectReference ref = build.getSpec().getStrategy().getSourceStrategy().getFrom();
        String kind = ref.getKind();
        String name = ref.getName();
        if ("DockerImage".equals(kind)) {
            log.error("Please, ensure that the Docker image '%s' exists and is accessible by OpenShift", name);
        } else if ("ImageStreamTag".equals(kind)) {
            String namespace = ref.getNamespace();
            String namespaceInfo = "current";
            String namespaceParams = "";
            if (namespace != null && !namespace.isEmpty()) {
                namespaceInfo = "'" + namespace + "'";
                namespaceParams = " -n " + namespace;
            }
            log.error("Please, ensure that the ImageStream Tag '%s' exists in the %s namespace (with 'oc get is%s')", name, namespaceInfo, namespaceParams);
        }
    } catch (Exception ex) {
        log.error("Unable to get detailed information from the BuildServiceConfig: " + ex.getMessage());
    }
}
Also used : BuildConfig(io.fabric8.openshift.api.model.BuildConfig) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 2 with ObjectReference

use of io.fabric8.kubernetes.api.model.ObjectReference in project strimzi by strimzi.

the class KafkaConnectS2ICluster method generateSourceImageStream.

/**
 * Generate new source ImageStream
 *
 * @return      Source ImageStream resource definition
 */
public ImageStream generateSourceImageStream() {
    ObjectReference image = new ObjectReference();
    image.setKind("DockerImage");
    image.setName(sourceImageBaseName + ":" + sourceImageTag);
    TagReference sourceTag = new TagReference();
    sourceTag.setName(sourceImageTag);
    sourceTag.setFrom(image);
    ImageStream imageStream = new ImageStreamBuilder().withNewMetadata().withName(getSourceImageStreamName()).withNamespace(namespace).withLabels(getLabelsWithName(getSourceImageStreamName())).endMetadata().withNewSpec().withLookupPolicy(new ImageLookupPolicyBuilder().withLocal(false).build()).withTags(sourceTag).endSpec().build();
    return imageStream;
}
Also used : ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) ObjectReference(io.fabric8.kubernetes.api.model.ObjectReference) ImageStream(io.fabric8.openshift.api.model.ImageStream) TagReference(io.fabric8.openshift.api.model.TagReference) ImageLookupPolicyBuilder(io.fabric8.openshift.api.model.ImageLookupPolicyBuilder)

Example 3 with ObjectReference

use of io.fabric8.kubernetes.api.model.ObjectReference 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

ObjectReference (io.fabric8.kubernetes.api.model.ObjectReference)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)1 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)1 ImageLookupPolicyBuilder (io.fabric8.openshift.api.model.ImageLookupPolicyBuilder)1 ImageStream (io.fabric8.openshift.api.model.ImageStream)1 ImageStreamBuilder (io.fabric8.openshift.api.model.ImageStreamBuilder)1 SecurityContextConstraints (io.fabric8.openshift.api.model.SecurityContextConstraints)1 TagReference (io.fabric8.openshift.api.model.TagReference)1 IOException (java.io.IOException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1