Skip to content

Commit

Permalink
Add kind targets to Makefile
Browse files Browse the repository at this point in the history
* Add targets for creating or resetting a `kind` cluster for development
* Fix the RBAC resources which are created by `kind-cluster` target for
  development

Signed-off-by: rustyclock <rustyclock@protonmail.com>
  • Loading branch information
rustycl0ck committed Oct 21, 2021
1 parent 0b084d1 commit d501dff
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 54 deletions.
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ test: manifests generate fmt vet ## Run tests.
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

kind-cluster: kind-cluster-create ## Deploy RBAC resources to kindd cluster for development
kubectl apply -f kind
kubectl apply -f kind/rbac

KIND_CLUSTER_NAME = spanner-autoscaler
kind-cluster-create: kind ## Create a kind cluster for development
@if [ -z $(shell $(KIND) get clusters | grep $(KIND_CLUSTER_NAME)) ]; then \
$(KIND) create cluster --name $(KIND_CLUSTER_NAME); \
fi
kubectl config use-context kind-$(KIND_CLUSTER_NAME)

kind-cluster-delete: kind ## Delete the kind cluster created for development
@$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)

kind-cluster-reset: kind kind-cluster-delete kind-cluster-create kind-cluster ## Recreate the kind cluster for development

##@ Build

build: generate fmt vet ## Build manager binary.
Expand Down Expand Up @@ -92,6 +108,12 @@ 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)

KIND = $(shell pwd)/bin/kind
.PHONY: kind
kind: ## Downlaod 'kind' locally if necessary
$(call go-get-tool,$(KIND),sigs.k8s.io/kind@v0.11.1)


# 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
Expand All @@ -105,3 +127,4 @@ GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

1 change: 1 addition & 0 deletions config/samples/spanner_v1alpha1_spannerautoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: spanner.mercari.com/v1alpha1
kind: SpannerAutoscaler
metadata:
name: spannerautoscaler-sample
namespace: test
spec:
scaleTargetRef:
projectId: test-project
Expand Down
41 changes: 0 additions & 41 deletions kind/rbac/cluster_role.yaml

This file was deleted.

22 changes: 9 additions & 13 deletions kind/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
kind: ClusterRole
metadata:
namespace: test
name: spanner-autoscaller-service-account-reader
rules:
- apiGroups: [""]
Expand All @@ -12,41 +11,38 @@ rules:

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
kind: ClusterRoleBinding
metadata:
namespace: test
name: spanner-autoscaller-service-account-reader
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
kind: ClusterRole
name: spanner-autoscaller-service-account-reader
subjects:
- kind: ServiceAccount
name: default
name: spanner-autoscaler-controller-manager
namespace: spanner-autoscaler

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
kind: ClusterRole
metadata:
namespace: test
name: spanner-autoscaller-event-publisher
rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["create"]
verbs: ["create", "patch"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
kind: ClusterRoleBinding
metadata:
namespace: test
name: spanner-autoscaller-event-publisher
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
kind: ClusterRole
name: spanner-autoscaller-event-publisher
subjects:
- kind: ServiceAccount
name: default
name: spanner-autoscaler-controller-manager
namespace: spanner-autoscaler

0 comments on commit d501dff

Please sign in to comment.