Search in sources :

Example 1 with Attribute

use of io.fabric8.mockwebserver.crud.Attribute in project fabric8-maven-plugin by fabric8io.

the class ImageStreamService method findTagSha.

private String findTagSha(OpenShiftClient client, String imageStreamName, String namespace) throws MojoExecutionException {
    ImageStream currentImageStream = null;
    for (int i = 0; i < IMAGE_STREAM_TAG_RETRIES; i++) {
        if (i > 0) {
            log.info("Retrying to find tag on ImageStream %s", imageStreamName);
            try {
                Thread.sleep(IMAGE_STREAM_TAG_RETRY_TIMEOUT_IN_MILLIS);
            } catch (InterruptedException e) {
                log.debug("interrupted", e);
            }
        }
        currentImageStream = client.imageStreams().withName(imageStreamName).get();
        if (currentImageStream == null) {
            continue;
        }
        ImageStreamStatus status = currentImageStream.getStatus();
        if (status == null) {
            continue;
        }
        List<NamedTagEventList> tags = status.getTags();
        if (tags == null || tags.isEmpty()) {
            continue;
        }
        // Iterate all imagestream tags and get the latest one by 'created' attribute
        TagEvent latestTag = null;
        TAG_EVENT_LIST: for (NamedTagEventList list : tags) {
            List<TagEvent> items = list.getItems();
            if (items == null || items.isEmpty()) {
                continue TAG_EVENT_LIST;
            }
            for (TagEvent tag : items) {
                latestTag = latestTag == null ? tag : newerTag(tag, latestTag);
            }
        }
        if (latestTag != null && StringUtils.isNotBlank(latestTag.getImage())) {
            String image = latestTag.getImage();
            log.info("Found tag on ImageStream " + imageStreamName + " tag: " + image);
            return image;
        }
    }
    // No image found, even after several retries:
    if (currentImageStream == null) {
        throw new MojoExecutionException("Could not find a current ImageStream with name " + imageStreamName + " in namespace " + namespace);
    } else {
        throw new MojoExecutionException("Could not find a tag in the ImageStream " + imageStreamName);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TagEvent(io.fabric8.openshift.api.model.TagEvent) ImageStream(io.fabric8.openshift.api.model.ImageStream) NamedTagEventList(io.fabric8.openshift.api.model.NamedTagEventList) ArrayList(java.util.ArrayList) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) NamedTagEventList(io.fabric8.openshift.api.model.NamedTagEventList) List(java.util.List) ImageStreamStatus(io.fabric8.openshift.api.model.ImageStreamStatus)

Example 2 with Attribute

use of io.fabric8.mockwebserver.crud.Attribute in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricher method getStringValue.

private Optional<String> getStringValue(String attribute, boolean readiness) {
    String specific = getSpecificPropertyName(readiness, attribute);
    String generic = VERTX_HEALTH + attribute;
    // Check if we have the specific user property.
    Configuration contextConfig = getContext().getConfiguration();
    String property = contextConfig.getProperty(specific);
    if (property != null) {
        return Optional.of(property).map(TRIM);
    }
    property = contextConfig.getProperty(generic);
    if (property != null) {
        return Optional.of(property).map(TRIM);
    }
    String[] specificPath = new String[] { readiness ? "readiness" : "liveness", attribute };
    Optional<String> config = getValueFromConfig(specificPath).map(TRIM);
    if (!config.isPresent()) {
        // Generic path.
        return getValueFromConfig(attribute).map(TRIM);
    } else {
        return config;
    }
}
Also used : Configuration(io.fabric8.maven.core.model.Configuration)

Example 3 with Attribute

use of io.fabric8.mockwebserver.crud.Attribute in project che-server by eclipse-che.

the class EnvironmentVariableSecretApplier method applySecret.

/**
 * Applies secret as environment variable into workspace containers, respecting automount
 * attribute and optional devfile automount property override.
 *
 * @param env kubernetes environment with workspace containers configuration
 * @param runtimeIdentity identity of current runtime
 * @param secret source secret to apply
 * @throws InfrastructureException on misconfigured secrets or other apply error
 */
@Override
public void applySecret(KubernetesEnvironment env, RuntimeIdentity runtimeIdentity, Secret secret) throws InfrastructureException {
    boolean secretAutomount = Boolean.parseBoolean(secret.getMetadata().getAnnotations().get(ANNOTATION_AUTOMOUNT));
    for (PodData podData : env.getPodsData().values()) {
        if (!podData.getRole().equals(PodRole.DEPLOYMENT)) {
            continue;
        }
        for (Container container : podData.getSpec().getContainers()) {
            Optional<ComponentImpl> component = getComponent(env, container.getName());
            // skip components that explicitly disable automount
            if (component.isPresent() && isComponentAutomountFalse(component.get())) {
                continue;
            }
            // if automount disabled globally and not overridden in component
            if (!secretAutomount && (!component.isPresent() || !isComponentAutomountTrue(component.get()))) {
                continue;
            }
            for (Entry<String, String> secretDataEntry : secret.getData().entrySet()) {
                final String mountEnvName = envName(secret, secretDataEntry.getKey(), runtimeIdentity);
                container.getEnv().add(new EnvVarBuilder().withName(mountEnvName).withValueFrom(new EnvVarSourceBuilder().withSecretKeyRef(new SecretKeySelectorBuilder().withName(secret.getMetadata().getName()).withKey(secretDataEntry.getKey()).build()).build()).build());
            }
        }
    }
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Container(io.fabric8.kubernetes.api.model.Container) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) SecretKeySelectorBuilder(io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder)

Example 4 with Attribute

use of io.fabric8.mockwebserver.crud.Attribute in project che-server by eclipse-che.

the class AsyncStorageProvisioner method provision.

public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    if (!parseBoolean(k8sEnv.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
        return;
    }
    if (!COMMON_STRATEGY.equals(pvcStrategy)) {
        String message = format("Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got %s", pvcStrategy);
        LOG.warn(message);
        k8sEnv.addWarning(new WarningImpl(4200, message));
        throw new InfrastructureException(message);
    }
    if (!isEphemeral(k8sEnv.getAttributes())) {
        String message = format("Workspace configuration not valid: Asynchronous storage available only if '%s' attribute set to false", PERSIST_VOLUMES_ATTRIBUTE);
        LOG.warn(message);
        k8sEnv.addWarning(new WarningImpl(4200, message));
        throw new InfrastructureException(message);
    }
    String namespace = identity.getInfrastructureNamespace();
    String userId = identity.getOwnerId();
    KubernetesClient k8sClient = kubernetesClientFactory.create(identity.getWorkspaceId());
    String configMapName = namespace + ASYNC_STORAGE_CONFIG;
    createPvcIfNotExist(k8sClient, namespace, userId);
    createConfigMapIfNotExist(k8sClient, namespace, configMapName, userId, k8sEnv);
    createAsyncStoragePodIfNotExist(k8sClient, namespace, configMapName, userId);
    createStorageServiceIfNotExist(k8sClient, namespace, userId);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 5 with Attribute

use of io.fabric8.mockwebserver.crud.Attribute in project che-server by eclipse-che.

the class KubernetesComponentToWorkspaceApplier method prepareMachineConfigs.

/**
 * Creates map of machine names and corresponding {@link MachineConfigImpl} with component alias
 * attribute set.
 */
private Map<String, MachineConfigImpl> prepareMachineConfigs(List<PodData> podsData, ComponentImpl component) throws DevfileException {
    Map<String, MachineConfigImpl> machineConfigs = new HashMap<>();
    for (PodData podData : podsData) {
        List<Container> containers = new ArrayList<>();
        containers.addAll(podData.getSpec().getContainers());
        containers.addAll(podData.getSpec().getInitContainers());
        for (Container container : containers) {
            String machineName = machineName(podData, container);
            MachineConfigImpl config = new MachineConfigImpl();
            if (!isNullOrEmpty(component.getAlias())) {
                config.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, component.getAlias());
            }
            provisionVolumes(component, container, config);
            provisionEndpoints(component, config);
            machineConfigs.put(machineName, config);
        }
    }
    return machineConfigs;
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Container(io.fabric8.kubernetes.api.model.Container) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

Attribute (io.fabric8.mockwebserver.crud.Attribute)33 AttributeSet (io.fabric8.mockwebserver.crud.AttributeSet)31 Test (org.junit.jupiter.api.Test)25 Container (io.fabric8.kubernetes.api.model.Container)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)8 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)7 Pod (io.fabric8.kubernetes.api.model.Pod)6 ArrayList (java.util.ArrayList)6 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)6 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)6 CustomResourceDefinitionContext (io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext)5 List (java.util.List)5 IngressBuilder (io.fabric8.kubernetes.api.model.extensions.IngressBuilder)3 WarningImpl (org.eclipse.che.api.workspace.server.model.impl.WarningImpl)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Beta (com.google.common.annotations.Beta)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2