Skip to content

Commit

Permalink
corrected local_setup.sh, added local_restore.sh, added script to add…
Browse files Browse the repository at this point in the history
… license headers
  • Loading branch information
unmarshall committed Sep 11, 2023
1 parent b7fe287 commit e89b6d6
Show file tree
Hide file tree
Showing 26 changed files with 667 additions and 131 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is used to set variables which will be referenced in the Makefile
# Currently variables defined in this file are used for local testing only.
# hack/local_setup.sh will populate variables and hack/local_restore.sh will clear the variables.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*.html
.vscode
.idea
**/.env
*.DS_Store
managevm
controller_manager
Expand Down
33 changes: 19 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

include .env

IMAGE_REPOSITORY := eu.gcr.io/gardener-project/gardener/machine-controller-manager
IMAGE_TAG := $(shell cat VERSION)
COVERPROFILE := test/output/coverprofile.out

CONTROL_NAMESPACE := default
CONTROL_KUBECONFIG := dev/target-kubeconfig.yaml
TARGET_KUBECONFIG := dev/target-kubeconfig.yaml

LEADER_ELECT := "true"
MACHINE_SAFETY_OVERSHOOTING_PERIOD:=1m

Expand All @@ -34,8 +32,8 @@ endif
# Rules When K8s cluster is Gardener Shoot#
###########################################

.PHONY: downlaod-kubeconfigs
download-kubeconfigs:
.PHONY: setup
setup:
@echo "enter project name"; \
read PROJECT; \
echo "enter seed name"; \
Expand All @@ -44,18 +42,21 @@ download-kubeconfigs:
read SHOOT; \
echo "enter cluster provider(gcp|aws|azure|vsphere|openstack|alicloud|metal|equinix-metal)"; \
read PROVIDER; \
./hack/local_setup.sh --SEED $$SEED --SHOOT $$SHOOT --PROJECT $$PROJECT --PROVIDER $$PROVIDER
./hack/local_setup.sh --seed $$SEED --shoot $$SHOOT --project $$PROJECT --provider $$PROVIDER

.PHONY: local-mcm-up
local-mcm-up: download-kubeconfigs
local-mcm-up: setup
$(MAKE) start;

.PHONY: local-mcm-down
local-mcm-down:
@kubectl --kubeconfig=${CONTROL_KUBECONFIG} -n ${CONTROL_NAMESPACE} annotate --overwrite=true deployment/machine-controller-manager dependency-watchdog.gardener.cloud/ignore-scaling-
@kubectl --kubeconfig=${CONTROL_KUBECONFIG} scale -n ${CONTROL_NAMESPACE} deployment/machine-controller-manager --replicas=1
@rm ${CONTROL_KUBECONFIG}
@rm ${TARGET_KUBECONFIG}
.PHONY: restore
restore:
@echo "enter project name"; \
read PROJECT; \
echo "enter shoot name"; \
read SHOOT; \
echo "enter cluster provider(gcp|aws|azure|vsphere|openstack|alicloud|metal|equinix-metal)"; \
read PROVIDER; \
./hack/local_restore.sh --shoot $$SHOOT --project $$PROJECT --provider $$PROVIDER

#########################################
# Rules for local development scenarios #
Expand Down Expand Up @@ -163,3 +164,7 @@ CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

.PHONY: add-license-headers
add-license-headers: $(GO_ADD_LICENSE)
@./hack/add_license_headers.sh
33 changes: 33 additions & 0 deletions hack/add_license_headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Copyright 2023 SAP SE or an SAP affiliate company
#
# 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 -e

echo "> Adding Apache License header to all go files where it is not present"

# Uses the tool https://github.com/google/addlicense
YEAR="$(date +%Y)"
addlicense \
-c "SAP SE or an SAP affiliate company" \
-y "${YEAR}" \
-l apache \
-ignore ".idea/**" \
-ignore ".vscode/**" \
-ignore "vendor/**" \
-ignore "**/*.md" \
-ignore "**/*.yaml" \
-ignore "**/Dockerfile" \
.
7 changes: 7 additions & 0 deletions hack/admin-kube-config-request-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"apiVersion": "authentication.gardener.cloud/v1alpha1",
"kind": "AdminKubeconfigRequest",
"spec": {
"expirationSeconds": ${expiry_seconds}
}
}
14 changes: 14 additions & 0 deletions hack/api-reference/generate-spec-doc.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2023 SAP SE or an SAP affiliate company
#
# 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.

cd ./hack/api-reference
./gen-crd-api-reference-docs -config "providerspec-config.json" -api-dir "../../pkg/apis/machine/v1alpha1" -out-file="../../docs/documents/apis.md"
sed 's/?id=//g' ../../docs/documents/apis.md > ../../docs/documents/apis-1.md
Expand Down
134 changes: 134 additions & 0 deletions hack/local_restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env bash
# Copyright 2023 SAP SE or an SAP affiliate company
#
# 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 -o errexit
set -o pipefail

