Skip to content

Commit f01162d

Browse files
authored
setup build structure (kubernetes-sigs#25)
Signed-off-by: James Strong <[email protected]>
1 parent 6161b13 commit f01162d

File tree

25 files changed

+922
-0
lines changed

25 files changed

+922
-0
lines changed

.github/golangci-lint.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: golangci-lint
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.go'
7+
- '.github/workflows/golangci-lint.yml'
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
golangci:
14+
name: lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19+
20+
- name: Get go version
21+
run: echo "GOLANG_VERSION=$(cat GOLANG_VERSION)" >> $GITHUB_ENV
22+
23+
- name: Set up Go
24+
id: go
25+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
26+
with:
27+
go-version: ${{ env.GOLANG_VERSION }}
28+
check-latest: true
29+
30+
- name: golangci-lint
31+
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
32+
with:
33+
version: v1.62
34+
only-new-issues: true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Downloaded in hack/verify-boilerplate.sh.
22
hack/verify_boilerplate.py
3+
images/ingate-controller/bin/

LAYOUT.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Code Layout for InGate project
3+
4+
| Directory | Description |
5+
| ------------- | ------------- |
6+
| docs | InGate documentation site |
7+
| tools | tools used for development, make etc |
8+
| tooks/hack | Directory for bash scripts |
9+
| internal | InGate internal golang source |
10+
| charts | Helm chart for InGate deployment |
11+
| cmd | Command line for InGate |
12+
| versions | Directory for versions of software InGate uses |
13+

Makefile

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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

cmd/ingate/main.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"fmt"
21+
"os"
22+
23+
"github.com/kubernetes-sigs/ingate/cmd/ingate/root"
24+
)
25+
26+
func main() {
27+
if err := root.GetRootCommand().Execute(); err != nil {
28+
fmt.Fprintln(os.Stderr, err)
29+
os.Exit(1)
30+
}
31+
}

cmd/ingate/root/root.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package root
18+
19+
import (
20+
"github.com/kubernetes-sigs/ingate/internal/cmd"
21+
22+
"github.com/spf13/cobra"
23+
)
24+
25+
func GetRootCommand() *cobra.Command {
26+
c := &cobra.Command{
27+
Use: "ingate",
28+
Short: "InGate Gateway and Ingress Controller",
29+
Long: "InGate is a kubernetes contoller for deploying and managing Gateway and Ingress resources",
30+
}
31+
32+
c.AddCommand(cmd.GetVersionCommand())
33+
return c
34+
}

go.mod

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/kubernetes-sigs/ingate
2+
3+
go 1.24.1
4+
5+
require github.com/spf13/cobra v1.9.1
6+
7+
require (
8+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9+
github.com/spf13/pflag v1.0.6 // indirect
10+
)

go.sum

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5+
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
6+
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
7+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
8+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
ARG TARGETARCH
19+
ARG VERSION_PACKAGE
20+
ARG INGATE_VERSION
21+
ARG COMMIT_SHA
22+
ARG PKG
23+
ARG TARGETS_DIR
24+
ARG GOOS
25+
26+
FROM golang:1.24.1-alpine3.21
27+
28+
WORKDIR /go/src/github.com/kubernetes-sigs/ingate/
29+
30+
COPY . .
31+
32+
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-buildid= -w -s \
33+
-X ${VERSION_PACKAGE}.inGateVersion=${INGATE_VERSION} \
34+
-X ${VERSION_PACKAGE}.gitCommitID=${COMMIT_SHA}" \
35+
-buildvcs=false \
36+
-o ${TARGETS_DIR}/ingate ./cmd/ingate
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2025 The Kubernetes Authors. All rights reserved.
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+
FROM gcr.io/distroless/base-debian12:latest
16+
ARG TARGET_ARCH
17+
COPY bin/${TARGET_ARCH}/ingate /opt/ingate
18+
CMD ["/opt/ingate"]

0 commit comments

Comments
 (0)