Skip to content

Commit

Permalink
test: port improvements from Talos
Browse files Browse the repository at this point in the history
REGISTRY_MIRROR_FLAGS can be set via direnv.

Signed-off-by: Alexey Palazhchenko <[email protected]>
  • Loading branch information
AlekSi authored and talos-bot committed Apr 28, 2021
1 parent c43f9ec commit b17f370
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
3 changes: 2 additions & 1 deletion hack/scripts/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ function build_registry_mirrors {
local service="registry-${registry//./-}.ci.svc"
local addr=`python3 -c "import socket; print(socket.gethostbyname('${service}'))"`

REGISTRY_MIRROR_FLAGS="${REGISTRY_MIRROR_FLAGS} --registry-mirrors ${registry}=http://${addr}:5000"
REGISTRY_MIRROR_FLAGS="${REGISTRY_MIRROR_FLAGS} --registry-mirror ${registry}=http://${addr}:5000"
done
else
# use the value from the environment, if present
REGISTRY_MIRROR_FLAGS=${REGISTRY_MIRROR_FLAGS:-}
fi
}
Expand Down
35 changes: 35 additions & 0 deletions hack/start-registry-proxies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Sync changes with Sfyra's README.

set -e

docker run -d -p 5000:5000 \
-e REGISTRY_PROXY_REMOTEURL=https://registry-1.docker.io \
--restart always \
--name registry-docker.io registry:2

docker run -d -p 5001:5000 \
-e REGISTRY_PROXY_REMOTEURL=https://k8s.gcr.io \
--restart always \
--name registry-k8s.gcr.io registry:2

docker run -d -p 5002:5000 \
-e REGISTRY_PROXY_REMOTEURL=https://quay.io \
--restart always \
--name registry-quay.io registry:2.5

docker run -d -p 5003:5000 \
-e REGISTRY_PROXY_REMOTEURL=https://gcr.io \
--restart always \
--name registry-gcr.io registry:2

docker run -d -p 5004:5000 \
-e REGISTRY_PROXY_REMOTEURL=https://ghcr.io \
--restart always \
--name registry-ghcr.io registry:2

docker run -d -p 5004:5000 \
-e REGISTRY_PROXY_REMOTEURL=https://ghcr.io \
--restart always \
--name registry-ghcr.io registry:2
6 changes: 3 additions & 3 deletions sfyra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ each time. After `make USERNAME=<username> TAG=v0.1.0 PUSH=true` run:

Then launch Sfyra manually with desired flags:

sudo -E _out/sfyra test integration --registry-mirrors docker.io=http://172.24.0.1:5000,k8s.gcr.io=http://172.24.0.1:5001,quay.io=http://172.24.0.1:5002,gcr.io=http://172.24.0.1:5003,ghcr.io=http://172.24.0.1:5004,127.0.0.1:5005=http://172.24.0.1:5005 --skip-teardown --clusterctl-config ~/.cluster-api/clusterctl.sfyra.yaml
sudo -E _out/sfyra test integration --registry-mirror docker.io=http://172.24.0.1:5000,k8s.gcr.io=http://172.24.0.1:5001,quay.io=http://172.24.0.1:5002,gcr.io=http://172.24.0.1:5003,ghcr.io=http://172.24.0.1:5004,127.0.0.1:5005=http://172.24.0.1:5005 --skip-teardown --clusterctl-config ~/.cluster-api/clusterctl.sfyra.yaml

With `-skip-teardown` flag test leaves the bootstrap cluster running so that next iteration of the test
can be run without waiting for the boostrap actions to be finished. It's possible to run Sfyra tests once
again without bringing down the test environment, but make sure that all the clusters are deleted with
`kubectl delete clusters --all`.

Flag `--registry-mirrors` is optional, but it speeds up provisioning significantly, see Talos guides on setting up registry
pull-through caches.
Flag `--registry-mirror` is optional, but it speeds up provisioning significantly. See Talos guides on setting up registry
pull-through caches, or just run `hack/start-registry-proxies.sh`.

Kubernetes config can be pulled with `talosconfig -n 172.24.0.2 kubeconfig --force`.