##############################################################################################################
# Script restores MCM deployment and removes the annotation dependency-watchdog.gardener.cloud/ignore-scaling
# This script should be called once you are done using local_setup.sh
##############################################################################################################

declare SHOOT PROJECT PROVIDER
declare PROVIDER_MCM_PROJECT_DIR
declare RELATIVE_KUBECONFIG_PATH="dev/kube-configs"
declare LANDSCAPE_NAME="dev"


SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
PROJECT_DIR="$(cd "$(dirname "${SCRIPT_DIR}")" &>/dev/null && pwd)"

function create_usage() {
usage=$(printf '%s\n' "
Usage: $(basename $0) [Options]
Options:
-t | --shoot <shoot-cluster-name> (Required) Name of the Gardener Shoot Cluster
-p | --project <project-name> (Required) Name of the Gardener Project
-l | --landscape <landscape-name> (Optional) Name of the landscape. Defaults to dev
-i | --provider <provider-name> (Required) Infrastructure provider name. Supported providers (gcp|aws|azure|vsphere|openstack|alicloud|metal|equinix-metal)
-k | --kubeconfig-path <relative-kubeconfig-path> (Optional) Relative path to the <PROJECT-DIR> where kubeconfigs will be downloaded. Path should not start with '/'. Default: <PROJECT-DIR>/dev/kube-configs
-m | --mcm-provider-project-path <absolute-mcm-provider-project-dir> (Optional) MCM Provider project directory. If not provided then it assumes that both mcm and mcm-provider projects are under the same parent directory
")
echo "${usage}"
}

function parse_flags() {
while test $# -gt 0; do
case "$1" in
--shoot | -t)
shift
SHOOT="$1"
;;
--project | -p)
shift
PROJECT="$1"
;;
--landscape | -l)
shift
LANDSCAPE_NAME="$1"
;;
--provider | -i)
shift
PROVIDER="$1"
;;
--kubeconfig-path | -k)
shift
RELATIVE_KUBECONFIG_PATH="$1"
;;
--mcm-provider-project-path | -m)
shift
PROVIDER_MCM_PROJECT_DIR="$1"
;;
--help | -h)
shift
echo "${USAGE}"
exit 0
;;
esac
shift
done
}

function validate_args() {
if [[ -z "${SHOOT}" ]]; then
echo -e "Shoot has not been passed. Please provide Shoot either by specifying --shoot or -t argument"
exit 1
fi
if [[ -z "${PROJECT}" ]]; then
echo -e "Project name has not been passed. Please provide Project name either by specifying --project or -p argument"
exit 1
fi
}

function initialize_variables() {
if [[ -z "${PROVIDER_MCM_PROJECT_DIR}" ]]; then
PROVIDER_MCM_PROJECT_DIR=$(dirname "${PROJECT_DIR}")/machine-controller-manager-provider-"${PROVIDER}"
fi
ABSOLUTE_KUBE_CONFIG_PATH="$(cd "$(dirname "${RELATIVE_KUBECONFIG_PATH}")"; pwd)/$(basename "${RELATIVE_KUBECONFIG_PATH}")"
ABSOLUTE_PROVIDER_KUBECONFIG_PATH="${PROVIDER_MCM_PROJECT_DIR}/dev/kube-configs"
}

function restore_mcm_deployment() {
local virtual_garden_cluster="sap-landscape-${LANDSCAPE_NAME}"
gardenctl target --garden "${virtual_garden_cluster}" --project "${PROJECT}" --shoot "${SHOOT}" --control-plane
eval "$(gardenctl kubectl-env zsh)"
echo "removing annotation dependency-watchdog.gardener.cloud/ignore-scaling from mcm deployment..."
kubectl annotate --overwrite=true deployment/machine-controller-manager dependency-watchdog.gardener.cloud/ignore-scaling-
echo "scaling up mcm deployment to 1..."
kubectl scale deployment/machine-controller-manager --replicas=1
}

function delete_generated_configs() {
echo "Removing downloaded kubeconfigs..."
rm -f "${ABSOLUTE_KUBE_CONFIG_PATH}"/*.yaml
rm -f "${ABSOLUTE_PROVIDER_KUBECONFIG_PATH}"/*.yaml
echo "Clearing .env files..."
sed -r -i '/^#/!d' "${PROJECT_DIR}"/.env
sed -r -i '/^#/!d' "${PROVIDER_MCM_PROJECT_DIR}"/.env
echo "Removing generated admin kube config json..."
rm -f "${SCRIPT_DIR}"/admin-kube-config-request.json
}

function main() {
parse_flags "$@"
validate_args
initialize_variables
restore_mcm_deployment
delete_generated_configs
}

USAGE=$(create_usage)
main "$@"
Loading

0 comments on commit e89b6d6

Please sign in to comment.