Skip to content

Commit

Permalink
Merge pull request kubeflow#4 from kuikuikuizzZ/clv-2.0-helm
Browse files Browse the repository at this point in the history
feat(helm): helm chart v2
  • Loading branch information
kuikuikuizzZ authored Dec 24, 2020
2 parents fb7b161 + fd20757 commit ff0d776
Show file tree
Hide file tree
Showing 12 changed files with 443 additions and 31 deletions.
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

141 changes: 141 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Copyright 2019 The Caicloud Authors.
#
# The old school Makefile, following are required targets. The Makefile is written
# to allow building multiple binaries. You are free to add more targets or change
# existing implementations, as long as the semantics are preserved.
#
# make - default to 'build' target
# make lint - code analysis
# make test - run unit test (or plus integration test)
# make build - alias to build-local target
# make build-local - build local binary targets
# make build-linux - build linux binary targets
# make container - build containers
# $ docker login registry -u username -p xxxxx
# make push - push containers
# make clean - clean up targets
#
# Not included but recommended targets:
# make e2e-test
#
# The makefile is also responsible to populate project version information.
#

#
# Tweak the variables based on your project.
#

# This repo's root import path (under GOPATH).
ROOT := github.com/kubeflow/tf-operator

# Target binaries. You can build multiple binaries for a single project.
TARGETS := tf-operator

# Container image prefix and suffix added to targets.
# The final built images are:
# $[REGISTRY]/$[IMAGE_PREFIX]$[TARGET]$[IMAGE_SUFFIX]:$[VERSION]
# $[REGISTRY] is an item from $[REGISTRIES], $[TARGET] is an item from $[TARGETS].
IMAGE_PREFIX ?= $(strip )
IMAGE_SUFFIX ?= $(strip )

# Container registries.
REGISTRY ?= cargo.dev.caicloud.xyz/release

# Container registry for base images.
BASE_REGISTRY ?= cargo.caicloud.xyz/library

#
# These variables should not need tweaking.
#

# It's necessary to set this because some environments don't link sh -> bash.
export SHELL := /bin/bash

# It's necessary to set the errexit flags for the bash shell.
export SHELLOPTS := errexit

# Project main package location (can be multiple ones).
CMD_DIR := ./cmd

# Project output directory.
OUTPUT_DIR := ./bin

# Build direcotory.
BUILD_DIR := ./build

# Current version of the project.
VERSION ?= $(shell git describe --tags --always --dirty)

# Available cpus for compiling, please refer to https://github.com/caicloud/engineering/issues/8186#issuecomment-518656946 for more information.
CPUS ?= $(shell /bin/bash hack/read_cpus_available.sh)

# Track code version with Docker Label.
DOCKER_LABELS ?= git-describe="$(shell date -u +v%Y%m%d)-$(shell git describe --tags --always --dirty)"

# Golang standard bin directory.
GOPATH ?= $(shell go env GOPATH)
BIN_DIR := $(GOPATH)/bin
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint

#
# Define all targets. At least the following commands are required:
#

# All targets.
.PHONY: lint test build container push

build: build-local

# more info about `GOGC` env: https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint
lint: $(GOLANGCI_LINT)
@$(GOLANGCI_LINT) run

$(GOLANGCI_LINT):
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(BIN_DIR) v1.20.1

test:
@go test -p $(CPUS) $$(go list ./... | grep -v /vendor | grep -v /test) -coverprofile=coverage.out
@go tool cover -func coverage.out | tail -n 1 | awk '{ print "Total coverage: " $$3 }'

build-local:
@for target in $(TARGETS); do \
go build -i -v -o $(OUTPUT_DIR)/$${target} -p $(CPUS) \
-ldflags "-s -w -X $(ROOT)/pkg/version.VERSION=$(VERSION) \
-X $(ROOT)/pkg/version.REPOROOT=$(ROOT)" \
$(CMD_DIR)/$${target}; \
done

build-linux:
@docker run --rm \
-v $(PWD):/go/src/$(ROOT) \
-w /go/src/$(ROOT) \
-e GOOS=linux \
-e GOARCH=amd64 \
-e GOPATH=/go \
-e SHELLOPTS=$(SHELLOPTS) \
-e CGO_ENABLED="0" \
$(BASE_REGISTRY)/golang:1.13-security \
/bin/bash -c 'for target in $(TARGETS); do \
go build -i -v -o $(OUTPUT_DIR)/$${target} -p $(CPUS) \
-ldflags "-s -w -X $(ROOT)/pkg/version.VERSION=$(VERSION) \
-X $(ROOT)/pkg/version.REPOROOT=$(ROOT)" \
$(CMD_DIR)/$${target}.v1; \
done'

container: build-linux
@for target in $(TARGETS); do \
image=$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX); \
docker build -t $(REGISTRY)/$${image}:$(VERSION) \
--label $(DOCKER_LABELS) \
-f $(BUILD_DIR)/$${target}/Dockerfile .; \
done

push: container
@for target in $(TARGETS); do \
image=$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX); \
docker push $(REGISTRY)/$${image}:$(VERSION); \
done

