Skip to content

Commit

Permalink
Merge pull request kubewharf#237 from gary-lgy/make-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-lgy authored Oct 26, 2023
2 parents b21eb4f + c2e8a9c commit 60a002b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 32 deletions.
41 changes: 27 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
#
Expand All @@ -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)
#
Expand Down
24 changes: 24 additions & 0 deletions hack/lib/dev-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
28 changes: 28 additions & 0 deletions hack/make-rules/dev-clean.sh
Original file line number Diff line number Diff line change
@@ -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}"
19 changes: 1 addition & 18 deletions hack/make-rules/dev-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 60a002b

Please sign in to comment.