From 325380d274d127d49de1fa97693e0d86054aafda Mon Sep 17 00:00:00 2001 From: Mateo Florido <32885896+mateoflorido@users.noreply.github.com> Date: Fri, 21 Jun 2024 01:18:39 -0500 Subject: [PATCH] Sync Calico CNI images from upstream (#506) * Add Calico upstream images to regsync configuration * Use `ghcr.io/canonical/k8s-snap` mirror for Calico images --- build-scripts/hack/upstream-images.yaml | 30 ++++++++++++++++ src/k8s/pkg/k8sd/features/calico/chart.go | 11 ++++-- src/k8s/pkg/k8sd/features/calico/network.go | 3 +- src/k8s/pkg/k8sd/features/calico/register.go | 37 +++++++------------- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/build-scripts/hack/upstream-images.yaml b/build-scripts/hack/upstream-images.yaml index aceb00c72..98af76843 100644 --- a/build-scripts/hack/upstream-images.yaml +++ b/build-scripts/hack/upstream-images.yaml @@ -7,3 +7,33 @@ sync: - source: registry.k8s.io/pause:3.10 target: ghcr.io/canonical/k8s-snap/pause:3.10 type: image + - source: docker.io/calico/apiserver:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/apiserver:v3.28.0 + type: image + - source: docker.io/calico/cni:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/cni:v3.28.0 + type: image + - source: docker.io/calico/csi:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/csi:v3.28.0 + type: image + - source: docker.io/calico/ctl:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/ctl:v3.28.0 + type: image + - source: docker.io/calico/kube-controllers:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/kube-controllers:v3.28.0 + type: image + - source: docker.io/calico/node-driver-registrar:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/node-driver-registrar:v3.28.0 + type: image + - source: docker.io/calico/node:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/node:v3.28.0 + type: image + - source: docker.io/calico/pod2daemon-flexvol:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/pod2daemon-flexvol:v3.28.0 + type: image + - source: docker.io/calico/typha:v3.28.0 + target: ghcr.io/canonical/k8s-snap/calico/typha:v3.28.0 + type: image + - source: quay.io/tigera/operator:v1.34.0 + target: ghcr.io/canonical/k8s-snap/tigera/operator:v1.34.0 + type: image diff --git a/src/k8s/pkg/k8sd/features/calico/chart.go b/src/k8s/pkg/k8sd/features/calico/chart.go index a645cd894..04a860a9c 100644 --- a/src/k8s/pkg/k8sd/features/calico/chart.go +++ b/src/k8s/pkg/k8sd/features/calico/chart.go @@ -14,10 +14,15 @@ var ( ManifestPath: path.Join("charts", "tigera-operator-v3.28.0.tgz"), } - // tigeraOperatorRepo represents the repo to fetch the tigera-operator image for calico. // Note: Tigera is the company behind Calico and the tigera-operator is the operator for Calico. // TODO: use ROCKs instead of upstream - tigeraOperatorRegistry = "quay.io" + // imageRepo represents the repo to fetch the Calico CNI images. + imageRepo = "ghcr.io/canonical/k8s-snap" + + // calicoImageRepo represents the repo to fetch the calico images. + calicoImageRepo = "ghcr.io/canonical/k8s-snap/calico" + // calicoTag represents the tag to use for the calico images. + calicoTag = "v3.28.0" // tigeraOperatorImage represents the image to fetch for calico. tigeraOperatorImage = "tigera/operator" @@ -27,7 +32,7 @@ var ( // calicoCtlImage represents the image to fetch for calicoctl. // TODO: use ROCKs instead of upstream - calicoCtlImage = "docker.io/calico/ctl" + calicoCtlImage = "ghcr.io/canonical/k8s-snap/calico/ctl" // calicoCtlTag represents the tag to use for the calicoctl image. calicoCtlTag = "v3.28.0" ) diff --git a/src/k8s/pkg/k8sd/features/calico/network.go b/src/k8s/pkg/k8sd/features/calico/network.go index 45c9a1333..6ea50df92 100644 --- a/src/k8s/pkg/k8sd/features/calico/network.go +++ b/src/k8s/pkg/k8sd/features/calico/network.go @@ -55,7 +55,7 @@ func ApplyNetwork(ctx context.Context, snap snap.Snap, cfg types.Network, _ type values := map[string]any{ "tigeraOperator": map[string]any{ - "registry": tigeraOperatorRegistry, + "registry": imageRepo, "image": tigeraOperatorImage, "version": tigeraOperatorVersion, }, @@ -67,6 +67,7 @@ func ApplyNetwork(ctx context.Context, snap snap.Snap, cfg types.Network, _ type "calicoNetwork": map[string]any{ "ipPools": podIpPools, }, + "registry": imageRepo, }, "serviceCIDRs": serviceCIDRs, } diff --git a/src/k8s/pkg/k8sd/features/calico/register.go b/src/k8s/pkg/k8sd/features/calico/register.go index e7f42a7e5..b3e843c21 100644 --- a/src/k8s/pkg/k8sd/features/calico/register.go +++ b/src/k8s/pkg/k8sd/features/calico/register.go @@ -8,30 +8,17 @@ import ( func init() { images.Register( - fmt.Sprintf("%s/%s:%s", tigeraOperatorRegistry, tigeraOperatorImage, tigeraOperatorVersion), - ) - - // TODO: configurable Calico images, include in this list - // - // Hardcoded list based on "k8s kubectl get node -o template='{{ range .items }}{{ .metadata.name }}{{":"}}{{ range .status.images }}{{ "\n- " }}{{ index .names 1 }}{{ end }}{{"\n"}}{{ end }}' | grep calico": - // - // - docker.io/calico/node:v3.28.0 - // - docker.io/calico/cni:v3.28.0 - // - docker.io/calico/apiserver:v3.28.0 - // - docker.io/calico/kube-controllers:v3.28.0 - // - docker.io/calico/typha:v3.28.0 - // - docker.io/calico/node-driver-registrar:v3.28.0 - // - docker.io/calico/csi:v3.28.0 - // - docker.io/calico/pod2daemon-flexvol:v3.28.0 - - images.Register( - "docker.io/calico/node:v3.28.0", - "docker.io/calico/cni:v3.28.0", - "docker.io/calico/apiserver:v3.28.0", - "docker.io/calico/kube-controllers:v3.28.0", - "docker.io/calico/typha:v3.28.0", - "docker.io/calico/node-driver-registrar:v3.28.0", - "docker.io/calico/csi:v3.28.0", - "docker.io/calico/pod2daemon-flexvol:v3.28.0", + // Tigera images + fmt.Sprintf("%s/%s:%s", imageRepo, tigeraOperatorImage, tigeraOperatorVersion), + // Calico images + fmt.Sprintf("%s/apiserver:%s", calicoImageRepo, calicoTag), + fmt.Sprintf("%s/cni:%s", calicoImageRepo, calicoTag), + fmt.Sprintf("%s/csi:%s", calicoImageRepo, calicoTag), + fmt.Sprintf("%s/ctl:%s", calicoImageRepo, calicoCtlTag), + fmt.Sprintf("%s/kube-controllers:%s", calicoImageRepo, calicoTag), + fmt.Sprintf("%s/node:%s", calicoImageRepo, calicoTag), + fmt.Sprintf("%s/node-driver-registrar:%s", calicoImageRepo, calicoTag), + fmt.Sprintf("%s/pod2daemon-flexvol:%s", calicoImageRepo, calicoTag), + fmt.Sprintf("%s/typha:%s", calicoImageRepo, calicoTag), ) }