Search in sources :

Example 81 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project docker-maven-plugin by fabric8io.

the class CopyMojoTest method copyWithCreateContainersButExceptionWhenCopying.

@Test
public void copyWithCreateContainersButExceptionWhenCopying() throws IOException, MojoExecutionException {
    final String containerPath = "/any/container/resource";
    final ImageConfiguration image = singleImageWithCopy(singleCopyEntry(containerPath, null));
    final String containerNamePattern = "constant-container-name";
    final String temporaryContainerId = "some-container-id";
    final Exception copyException = new RuntimeException("Test exception when copying from container");
    givenProjectWithResolvedImage(image);
    givenCreateContainersIsTrue();
    givenContainerNamePattern(containerNamePattern);
    givenCreatedContainerId(temporaryContainerId);
    givenExceptionWhenCopyingArchiveFromContainer(temporaryContainerId, copyException);
    try {
        whenMojoExecutes();
        fail();
    } catch (MojoExecutionException e) {
        assertEquals(copyException, e.getCause());
    } catch (Exception e) {
        assertEquals(copyException, e);
    }
    thenExistingImageIsPulled(image, copyMojo.getPullRegistry());
    thenContainerIsCreated(image, containerNamePattern);
    thenContainerIsRemoved(temporaryContainerId);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Test(org.junit.Test)

Example 82 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project docker-maven-plugin by fabric8io.

the class CopyMojoTest method copyWithCreateContainersAndUndefinedHostDirectory.

@Test
public void copyWithCreateContainersAndUndefinedHostDirectory() throws IOException, MojoExecutionException {
    final String containerPath = "/absolute/path/to/some/container/filesystem/resource";
    final ImageConfiguration image = singleImageWithCopy(singleCopyEntry(containerPath, null));
    final String containerNamePattern = ContainerNamingUtil.DEFAULT_CONTAINER_NAME_PATTERN;
    final String temporaryContainerId = "another-test-container";
    givenProjectWithResolvedImage(image);
    givenCreateContainersIsTrue();
    givenContainerNamePattern(containerNamePattern);
    givenCreatedContainerId(temporaryContainerId);
    whenMojoExecutes();
    thenExistingImageIsPulled(image, copyMojo.getPullRegistry());
    thenContainerIsCreated(image, containerNamePattern);
    thenContainerPathIsCopied(temporaryContainerId, containerPath, new File(projectBaseDirectory));
    thenContainerIsRemoved(temporaryContainerId);
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) File(java.io.File) Test(org.junit.Test)

Example 83 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.

the class Controller method applyEntity.

/**
 * Applies the given DTOs onto the Kubernetes master
 */
public void applyEntity(Object dto, String sourceName) throws Exception {
    if (dto instanceof Pod) {
        applyPod((Pod) dto, sourceName);
    } else if (dto instanceof ReplicationController) {
        applyReplicationController((ReplicationController) dto, sourceName);
    } else if (dto instanceof Service) {
        applyService((Service) dto, sourceName);
    } else if (dto instanceof Namespace) {
        applyNamespace((Namespace) dto);
    } else if (dto instanceof Route) {
        applyRoute((Route) dto, sourceName);
    } else if (dto instanceof BuildConfig) {
        applyBuildConfig((BuildConfig) dto, sourceName);
    } else if (dto instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) dto;
        OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
        if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.APPS)) {
            applyResource(resource, sourceName, openShiftClient.deploymentConfigs());
        } else {
            LOG.warn("Not connected to OpenShift cluster so cannot apply entity " + dto);
        }
    } else if (dto instanceof PolicyBinding) {
        applyPolicyBinding((PolicyBinding) dto, sourceName);
    } else if (dto instanceof RoleBinding) {
        applyRoleBinding((RoleBinding) dto, sourceName);
    } else if (dto instanceof Role) {
        Role resource = (Role) dto;
        OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
        if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.AUTHORIZATION)) {
            applyResource(resource, sourceName, openShiftClient.roles());
        } else {
            LOG.warn("Not connected to OpenShift cluster so cannot apply entity " + dto);
        }
    } else if (dto instanceof ImageStream) {
        applyImageStream((ImageStream) dto, sourceName);
    } else if (dto instanceof OAuthClient) {
        applyOAuthClient((OAuthClient) dto, sourceName);
    } else if (dto instanceof Template) {
        applyTemplate((Template) dto, sourceName);
    } else if (dto instanceof ServiceAccount) {
        applyServiceAccount((ServiceAccount) dto, sourceName);
    } else if (dto instanceof Secret) {
        applySecret((Secret) dto, sourceName);
    } else if (dto instanceof ConfigMap) {
        applyResource((ConfigMap) dto, sourceName, kubernetesClient.configMaps());
    } else if (dto instanceof DaemonSet) {
        applyResource((DaemonSet) dto, sourceName, kubernetesClient.extensions().daemonSets());
    } else if (dto instanceof Deployment) {
        applyResource((Deployment) dto, sourceName, kubernetesClient.extensions().deployments());
    } else if (dto instanceof ReplicaSet) {
        applyResource((ReplicaSet) dto, sourceName, kubernetesClient.extensions().replicaSets());
    } else if (dto instanceof StatefulSet) {
        applyResource((StatefulSet) dto, sourceName, kubernetesClient.apps().statefulSets());
    } else if (dto instanceof Ingress) {
        applyResource((Ingress) dto, sourceName, kubernetesClient.extensions().ingresses());
    } else if (dto instanceof PersistentVolumeClaim) {
        applyPersistentVolumeClaim((PersistentVolumeClaim) dto, sourceName);
    } else if (dto instanceof HasMetadata) {
        HasMetadata entity = (HasMetadata) dto;
        try {
            String namespace = getNamespace();
            String resourceNamespace = getNamespace(entity);
            if (Strings.isNotBlank(namespace) && Strings.isNullOrBlank(resourceNamespace)) {
                getOrCreateMetadata(entity).setNamespace(namespace);
            }
            LOG.info("Applying " + getKind(entity) + " " + getName(entity) + " from " + sourceName);
            kubernetesClient.resource(entity).inNamespace(namespace).createOrReplace();
        } catch (Exception e) {
            onApplyError("Failed to create " + getKind(entity) + " from " + sourceName + ". " + e, e);
        }
    } else {
        throw new IllegalArgumentException("Unknown entity type " + dto);
    }
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) OAuthClient(io.fabric8.openshift.api.model.OAuthClient) DoneableImageStream(io.fabric8.openshift.api.model.DoneableImageStream) ImageStream(io.fabric8.openshift.api.model.ImageStream) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) Template(io.fabric8.openshift.api.model.Template) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) Route(io.fabric8.openshift.api.model.Route) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Pod(io.fabric8.kubernetes.api.model.Pod) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Namespace(io.fabric8.kubernetes.api.model.Namespace) PolicyBinding(io.fabric8.openshift.api.model.PolicyBinding) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) FileNotFoundException(java.io.FileNotFoundException) OpenShiftNotAvailableException(io.fabric8.openshift.client.OpenShiftNotAvailableException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Role(io.fabric8.openshift.api.model.Role) Secret(io.fabric8.kubernetes.api.model.Secret) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DaemonSet(io.fabric8.kubernetes.api.model.extensions.DaemonSet) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Example 84 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.

the class KubernetesHelper method summaryText.

/**
 * Returns a short summary text message for the given kubernetes resource
 */
public static String summaryText(Template entity) {
    StringBuilder buffer = new StringBuilder();
    List<Parameter> parameters = entity.getParameters();
    if (parameters != null) {
        for (Parameter parameter : parameters) {
            String name = parameter.getName();
            appendText(buffer, name);
        }
    }
    return "parameters: " + buffer;
}
Also used : Parameter(io.fabric8.openshift.api.model.Parameter)

Example 85 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.

the class KubernetesHelper method summaryText.

/**
 * Returns a short summary text message for the given kubernetes resource
 */
public static String summaryText(DeploymentConfig entity) {
    StringBuilder buffer = new StringBuilder();
    DeploymentConfigSpec spec = entity.getSpec();
    if (spec != null) {
        buffer.append("replicas: " + spec.getReplicas());
        PodTemplateSpec podTemplateSpec = spec.getTemplate();
        if (podTemplateSpec != null) {
            appendSummaryText(buffer, podTemplateSpec);
        }
    }
    return buffer.toString();
}
Also used : DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)30 IOException (java.io.IOException)30 Test (org.junit.Test)29 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)23 Map (java.util.Map)23 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)18 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)17 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)15 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)15 Session (io.fabric8.arquillian.kubernetes.Session)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 File (java.io.File)14 Resource (org.osgi.resource.Resource)14 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)12 Service (io.fabric8.kubernetes.api.model.Service)12 Async (io.vertx.ext.unit.Async)12 List (java.util.List)11 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)10