From 20d2ffcde4f5b45f57bc74e25d5b4c46287851cc Mon Sep 17 00:00:00 2001 From: Naadir Jeewa Date: Sat, 6 Oct 2018 16:55:30 +0100 Subject: [PATCH] Adds utilities to speed up dev process (#177) cluster-api-dev-helper encodes a few common development tasks such as stand up and teardown within minikube, tailing logs etc... minikube_build adds a faster development experience by utilising the Docker endpoint in Minikube so images do not need to be pushed to an external repository. Signed-off-by: Naadir Jeewa --- .gitignore | 5 + Makefile | 64 ++++-- cmd/cluster-controller/Dockerfile.minikube | 22 ++ cmd/cluster-controller/Makefile | 3 + cmd/machine-controller/Dockerfile.minikube | 20 ++ cmd/machine-controller/Makefile | 3 + docs/development.md | 23 ++ hack/cluster-api-dev-helper/cmd/exec.go | 49 +++++ hack/cluster-api-dev-helper/cmd/minikube.go | 114 ++++++++++ hack/cluster-api-dev-helper/cmd/root.go | 48 +++++ hack/cluster-api-dev-helper/cmd/testing.go | 221 ++++++++++++++++++++ hack/cluster-api-dev-helper/main.go | 27 +++ scripts/ci-build.sh | 2 +- 13 files changed, 581 insertions(+), 20 deletions(-) create mode 100644 cmd/cluster-controller/Dockerfile.minikube create mode 100644 cmd/machine-controller/Dockerfile.minikube create mode 100644 hack/cluster-api-dev-helper/cmd/exec.go create mode 100644 hack/cluster-api-dev-helper/cmd/minikube.go create mode 100644 hack/cluster-api-dev-helper/cmd/root.go create mode 100644 hack/cluster-api-dev-helper/cmd/testing.go create mode 100644 hack/cluster-api-dev-helper/main.go diff --git a/.gitignore b/.gitignore index 882952ecd1..217ac5575b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,10 @@ vendor *.swp # envfile +.env envfile minikube.kubeconfig + +# binaries +cmd/cluster-controller/cluster-controller +cmd/machine-controller/machine-controller diff --git a/Makefile b/Makefile index 08606e7f4b..a8821f88ef 100644 --- a/Makefile +++ b/Makefile @@ -12,27 +12,38 @@ # See the License for the specific language governing permissions and # limitations under the License. +GOFLAGS += -ldflags '-extldflags "-static"' +GOREBUILD := + .PHONY: gendeepcopy all: generate build images -depend: +ifndef FASTBUILD +# If FASTBUILD isn't defined, fully rebuild Go binaries, and always +# run dep ensure +GOREBUILD += -a +.PHONY: vendor +endif + +vendor: dep version || go get -u github.com/golang/dep/cmd/dep dep ensure depend-update: + dep version || go get -u github.com/golang/dep/cmd/dep dep ensure -update generate: gendeepcopy -gendeepcopy: depend +gendeepcopy: vendor go build -o $$GOPATH/bin/deepcopy-gen sigs.k8s.io/cluster-api-provider-aws/vendor/k8s.io/code-generator/cmd/deepcopy-gen $$GOPATH/bin/deepcopy-gen \ -i ./cloud/aws/providerconfig,./cloud/aws/providerconfig/v1alpha1 \ -O zz_generated.deepcopy \ -h boilerplate.go.txt -genmocks: depend +genmocks: vendor hack/generate-mocks.sh "github.com/aws/aws-sdk-go/service/ec2/ec2iface EC2API" "cloud/aws/services/ec2/mock_ec2iface/mock.go" hack/generate-mocks.sh "github.com/aws/aws-sdk-go/service/elb/elbiface ELBAPI" "cloud/aws/services/elb/mock_elbiface/mock.go" hack/generate-mocks.sh "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1 MachineInterface" "cloud/aws/actuators/machine/mock_machineiface/mock.go" @@ -41,45 +52,48 @@ genmocks: depend hack/generate-mocks.sh "sigs.k8s.io/cluster-api-provider-aws/cloud/aws/services EC2Interface" "cloud/aws/services/mocks/ec2.go" hack/generate-mocks.sh "sigs.k8s.io/cluster-api-provider-aws/cloud/aws/services ELBInterface" "cloud/aws/services/mocks/elb.go" -build: depend clusterctl-bin clusterawsadm-bin cluster-controller machine-controller +build: clusterctl-bin clusterawsadm-bin cluster-controller machine-controller + +clusterctl-bin: vendor + CGO_ENABLED=0 go install $(GOFLAGS) $(GOREBUILD) sigs.k8s.io/cluster-api-provider-aws/clusterctl -clusterctl-bin: - CGO_ENABLED=0 go install -a -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/clusterctl +clusterawsadm-bin: vendor + CGO_ENABLED=0 go install $(GOFLAGS) $(GOREBUILD) sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm -clusterawsadm-bin: - CGO_ENABLED=0 go install -a -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm +cluster-api-dev-helper-bin: vendor + CGO_ENABLED=0 go install $(GOFLAGS) sigs.k8s.io/cluster-api-provider-aws/hack/cluster-api-dev-helper -images: depend +images: vendor $(MAKE) -C cmd/cluster-controller image $(MAKE) -C cmd/machine-controller image -dev_push: depend cluster-controller-dev-push machine-controller-dev-push +dev_push: cluster-controller-dev-push machine-controller-dev-push -cluster-controller: - CGO_ENABLED=0 go install -a -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/cluster-controller +cluster-controller: vendor + CGO_ENABLED=0 go install $(GOFLAGS) $(GOREBUILD) sigs.k8s.io/cluster-api-provider-aws/cmd/cluster-controller cluster-controller-dev-push: cluster-controller $(MAKE) -C cmd/cluster-controller dev_push -machine-controller: - CGO_ENABLED=0 go install -a -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-aws/cmd/machine-controller +machine-controller: vendor + CGO_ENABLED=0 go install $(GOFLAGS) $(GOREBUILD) sigs.k8s.io/cluster-api-provider-aws/cmd/machine-controller machine-controller-dev-push: machine-controller $(MAKE) -C cmd/machine-controller dev_push -push: depend +push: vendor $(MAKE) -C cmd/cluster-controller push $(MAKE) -C cmd/machine-controller push -check: depend fmt vet +check: fmt vet -test: depend +test: vendor go test -race -cover ./cmd/... ./cloud/... ./clusterctl/... -fmt: +fmt: vendor hack/verify-gofmt.sh -vet: +vet: vendor go vet ./... lint: @@ -100,3 +114,15 @@ envfile: envfile.example clean: rm -rf clusterctl/examples/aws/out + +# These should become unnecessary after Bazelification + +minikube_build: cluster-controller-minikube-build machine-controller-minikube-build + +cluster-controller-minikube-build: vendor + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(GOFLAGS) -o cmd/cluster-controller/cluster-controller sigs.k8s.io/cluster-api-provider-aws/cmd/cluster-controller + $(MAKE) -C cmd/cluster-controller minikube_build + +machine-controller-minikube-build: vendor + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(GOFLAGS) -o cmd/machine-controller/machine-controller sigs.k8s.io/cluster-api-provider-aws/cmd/machine-controller + $(MAKE) -C cmd/machine-controller minikube_build diff --git a/cmd/cluster-controller/Dockerfile.minikube b/cmd/cluster-controller/Dockerfile.minikube new file mode 100644 index 0000000000..7d8fb81290 --- /dev/null +++ b/cmd/cluster-controller/Dockerfile.minikube @@ -0,0 +1,22 @@ +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + +# Final container +FROM debian:stretch-slim +RUN apt-get update && apt-get install -y ca-certificates openssh-server && rm -rf /var/lib/apt/lists/* + +# We don't care about reproducability whilst developing, so copy our local binary +COPY cluster-controller . \ No newline at end of file diff --git a/cmd/cluster-controller/Makefile b/cmd/cluster-controller/Makefile index aab424a8af..f1d9491e49 100644 --- a/cmd/cluster-controller/Makefile +++ b/cmd/cluster-controller/Makefile @@ -57,3 +57,6 @@ dev_image: dev_push: dev_image docker push "$(DEV_PREFIX)/$(NAME):$(DEV_TAG)" + +minikube_build: + eval $$(minikube docker-env) && docker build -t "$(DEV_PREFIX)/$(NAME):$(DEV_TAG)" -f ./Dockerfile.minikube . diff --git a/cmd/machine-controller/Dockerfile.minikube b/cmd/machine-controller/Dockerfile.minikube new file mode 100644 index 0000000000..c2aa16cf9d --- /dev/null +++ b/cmd/machine-controller/Dockerfile.minikube @@ -0,0 +1,20 @@ +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Final container +FROM debian:stretch-slim +RUN apt-get update && apt-get install -y ca-certificates openssh-server && rm -rf /var/lib/apt/lists/* + +# We don't care about reproducability whilst developing, so copy our local binary +COPY machine-controller . diff --git a/cmd/machine-controller/Makefile b/cmd/machine-controller/Makefile index 846c244c7b..81fdf4a14a 100644 --- a/cmd/machine-controller/Makefile +++ b/cmd/machine-controller/Makefile @@ -57,3 +57,6 @@ dev_image: dev_push: dev_image docker push "$(DEV_PREFIX)/$(NAME):$(DEV_TAG)" + +minikube_build: + eval $$(minikube docker-env) && docker build -t "$(DEV_PREFIX)/$(NAME):$(DEV_TAG)" -f ./Dockerfile.minikube . diff --git a/docs/development.md b/docs/development.md index 54dc028ce6..b4a2f7ccd1 100644 --- a/docs/development.md +++ b/docs/development.md @@ -12,6 +12,8 @@ - [Using images on Google Cloud](#using-images-on-google-cloud) - [Using AWS Elastic Container Registry](#using-aws-elastic-container-registry) - [Using images on Elastic Container Registry](#using-images-on-elastic-container-registry) + - [Using Minikube only](#using-minikube-only) +- [cluster-api-dev-helper](#cluster-api-dev-helper) @@ -85,6 +87,27 @@ Then generate the [example configuration](getting-started.md#generating-cluster- You will also need to configure minikube or your bootstrap cluster with credentials to access ECR, using [image pull secrets][image_pull_secrets] or another mechanism. +#### Using Minikube only + +You can also build and test using only the local storage on the minikube VM, +using: + +``` bash +make minikube_build FASTBUILD=true +``` + +## cluster-api-dev-helper + +Some command development tasks have been put into a cluster-api-dev-helper +utility in the /hack directory. + +To install it, run: + +``` bash +make cluster-api-dev-helper-bin FASTBUILD=true +``` + + [jq]: https://stedolan.github.io/jq/download/ diff --git a/hack/cluster-api-dev-helper/cmd/exec.go b/hack/cluster-api-dev-helper/cmd/exec.go new file mode 100644 index 0000000000..5db1d18155 --- /dev/null +++ b/hack/cluster-api-dev-helper/cmd/exec.go @@ -0,0 +1,49 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "log" + "os" + "os/exec" +) + +func runShellWithWait(cmd string) { + runCommandWithWait("sh", "-c", cmd) +} + +func runCommandWithWait(cmd string, args ...string) bool { + command := runCommand(cmd, args...) + if err := command.Wait(); err != nil { + log.Println(err) + } + return command.ProcessState.Success() +} + +func runShell(cmd string) *exec.Cmd { + return runCommand("sh", "-c", cmd) +} + +func runCommand(cmd string, args ...string) *exec.Cmd { + command := exec.Command(cmd, args...) + command.Stdout = os.Stdout + command.Stderr = os.Stderr + if err := command.Start(); err != nil { + log.Println(err) + } + return command +} diff --git a/hack/cluster-api-dev-helper/cmd/minikube.go b/hack/cluster-api-dev-helper/cmd/minikube.go new file mode 100644 index 0000000000..ccdd262436 --- /dev/null +++ b/hack/cluster-api-dev-helper/cmd/minikube.go @@ -0,0 +1,114 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func defineMinikubeCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "minikube", + Short: "minikube helper commands", + Long: `minikube helper commands`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(cmd.Help()) + }, + } + + defineMinikubeFixLibVirtNetworkCmd(newCmd) + defineMinikubeClean(newCmd) + defineMinikubeKVMDestroy(newCmd) + defineMinikubeSetup(newCmd) + defineMinikubeReset(newCmd) + + parent.AddCommand(newCmd) +} + +func defineMinikubeFixLibVirtNetworkCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "fix-libvirt-network", + Short: "Make the KVM minikube network permanent using LibVirt", + Long: `Make the KVM minikube network permanent using LibVirt. Requires virsh`, + Run: func(cmd *cobra.Command, args []string) { + runCommandWithWait("virsh", "-c", "qemu:///system", "net-autostart", "minikube-net") + }, + } + parent.AddCommand(newCmd) +} + +func defineMinikubeClean(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "clean", + Short: "Clean up .minikube directory", + Long: `Clean up .minikube directory, deleting machines`, + Run: func(cmd *cobra.Command, args []string) { + minikubeClean() + }, + } + parent.AddCommand(newCmd) +} + +func defineMinikubeKVMDestroy(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "kvm-destroy", + Short: "Destroy the KVM VM backing minikube", + Long: `Destroy the KVM VM backing minikube`, + Run: func(cmd *cobra.Command, args []string) { + runCommandWithWait("virsh", "-c", "qemu:///system", "destroy", "minikube") + runCommandWithWait("virsh", "-c", "qemu:///system", "undefine", "--remove-all-storage", "--delete-snapshots", "minikube") + runCommandWithWait("virsh", "-c", "qemu:///system", "net-undefine", "minikube-net") + minikubeClean() + }, + } + parent.AddCommand(newCmd) +} + +func defineMinikubeSetup(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "setup", + Short: "Set up minikube for use with Cluster API", + Long: `Set up minikube for use with Cluster API`, + Run: func(cmd *cobra.Command, args []string) { + runCommandWithWait("minikube", "config", "set", "bootstrapper", "kubeadm") + runCommandWithWait("minikube", "config", "set", "kubernetes-version", "v1.9.4") + }, + } + parent.AddCommand(newCmd) +} + +func defineMinikubeReset(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "reset", + Short: "Remove Cluster API specific minikube configuration", + Long: `Remove Cluster API specific minikube configuration`, + Run: func(cmd *cobra.Command, args []string) { + runCommandWithWait("minikube", "config", "unset", "kubernetes-version") + runCommandWithWait("minikube", "config", "unset", "bootstrapper") + }, + } + parent.AddCommand(newCmd) +} + +func minikubeClean() { + runCommandWithWait("sh", "-c", "rm -rf $HOME/.minikube/machines") + runCommandWithWait("sh", "-c", "rm -rf $HOME/.minikube/profiles") + runCommandWithWait("sh", "-c", "rm -rf $HOME/.minikube/certs") + runCommandWithWait("sh", "-c", "rm -rf $HOME/.minikube/*.pem") +} diff --git a/hack/cluster-api-dev-helper/cmd/root.go b/hack/cluster-api-dev-helper/cmd/root.go new file mode 100644 index 0000000000..56b4bcd156 --- /dev/null +++ b/hack/cluster-api-dev-helper/cmd/root.go @@ -0,0 +1,48 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +func defineRootCmd() { + rootCmd := &cobra.Command{ + Use: "cluster-api-dev-helper", + Short: "Cluster API Development Helpers", + Long: `A lot of hacks to help with developing Cluster API`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(cmd.Help()) + }, + } + + defineTestingCmd(rootCmd) + defineMinikubeCmd(rootCmd) + + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +// Execute bootstraps Cobra +func Execute() { + defineRootCmd() +} diff --git a/hack/cluster-api-dev-helper/cmd/testing.go b/hack/cluster-api-dev-helper/cmd/testing.go new file mode 100644 index 0000000000..c529527f99 --- /dev/null +++ b/hack/cluster-api-dev-helper/cmd/testing.go @@ -0,0 +1,221 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "fmt" + "sync" + "time" + + "github.com/spf13/cobra" +) + +func defineTestingCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "testing", + Short: "Test Cluster API", + Long: `Commands to help test Cluster API`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(cmd.Help()) + }, + } + + defineTestingStartCmd(newCmd) + defineTestingLogsCmd(newCmd) + defineTestingDestroyAllCmd(newCmd) + defineTestingDeleteClustersCmd(newCmd) + defineTestingDestroyClustersCmd(newCmd) + defineTestingDeleteMachinesCmd(newCmd) + defineTestingDestroyMachinesCmd(newCmd) + defineTestingClusterLogs(newCmd) + defineTestingMachineLogs(newCmd) + + parent.AddCommand(newCmd) +} + +func defineTestingStartCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "start-with-existing-context", + Short: "Start tests with an existing kubeconfig context", + Long: `Start tests with an existing kubeconfig context. Expects to be run in the repository using Go 1.11`, + Run: func(cmd *cobra.Command, args []string) { + var wg sync.WaitGroup + a := runShell(`go run ./clusterctl create cluster -v2 \ + -m ./clusterctl/examples/aws/out/machines.yaml \ + -c ./clusterctl/examples/aws/out/cluster.yaml \ + -p ./clusterctl/examples/aws/out/provider-components.yaml \ + --provider aws \ + --existing-bootstrap-cluster-kubeconfig ~/.kube/config`) + wg.Add(2) + go clusterLogs(&wg) + go machineLogs(&wg) + a.Wait() + }, + } + + parent.AddCommand(newCmd) +} + +func defineTestingLogsCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "controller-logs", + Short: "Start tailing controller logs", + Long: `Start tailing controller logs`, + Run: func(cmd *cobra.Command, args []string) { + var wg sync.WaitGroup + wg.Add(2) + go clusterLogs(&wg) + go machineLogs(&wg) + wg.Wait() + }, + } + parent.AddCommand(newCmd) +} + +func defineTestingDestroyAllCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "destroy-all", + Short: "Destroys Cluster API without finalizers", + Long: `Destroys Cluster API without finalizers`, + Run: func(cmd *cobra.Command, args []string) { + destroyMachines() + destroyClusters() + destroyControlPlane() + }, + } + parent.AddCommand(newCmd) +} + +func defineTestingDeleteClustersCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "delete-clusters", + Short: "Delete all clusters and tail logs", + Long: `Delete all clusters and tail logs`, + Run: func(cmd *cobra.Command, args []string) { + var wg sync.WaitGroup + wg.Add(1) + go clusterLogs(&wg) + runShell("kubectl delete clusters --all --wait=true") + wg.Wait() + }, + } + parent.AddCommand(newCmd) +} + +func defineTestingDestroyClustersCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "destroy-clusters", + Short: "Forcefully destroy clusters", + Long: `Forcefully destroy clusters`, + Run: func(cmd *cobra.Command, args []string) { + destroyClusters() + }, + } + parent.AddCommand(newCmd) +} + +func defineTestingDeleteMachinesCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "delete-machines", + Short: "Delete all machines and tail logs", + Long: `Delete all machines and tail logs`, + Run: func(cmd *cobra.Command, args []string) { + var wg sync.WaitGroup + wg.Add(1) + go machineLogs(&wg) + runShell("kubectl delete machines --all --wait=true") + wg.Wait() + }, + } + parent.AddCommand(newCmd) +} + +func defineTestingDestroyMachinesCmd(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "destroy-machines", + Short: "Forcefully destroy machines", + Long: `Forcefully destroy machines`, + Run: func(cmd *cobra.Command, args []string) { + destroyMachines() + }, + } + parent.AddCommand(newCmd) +} + +func defineTestingClusterLogs(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "cluster-controller-logs", + Short: "Tail cluster controller logs", + Long: `Tail cluster controller logs`, + Run: func(cmd *cobra.Command, args []string) { + var wg sync.WaitGroup + wg.Add(1) + go clusterLogs(&wg) + wg.Wait() + }, + } + parent.AddCommand(newCmd) +} + +func defineTestingMachineLogs(parent *cobra.Command) { + newCmd := &cobra.Command{ + Use: "machine-controller-logs", + Short: "Tail cluster controller logs", + Long: `Tail cluster controller logs`, + Run: func(cmd *cobra.Command, args []string) { + var wg sync.WaitGroup + wg.Add(1) + go machineLogs(&wg) + wg.Wait() + }, + } + parent.AddCommand(newCmd) +} + +func destroyMachines() { + runShellWithWait("kubectl get machine -o name | xargs kubectl patch -p '{\"metadata\":{\"finalizers\":null}}'") + runShellWithWait("kubectl delete machines --force=true --grace-period 0 --all --wait=true") +} + +func destroyClusters() { + runShellWithWait("kubectl patch cluster test1 -p '{\"metadata\":{\"finalizers\":null}}'") + runShellWithWait("kubectl delete clusters --force=true --grace-period 0 --all --wait=true") +} + +func destroyControlPlane() { + runShellWithWait("kubectl delete deployment clusterapi-apiserver --force=true --grace-period 0 --wait=true") + runShellWithWait("kubectl delete deployment clusterapi-controllers --force=true --grace-period 0 --wait=true") + runShellWithWait("kubectl delete statefulsets etcd-clusterapi --force=true --grace-period 0 --wait=true") +} + +func clusterLogs(wg *sync.WaitGroup) { + defer wg.Done() + for { + b := runShell("kubectl get po -o name | grep clusterapi-controllers | xargs kubectl logs -c aws-cluster-controller -f") + b.Wait() + time.Sleep(5 * 1000 * 1000 * 1000) + } +} + +func machineLogs(wg *sync.WaitGroup) { + defer wg.Done() + for { + c := runShell("kubectl get po -o name | grep clusterapi-controllers | xargs kubectl logs -c aws-machine-controller -f") + c.Wait() + time.Sleep(5 * 1000 * 1000 * 1000) + } +} diff --git a/hack/cluster-api-dev-helper/main.go b/hack/cluster-api-dev-helper/main.go new file mode 100644 index 0000000000..d0bddc529d --- /dev/null +++ b/hack/cluster-api-dev-helper/main.go @@ -0,0 +1,27 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This is a load of hacks, and should eventually be deleted. + +package main + +import ( + "sigs.k8s.io/cluster-api-provider-aws/hack/cluster-api-dev-helper/cmd" +) + +func main() { + cmd.Execute() +} diff --git a/scripts/ci-build.sh b/scripts/ci-build.sh index 06666cca0d..17a5c14b56 100755 --- a/scripts/ci-build.sh +++ b/scripts/ci-build.sh @@ -19,5 +19,5 @@ set -o nounset set -o pipefail REPO_ROOT=$(dirname "${BASH_SOURCE}")/.. -cd "${REPO_ROOT}" && make depend +cd "${REPO_ROOT}" && make vendor go build "${REPO_ROOT}"/...