Expand Down
4 changes: 3 additions & 1 deletion sfyra/cmd/sfyra/cmd/bootstrap_capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func init() {
bootstrapCAPICmd.Flags().StringVar(&options.BootstrapTalosInstaller, "bootstrap-installer", options.BootstrapTalosInstaller, "Talos install image for bootstrap cluster")
bootstrapCAPICmd.Flags().StringVar(&options.BootstrapCIDR, "bootstrap-cidr", options.BootstrapCIDR, "bootstrap cluster network CIDR")
bootstrapCAPICmd.Flags().StringVar(&options.TalosctlPath, "talosctl-path", options.TalosctlPath, "path to the talosctl (for the QEMU provisioner)")
bootstrapCAPICmd.Flags().StringSliceVar(&options.RegistryMirrors, "registry-mirrors", options.RegistryMirrors, "registry mirrors to use")
bootstrapCAPICmd.Flags().StringSliceVar(&options.RegistryMirrors, "registry-mirror", options.RegistryMirrors, "registry mirrors to use")
bootstrapCAPICmd.Flags().StringSliceVar(&options.RegistryMirrors, "registry-mirrors", options.RegistryMirrors, "")
Should(bootstrapCAPICmd.Flags().MarkDeprecated("registry-mirrors", "please use --registry-mirror (singular) instead"))
bootstrapCAPICmd.Flags().StringVar(&options.ClusterctlConfigPath, "clusterctl-config", options.ClusterctlConfigPath, "path to the clusterctl config file")
}
2 changes: 2 additions & 0 deletions sfyra/cmd/sfyra/cmd/bootstrap_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ func init() {
bootstrapClusterCmd.Flags().StringVar(&options.BootstrapTalosInstaller, "bootstrap-installer", options.BootstrapTalosInstaller, "Talos install image for bootstrap cluster")
bootstrapClusterCmd.Flags().StringVar(&options.BootstrapCIDR, "bootstrap-cidr", options.BootstrapCIDR, "bootstrap cluster network CIDR")
bootstrapClusterCmd.Flags().StringVar(&options.TalosctlPath, "talosctl-path", options.TalosctlPath, "path to the talosctl (for the QEMU provisioner)")
bootstrapClusterCmd.Flags().StringSliceVar(&options.RegistryMirrors, "registry-mirror", options.RegistryMirrors, "registry mirrors to use")
bootstrapClusterCmd.Flags().StringSliceVar(&options.RegistryMirrors, "registry-mirrors", options.RegistryMirrors, "registry mirrors to use")
Should(bootstrapClusterCmd.Flags().MarkDeprecated("registry-mirrors", "please use --registry-mirror (singular) instead"))
}
15 changes: 15 additions & 0 deletions sfyra/cmd/sfyra/cmd/should.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package cmd

// Should panics if err != nil
//
// Should is useful when error should never happen in customer environment,
// it can only be development error.
func Should(err error) {
if err != nil {
panic(err)
}
}
2 changes: 2 additions & 0 deletions sfyra/cmd/sfyra/cmd/test_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ func init() {
testIntegrationCmd.Flags().StringVar(&options.ManagementCIDR, "management-cidr", options.ManagementCIDR, "management cluster network CIDR")
testIntegrationCmd.Flags().IntVar(&options.ManagementNodes, "management-nodes", options.ManagementNodes, "number of PXE nodes to create for the management rack")
testIntegrationCmd.Flags().StringVar(&options.TalosctlPath, "talosctl-path", options.TalosctlPath, "path to the talosctl (for the QEMU provisioner)")
testIntegrationCmd.Flags().StringSliceVar(&options.RegistryMirrors, "registry-mirror", options.RegistryMirrors, "registry mirrors to use")
testIntegrationCmd.Flags().StringSliceVar(&options.RegistryMirrors, "registry-mirrors", options.RegistryMirrors, "registry mirrors to use")
Should(testIntegrationCmd.Flags().MarkDeprecated("registry-mirrors", "please use --registry-mirror (singular) instead"))
testIntegrationCmd.Flags().StringVar(&options.TalosKernelURL, "talos-kernel-url", options.TalosKernelURL, "Talos kernel image URL for Cluster API Environment")
testIntegrationCmd.Flags().StringVar(&options.TalosInitrdURL, "talos-initrd-url", options.TalosInitrdURL, "Talos initramfs image URL for Cluster API Environment")
testIntegrationCmd.Flags().StringVar(&options.ClusterctlConfigPath, "clusterctl-config", options.ClusterctlConfigPath, "path to the clusterctl config file")
Expand Down

0 comments on commit b17f370

Please sign in to comment.