public HasMetadata convert()

in plugin/src/main/java/io/fabric8/maven/plugin/converter/DeploymentOpenShiftConverter.java [53:137]


    public HasMetadata convert(HasMetadata item) {
            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
                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(true)
                                    .withNewFrom()
                                    .withKind("ImageStreamTag")
                                    .withName(image.getSimpleName() + ":" + tag)
                                    .endFrom()
                                    .withContainerNames(containerName)
                                    .endImageChangeParams()
                                    .endTrigger();
                        }
                    }
                }

                specBuilder.endSpec();
            }
            return builder.build();
    }