Skip to content

Commit 4118056

Browse files
committed
First commit with supporting TFJob.
1 parent 7605c40 commit 4118056

File tree

87 files changed

+51788
-0
lines changed

Some content is hidden

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

87 files changed

+51788
-0
lines changed

.dockerignore

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

.gitignore

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

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ARG BUILDER_IMAGE
2+
ARG BASE_IMAGE
3+
# Build the manager binary
4+
FROM ${BUILDER_IMAGE} as builder
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 main.go main.go
16+
COPY pkg/ pkg/
17+
18+
# Build
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
20+
21+
FROM ${BASE_IMAGE}
22+
WORKDIR /
23+
COPY --from=builder /workspace/manager .
24+
USER 65532:65532
25+
26+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# Copyright 2022 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+
GIT_TAG ?= $(shell git describe --tags --dirty --always)
16+
# Image URL to use all building/pushing image targets
17+
IMAGE_BUILD_CMD ?= docker build
18+
IMAGE_PUSH_CMD ?= docker push
19+
IMAGE_BUILD_EXTRA_OPTS ?=
20+
IMAGE_REGISTRY ?= ccr.ccs.tencentyun.com/elastic-ai
21+
IMAGE_NAME := elastic-queue
22+
IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME)
23+
IMAGE_TAG ?= $(IMAGE_REPO):$(GIT_TAG)
24+
KUEUE_DIR ?= ./vendor/sigs.k8s.io/kueue
25+
# kubeflow training-operator for elastic-queue version
26+
TRAINING_OPERATOR_DIR ?= ./config/kubeflow/trainingoperator
27+
TRAINING_OPERATOR_IMG ?= $(IMAGE_REGISTRY)/training-operator
28+
29+
ifdef EXTRA_TAG
30+
IMAGE_EXTRA_TAG ?= $(IMAGE_REPO):$(EXTRA_TAG)
31+
endif
32+
ifdef IMAGE_EXTRA_TAG
33+
IMAGE_BUILD_EXTRA_OPTS += -t $(IMAGE_EXTRA_TAG)
34+
endif
35+
36+
# Use distroless as minimal base image to package the manager binary
37+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
38+
BASE_IMAGE ?= gcr.io/distroless/static:nonroot
39+
BUILDER_IMAGE ?= golang:1.18
40+
41+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
42+
ENVTEST_K8S_VERSION = 1.23
43+
44+
INTEGRATION_TARGET ?= ./test/integration/...
45+
46+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
47+
ifeq (,$(shell go env GOBIN))
48+
GOBIN=$(shell go env GOPATH)/bin
49+
else
50+
GOBIN=$(shell go env GOBIN)
51+
endif
52+
53+
GO_CMD ?= go
54+
GO_FMT ?= gofmt
55+
GO_TEST_FLAGS ?= -race
56+
57+
# Setting SHELL to bash allows bash commands to be executed by recipes.
58+
# This is a requirement for 'setup-envtest.sh' in the test target.
59+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
60+
SHELL = /usr/bin/env bash -o pipefail
61+
.SHELLFLAGS = -ec
62+
63+
.PHONY: all
64+
all: build
65+
66+
##@ General
67+
68+
# The help target prints out all targets with their descriptions organized
69+
# beneath their categories. The categories are represented by '##@' and the
70+
# target descriptions by '##'. The awk commands is responsible for reading the
71+
# entire set of makefiles included in this invocation, looking for lines of the
72+
# file as xyz: ## something, and then pretty-format the target and help. Then,
73+
# if there's a line with ##@ something, that gets pretty-printed as a category.
74+
# More info on the usage of ANSI control characters for terminal formatting:
75+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
76+
# More info on the awk command:
77+
# http://linuxcommand.org/lc3_adv_awk.php
78+
79+
.PHONY: help
80+
help: ## Display this help.
81+
@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)
82+
83+
##@ Development
84+
85+
.PHONY: manifests
86+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
87+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./$(KUEUE_DIR)/..." output:crd:artifacts:config=config/crd/bases
88+
89+
.PHONY: generate
90+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
91+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./$(KUEUE_DIR)/..."
92+
93+
.PHONY: fmt
94+
fmt: ## Run go fmt against code.
95+
$(GO_CMD) fmt ./...
96+
97+
.PHONY: fmt-verify
98+
fmt-verify:
99+
@out=`$(GO_FMT) -w -l -d $$(find . -name '*.go')`; \
100+
if [ -n "$$out" ]; then \
101+
echo "$$out"; \
102+
exit 1; \
103+
fi
104+
105+
.PHONY: gomod-verify
106+
gomod-verify:
107+
$(GO_CMD) mod tidy
108+
git --no-pager diff --exit-code go.mod go.sum
109+
110+
.PHONY: vet
111+
vet: ## Run go vet against code.
112+
$(GO_CMD) vet ./...
113+
114+
.PHONY: test
115+
test: generate fmt vet ## Run tests.
116+
$(GO_CMD) test $(GO_TEST_FLAGS) ./pkg/... -coverprofile cover.out
117+
118+
.PHONY: test-integration
119+
test-integration: manifests generate fmt vet envtest ginkgo ## Run tests.
120+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" \
121+
$(GINKGO) -v $(INTEGRATION_TARGET)
122+
123+
.PHONY: ci-lint
124+
ci-lint: golangci-lint
125+
$(GOLANGCI_LINT) run --timeout 7m0s
126+
127+
.PHONY: verify
128+
verify: gomod-verify vet ci-lint fmt-verify
129+
130+
##@ Build
131+
132+
.PHONY: build
133+
build: generate fmt vet ## Build manager binary.
134+
$(GO_CMD) build -o bin/manager main.go
135+
136+
.PHONY: run
137+
run: fmt vet ## Run a controller from your host.
138+
$(GO_CMD) run ./main.go
139+
140+
# Build the container image
141+
.PHONY: image-build
142+
image-build:
143+
$(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \
144+
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
145+
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
146+
$(IMAGE_BUILD_EXTRA_OPTS) ./
147+
148+
.PHONY: image-push
149+
image-push:
150+
$(IMAGE_PUSH_CMD) $(IMAGE_TAG)
151+
if [ -n "$(IMAGE_EXTRA_TAG)" ]; then \
152+
$(IMAGE_PUSH_CMD) $(IMAGE_EXTRA_TAG); \
153+
fi
154+
155+
##@ Deployment
156+
157+
ifndef ignore-not-found
158+
ignore-not-found = false
159+
endif
160+
161+
clean-manifests = (cd config/manager && $(KUSTOMIZE) edit set image controller=ccr.ccs.tencentyun.com/elastic-ai/elastic-queue:main)
162+
163+
.PHONY: install
164+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
165+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
166+
167+
.PHONY: uninstall
168+
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.
169+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
170+
171+
.PHONY: deploy
172+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
173+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE_TAG}
174+
$(KUSTOMIZE) build config/default | kubectl apply -f -
175+
@$(call clean-manifests)
176+
177+
.PHONY: undeploy
178+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
179+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
180+
181+
##@ Release
182+
.PHONY: artifacts
183+
artifacts: kustomize
184+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE_TAG}
185+
if [ -d artifacts ]; then rm -rf artifacts; fi
186+
@mkdir -p artifacts
187+
$(KUSTOMIZE) build config/default -o artifacts/manifests.yaml
188+
## Release kubeflow trainnig-operator for elastic-queue version
189+
cd $(TRAINING_OPERATOR_DIR)/overlays/standalone && $(KUSTOMIZE) edit set image kubeflow/training-operator=${TRAINING_OPERATOR_IMG}
190+
$(KUSTOMIZE) build $(TRAINING_OPERATOR_DIR)/overlays/standalone -o artifacts/kubeflow-training-operator-manifests.yaml
191+
192+
##@ Tools
193+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
194+
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
195+
.PHONY: golangci-lint
196+
golangci-lint: ## Download golangci-lint locally if necessary.
197+
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.0
198+
199+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
200+
.PHONY: controller-gen
201+
controller-gen: ## Download controller-gen locally if necessary.
202+
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0
203+
204+
KUSTOMIZE = $(shell pwd)/bin/kustomize
205+
.PHONY: kustomize
206+
kustomize: ## Download kustomize locally if necessary.
207+
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install sigs.k8s.io/kustomize/kustomize/v4@v4.5.2
208+
209+
ENVTEST = $(shell pwd)/bin/setup-envtest
210+
.PHONY: envtest
211+
envtest: ## Download envtest-setup locally if necessary.
212+
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
213+
214+
GINKGO = $(shell pwd)/bin/ginkgo
215+
.PHONY: ginkgo
216+
ginkgo: ## Download ginkgo locally if necessary.
217+
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install github.com/onsi/ginkgo/v2/ginkgo@v2.1.4

