diff --git a/Makefile b/Makefile index d9225d0c..50d07315 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ GOOS ?= $(shell go env GOOS) GOARCH ?= $(shell go env GOARCH) GOPROXY ?= $(shell go env GOPROXY) TARGET_NAME ?= kubeadmiral-controller-manager +DEBUG_TARGET_NAME ?= $(TARGET_NAME)_debug # image information REGISTRY ?= ghcr.io/kubewharf @@ -33,20 +34,38 @@ all: build build: BUILD_FLAGS="$(BUILD_FLAGS)" TARGET_NAME="$(TARGET_NAME)" GOPROXY="$(GOPROXY)" bash hack/make-rules/build.sh +# Debug build +.PHONY: build-debug +build-debug: BUILD_FLAGS+=-race +build-debug: TARGET_NAME:=$(DEBUG_TARGET_NAME) +build-debug: build + # Start a local kubeadmiral cluster for developers. # # It will directly start the kubeadmiral control-plane cluster(excluding the kubeadmiral-controller-manager) and three member-clusters. -# Users can run the kubeadmiral-controller-manager component through binary for easy debugging, e.g.: -# ./output/bin/darwin/amd64/kubeadmiral-controller-manager_debug \ -# --klog-logtostderr=false \ -# --klog-log-file "./kubeadmiral.log" \ -# --kubeconfig "$HOME/.kube/kubeadmiral/kubeadmiral-host.yaml" \ -# 2>/dev/null +# Users can run the kubeadmiral-controller-manager component through binary for easy debugging using make dev-run. .PHONY: dev-up dev-up: - make clean-local-cluster bash hack/make-rules/dev-up.sh - make debug + make build-debug + +# Clean up the clusters created by dev-up. +.PHONY: dev-clean +dev-clean: + bash hack/make-rules/dev-clean.sh + +# Run the kubeadmiral-controller-manager component with sane defaults for development. +.PHONY: dev-run +dev-run: + ./output/bin/$(GOOS)/$(GOARCH)/$(DEBUG_TARGET_NAME) \ + --enable-leader-elect=false \ + --worker-count=5 \ + --kubeconfig=${HOME}/.kube/kubeadmiral/kubeadmiral-host.yaml \ + --klog-v=4 \ + --klog-add-dir-header=true \ + --klog-logtostderr=false \ + --klog-log-file=/dev/stdout \ + --cluster-join-timeout=15s 2>&1 # Local up the KubeAdmiral. # @@ -63,12 +82,6 @@ local-up: make clean-local-cluster REGION="$(REGION)" NUM_MEMBER_CLUSTERS="$(NUM_MEMBER_CLUSTERS)" bash hack/make-rules/local-up.sh -# Debug build -.PHONY: debug -debug: BUILD_FLAGS+=-race -debug: TARGET_NAME:=$(TARGET_NAME)_debug -debug: build - # Build binaries and docker images. # The supported OS is linux, and user can specify the arch type (only amd64,arm64,arm are supported) # diff --git a/hack/lib/dev-up.sh b/hack/lib/dev-up.sh index f0d19fdd..6b6e123e 100644 --- a/hack/lib/dev-up.sh +++ b/hack/lib/dev-up.sh @@ -155,3 +155,27 @@ EOF exit 1 fi } + +function dev-up::clean() { + local HOST_CLUSTER_NAME=${1} + local MEMBER_CLUSTER_NAME=${2} + local NUM_MEMBER_CLUSTERS=${3} + local CLUSTER_PROVIDER=${4} + + if [[ "${NUM_MEMBER_CLUSTERS}" -gt "0" ]]; then + if [[ $CLUSTER_PROVIDER == "kind" ]]; then + kind delete cluster --name="${HOST_CLUSTER_NAME}" + for i in $(seq 1 "${NUM_MEMBER_CLUSTERS}"); do + kind delete cluster --name="${MEMBER_CLUSTER_NAME}-${i}" + done + elif [[ $CLUSTER_PROVIDER == "kwok" ]]; then + kwokctl delete cluster --name="${HOST_CLUSTER_NAME}" || true + for i in $(seq 1 "${NUM_MEMBER_CLUSTERS}"); do + kwokctl delete cluster --name="$MEMBER_CLUSTER_NAME-${i}" || true + done + else + echo "Invalid provider, only kwok or kind allowed" + exit 1 + fi + fi +} diff --git a/hack/make-rules/dev-clean.sh b/hack/make-rules/dev-clean.sh new file mode 100755 index 00000000..65f7ea43 --- /dev/null +++ b/hack/make-rules/dev-clean.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# Copyright 2023 The KubeAdmiral 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. + +set -eu +set -o pipefail + +REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. +source "${REPO_ROOT}"/hack/lib/dev-up.sh + +HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"kubeadmiral-host"} +MEMBER_CLUSTER_NAME=${MEMBER_CLUSTER_NAME:-"kubeadmiral-member"} +NUM_MEMBER_CLUSTERS=${NUM_MEMBER_CLUSTERS:-"3"} +CLUSTER_PROVIDER=${CLUSTER_PROVIDER:-"kwok"} + +dev-up::clean "${HOST_CLUSTER_NAME}" "${MEMBER_CLUSTER_NAME}" "${NUM_MEMBER_CLUSTERS}" "${CLUSTER_PROVIDER}" diff --git a/hack/make-rules/dev-up.sh b/hack/make-rules/dev-up.sh index 101d2512..65d9d54e 100755 --- a/hack/make-rules/dev-up.sh +++ b/hack/make-rules/dev-up.sh @@ -27,26 +27,9 @@ MEMBER_CLUSTER_NAME=${MEMBER_CLUSTER_NAME:-"kubeadmiral-member"} MANIFEST_DIR=${MANIFEST_DIR:-"${REPO_ROOT}/config/crds"} CONFIG_DIR=${CONFIG_DIR:-"${REPO_ROOT}/config/sample/host"} NUM_MEMBER_CLUSTERS=${NUM_MEMBER_CLUSTERS:-"3"} -CLUSTER_PROVIDER=${CLUSTER_PROVIDER:-"kind"} +CLUSTER_PROVIDER=${CLUSTER_PROVIDER:-"kwok"} KUBE_VERSION=${KUBE_VERSION:="v1.20.15"} -if [[ "${NUM_MEMBER_CLUSTERS}" -gt "0" ]]; then - if [[ $CLUSTER_PROVIDER == "kind" ]]; then - kind delete cluster --name=${HOST_CLUSTER_NAME} - for i in $(seq 1 "${NUM_MEMBER_CLUSTERS}"); do - kind delete cluster --name="${MEMBER_CLUSTER_NAME}-${i}" - done - elif [[ $CLUSTER_PROVIDER == "kwok" ]]; then - kwokctl delete cluster --name=${HOST_CLUSTER_NAME} || true - for i in $(seq 1 "${NUM_MEMBER_CLUSTERS}"); do - kwokctl delete cluster --name="$MEMBER_CLUSTER_NAME-${i}" || true - done - else - echo "Invalid provider, only kwok or kind allowed" - exit 1 - fi -fi - mkdir -p "$(dirname "${KUBECONFIG_DIR}")" # start host cluster