Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ go-bootstrap
.cache/
.public/
node_modules/

# kind
.kind/
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ MAKEFLAGS += --no-builtin-variables
# General variables
include Makefile.vars.mk

# Documentation module. If files not found, no warning/error is printed
# Following includes do not print warnings or error if files aren't found
# Optional Documentation module.
-include docs/antora-preview.mk docs/antora-build.mk
# Optional kind module
-include kind/kind.mk

.PHONY: help
help: ## Show this help
Expand Down
15 changes: 13 additions & 2 deletions Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ PROJECT_ROOT_DIR = .
PROJECT_NAME ?= go-bootstrap
PROJECT_OWNER ?= vshn

## Variables relevant for building Go
## BUILD:go
BIN_FILENAME ?= $(PROJECT_NAME)

## Variables relevant for building with Docker
## BUILD:docker
DOCKER_CMD ?= docker

IMG_TAG ?= latest
# Image URL to use all building/pushing image targets
CONTAINER_IMG ?= local.dev/$(PROJECT_OWNER)/$(PROJECT_NAME):$(IMG_TAG)


## KIND:setup

# https://hub.docker.com/r/kindest/node/tags
KIND_NODE_VERSION ?= v1.23.0
KIND_IMAGE ?= docker.io/kindest/node:$(KIND_NODE_VERSION)
KIND ?= go run sigs.k8s.io/kind
KIND_KUBECONFIG ?= $(kind_dir)/kind-kubeconfig-$(KIND_NODE_VERSION)
KIND_CLUSTER ?= $(PROJECT_NAME)-$(KIND_NODE_VERSION)
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Template repository for common Go setups
- Build default documentation with VSHN styling
- Publish to GitHub Pages by default (opt-out)
- Automated with GitHub workflows to build in `master` branch and (pre-)releases.
- Available `make` targets are prefixed with `docs-`

* Local Kubernetes environment
- Setup Kubernetes-In-Docker (kind)
- Prepares a kubeconfig file in `.kind/`
- Optionally install NGINX as ingress controller
- Available `make` targets are prefixed with `kind-`

## TODO's after generating from this template

Expand All @@ -38,6 +45,8 @@ TIP: You can search for these tasks using `grep -n -r "TODO:" .`
1. `docs/antora-playbook.yml`: Adjust project meta.
1. `docs/modules/pages/index.adoc`: Edit start page.
1. `docs/modules/nav.adoc`: Edit navigation.
1. Edit this README

After completing a task, you can remove the comment in the files.

## Other repository settings
Expand Down
22 changes: 19 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@ module github.com/vshn/go-bootstrap

go 1.17

require github.com/stretchr/testify v1.7.0
require (
github.com/stretchr/testify v1.7.0
sigs.k8s.io/kind v0.11.1
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch/v5 v5.2.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
github.com/spf13/cobra v1.1.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apimachinery v0.20.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
420 changes: 417 additions & 3 deletions go.sum

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions kind/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 8081
protocol: TCP
- containerPort: 443
hostPort: 8443
protocol: TCP
38 changes: 38 additions & 0 deletions kind/kind.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
kind_dir ?= .kind

.PHONY: kind
kind: export KUBECONFIG = $(KIND_KUBECONFIG)
kind: kind-setup-ingress kind-load-image ## All-in-one kind target

.PHONY: kind-setup
kind-setup: export KUBECONFIG = $(KIND_KUBECONFIG)
kind-setup: $(KIND_KUBECONFIG) ## Creates the kind cluster

.PHONY: kind-setup-ingress
kind-setup-ingress: export KUBECONFIG = $(KIND_KUBECONFIG)
kind-setup-ingress: kind-setup ## Install NGINX as ingress controller onto kind cluster (localhost:8081)
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

.PHONY: kind-load-image
kind-load-image: kind-setup build-docker ## Load the container image onto kind cluster
@$(KIND) load docker-image --name $(KIND_CLUSTER) $(CONTAINER_IMG)

.PHONY: kind-clean
kind-clean: export KUBECONFIG = $(KIND_KUBECONFIG)
kind-clean: ## Removes the kind Cluster
@$(KIND) delete cluster --name $(KIND_CLUSTER) || true
@rm -rf $(kind_dir)

$(KIND_KUBECONFIG): export KUBECONFIG = $(KIND_KUBECONFIG)
$(KIND_KUBECONFIG):
$(KIND) create cluster \
--name $(KIND_CLUSTER) \
--image $(KIND_IMAGE) \
--config kind/config.yaml
@kubectl version
@kubectl cluster-info
@kubectl config use-context kind-$(KIND_CLUSTER)
@echo =======
@echo "Setup finished. To interact with the local dev cluster, set the KUBECONFIG environment variable as follows:"
@echo "export KUBECONFIG=$$(realpath "$(KIND_KUBECONFIG)")"
@echo =======
11 changes: 11 additions & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build tools
// +build tools

// Package tools is a place to put any tooling dependencies as imports.
// Go modules will be forced to download and install them.
package tools

import (
// To have kind updated via Renovate.
_ "sigs.k8s.io/kind"
)