diff --git a/.github/workflows/dev-tools.yaml b/.github/workflows/dev-tools.yaml new file mode 100644 index 00000000..1cf3241c --- /dev/null +++ b/.github/workflows/dev-tools.yaml @@ -0,0 +1,34 @@ +name: Dev Tools + +on: + push: + branches: ["main"] + paths: + - 'scripts/**' + - 'Makefile' + pull_request: + branches: ["main"] + paths: + - 'scripts/**' + - 'Makefile' + +jobs: + + dev-tools: + name: dev-tools + strategy: + matrix: + go-version: [ 1.17.x, 1.18.x] + platform: [ ubuntu-20.04, macos-11 ] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - run: make controller-gen + - run: make kcp + - run: make kind + # Hitting GH rate limit issues, leaving it out for now. + #- run: make kustomize + - run: make generate diff --git a/Makefile b/Makefile index 5c09a548..78ab95e1 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,6 @@ IMAGE_TAG_BASE ?= quay.io/kuadrant/kcp-glbc IMAGE_TAG ?= latest IMG ?= $(IMAGE_TAG_BASE):$(IMAGE_TAG) -GO_VERSION = $(shell go version | awk '{print $$3}') -GO_GET_INSTALL = go get -ifeq ($(GO_VERSION),go1.18) - GO_GET_INSTALL = go install -endif - KUBECONFIG ?= $(shell pwd)/.kcp/admin.kubeconfig CLUSTERS_KUBECONFIG_DIR ?= $(shell pwd)/tmp @@ -34,21 +28,25 @@ clean: ## Clean up temporary files. -rm -f ./bin/* -rm -rf ./tmp +.PHONY: generate generate: generate-deepcopy generate-crd generate-client ## Generate code containing DeepCopy method implementations, CustomResourceDefinition objects and Clients. +.PHONY: generate-deepcopy generate-deepcopy: controller-gen cd pkg/apis/kuadrant && $(CONTROLLER_GEN) paths="./..." object +.PHONY: generate-deepcopy generate-crd: controller-gen cd pkg/apis/kuadrant && $(CONTROLLER_GEN) crd paths=./... output:crd:artifacts:config=../../../config/crd output:crd:dir=../../../config/crd/bases crd:crdVersions=v1 && rm -rf ./config +.PHONY: generate-client generate-client: ./scripts/gen_client.sh +.PHONY: vendor vendor: ## Vendor the dependencies. go mod tidy go mod vendor -.PHONY: vendor .PHONY: fmt fmt: ## Run go fmt against code. @@ -58,14 +56,15 @@ fmt: ## Run go fmt against code. vet: ## Run go vet against code. go vet ./... +.PHONY: lint lint: ## Run golangci-lint against code. golangci-lint run ./... -.PHONY: lint .PHONY: test test: generate ## Run tests. go test -v ./... -coverprofile=cover.out +.PHONY: e2e e2e: build KUBECONFIG="$(KUBECONFIG)" CLUSTERS_KUBECONFIG_DIR="$(CLUSTERS_KUBECONFIG_DIR)" \ go test -timeout 60m -v ./e2e -tags=e2e @@ -80,9 +79,9 @@ verify-generate: generate ## Verify generate update. ##@ Build +.PHONY: build build: ## Build the project. go build -o bin ./cmd/... -.PHONY: build .PHONY: docker-build docker-build: ## Build docker image. @@ -90,16 +89,20 @@ docker-build: ## Build docker image. ##@ Deployment +.PHONY: install install: generate-crd kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/crd | kubectl apply -f - +.PHONY: uninstall uninstall: generate-crd kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/crd | kubectl delete -f - +.PHONY: deploy deploy: generate-crd kustomize deploy-glbc-config ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} $(KUSTOMIZE) build config/default | kubectl apply -f - +.PHONY: undeploy undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/default | kubectl delete -f - @@ -112,6 +115,7 @@ GLBC_ENABLE_CUSTOM_HOSTS ?= false GLBC_DOMAIN ?= dev.hcpapps.net GLBC_DNS_PROVIDER ?= aws AWS_DNS_PUBLIC_ZONE_ID ?= Z08652651232L9P84LRSB +.PHONY: deploy-glbc-config deploy-glbc-config: ## Deploy glbc secrets and config to K8s cluster specified in ~/.kube/config. kubectl create ns kcp-glbc | true kubectl -n kcp-glbc create secret generic kcp-kubeconfig --from-file=kubeconfig=$(KCP_KUBECONFIG) | true @@ -132,44 +136,53 @@ deploy-glbc-config: ## Deploy glbc secrets and config to K8s cluster specified i local-setup: clean build kind kcp ## Setup kcp locally using kind. ./utils/local-setup.sh -c ${NUM_CLUSTERS} -KCP = $(shell pwd)/bin/kcp -kcp: ## Download kcp locally. +##@ Build Dependencies + +## Location to install dependencies to +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): ## Ensure that the directory exists + mkdir -p $(LOCALBIN) + +## Tool Binaries +KCP ?= $(LOCALBIN)/kcp +KUSTOMIZE ?= $(LOCALBIN)/kustomize +CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen +KIND ?= $(LOCALBIN)/kind + +## Tool Versions +KUSTOMIZE_VERSION ?= v3.8.7 +CONTROLLER_TOOLS_VERSION ?= v0.8.0 +KIND_VERSION ?= v0.11.1 + +.PHONY: kcp +kcp: $(KCP) ## Download kcp locally if necessary. +$(KCP): rm -rf ./tmp/kcp git clone --depth=1 --branch ${KCP_BRANCH} https://github.com/kuadrant/kcp ./tmp/kcp cd ./tmp/kcp && make - cp ./tmp/kcp/bin/cluster-controller $(shell pwd)/bin - cp ./tmp/kcp/bin/compat $(shell pwd)/bin - cp ./tmp/kcp/bin/crd-puller $(shell pwd)/bin - cp ./tmp/kcp/bin/deployment-splitter $(shell pwd)/bin - cp ./tmp/kcp/bin/kcp $(shell pwd)/bin - cp ./tmp/kcp/bin/kubectl-kcp $(shell pwd)/bin - cp ./tmp/kcp/bin/shard-proxy $(shell pwd)/bin - cp ./tmp/kcp/bin/syncer $(shell pwd)/bin - cp ./tmp/kcp/bin/virtual-workspaces $(shell pwd)/bin + cp ./tmp/kcp/bin/cluster-controller $(LOCALBIN) + cp ./tmp/kcp/bin/compat $(LOCALBIN) + cp ./tmp/kcp/bin/crd-puller $(LOCALBIN) + cp ./tmp/kcp/bin/deployment-splitter $(LOCALBIN) + cp ./tmp/kcp/bin/kcp $(LOCALBIN) + cp ./tmp/kcp/bin/kubectl-kcp $(LOCALBIN) + cp ./tmp/kcp/bin/shard-proxy $(LOCALBIN) + cp ./tmp/kcp/bin/syncer $(LOCALBIN) + cp ./tmp/kcp/bin/virtual-workspaces $(LOCALBIN) rm -rf ./tmp/kcp -CONTROLLER_GEN = $(shell pwd)/bin/controller-gen -controller-gen: ## Download controller-gen locally if necessary. - $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0) - -KIND = $(shell pwd)/bin/kind -kind: ## Download kind locally if necessary. - $(call go-get-tool,$(KIND),sigs.k8s.io/kind@v0.11.1) - -KUSTOMIZE = $(shell pwd)/bin/kustomize -kustomize: ## Download kustomize locally if necessary. - $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7) - -# go-get-tool will 'go get' any package $2 and install it to $1. -PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) -define go-get-tool -@[ -f $(1) ] || { \ -set -e ;\ -TMP_DIR=$$(mktemp -d) ;\ -cd $$TMP_DIR ;\ -go mod init tmp ;\ -echo "Downloading $(2)" ;\ -GOBIN=$(PROJECT_DIR)/bin $(GO_GET_INSTALL) $(2) ;\ -rm -rf $$TMP_DIR ;\ -} -endef +.PHONY: controller-gen +controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. +$(CONTROLLER_GEN): + GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) + +.PHONY: kind +kind: $(KIND) ## Download kind locally if necessary. +$(KIND): + GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION) + +KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" +.PHONY: kustomize +kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. +$(KUSTOMIZE): + curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)