Openshift ImageChange trigger gets deleted in Deploymentconfig when applying templage

1/21/2019

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

  • ImageStream
  • BuildConfig
  • Service
  • Route
  • Deploymentconfig

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)

ImageStream

- kind: ImageStream 
    apiVersion: v1
    metadata:
      labels:
        app: my-app
      name: my-app
      namespace: ${IMAGE_NAMESPACE}

BuildConfig

- 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}

Service

- 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

DeploymentConfig

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)

- 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

I deploy the application using

oc process -f ./openshift/template.yaml ..Parameters... | oc apply -f -

But the outcome is the same when I use oc new-app.

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

triggers:
  - type: ConfigChange

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

enter image description here

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

enter image description here

Versions I am using are

oc: v3.9.0

kubernetes: v1.6.1

openshift v3.6.173.0.140

-- relief.melone
deployment
kubernetes
openshift

1 Answer

1/24/2019

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

    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

It has to be

    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

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

-- relief.melone
Source: StackOverflow