Skip to content

Commit 0d337bd

Browse files
authored
CRD implementation (#20)
* Initial commit via kubebuilder. Edited Resources, & restructured kubebuilder output to be top level. Left much of the boilerplate for historical reference. Would like to delete much of the config * Hooking Code-generator tool into `make generate`. And including output. * fixing typo and regenerating output * Swapping LLMServerPool to reference a label selector field instead of a Service objectRef, and regenerating output. Also updating proposal to reflect this change. * review changes and regeneration
1 parent fcad109 commit 0d337bd

File tree

88 files changed

+5960
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+5960
-5
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
bin/*
8+
Dockerfile.cross
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
16+
# Go workspace file
17+
go.work
18+
19+
# Kubernetes Generated files - skip generated files, except for vendored files
20+
!vendor/**/zz_generated.*
21+
22+
# editor and IDE paraphernalia
23+
.idea
24+
.vscode
25+
*.swp
26+
*.swo
27+
*~

.golangci.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
run:
2+
timeout: 5m
3+
allow-parallel-runners: true
4+
5+
issues:
6+
# don't skip warning about doc comments
7+
# don't exclude the default set of lint
8+
exclude-use-default: false
9+
# restore some of the defaults
10+
# (fill in the rest as needed)
11+
exclude-rules:
12+
- path: "api/*"
13+
linters:
14+
- lll
15+
- path: "internal/*"
16+
linters:
17+
- dupl
18+
- lll
19+
linters:
20+
disable-all: true
21+
enable:
22+
- dupl
23+
- errcheck
24+
- exportloopref
25+
- ginkgolinter
26+
- goconst
27+
- gocyclo
28+
- gofmt
29+
- goimports
30+
- gosimple
31+
- govet
32+
- ineffassign
33+
- lll
34+
- misspell
35+
- nakedret
36+
- prealloc
37+
- revive
38+
- staticcheck
39+
- typecheck
40+
- unconvert
41+
- unparam
42+
- unused
43+
44+
linters-settings:
45+
revive:
46+
rules:
47+
- name: comment-spacings

Makefile

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# Image URL to use all building/pushing image targets
2+
IMG ?= controller:latest
3+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
4+
ENVTEST_K8S_VERSION = 1.31.0
5+
6+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
7+
ifeq (,$(shell go env GOBIN))
8+
GOBIN=$(shell go env GOPATH)/bin
9+
else
10+
GOBIN=$(shell go env GOBIN)
11+
endif
12+
13+
# CONTAINER_TOOL defines the container tool to be used for building images.
14+
# Be aware that the target commands are only tested with Docker which is
15+
# scaffolded by default. However, you might want to replace it to use other
16+
# tools. (i.e. podman)
17+
CONTAINER_TOOL ?= docker
18+
19+
# Setting SHELL to bash allows bash commands to be executed by recipes.
20+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
21+
SHELL = /usr/bin/env bash -o pipefail
22+
.SHELLFLAGS = -ec
23+
24+
.PHONY: all
25+
all: build
26+
27+
##@ General
28+
29+
# The help target prints out all targets with their descriptions organized
30+
# beneath their categories. The categories are represented by '##@' and the
31+
# target descriptions by '##'. The awk command is responsible for reading the
32+
# entire set of makefiles included in this invocation, looking for lines of the
33+
# file as xyz: ## something, and then pretty-format the target and help. Then,
34+
# if there's a line with ##@ something, that gets pretty-printed as a category.
35+
# More info on the usage of ANSI control characters for terminal formatting:
36+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
37+
# More info on the awk command:
38+
# http://linuxcommand.org/lc3_adv_awk.php
39+
40+
.PHONY: help
41+
help: ## Display this help.
42+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[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)
43+
44+
##@ Development
45+
46+
.PHONY: manifests
47+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
48+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
49+
50+
.PHONY: generate
51+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
52+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
53+
./hack/update-codegen.sh
54+
55+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
56+
# Use same code-generator version as k8s.io/api
57+
CODEGEN_VERSION := $(shell go list -m -f '{{.Version}}' k8s.io/api)
58+
CODEGEN = $(shell pwd)/bin/code-generator
59+
CODEGEN_ROOT = $(shell go env GOMODCACHE)/k8s.io/code-generator@$(CODEGEN_VERSION)
60+
.PHONY: code-generator
61+
code-generator:
62+
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on go install k8s.io/code-generator/cmd/client-gen@$(CODEGEN_VERSION)
63+
cp -f $(CODEGEN_ROOT)/generate-groups.sh $(PROJECT_DIR)/bin/
64+
cp -f $(CODEGEN_ROOT)/generate-internal-groups.sh $(PROJECT_DIR)/bin/
65+
cp -f $(CODEGEN_ROOT)/kube_codegen.sh $(PROJECT_DIR)/bin/
66+
67+
68+
.PHONY: fmt
69+
fmt: ## Run go fmt against code.
70+
go fmt ./...
71+
72+
.PHONY: vet
73+
vet: ## Run go vet against code.
74+
go vet ./...
75+
76+
.PHONY: test
77+
test: manifests generate fmt vet envtest ## Run tests.
78+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
79+
80+
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
81+
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
82+
test-e2e:
83+
go test ./test/e2e/ -v -ginkgo.v
84+
85+
.PHONY: lint
86+
lint: golangci-lint ## Run golangci-lint linter
87+
$(GOLANGCI_LINT) run
88+
89+
.PHONY: lint-fix
90+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
91+
$(GOLANGCI_LINT) run --fix
92+
93+
##@ Build
94+
95+
.PHONY: build
96+
build: manifests generate fmt vet ## Build manager binary.
97+
go build -o bin/manager cmd/main.go
98+
99+
.PHONY: run
100+
run: manifests generate fmt vet ## Run a controller from your host.
101+
go run ./cmd/main.go
102+
103+
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
104+
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
105+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
106+
.PHONY: docker-build
107+
docker-build: ## Build docker image with the manager.
108+
$(CONTAINER_TOOL) build -t ${IMG} .
109+
110+
.PHONY: docker-push
111+
docker-push: ## Push docker image with the manager.
112+
$(CONTAINER_TOOL) push ${IMG}
113+
114+
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
115+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
116+
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
117+
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
118+
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
119+
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
120+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
121+
.PHONY: docker-buildx
122+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
123+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
124+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
125+
- $(CONTAINER_TOOL) buildx create --name api-builder
126+
$(CONTAINER_TOOL) buildx use api-builder
127+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
128+
- $(CONTAINER_TOOL) buildx rm api-builder
129+
rm Dockerfile.cross
130+
131+
.PHONY: build-installer
132+
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
133+
mkdir -p dist
134+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
135+
$(KUSTOMIZE) build config/default > dist/install.yaml
136+
137+
##@ Deployment
138+
139+
ifndef ignore-not-found
140+
ignore-not-found = false
141+
endif
142+
143+
.PHONY: install
144+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
145+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
146+
147+
.PHONY: uninstall
148+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
149+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
150+
151+
.PHONY: deploy
152+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
153+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
154+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
155+
156+
.PHONY: undeploy
157+
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
158+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
159+
160+
##@ Dependencies
161+
162+
## Location to install dependencies to
163+
LOCALBIN ?= $(shell pwd)/bin
164+
$(LOCALBIN):
165+
mkdir -p $(LOCALBIN)
166+
167+
## Tool Binaries
168+
KUBECTL ?= kubectl
169+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
170+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
171+
ENVTEST ?= $(LOCALBIN)/setup-envtest
172+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
173+
174+
## Tool Versions
175+
KUSTOMIZE_VERSION ?= v5.4.3
176+
CONTROLLER_TOOLS_VERSION ?= v0.16.1
177+
ENVTEST_VERSION ?= release-0.19
178+
GOLANGCI_LINT_VERSION ?= v1.59.1
179+
180+
.PHONY: kustomize
181+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
182+
$(KUSTOMIZE): $(LOCALBIN)
183+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
184+
185+
.PHONY: controller-gen
186+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
187+
$(CONTROLLER_GEN): $(LOCALBIN)
188+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
189+
190+
.PHONY: envtest
191+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
192+
$(ENVTEST): $(LOCALBIN)
193+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
194+
195+
.PHONY: golangci-lint
196+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
197+
$(GOLANGCI_LINT): $(LOCALBIN)
198+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
199+
200+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
201+
# $1 - target path with name of binary
202+
# $2 - package url which can be installed
203+
# $3 - specific version of package
204+
define go-install-tool
205+
@[ -f "$(1)-$(3)" ] || { \
206+
set -e; \
207+
package=$(2)@$(3) ;\
208+
echo "Downloading $${package}" ;\
209+
rm -f $(1) || true ;\
210+
GOBIN=$(LOCALBIN) go install $${package} ;\
211+
mv $(1) $(1)-$(3) ;\
212+
} ;\
213+
ln -sf $(1)-$(3) $(1)
214+
endef

PROJECT

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
5+
domain: x-k8s.io
6+
layout:
7+
- go.kubebuilder.io/v4
8+
projectName: llm-instance-gateway
9+
repo: sigs.k8s.io/llm-instance-gateway
10+
resources:
11+
- api:
12+
crdVersion: v1
13+
namespaced: true
14+
domain: x-k8s.io
15+
group: inference
16+
kind: LLMServerPool
17+
path: sigs.k8s.io/llm-instance-gateway/api/v1alpha1
18+
version: v1alpha1
19+
- api:
20+
crdVersion: v1
21+
namespaced: true
22+
domain: x-k8s.io
23+
group: inference
24+
kind: LLMService
25+
path: sigs.k8s.io/llm-instance-gateway/api/v1alpha1
26+
version: v1alpha1
27+
version: "3"

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ This project is currently in development.
1010

1111
For more rapid testing, our PoC is in the `./examples/` dir.
1212

13+
14+
## Getting Started
15+
16+
**Install the CRDs into the cluster:**
17+
18+
```sh
19+
make install
20+
```
21+
22+
**Delete the APIs(CRDs) from the cluster:**
23+
24+
```sh
25+
make uninstall
26+
```
27+
28+
**Deploying the ext-proc image**
29+
Refer to this [README](https://github.com/kubernetes-sigs/llm-instance-gateway/blob/main/pkg/README.md) on how to deploy the Ext-Proc image used to support Instance Gateway.
30+
1331
## Contributing
1432

1533
Our community meeting is weekly at Th 10AM PDT; [zoom link here](https://zoom.us/j/9955436256?pwd=Z2FQWU1jeDZkVC9RRTN4TlZyZTBHZz09).

api/Dockerfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Build the manager binary
2+
FROM golang:1.22 AS builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY cmd/main.go cmd/main.go
16+
COPY api/ api/
17+
COPY internal/controller/ internal/controller/
18+
19+
# Build
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
25+
26+
# Use distroless as minimal base image to package the manager binary
27+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28+
FROM gcr.io/distroless/static:nonroot
29+
WORKDIR /
30+
COPY --from=builder /workspace/manager .
31+
USER 65532:65532
32+
33+
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)