PROJECT

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
domain: elasticai.io
2+
layout:
3+
- go.kubebuilder.io/v3
4+
projectName: elastic-queue
5+
repo: elasticai.io/elastic-queue
6+
resources:
7+
- controller: true
8+
domain: elasticai.io
9+
group: kubeflow.org
10+
kind: TFJob
11+
version: v1
12+
version: "3"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# The following manifests contain a self-signed issuer CR and a certificate CR.
2+
# More document can be found at https://docs.cert-manager.io
3+
# WARNING: Targets CertManager v1.0. Check https://cert-manager.io/docs/installation/upgrading/ for breaking changes.
4+
apiVersion: cert-manager.io/v1
5+
kind: Issuer
6+
metadata:
7+
name: selfsigned-issuer
8+
namespace: system
9+
spec:
10+
selfSigned: {}
11+
---
12+
apiVersion: cert-manager.io/v1
13+
kind: Certificate
14+
metadata:
15+
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
16+
namespace: system
17+
spec:
18+
# $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize
19+
dnsNames:
20+
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc
21+
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local
22+
issuerRef:
23+
kind: Issuer
24+
name: selfsigned-issuer
25+
secretName: webhook-server-cert # this secret will not be prefixed, since it's not managed by kustomize
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resources:
2+
- certificate.yaml
3+
4+
configurations:
5+
- kustomizeconfig.yaml
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This configuration is for teaching kustomize how to update name ref and var substitution
2+
nameReference:
3+
- kind: Issuer
4+
group: cert-manager.io
5+
fieldSpecs:
6+
- kind: Certificate
7+
group: cert-manager.io
8+
path: spec/issuerRef/name
9+
10+
varReference:
11+
- kind: Certificate
12+
group: cert-manager.io
13+
path: spec/commonName
14+
- kind: Certificate
15+
group: cert-manager.io
16+
path: spec/dnsNames

0 commit comments

Comments
 (0)