1
votes

I am importing the following template in the OpenShift web client to create ImageStream, DeploymentConfig & Service.

ImageStream is created from a Docker Image available on an External Docker Registry.

Everything seems to be working fine apart from the fact that whenever the Docker Image changes in the external registry redeployment doesn't take place.

Is it possible with Openshift & External Registry to trigger auto deployments when Docker Image is changed in the external registry.

{
    "kind": "Template",
    "apiVersion": "v1",
    "metadata": {
        "name": "test-100"
    },
    "objects": [
        {
            "kind": "ImageStream",
            "apiVersion": "image.openshift.io/v1",
            "metadata": {
                "name": "test-100",
                "creationTimestamp": null,
                "labels": {
                    "app": "test-100"
                },
                "annotations": {
                    "openshift.io/generated-by": "OpenShiftNewApp"
                }
            },
            "spec": {
                "lookupPolicy": {
                    "local": false
                },
                "tags": [
                    {
                        "name": "latest",
                        "annotations": {
                            "openshift.io/imported-from": "artifactory.company.com/docker-dev-local/test/dev/test:latest"
                        },
                        "from": {
                            "kind": "DockerImage",
                            "name": "artifactory.company.com/docker-dev-local/test/dev/test:latest"
                        },
                        "generation": null,
                        "importPolicy": {},
                        "referencePolicy": {
                            "type": ""
                        }
                    }
                ]
            }
        },
        {
            "kind": "DeploymentConfig",
            "apiVersion": "apps.openshift.io/v1",
            "metadata": {
                "name": "test-100",
                "creationTimestamp": null,
                "labels": {
                    "app": "test-100"
                },
                "annotations": {
                    "openshift.io/generated-by": "OpenShiftNewApp"
                }
            },
            "spec": {
                "strategy": {
                    "resources": {}
                },
                "triggers": [
                    {
                        "type": "ConfigChange"
                    },
                    {
                        "type": "ImageChange",
                        "imageChangeParams": {
                            "automatic": true,
                            "containerNames": [
                                "test-100"
                            ],
                            "from": {
                                "kind": "ImageStreamTag",
                                "name": "test-100:latest"
                            }
                        }
                    }
                ],
                "replicas": 1,
                "test": false,
                "selector": {
                    "app": "test-100",
                    "deploymentconfig": "test-100"
                },
                "template": {
                    "metadata": {
                        "creationTimestamp": null,
                        "labels": {
                            "app": "test-100",
                            "deploymentconfig": "test-100"
                        },
                        "annotations": {
                            "openshift.io/generated-by": "OpenShiftNewApp"
                        }
                    },
                    "spec": {
                        "containers": [
                            {
                                "name": "test-100",
                                "image": "artifactory.company.com/docker-dev-local/test/dev/test:latest",
                                "ports": [
                                    {
                                        "containerPort": 8080,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "containerPort": 8443,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "containerPort": 8778,
                                        "protocol": "TCP"
                                    }
                                ],
                                "resources": {}
                            }
                        ]
                    }
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "metadata": {
                "name": "test-100",
                "creationTimestamp": null,
                "labels": {
                    "app": "test-100"
                },
                "annotations": {
                    "openshift.io/generated-by": "OpenShiftNewApp"
                }
            },
            "spec": {
                "ports": [
                    {
                        "name": "8080-tcp",
                        "protocol": "TCP",
                        "port": 8080,
                        "targetPort": 8080
                    },
                    {
                        "name": "8443-tcp",
                        "protocol": "TCP",
                        "port": 8443,
                        "targetPort": 8443
                    },
                    {
                        "name": "8778-tcp",
                        "protocol": "TCP",
                        "port": 8778,
                        "targetPort": 8778
                    }
                ],
                "selector": {
                    "app": "test-100",
                    "deploymentconfig": "test-100"
                }
            }
        }
    ]
}
1

1 Answers

2
votes

OpenShift can not detect image changes on external registry. So you should configure importPolicy.scheduled: true to refresh the image.

e.g.> you can configure imagePolicy every image tag.

apiVersion: v1
kind: ImageStream
metadata:
  name: ruby
spec:
  tags:
  - from:
      kind: DockerImage
      name: openshift/ruby-20-centos7
    name: latest
    importPolicy:
      scheduled: true

The interval is 15 minutes by default. If you want to change the value, you can adjust the config from /etc/origin/master/master-config.yaml as follows.

e.g.> ScheduledImageImportMinimumIntervalSeconds is interval time for imagestream import. Refer Image Policy Configuration for other parameter details.

imagePolicyConfig:
  MaxScheduledImageImportsPerMinute: 10  
  ScheduledImageImportMinimumIntervalSeconds: 1800
  disableScheduledImport: false
  maxImagesBulkImportedPerRepository: 3

Further information is here: Automatically Update Red Hat Container Images on OpenShift 3.11.