Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable pairing with branches from ksctl repository #1030

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions make/ksctl.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,62 @@
KSCTL_GH_OWNER=kubesaw
KSCTL_GH_BRANCH=master
USE_INSTALLED_KSCTL = false

BIN_DIR := $(shell pwd)/build/_output/bin

ifneq ($(USE_INSTALLED_KSCTL),true)
KSCTL_BIN_DIR = ${BIN_DIR}/
endif

.PHONY: ksctl
ksctl:
GOBIN=${BIN_DIR} CGO_ENABLED=0 go install github.com/${KSCTL_GH_OWNER}/ksctl/cmd/ksctl@${KSCTL_GH_BRANCH}
ifneq ($(USE_INSTALLED_KSCTL),true)
@$(MAKE) get-ksctl-and-install --no-print-directory
else
@echo "Using local version of ksctl"
endif

get-ksctl-and-install:
ifeq ($(strip $(KSCTL_REPO_PATH)),)
ifneq ($(CI),)
ifneq ($(GITHUB_ACTIONS),)
$(eval BRANCH_NAME = ${GITHUB_HEAD_REF})
$(eval AUTHOR_LINK = https://github.com/${AUTHOR})
else
$(eval AUTHOR_LINK = $(shell jq -r '.refs[0].pulls[0].author_link' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'))
@echo "found author link ${AUTHOR_LINK}"
$(eval BRANCH_NAME := $(shell jq -r '.refs[0].pulls[0].head_ref' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'))
endif
@echo "using author link ${AUTHOR_LINK}"
@echo "detected branch ${BRANCH_NAME}"
# check if a branch with the same ref exists in the user's fork of ksctl repo
$(eval REMOTE_KSCTL_BRANCH := $(shell curl ${AUTHOR_LINK}/ksctl.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "refs/heads/${BRANCH_NAME}$$" | awk '{print $$2}'))
@echo "branch ref of the user's fork: \"${REMOTE_KSCTL_BRANCH}\" - if empty then not found"
# check if the branch with the same name exists, if so then merge it with master and use the merge branch, if not then use master
ifneq ($(REMOTE_KSCTL_BRANCH),"")
# define temp dir
$(eval KSCTL_REPO_PATH := /tmp/ksctl)
# delete to have clear environment
rm -rf ${KSCTL_REPO_PATH}

git config --global user.email "[email protected]"
git config --global user.name "Devtools"
# clone
git clone --depth=1 https://github.com/kubesaw/ksctl.git ${KSCTL_REPO_PATH}
# add the user's fork as remote repo
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} remote add external ${AUTHOR_LINK}/ksctl.git
# fetch the branch
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} fetch external ${REMOTE_KSCTL_BRANCH}
# merge the branch with master
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} merge --allow-unrelated-histories --no-commit FETCH_HEAD
endif
mfrancisc marked this conversation as resolved.
Show resolved Hide resolved
endif
endif
@$(MAKE) install-ksctl KSCTL_REPO_PATH=${KSCTL_REPO_PATH}

install-ksctl:
ifneq ($(strip $(KSCTL_REPO_PATH)),)
@echo "Installing ksctl from directory ${KSCTL_REPO_PATH}"
$(MAKE) -C ${KSCTL_REPO_PATH} GOBIN=${BIN_DIR} install
else
@echo "Installing ksctl from master"
GOBIN=${BIN_DIR} CGO_ENABLED=0 go install github.com/kubesaw/ksctl/cmd/ksctl@master
endif
6 changes: 3 additions & 3 deletions make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ print-operator-logs:

.PHONY: setup-toolchainclusters
setup-toolchainclusters: ksctl
${BIN_DIR}/ksctl adm register-member --host-ns="$(HOST_NS)" --member-ns="$(MEMBER_NS)" --host-kubeconfig="$(or ${KUBECONFIG}, ${HOME}/.kube/config)" --member-kubeconfig="$(or ${KUBECONFIG}, ${HOME}/.kube/config)" ${LETS_ENCRYPT_PARAM} -y
if [[ ${SECOND_MEMBER_MODE} == true ]]; then ${BIN_DIR}/ksctl adm register-member --host-ns="$(HOST_NS)" --member-ns="$(MEMBER_NS_2)" --host-kubeconfig="$(or ${KUBECONFIG}, ${HOME}/.kube/config)" --member-kubeconfig="$(or ${KUBECONFIG}, ${HOME}/.kube/config)" ${LETS_ENCRYPT_PARAM} --name-suffix="2" -y ; fi
${KSCTL_BIN_DIR}ksctl adm register-member --host-ns="$(HOST_NS)" --member-ns="$(MEMBER_NS)" --host-kubeconfig="$(or ${KUBECONFIG}, ${HOME}/.kube/config)" --member-kubeconfig="$(or ${KUBECONFIG}, ${HOME}/.kube/config)" ${LETS_ENCRYPT_PARAM} -y
if [[ ${SECOND_MEMBER_MODE} == true ]]; then ${KSCTL_BIN_DIR}ksctl adm register-member --host-ns="$(HOST_NS)" --member-ns="$(MEMBER_NS_2)" --host-kubeconfig="$(or ${KUBECONFIG}, ${HOME}/.kube/config)" --member-kubeconfig="$(or ${KUBECONFIG}, ${HOME}/.kube/config)" ${LETS_ENCRYPT_PARAM} --name-suffix="2" -y ; fi
echo "Restart host operator pods so it can get the ToolchainCluster CRs while it's starting up".
oc delete pods --namespace ${HOST_NS} -l control-plane=controller-manager

Expand Down Expand Up @@ -404,7 +404,7 @@ create-spaceprovisionerconfigs-for-members:
## Generate and apply appstudio tiers using the latest version of ksctl
tiers-via-ksctl: ksctl
rm -rf /tmp/e2e-tiers-out 2>/dev/null || true
${BIN_DIR}/ksctl generate nstemplatetiers --source deploy/nstemplatetiers --out-dir /tmp/e2e-tiers-out
${KSCTL_BIN_DIR}ksctl generate nstemplatetiers --source deploy/nstemplatetiers --out-dir /tmp/e2e-tiers-out
oc kustomize /tmp/e2e-tiers-out | sed 's/toolchain-host-operator/${HOST_NS}/g' | oc apply -f -

.PHONY: create-thirdparty-crds
Expand Down
Loading