<p>I am currently working on a template for OpenShift and my ImageChange trigger gets deleted when I initally instantiate the application. My Template contains the following objects</p>

<ul>
<li>ImageStream</li>
<li>BuildConfig</li>
<li>Service</li>
<li>Route</li>
<li>Deploymentconfig</li>
</ul>

<p>I guess the route is irrelevant but this is what it looks like so far (for better overview I will post the objects seperated, but they are all items in my Template)</p>

<p><strong>ImageStream</strong></p>

<pre><code>- kind: ImageStream 
    apiVersion: v1
    metadata:
      labels:
        app: my-app
      name: my-app
      namespace: ${IMAGE_NAMESPACE}
</code></pre>

<p><strong>BuildConfig</strong></p>

<pre><code>- kind: BuildConfig
    apiVersion: v1
    metadata:
      labels:
        app: my-app
        deploymentconfig: my-app
      name: my-app
      namespace: ${IMAGE_NAMESPACE}
      selfLink: /oapi/v1/namespaces/${IMAGE_NAMESPACE}/buildconfigs/my-app
    spec:
      runPolicy: Serial
      source:
        git:
          ref: pre-prod
          uri: 'ssh://git@git.myreopo.net:port/project/my-app.git'
        sourceSecret:
          name: git-secret
        type: Git
      strategy:
        type: Source
        sourceStrategy:
          env:
            - name: HTTP_PROXY
              value: 'http://user:password@proxy.com:8080'
            - name: HTTPS_PROXY
              value: 'http://user:password@proxy.com:8080'
            - name: NO_PROXY
              value: .something.net
          from:
            kind: ImageStreamTag
            name: 'nodejs:8'
            namespace: openshift
      output:
          to:
            kind: ImageStreamTag
            name: 'my-app:latest'
            namespace: ${IMAGE_NAMESPACE}
</code></pre>

<p><strong>Service</strong></p>

<pre><code>- kind: Service
    apiVersion: v1
    metadata:
      name: my-app
      labels:
        app: my-app
    spec:
      selector:
        deploymentconfig: my-app
      ports:
        - name: 8080-tcp
          port: 8080
          protocol: TCP
          targetPort: 8080
      sessionAffinity: None
      type: ClusterIP
</code></pre>

<p><strong>DeploymentConfig</strong></p>

<p>Now what is already weird in the DeploymentConfig is that under spec.template.spec.containers[0].image I have to specify the full path to the repository to make it work, otherwise I get an error pulling the image. (even though documentation says my-app:latest would be correct)</p>

<pre><code>- kind: DeploymentConfig
    apiVersion: v1
    metadata:
      labels:
        app: my-app
        deploymentconfig: my-app
      name: my-app
      namespace: ${IMAGE_NAMESPACE}
      selfLink: /oapi/v1/namespaces/${IMAGE_NAMESPACE}/deploymentconfigs/my-app
    spec:
      selector:
        app: my-app
        deploymentconfig: my-app
      strategy:
        type: Rolling
        rollingParams:
          intervalSeconds: 1
          maxSurge: 25%
          maxUnavailability: 25%
          timeoutSeconds: 600
          updatePeriodSeconds: 1
      replicas: 1
      template:
        metadata:
          labels:
            app: my-app
            deploymentconfig: my-app
        spec:
          containers:
            - name: my-app-container
              image: "${REPOSITORY_IP}:${REPOSITORY_PORT}/${IMAGE_NAMESPACE}/my-app:latest"
              imagePullPolicy: Always
              ports:
                - containerPort: 8080
                  protocol: TCP
                - containerPort: 8081
                  protocol: TCP
              env:
                - name: MONGODB_USERNAME
                  valueFrom:
                    secretKeyRef:
                      name: my-app-database
                      key: database-user
                - name: MONGODB_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: my-app-database
                      key: database-password
                - name: MONGODB_DATABASE
                  value: "myapp"
                - name: ROUTE_PATH
                  value: /my-app
                - name: MONGODB_AUTHDB
                  value: "myapp"
                - name: MONGODB_PORT
                  value: "27017"
                - name: HTTP_PORT
                  value: "8080"
                - name: HTTPS_PORT
                  value: "8082"
        restartPolicy: Always
        dnsPolicy: ClusterFirst
        triggers:
          - type: ImageChange
            imageChangeParams:
              automatic: true
              from: 
                kind: ImageStreamTag
                name: 'my-app:latest'
                namespace: ${IMAGE_NAMESPACE}
              containerNames:
                - my-app-container
          - type: ConfigChange
</code></pre>

<p>I deploy the application using</p>

<pre><code>oc process -f ./openshift/template.yaml ..Parameters... | oc apply -f -
</code></pre>

<p>But the outcome is the same when I use oc new-app.</p>

<p>The weird thing is. The application gets deployed and is running fine, but image changes will have no effect. So I exported DeploymentConfig and found that it was missing the ImageChangeTrigger leaving the trigger part being</p>

<pre><code>triggers:
  - type: ConfigChange
</code></pre>

<p>At first I thought this was due to the fact that maybe the build was not ready when I tried to apply the DeploymentConfig so I created a build first and waited for it to finish. Afterwards I deployed the rest of the application (Service, Route, DeploymentConfig). The outcome was the same however. If I use the Webgui and change the DeploymentConfig there from</p>

<p><a href="https://i.stack.imgur.com/RVozP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RVozP.png" alt="enter image description here"></a></p>

<p>to this, fill out namespace, app and tag (latest) and hit apply everything works as it should. I just can't figure out why the trigger is beeing ignored initially. Would be great if someone has an idea where I'm wrong</p>

<p><a href="https://i.stack.imgur.com/niNlY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/niNlY.png" alt="enter image description here"></a></p>

<p>Versions I am using are</p>

<p>oc: v3.9.0</p>

<p>kubernetes: v1.6.1</p>

<p>openshift v3.6.173.0.140</p>

<p>OK the answer was pretty simple. Turned out it was just an indentation error in the yaml file for the DeploymentConfig. Instead of</p>

<pre><code>    dnsPolicy: ClusterFirst
    restartPolicy: Always
    terminationGracePeriodSeconds: 30
    triggers:
      - type: ImageChange
        imageChangeParams:
          automatic: true
          containerNames:
            - alpac-studio-container
          from:
            kind: ImageStreamTag
            name: alpac-studio:latest
      - type: ConfigChange
</code></pre>

<p>It has to be</p>

<pre><code>    dnsPolicy: ClusterFirst
    restartPolicy: Always
    terminationGracePeriodSeconds: 30
triggers:
  - type: ImageChange
    imageChangeParams:
      automatic: true
      containerNames:
        - alpac-studio-container
      from:
        kind: ImageStreamTag
        name: alpac-studio:latest
  - type: ConfigChange
</code></pre>

<p>So the triggers have to be on the same level as e.g. template and strategy</p>
