private DeploymentConfig generateDeploymentConfig(String namespace, Map<String, String> labels) {
    Object exposedPorts =
        osActiveStreamTag
            .getImage()
            .getDockerImageMetadata()
            .getContainerConfig()
            .getExposedPorts();
    List<ContainerPort> ports = parsePorts(exposedPorts);

    Map<String, String> templateLabels = new HashMap<>(labels);
    templateLabels.put("deploymentconfig", osAppName);

    List<EnvVar> env = newArrayList();

    for (KeyValue variable : view.getEnvironmentVariables()) {
      env.add(newDto(EnvVar.class).withName(variable.getKey()).withValue(variable.getValue()));
    }

    final String steamTagName = osAppName + ":latest";
    PodSpec podSpec =
        newDto(PodSpec.class)
            .withContainers(
                newArrayList(
                    newDto(Container.class)
                        .withImage(steamTagName)
                        .withName(osAppName)
                        .withPorts(ports)
                        .withEnv(env)));

    PodTemplateSpec template =
        newDto(PodTemplateSpec.class)
            .withMetadata(newDto(ObjectMeta.class).withLabels(templateLabels))
            .withSpec(podSpec);

    DeploymentTriggerPolicy imageChange =
        newDto(DeploymentTriggerPolicy.class)
            .withType("ImageChange")
            .withImageChangeParams(
                newDto(DeploymentTriggerImageChangeParams.class)
                    .withAutomatic(true)
                    .withContainerNames(newArrayList(osAppName))
                    .withFrom(
                        newDto(ObjectReference.class)
                            .withKind("ImageStreamTag")
                            .withName(steamTagName)));

    DeploymentTriggerPolicy configChange =
        newDto(DeploymentTriggerPolicy.class).withType("ConfigChange");

    return newDto(DeploymentConfig.class)
        .withApiVersion(API_VERSION)
        .withKind("DeploymentConfig")
        .withMetadata(
            newDto(ObjectMeta.class)
                .withName(osAppName)
                .withLabels(labels)
                .withNamespace(namespace))
        .withSpec(
            newDto(DeploymentConfigSpec.class)
                .withReplicas(1)
                .withSelector(Collections.singletonMap("deploymentconfig", osAppName))
                .withTemplate(template)
                .withTriggers(newArrayList(imageChange, configChange)));
  }
  private BuildConfig generateBuildConfig(String namespace, Map<String, String> labels) {
    BuildSource source =
        newDto(BuildSource.class)
            .withType("Git")
            .withGit(
                newDto(GitBuildSource.class)
                    .withRef("master") // load branch
                    .withUri(projectRemotes.get(0).getUrl()));

    SourceBuildStrategy sourceStrategy =
        newDto(SourceBuildStrategy.class)
            .withFrom(
                newDto(ObjectReference.class)
                    .withKind("ImageStreamTag")
                    .withName(osActiveStreamTag.getMetadata().getName())
                    .withNamespace("openshift"));

    BuildStrategy strategy =
        newDto(BuildStrategy.class).withType("Source").withSourceStrategy(sourceStrategy);

    BuildTriggerPolicy generic =
        newDto(BuildTriggerPolicy.class)
            .withType("generic")
            .withGeneric(newDto(WebHookTrigger.class).withSecret(generateSecret()));

    BuildTriggerPolicy github =
        newDto(BuildTriggerPolicy.class)
            .withType("github")
            .withGithub(newDto(WebHookTrigger.class).withSecret(generateSecret()));

    BuildTriggerPolicy imageChange =
        newDto(BuildTriggerPolicy.class)
            .withType("imageChange")
            .withImageChange(newDto(ImageChangeTrigger.class));

    BuildTriggerPolicy configChange = newDto(BuildTriggerPolicy.class).withType("ConfigChange");

    BuildOutput output =
        newDto(BuildOutput.class)
            .withTo(
                newDto(ObjectReference.class)
                    .withName(osAppName + ":latest")
                    .withKind("ImageStreamTag"));

    final BuildConfigSpec spec =
        newDto(BuildConfigSpec.class)
            .withSource(source)
            .withStrategy(strategy)
            .withTriggers(newArrayList(generic, github, imageChange, configChange))
            .withOutput(output);

    return newDto(BuildConfig.class)
        .withApiVersion(API_VERSION)
        .withKind("BuildConfig")
        .withMetadata(
            newDto(ObjectMeta.class)
                .withName(osAppName)
                .withLabels(labels)
                .withNamespace(namespace))
        .withSpec(spec);
  }