Skip to content

Commit

Permalink
Add rewrite test to privateregistry e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Dec 3, 2024
1 parent c216848 commit 666b590
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions tests/e2e/privateregistry/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
14 changes: 9 additions & 5 deletions tests/e2e/privateregistry/privateregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit 666b590

Please sign in to comment.