From 67a19b2799cdc5a5f88f7f44d376cd1196df0083 Mon Sep 17 00:00:00 2001 From: Angie Wang Date: Wed, 9 Oct 2019 13:37:53 -0400 Subject: [PATCH] Strip out port from the alternative registry url All system images were changed to push to local registry. The image reference conversion approach(local registry prepended) is: registry.local:9001//image:tag In the case that private registry contains a port, we need to strip it out as Docker does not allow the format of the image reference that has port in repositores/namespaces, otherwise, the image reference conversion will fail. Test conducted (AIO-DX): - deploy system with private registry that has port in address - deploy system with public registry Change-Id: I1e3867dde932b60dd2e7f0a42331a7c12aaba752 Closes-Bug: #1847409 Signed-off-by: Angie Wang --- .../files/download_images.py | 26 ++++++++++++++++++- .../tasks/bringup_kubemaster.yml | 2 +- .../tasks/push_images_to_local_registry.yml | 11 ++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/files/download_images.py b/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/files/download_images.py index c7d440cad..cfe831da7 100644 --- a/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/files/download_images.py +++ b/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/files/download_images.py @@ -15,7 +15,31 @@ MAX_DOWNLOAD_THREAD = 5 def download_an_image(img): - local_img = 'registry.local:9001/' + img + # This function is to pull image from public/private + # registry and push to local registry. + # + # Examples of passed img reference: + # - k8s.gcr.io/kube-proxy:v.16.0 + # - privateregistry.io:5000/kube-proxy:v1.16.0 + # + # To push to local registry, local registry url + # 'registry.local:9001' needs to be prepended to + # image reference. The registry url of passed img + # may contains a port, if it has a port, we strip + # it out as Docker does not allow the format of + # the image that has port in repositories/namespaces + # i.e. + # Invalid format: + # registry.local:9001/privateregistry.io:5000/kube-proxy:v1.16.0 + + registry_url = img[:img.find('/')] + if ':' in registry_url: + img_name = img[img.find('/'):] + new_img = registry_url.split(':')[0] + img_name + else: + new_img = img + + local_img = 'registry.local:9001/' + new_img err_msg = " Image %s download failed: " % img for i in range(MAX_DOWNLOAD_ATTEMPTS): diff --git a/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/tasks/bringup_kubemaster.yml b/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/tasks/bringup_kubemaster.yml index 0efb68ad9..b65e28521 100644 --- a/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/tasks/bringup_kubemaster.yml +++ b/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/tasks/bringup_kubemaster.yml @@ -115,7 +115,7 @@ ETCD_ENDPOINT: "http://{{ cluster_floating_address | ipwrap }}:2379" POD_NETWORK_CIDR: "{{ cluster_pod_subnet }}" SERVICE_NETWORK_CIDR: "{{ cluster_service_subnet }}" - K8S_REGISTRY: "{{ k8s_registry.url }}" + K8S_REGISTRY: "{{ k8s_registry.url | regex_replace(':[0-9]+', '') }}" - name: Add apiserver certificate SANs to kubeadm replace: diff --git a/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/tasks/push_images_to_local_registry.yml b/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/tasks/push_images_to_local_registry.yml index 6d774419c..7102ddb1f 100644 --- a/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/tasks/push_images_to_local_registry.yml +++ b/playbookconfig/src/playbooks/roles/bootstrap/bringup-essential-services/tasks/push_images_to_local_registry.yml @@ -220,6 +220,17 @@ registry: "{{ local_registry }}" state: absent +- name: Strip out port from Tiller, Armada, Calico, Multus, Sriov image tags + set_fact: + tiller_img: "{{ tiller_img | regex_replace(':[0-9]+/', '/') }}" + armada_img: "{{ armada_img | regex_replace(':[0-9]+/', '/') }}" + calico_cni_img: "{{ calico_cni_img | regex_replace(':[0-9]+/', '/') }}" + calico_node_img: "{{ calico_node_img | regex_replace(':[0-9]+/', '/') }}" + calico_kube_controllers_img: "{{ calico_kube_controllers_img | regex_replace(':[0-9]+/', '/') }}" + multus_img: "{{ multus_img | regex_replace(':[0-9]+/', '/') }}" + sriov_cni_img: "{{ sriov_cni_img | regex_replace(':[0-9]+/', '/') }}" + sriov_network_device_img: "{{ sriov_network_device_img | regex_replace(':[0-9]+/', '/') }}" + - name: Remove local registry host from /etc/hosts command: >- sed -i -e 's|'$CONTROLLER_ADDRESS'\t'$CONTROLLER'\t'$LOCAL_REGISTRY'|'$CONTROLLER_ADDRESS'\t'$CONTROLLER'|g' /etc/hosts