From 90cacd80827ccc411f1a54b846f3d95847faf6bf Mon Sep 17 00:00:00 2001 From: Madson Ramos Date: Thu, 20 Jun 2024 09:02:42 -0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactoring=20the=20init?= =?UTF-8?q?=20from=20sh=20to=20make?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mk-lib/common.mk | 7 +++++++ .mk-lib/variables.mk | 23 +++++++++++++++++++++++ Makefile | 15 +++++++++++++++ README.md | 4 ++-- init.sh | 5 ----- 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 .mk-lib/common.mk create mode 100644 .mk-lib/variables.mk create mode 100644 Makefile delete mode 100755 init.sh diff --git a/.mk-lib/common.mk b/.mk-lib/common.mk new file mode 100644 index 00000000..d0e63c07 --- /dev/null +++ b/.mk-lib/common.mk @@ -0,0 +1,7 @@ +MK_DIR := $(ROOT_DIR)/.mk-lib +-include $(MK_DIR)/variables.mk + +.DEFAULT_GOAL := help + +help: ##@other Show this help. + @perl -e '$(HELP_FUN)' $(MAKEFILE_LIST) diff --git a/.mk-lib/variables.mk b/.mk-lib/variables.mk new file mode 100644 index 00000000..8fe8dd15 --- /dev/null +++ b/.mk-lib/variables.mk @@ -0,0 +1,23 @@ +#COLORS +GREEN := $(shell tput -Txterm setaf 2) +WHITE := $(shell tput -Txterm setaf 7) +YELLOW := $(shell tput -Txterm setaf 3) +RED := $(shell tput -Txterm setaf 1) +RESET := $(shell tput -Txterm sgr0) + +# Add the following 'help' target to your Makefile +# And add help text after each target name starting with '\#\#' +# A category can be added with @category +HELP_FUN = \ + %help; \ + while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \ + print "usage: make [target]\n\n"; \ + for (sort keys %help) { \ + print "${WHITE}$$_:${RESET}\n"; \ + for (@{$$help{$$_}}) { \ + $$sep = " " x (32 - length $$_->[0]); \ + print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \ + }; \ + print "\n"; } + +kget := kubectl get all -A \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..266e3e22 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +# REQUIRED SECTION +ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +include $(ROOT_DIR)/.mk-lib/common.mk + +init: + @kubectl apply --server-side --kustomize ./cluster/bootstrap/flux + @export SOPS_AGE_KEY_FILE=~/AGE/sops-key.txt + @sops --decrypt cluster/flux/vars/cluster-secrets.sops.yaml | kubectl apply -f - + @kubectl apply -f cluster/flux/vars/cluster-settings.yaml + @kubectl apply --server-side --kustomize ./cluster/flux/config +nodes: + @kubectl get nodes + +kget: + @$(kget) diff --git a/README.md b/README.md index ce699ce3..c9aaddcd 100644 --- a/README.md +++ b/README.md @@ -332,7 +332,7 @@ And after less than 2 minutes you should end up with working cluster with Cilium ❯ ~ k0sctl kubeconfig > ~/.kube/config [☸ lab:default] -❯ ~ kubectl get nodes +❯ ~ make nodes NAME STATUS ROLES AGE VERSION node1 Ready 2m10s v1.29.1+k0s node2 Ready 2m16s v1.29.1+k0s @@ -473,7 +473,7 @@ All of the above in one shot using init.sh: ```sh [☸ lab:default] [ main] -❯ ~/homelab ./init.sh +❯ ~/homelab make init namespace/flux-system serverside-applied resourcequota/critical-pods serverside-applied customresourcedefinition.apiextensions.k8s.io/alerts.notification.toolkit.fluxcd.io serverside-applied diff --git a/init.sh b/init.sh deleted file mode 100755 index 27a619c8..00000000 --- a/init.sh +++ /dev/null @@ -1,5 +0,0 @@ -kubectl apply --server-side --kustomize ./cluster/bootstrap/flux -export SOPS_AGE_KEY_FILE=~/AGE/sops-key.txt -sops --decrypt cluster/flux/vars/cluster-secrets.sops.yaml | kubectl apply -f - -kubectl apply -f cluster/flux/vars/cluster-settings.yaml -kubectl apply --server-side --kustomize ./cluster/flux/config