use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8-maven-plugin by fabric8io.
the class ImageEnricher method mergeEnvVariables.
private void mergeEnvVariables(Container container) {
List<EnvVar> env = container.getEnv();
if (env == null) {
env = new LinkedList<>();
container.setEnv(env);
}
ResourceConfig resource = getContext().getResources();
Map<String, String> userEnv = resource != null ? resource.getEnv() : null;
if (userEnv != null) {
for (Map.Entry<String, String> entry : userEnv.entrySet()) {
EnvVar existingVariable = KubernetesResourceUtil.setEnvVarNoOverride(env, entry.getKey(), entry.getValue());
if (existingVariable != null) {
String actualValue = existingVariable.getValue();
if (actualValue == null) {
actualValue = "retrieved using the downward API";
}
log.warn("Environment variable %s will not be overridden: trying to set the value %s, but its actual value will be %s", entry.getKey(), entry.getValue(), actualValue);
}
}
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8-maven-plugin by fabric8io.
the class DeploymentOpenShiftConverter method convert.
@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
Deployment resource = (Deployment) item;
DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
builder.withMetadata(resource.getMetadata());
DeploymentSpec spec = resource.getSpec();
if (spec != null) {
DeploymentConfigFluent.SpecNested<DeploymentConfigBuilder> specBuilder = builder.withNewSpec();
Integer replicas = spec.getReplicas();
if (replicas != null) {
specBuilder.withReplicas(replicas);
}
Integer revisionHistoryLimit = spec.getRevisionHistoryLimit();
if (revisionHistoryLimit != null) {
specBuilder.withRevisionHistoryLimit(revisionHistoryLimit);
}
LabelSelector selector = spec.getSelector();
if (selector != null) {
Map<String, String> matchLabels = selector.getMatchLabels();
if (matchLabels != null && !matchLabels.isEmpty()) {
specBuilder.withSelector(matchLabels);
}
}
Map<String, String> containerToImageMap = new HashMap<>();
PodTemplateSpec template = spec.getTemplate();
if (template != null) {
specBuilder.withTemplate(template);
PodSpec podSpec = template.getSpec();
notNull(podSpec, "No PodSpec for PodTemplate:" + template);
List<Container> containers = podSpec.getContainers();
notNull(podSpec, "No containers for PodTemplate.spec: " + template);
for (Container container : containers) {
validateContainer(container);
containerToImageMap.put(container.getName(), container.getImage());
}
}
DeploymentStrategy strategy = spec.getStrategy();
String strategyType = null;
if (strategy != null) {
strategyType = strategy.getType();
}
if (openshiftDeployTimeoutSeconds != null && openshiftDeployTimeoutSeconds > 0) {
if (Strings.isNullOrBlank(strategyType) || "Rolling".equals(strategyType)) {
specBuilder.withNewStrategy().withType("Rolling").withNewRollingParams().withTimeoutSeconds(openshiftDeployTimeoutSeconds).endRollingParams().endStrategy();
} else if ("Recreate".equals(strategyType)) {
specBuilder.withNewStrategy().withType("Recreate").withNewRecreateParams().withTimeoutSeconds(openshiftDeployTimeoutSeconds).endRecreateParams().endStrategy();
} else {
specBuilder.withNewStrategy().withType(strategyType).endStrategy();
}
} else if (Strings.isNotBlank(strategyType)) {
// TODO is there any values we can copy across?
specBuilder.withNewStrategy().withType(strategyType).endStrategy();
}
// lets add a default trigger so that its triggered when we change its config
if (enableAutomaticTrigger) {
specBuilder.addNewTrigger().withType("ConfigChange").endTrigger();
}
// add a new image change trigger for the build stream
if (containerToImageMap.size() != 0) {
if (mode.equals(PlatformMode.openshift)) {
for (Map.Entry<String, String> entry : containerToImageMap.entrySet()) {
String containerName = entry.getKey();
ImageName image = new ImageName(entry.getValue());
String tag = image.getTag() != null ? image.getTag() : "latest";
specBuilder.addNewTrigger().withType("ImageChange").withNewImageChangeParams().withAutomatic(enableAutomaticTrigger).withNewFrom().withKind("ImageStreamTag").withName(image.getSimpleName() + ":" + tag).withNamespace(image.getUser()).endFrom().withContainerNames(containerName).endImageChangeParams().endTrigger();
}
}
if (trimImageInContainerSpec) {
/*
* In Openshift 3.7, update to container image is automatically triggering redeployments
* and those subsequent rollouts lead to RC complaining about a missing image reference.
*
* See this : https://github.com/openshift/origin/issues/18406#issuecomment-364090247
*
* this the time it gets fixed. Do this:
* Since we're using ImageTrigger here, set container image to " ". If there is any config
* change never set to image else than " "; so doing oc apply/rollouts won't be creating
* re-deployments again and again.
*
*/
List<Container> containers = template.getSpec().getContainers();
for (Integer nIndex = 0; nIndex < containers.size(); nIndex++) {
containers.get(nIndex).setImage(" ");
}
template.getSpec().setContainers(containers);
specBuilder.withTemplate(template);
}
}
specBuilder.endSpec();
}
return builder.build();
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8-maven-plugin by fabric8io.
the class SecretEnricher method addMissingResources.
@Override
public void addMissingResources(KubernetesListBuilder builder) {
Map<String, String> config = getRawConfig();
SecretBuilder secretBuilder = createSecretBuilder();
for (Map.Entry<String, String> entry : config.entrySet()) {
if (!isTypedKey(entry.getKey())) {
addToSecretBuilder(secretBuilder, entry.getKey(), entry.getValue());
}
}
if (secretBuilder.hasData() && secretBuilder.getData().size() > 0) {
builder.addToSecretItems(secretBuilder.build());
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by fabric8io.
the class Example method listPods.
protected static void listPods(KubernetesClient kube) {
System.out.println("\n\nLooking up pods");
System.out.println("=========================================================================");
PodList pods = kube.pods().list();
// System.out.println("Got pods: " + pods);
List<Pod> items = pods.getItems();
for (Pod item : items) {
System.out.println("Pod " + KubernetesHelper.getName(item) + " with ip: " + item.getStatus().getPodIP() + " created: " + item.getMetadata().getCreationTimestamp());
PodSpec spec = item.getSpec();
if (spec != null) {
List<Container> containers = spec.getContainers();
if (containers != null) {
for (Container container : containers) {
System.out.println("Container " + container.getImage() + " " + container.getCommand() + " ports: " + container.getPorts());
}
}
}
Map<String, ContainerStatus> currentContainers = KubernetesHelper.getCurrentContainers(item);
System.out.println("Has " + currentContainers.size() + " container(s)");
Set<Map.Entry<String, ContainerStatus>> entries = currentContainers.entrySet();
for (Map.Entry<String, ContainerStatus> entry : entries) {
String id = entry.getKey();
ContainerStatus info = entry.getValue();
System.out.println("Current container: " + id + " info: " + info);
}
}
System.out.println();
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by fabric8io.
the class Templates method combineTemplates.
public static Template combineTemplates(Template firstTemplate, Template template) {
List<HasMetadata> objects = template.getObjects();
if (objects != null) {
for (HasMetadata object : objects) {
addTemplateObject(firstTemplate, object);
}
}
List<Parameter> parameters = firstTemplate.getParameters();
if (parameters == null) {
parameters = new ArrayList<>();
firstTemplate.setParameters(parameters);
}
combineParameters(parameters, template.getParameters());
String name = KubernetesHelper.getName(template);
if (Strings.isNotBlank(name)) {
// lets merge all the fabric8 annotations using the template id qualifier as a postfix
Map<String, String> annotations = KubernetesHelper.getOrCreateAnnotations(firstTemplate);
Map<String, String> otherAnnotations = KubernetesHelper.getOrCreateAnnotations(template);
Set<Map.Entry<String, String>> entries = otherAnnotations.entrySet();
for (Map.Entry<String, String> entry : entries) {
String key = entry.getKey();
String value = entry.getValue();
if (!annotations.containsKey(key)) {
annotations.put(key, value);
}
}
}
return firstTemplate;
}
Aggregations