|
| 1 | +# Copyright 2025 The Kubernetes Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Add the following 'help' target to your Makefile |
| 16 | +# And add help text after each target name starting with '\#\#' |
| 17 | +.DEFAULT_GOAL:=help |
| 18 | + |
| 19 | +.EXPORT_ALL_VARIABLES: |
| 20 | + |
| 21 | +ifndef VERBOSE |
| 22 | +.SILENT: |
| 23 | +endif |
| 24 | + |
| 25 | +# set default shell |
| 26 | +SHELL=/bin/bash -o pipefail -o errexit |
| 27 | +# Set Root Directory Path |
| 28 | +ifeq ($(origin ROOT_DIR),undefined) |
| 29 | +ROOT_DIR := $(abspath $(shell pwd -P)) |
| 30 | +endif |
| 31 | + |
| 32 | +# Golang root package |
| 33 | +PKG = github.com/kubernetes-sigs/ingate |
| 34 | +# Ingate version building |
| 35 | +INGATE_VERSION=$(shell cat versions/INGATE) |
| 36 | +# Golang version to build controller and container |
| 37 | +GOLANG=$(shell cat versions/GOLANG) |
| 38 | + |
| 39 | +# HOST_ARCH is the architecture that the developer is using to build it |
| 40 | +HOST_ARCH=$(shell which go >/dev/null 2>&1 && go env GOARCH) |
| 41 | +ARCH ?= $(HOST_ARCH) |
| 42 | +ifeq ($(ARCH),) |
| 43 | + $(error mandatory variable ARCH is empty, either set it when calling the command or make sure 'go env GOARCH' works) |
| 44 | +endif |
| 45 | + |
| 46 | +## Build information for the repo source |
| 47 | +REPO_INFO ?= $(shell git config --get remote.origin.url) |
| 48 | + |
| 49 | +## Build information for git commit |
| 50 | +COMMIT_SHA ?= git-$(shell git rev-parse --short HEAD) |
| 51 | + |
| 52 | +## Build information for build id in cloud build |
| 53 | +BUILD_ID ?= "UNSET" |
| 54 | + |
| 55 | +# REGISTRY is the image registry to use for build and push image targets. |
| 56 | +REGISTRY ?= gcr.io/k8s-staging/ingate |
| 57 | +# Name of the image |
| 58 | +INGATE_IMAGE_NAME ?= ingate-controller |
| 59 | +# IMAGE is the image URL for build and push image targets. |
| 60 | +IMAGE ?= $(REGISTRY)/$(IMAGE_NAME) |
| 61 | +BASE_IMAGE ?= $(shell cat versions/BASE_IMAGE) |
| 62 | + |
| 63 | +## help: Show this help info. |
| 64 | +.PHONY: help |
| 65 | +help: |
| 66 | + @awk 'BEGIN {FS = ":.*##"; printf ""} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 67 | + |
| 68 | + |
| 69 | +.PHONY: versions |
| 70 | +versions: ## List out versions of Software being used to develop InGate |
| 71 | + echo "GOLANG: ${GOLANG}" |
| 72 | + echo "INGATE: ${INGATE_VERSION}" |
| 73 | + echo "BASE_IMAGE: ${BASE_IMAGE}" |
| 74 | + echo "Commit SHA: ${COMMIT_SHA}" |
| 75 | + echo "HOST_ARCH: ${ARCH}" |
| 76 | + |
| 77 | + |
| 78 | +## All Make targets for docker build |
| 79 | + |
| 80 | +# Name of the docker buildx builder for InGate |
| 81 | +BUILDER ?= ingate |
| 82 | + |
| 83 | +# Supported Platforms for building multiarch binaries. |
| 84 | +PLATFORMS ?= linux/amd64,linux/arm,linux/arm64 |
| 85 | + |
| 86 | +.PHONY: builder |
| 87 | +docker.builder: |
| 88 | + docker buildx create --name $(BUILDER) --bootstrap --use || : |
| 89 | + docker buildx inspect $(BUILDER) |
| 90 | + |
| 91 | +## Docker output, --push or --load |
| 92 | +OUTPUT ?= |
| 93 | + |
| 94 | +.PHONY: docker.build |
| 95 | +docker.build: docker.builder docker.clean ## Build Ingate Controller image for a particular arch. |
| 96 | + echo "Building docker $(REGISTRY)/controller:$(INGATE_VERSION) ($(ARCH))..." |
| 97 | + docker buildx build \ |
| 98 | + --builder $(BUILDER) \ |
| 99 | + --platform $(PLATFORMS) \ |
| 100 | + --no-cache \ |
| 101 | + --build-arg TARGET_ARCH=$(ARCH) \ |
| 102 | + -t $(REGISTRY)/controller:$(INGATE_VERSION) \ |
| 103 | + -f images/ingate-controller/Dockerfile.run images/ingate-controller \ |
| 104 | + $(OUTPUT) |
| 105 | + |
| 106 | + |
| 107 | +.PHONY: docker.push |
| 108 | +docker.push: OUTPUT = --push |
| 109 | +docker.push: docker.build ## Push docker container to a $REGISTRY |
| 110 | + |
| 111 | +.PHONY: docker.clean |
| 112 | +docker.clean: ## Removes local image |
| 113 | + echo "removing old image $(REGISTRY)/controller:$(INGATE_VERSION)" |
| 114 | + docker rmi -f $(REGISTRY)/controller:$(INGATE_VERSION) || true |
| 115 | + |
| 116 | +.PHONY: docker.registry |
| 117 | +docker.registry: ## Starts a local docker registry for testing |
| 118 | + docker stop registry && docker rm registry || true |
| 119 | + docker run -d --publish "0.0.0.0:6000:5000" --name registry registry:2.7 |
| 120 | + |
| 121 | +## All Make targets for golang |
| 122 | + |
| 123 | +# Where to place the golang built binarys |
| 124 | +TARGETS_DIR = "./images/ingate-controller/bin/${ARCH}" |
| 125 | + |
| 126 | +## Where to get the version information |
| 127 | +VERSION_PACKAGE = github.com/kubernetes-sigs/ingate/internal/cmd/version |
| 128 | + |
| 129 | +GOOS := $(shell go env GOOS) |
| 130 | +ifeq ($(origin GOOS), undefined) |
| 131 | + GOOS := $(shell go env GOOS) |
| 132 | +endif |
| 133 | + |
| 134 | +.PHONY: go.build |
| 135 | +go.build: go.clean ## Go build for ingate controller |
| 136 | + docker run \ |
| 137 | + --volume "${PWD}":/go/src/$(PKG) \ |
| 138 | + -w /go/src/$(PKG) \ |
| 139 | + -e CGO_ENABLED=0 \ |
| 140 | + -e GOOS=$(GOOS) \ |
| 141 | + -e GOARCH=$(TARGETARCH) \ |
| 142 | + golang:1.24.1-alpine3.21 \ |
| 143 | + go build -trimpath -ldflags="-buildid= -w -s \ |
| 144 | + -X $(VERSION_PACKAGE).inGateVersion=$(INGATE_VERSION) \ |
| 145 | + -X $(VERSION_PACKAGE).gitCommitID=$(COMMIT_SHA)" \ |
| 146 | + -buildvcs=false \ |
| 147 | + -o $(TARGETS_DIR)/ingate $(PKG)/cmd/ingate |
| 148 | + |
| 149 | +.PHONY: go.clean |
| 150 | +go.clean: ## Clean go building output files |
| 151 | + rm -rf $(TARGETS_DIR) |
| 152 | + |
| 153 | +.PHONY: go.test.unit |
| 154 | +go.test.unit: ## Run go unit tests |
| 155 | + docker run -e CGO_ENABLED=1 golang:1.24.1-alpine3.21 go test -race ./... |
| 156 | + |
| 157 | +## All make targets for deploying a dev environment for InGate development |
| 158 | + |
| 159 | +# Version of kubernetes to deploy on kind cluster |
| 160 | +K8S_VERSION ?= $(shell cat versions/KUBERNETES_VERSIONS | head -n1) |
| 161 | +# Name of kind cluster to deploy |
| 162 | +KIND_CLUSTER_NAME := ingate-dev |
| 163 | +# Gateway API Version to deploy on kind cluster |
| 164 | +GW_VERSION ?= $(shell cat versions/GATEWAY_API) |
| 165 | +# Gateway API channel to deploy on kind cluster See https://gateway-api.sigs.k8s.io/concepts/versioning/?h=chann#release-channels for more details |
| 166 | +GW_CHANNEL ?= standard |
| 167 | + |
| 168 | +kind.all: kind.build go.build docker.build kind.load loadbalancer.install gateway.install ## Start a Development environment for InGate |
| 169 | + |
| 170 | +kind.build: kind.clean ## Build a kind cluster for testing |
| 171 | + kind create cluster --config tools/kind/config.yaml --name $(KIND_CLUSTER_NAME) --image "kindest/node:$(K8S_VERSION)" |
| 172 | + |
| 173 | +kind.clean: ## Deletes kind cluster |
| 174 | + kind delete clusters $(KIND_CLUSTER_NAME) |
| 175 | + |
| 176 | +KIND_WORKERS=$(shell kind get nodes --name="${KIND_CLUSTER_NAME}" | grep worker | awk '{printf (NR>1?",":"") $1}') |
| 177 | + |
| 178 | +kind.load: ## Load InGate Image onto kind cluster |
| 179 | + kind load docker-image --name="$(KIND_CLUSTER_NAME)" --nodes="$(KIND_WORKERS)" "$(REGISTRY)"/controller:"$(TAG)" |
| 180 | + |
| 181 | +## Using the kubernetes sig tool https://github.com/kubernetes-sigs/cloud-provider-kind |
| 182 | +loadbalancer.install: ## Install Load Balancer in kind cluster for Gateway deployments |
| 183 | + docker run --rm --network kind --detach -v /var/run/docker.sock:/var/run/docker.sock registry.k8s.io/cloud-provider-kind/cloud-controller-manager:v0.6.0 |
| 184 | + |
| 185 | +# example https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/refs/heads/release-1.2/config/crd/standard/gateway.networking.k8s.io_gateways.yaml |
| 186 | +gateway.install: ## Install Gateway API CRDs in cluster |
| 187 | + kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/$(GW_VERSION)/config/crd/$(GW_CHANNEL)/gateway.networking.k8s.io_gatewayclasses.yaml |
| 188 | + kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/$(GW_VERSION)/config/crd/$(GW_CHANNEL)/gateway.networking.k8s.io_gateways.yaml |
| 189 | + kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/$(GW_VERSION)/config/crd/$(GW_CHANNEL)/gateway.networking.k8s.io_httproutes.yaml |
| 190 | + kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/$(GW_VERSION)/config/crd/$(GW_CHANNEL)/gateway.networking.k8s.io_referencegrants.yaml |
| 191 | + kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/$(GW_VERSION)/config/crd/$(GW_CHANNEL)/gateway.networking.k8s.io_grpcroutes.yaml |
0 commit comments