From 6e6af9885f20413c28da7ba15feac3774375e822 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Mon, 2 Dec 2024 23:24:10 +0000 Subject: [PATCH] Add rewrite test to privateregistry e2e Signed-off-by: Brad Davidson --- tests/e2e/privateregistry/Vagrantfile | 7 +++++-- tests/e2e/privateregistry/privateregistry_test.go | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/e2e/privateregistry/Vagrantfile b/tests/e2e/privateregistry/Vagrantfile index 8300f81b30ab..0fd7a3d3f1c8 100644 --- a/tests/e2e/privateregistry/Vagrantfile +++ b/tests/e2e/privateregistry/Vagrantfile @@ -32,10 +32,13 @@ def provision(vm, role, role_num, node_num) # and still using the heredoc formatting with escapped quotes writePrivateRegistry = <<~'SCRIPT'.chomp % {net: NETWORK_PREFIX} mkdir -p /etc/rancher/k3s/ - echo "mirrors: + echo 'mirrors: my-registry.local: endpoint: - - \"http://%{net}.100:5000\"" > /etc/rancher/k3s/registries.yaml + - http://%{net}.100:5000 + rewrite: + "^library/(.*)$": "docker-io-library/$1" + ' > /etc/rancher/k3s/registries.yaml SCRIPT setInsecureRegistryPolicy = <<~'SCRIPT'.chomp % {net: NETWORK_PREFIX} diff --git a/tests/e2e/privateregistry/privateregistry_test.go b/tests/e2e/privateregistry/privateregistry_test.go index b3d4f2f237f8..856f49b596c6 100644 --- a/tests/e2e/privateregistry/privateregistry_test.go +++ b/tests/e2e/privateregistry/privateregistry_test.go @@ -95,28 +95,32 @@ var _ = Describe("Verify Create", Ordered, func() { Expect(err).NotTo(HaveOccurred()) }) + // Mirror the image as NODEIP:5000/docker-io-library/nginx:1.27.3, but reference it as my-registry.local/library/nginx:1.27.3 - + // the rewrite in registries.yaml's entry for my-registry.local should ensure that it is rewritten properly when pulling from + // NODEIP:5000 as a mirror. It("Should pull and image from dockerhub and send it to private registry", func() { - cmd := "docker pull nginx" + cmd := "docker pull docker.io/library/nginx:1.27.3" _, err := e2e.RunCmdOnNode(cmd, serverNodeNames[0]) Expect(err).NotTo(HaveOccurred(), "failed: "+cmd) nodeIP, err := e2e.FetchNodeExternalIP(serverNodeNames[0]) Expect(err).NotTo(HaveOccurred()) - cmd = "docker tag nginx " + nodeIP + ":5000/my-webpage" + cmd = "docker tag docker.io/library/nginx:1.27.3 " + nodeIP + ":5000/docker-io-library/nginx:1.27.3" _, err = e2e.RunCmdOnNode(cmd, serverNodeNames[0]) Expect(err).NotTo(HaveOccurred(), "failed: "+cmd) - cmd = "docker push " + nodeIP + ":5000/my-webpage" + cmd = "docker push " + nodeIP + ":5000/docker-io-library/nginx:1.27.3" _, err = e2e.RunCmdOnNode(cmd, serverNodeNames[0]) Expect(err).NotTo(HaveOccurred(), "failed: "+cmd) - cmd = "docker image remove nginx " + nodeIP + ":5000/my-webpage" + cmd = "docker image remove docker.io/library/nginx:1.27.3 " + nodeIP + ":5000/docker-io-library/nginx:1.27.3" _, err = e2e.RunCmdOnNode(cmd, serverNodeNames[0]) Expect(err).NotTo(HaveOccurred(), "failed: "+cmd) }) + It("Should create and validate deployment with private registry on", func() { - res, err := e2e.RunCmdOnNode("kubectl create deployment my-webpage --image=my-registry.local/my-webpage", serverNodeNames[0]) + res, err := e2e.RunCmdOnNode("kubectl create deployment my-webpage --image=my-registry.local/library/nginx:1.27.3", serverNodeNames[0]) fmt.Println(res) Expect(err).NotTo(HaveOccurred())