Skip to content

Commit

Permalink
Switched from named to IP for private registry
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <derek.nola@suse.com>
  • Loading branch information
dereknola committed May 31, 2023
1 parent a16bee1 commit 35bfd6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
29 changes: 13 additions & 16 deletions tests/e2e/privateregistry/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,25 @@ def provision(vm, role, role_num, node_num)
install_type = getInstallType(vm, RELEASE_VERSION, GITHUB_BRANCH)

vm.provision "shell", inline: "ping -c 2 k3s.io"

writePrivateRegistry = <<-'SCRIPT'

# The formatting on this is a little weird, but it allows inserting variables
# and still using the heredoc formatting with escapped quotes
writePrivateRegistry = <<~'SCRIPT'.chomp % {net: NETWORK_PREFIX}
mkdir -p /etc/rancher/k3s/
echo "mirrors:
server-0.local:
endpoint:
- \"http://server-0.local:5000\"" >> /etc/rancher/k3s/registries.yaml
my-registry.local:
endpoint:
- \"http://%{net}.100:5000\"" > /etc/rancher/k3s/registries.yaml
SCRIPT

setInsecureRegistryPolicy = <<-'SCRIPT'
setInsecureRegistryPolicy = <<~'SCRIPT'.chomp % {net: NETWORK_PREFIX}
mkdir -p /etc/docker/
echo "{ \"insecure-registries\" : [\"server-0.local:5000\"] }" >> /etc/docker/daemon.json
SCRIPT

setEtcHost = <<-'SCRIPT'
echo "10.10.10.100 server-0.local" >> /etc/hosts
echo "{ \"insecure-registries\" : [\"%{net}.100:5000\"] }" > /etc/docker/daemon.json
SCRIPT

if role.include?("server") && role_num == 0
vm.provision "shell", inline: setInsecureRegistryPolicy
vm.provision "shell", inline: writePrivateRegistry
vm.provision "insecure-registry", type: "shell", inline: setInsecureRegistryPolicy
vm.provision "private-registry", type: "shell", inline: writePrivateRegistry
dockerInstall(vm)

vm.provision 'k3s-primary-server', type: 'k3s', run: 'once' do |k3s|
Expand All @@ -63,8 +61,8 @@ def provision(vm, role, role_num, node_num)
end

elsif role.include?("server") && role_num != 0
vm.provision "shell", inline: setInsecureRegistryPolicy
vm.provision "shell", inline: setEtcHost
vm.provision "shell", inline: writePrivateRegistry

vm.provision 'k3s-secondary-server', type: 'k3s', run: 'once' do |k3s|
k3s.args = "server"
k3s.config = <<~YAML
Expand All @@ -80,7 +78,6 @@ def provision(vm, role, role_num, node_num)

if role.include?("agent")
vm.provision "shell", inline: writePrivateRegistry
vm.provision "shell", inline: setEtcHost

vm.provision 'k3s-agent', type: 'k3s', run: 'once' do |k3s|
k3s.args = "agent"
Expand Down
11 changes: 7 additions & 4 deletions tests/e2e/privateregistry/privateregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,23 @@ var _ = Describe("Verify Create", Ordered, func() {
_, err := e2e.RunCmdOnNode(cmd, serverNodeNames[0])
Expect(err).NotTo(HaveOccurred(), "failed: "+cmd)

cmd = "sudo docker tag nginx server-0.local:5000/my-webpage"
nodeIP, err := e2e.FetchNodeExternalIP(serverNodeNames[0])
Expect(err).NotTo(HaveOccurred())

cmd = "sudo docker tag nginx " + nodeIP + ":5000/my-webpage"
_, err = e2e.RunCmdOnNode(cmd, serverNodeNames[0])
Expect(err).NotTo(HaveOccurred(), "failed: "+cmd)

cmd = "sudo docker push server-0.local:5000/my-webpage"
cmd = "sudo docker push " + nodeIP + ":5000/my-webpage"
_, err = e2e.RunCmdOnNode(cmd, serverNodeNames[0])
Expect(err).NotTo(HaveOccurred(), "failed: "+cmd)

cmd = "sudo docker image remove nginx server-0.local:5000/my-webpage"
cmd = "sudo docker image remove nginx " + nodeIP + ":5000/my-webpage"
_, 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("sudo kubectl create deployment my-webpage --image=server-0.local/my-webpage", serverNodeNames[0])
res, err := e2e.RunCmdOnNode("sudo kubectl create deployment my-webpage --image=my-registry.local/my-webpage", serverNodeNames[0])
fmt.Println(res)
Expect(err).NotTo(HaveOccurred())

Expand Down

0 comments on commit 35bfd6f

Please sign in to comment.