Search in sources :

Example 91 with HasMetadata

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

the class KubernetesResourceUtil method mergeConfigMaps.

protected static HasMetadata mergeConfigMaps(ConfigMap cm1, ConfigMap cm2, Logger log, boolean switchOnLocalCustomisation) {
    ConfigMap cm1OrCopy = cm1;
    if (!switchOnLocalCustomisation) {
        // lets copy the original to avoid modifying it
        cm1OrCopy = new ConfigMapBuilder(cm1OrCopy).build();
    }
    log.info("Merging 2 resources for " + getKind(cm1OrCopy) + " " + getName(cm1OrCopy) + " from " + getSourceUrlAnnotation(cm1OrCopy) + " and " + getSourceUrlAnnotation(cm2) + " and removing " + getSourceUrlAnnotation(cm1OrCopy));
    cm1OrCopy.setData(mergeMapsAndRemoveEmptyStrings(cm2.getData(), cm1OrCopy.getData()));
    mergeMetadata(cm1OrCopy, cm2);
    return cm1OrCopy;
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder)

Example 92 with HasMetadata

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

the class KubernetesResourceUtil method getPodLabelSelector.

public static LabelSelector getPodLabelSelector(HasMetadata entity) {
    LabelSelector selector = null;
    if (entity instanceof Deployment) {
        Deployment resource = (Deployment) entity;
        DeploymentSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof ReplicaSet) {
        ReplicaSet resource = (ReplicaSet) entity;
        ReplicaSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) entity;
        DeploymentConfigSpec spec = resource.getSpec();
        if (spec != null) {
            selector = toLabelSelector(spec.getSelector());
        }
    } else if (entity instanceof ReplicationController) {
        ReplicationController resource = (ReplicationController) entity;
        ReplicationControllerSpec spec = resource.getSpec();
        if (spec != null) {
            selector = toLabelSelector(spec.getSelector());
        }
    } else if (entity instanceof DaemonSet) {
        DaemonSet resource = (DaemonSet) entity;
        DaemonSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof StatefulSet) {
        StatefulSet resource = (StatefulSet) entity;
        StatefulSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof Job) {
        Job resource = (Job) entity;
        JobSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    }
    return selector;
}
Also used : StatefulSetSpec(io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec) ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DaemonSetSpec(io.fabric8.kubernetes.api.model.extensions.DaemonSetSpec) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DaemonSet(io.fabric8.kubernetes.api.model.extensions.DaemonSet) JobSpec(io.fabric8.kubernetes.api.model.JobSpec) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Job(io.fabric8.kubernetes.api.model.Job) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 93 with HasMetadata

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

the class OpenShiftDependencyResources method addMissingResources.

public void addMissingResources(List<HasMetadata> objects) {
    Map<KindAndName, HasMetadata> itemMap = new HashMap<>();
    for (HasMetadata item : objects) {
        itemMap.put(new KindAndName(item), item);
    }
    // lets add any openshift specific dependencies (OAuthClient etc) which are not already added
    for (Map.Entry<KindAndName, HasMetadata> entry : openshiftDependencyResources.entrySet()) {
        KindAndName key = entry.getKey();
        HasMetadata dependency = entry.getValue();
        if (!itemMap.containsKey(key)) {
            objects.add(dependency);
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 94 with HasMetadata

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

the class OpenShiftOverrideResources method overrideResource.

/**
 * Applies any overrides if we have any for the given item
 */
public HasMetadata overrideResource(HasMetadata item) {
    KindAndName key = new KindAndName(item);
    HasMetadata override = map.get(key);
    if (override != null) {
        log.info("Overriding " + key);
        HasMetadata answer = KubernetesResourceUtil.mergeResources(item, override, log, false);
        if (answer != null) {
            return answer;
        }
    }
    return item;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata)

Example 95 with HasMetadata

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

the class PodLogService method tailAppPodsLogs.

public void tailAppPodsLogs(final KubernetesClient kubernetes, final String namespace, final Set<HasMetadata> entities, boolean watchAddedPodsOnly, String onExitOperation, boolean followLog, Date ignorePodsOlderThan, boolean waitInCurrentThread) {
    LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(entities);
    if (selector != null) {
        String ctrlCMessage = "stop tailing the log";
        if (Strings.isNotBlank(onExitOperation)) {
            final String onExitOperationLower = onExitOperation.toLowerCase().trim();
            if (onExitOperationLower.equals(OPERATION_UNDEPLOY)) {
                ctrlCMessage = "undeploy the app";
            } else if (onExitOperationLower.equals(OPERATION_STOP)) {
                ctrlCMessage = "scale down the app and stop tailing the log";
            } else {
                log.warn("Unknown on-exit command: `%s`", onExitOperationLower);
            }
            resizeApp(kubernetes, namespace, entities, 1, log);
            Runtime.getRuntime().addShutdownHook(new Thread("pod log service shutdown hook") {

                @Override
                public void run() {
                    if (onExitOperationLower.equals(OPERATION_UNDEPLOY)) {
                        log.info("Undeploying the app:");
                        deleteEntities(kubernetes, namespace, entities, context.getS2iBuildNameSuffix(), log);
                    } else if (onExitOperationLower.equals(OPERATION_STOP)) {
                        log.info("Stopping the app:");
                        resizeApp(kubernetes, namespace, entities, 0, log);
                    }
                    if (podWatcher != null) {
                        podWatcher.close();
                    }
                    closeLogWatcher();
                }
            });
        }
        waitAndLogPods(kubernetes, namespace, selector, watchAddedPodsOnly, ctrlCMessage, followLog, ignorePodsOlderThan, waitInCurrentThread);
    } else {
        log.warn("No selector in deployment so cannot watch pods!");
    }
}
Also used : LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)90 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)25 File (java.io.File)24 IOException (java.io.IOException)24 Template (io.fabric8.openshift.api.model.Template)19 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)18 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)18 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)17 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)16 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)14 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)14 Service (io.fabric8.kubernetes.api.model.Service)14 URL (java.net.URL)11 HashMap (java.util.HashMap)11 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)10 Map (java.util.Map)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9