.PHONY: clean
clean:
@-rm -vrf ${OUTPUT_DIR}
11 changes: 11 additions & 0 deletions build/tf-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Copyright 2018 The Caicloud Authors.
#

FROM cargo.caicloud.xyz/library/debian:stretch

LABEL maintainer="Ce Gao <[email protected]>"

ADD bin/tf-operator /tf-operator

ENTRYPOINT ["/tf-operator"]
22 changes: 22 additions & 0 deletions hack/read_cpus_available.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

CPUS_AVAILABLE=1

case "$(uname -s)" in
Darwin)
CPUS_AVAILABLE=$(sysctl -n machdep.cpu.core_count)
;;
Linux)
CFS_QUOTA=$(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)
if [ $CFS_QUOTA -ge 100000 ]; then
CPUS_AVAILABLE=$(expr ${CFS_QUOTA} / 100 / 1000)
fi
;;
*)
# Unsupported host OS. Must be Linux or Mac OS X.
;;
esac

echo ${CPUS_AVAILABLE}
12 changes: 12 additions & 0 deletions manifests/tf-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 固定值
apiVersion: v2
# 组件名称
name: tf-operator
# chart 描述
description: A helm chart for tf-operator addon
# 固定值
type: application
# 组件版本号
appVersion: v1.0.3
# chart 版本号,与组件版本号 appVersion 字段保持一致
version: v1.0.3
89 changes: 89 additions & 0 deletions manifests/tf-operator/templates/_container.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{{- define "container.image" }}
{{- $imageRegistry := .platformConfig.imageRegistry }}
{{- $imageRepository := .platformConfig.imageRepositoryRelease }}
{{- $imageName := (default .context.Chart .image.name )}}
{{- $imageTag := (default .context.Chart.AppVersion .image.tag )}}
{{- $imagePullPolicy := (default "Always" .platformConfig.imagePullPolicy )}}
image: {{ $imageRegistry }}/{{ $imageRepository }}/{{ $imageName }}:{{ $imageTag }}
imagePullPolicy: {{ $imagePullPolicy }}
{{- end }}

{{- define "container.container" }}
{{- $context := .context }}
- name: {{ .containerName }}
{{- include "container.image" (dict "image" .container.image "context" $context "platformConfig" .context.Values.platformConfig) | indent 2 }}
env:
- name: "POD_NAME"
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- if .container.env }}
{{- include "common.tplvalues.render" (dict "value" .container.env "context" $context) | nindent 2 }}
{{- end }}
{{- if .container.command }}
command: {{- include "common.tplvalues.render" (dict "value" .container.command "context" $context) | nindent 2 }}
{{- end }}
{{- if .container.args }}
args: {{- include "common.tplvalues.render" (dict "value" .container.args "context" $context) | nindent 2 }}
{{- end }}
{{- if .container.ports }}
ports:
{{- range $portName, $port := .container.ports }}
- name: {{ $portName }}
{{- include "common.tplvalues.render" (dict "value" $port "context" $context) | nindent 4 }}
{{- end }}
{{- end }}
{{- if .container.livenessProbe }}
livenessProbe:
{{- if .container.livenessProbe.useDefault }}
initialDelaySeconds: 10
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
httpGet:
path: /healthz?type=liveness
port: 8080
{{- else }}
{{- include "common.tplvalues.render" (dict "value" (omit .container.livenessProbe "useDefault") "context" $context) | nindent 4 }}
{{- end }}
{{- end }}
{{- if .container.readinessProbe }}
readinessProbe:
{{- if .container.readinessProbe.useDefault }}
initialDelaySeconds: 10
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
httpGet:
path: /healthz?type=liveness
port: 8080
{{- else }}
{{- include "common.tplvalues.render" (dict "value" (omit .container.readinessProbe "useDefault") "context" $context) | nindent 4 }}
{{- end }}
{{- end }}
{{- if .container.resources }}
resources:
{{- if .container.resources.useDefault }}
limits:
cpu: 100m
memory: 200Mi
requests:
cpu: 50m
memory: 100Mi
{{- else }}
{{- include "common.tplvalues.render" (dict "value" (omit .container.resources "useDefault") "context" $context) | nindent 4 }}
{{- end }}
{{- end }}
{{- if .container.mounts }}
volumeMounts:
{{- range $mountName, $mount := .container.mounts }}
- name: {{ $mountName }}
mountPath: {{ $mount.path }}
{{- if $mount.subPath }}
subPath: {{ $mount.subPath }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions manifests/tf-operator/templates/_deployment.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- define "deployment.labels" }}
labels: {{- include "common.labels.standard" .context | nindent 2 }}
{{- if .commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .commonLabels "context" .context ) | nindent 2 }}
{{- end }}
{{- end }}

{{- define "deployment.annotations" }}
{{- if .commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .commonAnnotations "context" .context ) | nindent 2 }}
{{- end }}
{{- end }}
21 changes: 21 additions & 0 deletions manifests/tf-operator/templates/_labels.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Kubernetes standard labels
*/}}
{{- define "common.labels.standard" -}}
helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
{{- end }}

{{/*
Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
*/}}
{{- define "common.labels.matchLabels" -}}
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
Loading

0 comments on commit ff0d776

Please sign in to comment.