Skip to content

Commit

Permalink
Deployment.
Browse files Browse the repository at this point in the history
  • Loading branch information
yongzhi.yang committed Jun 20, 2019
1 parent ca04b14 commit 13cf089
Show file tree
Hide file tree
Showing 1,854 changed files with 283,444 additions and 30,420 deletions.
99 changes: 99 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#
# make - default to 'build' target
# make test - run unit test
# make build - build local binary targets
# make docker-build - build local binary targets by docker
# make container - build containers
# make push - push containers
# make clean - clean up targets
#
# The makefile is also responsible to populate project version information.

#
# Tweak the variables based on your project.
#

# Current version of the project.
VERSION ?= v0.0.1

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

# Container registries.
# REGISTRIES := hub.tencentyun.com/xkcp0324/
REGISTRIES := hub.tencentyun.com/demo001/

# 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 )

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

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

# Project output directory.
OUTPUT_DIR := ./bin

# docker file direcotory.
DOCKER_DIR := ./docker

# Git commit sha.
COMMIT := $(strip $(shell git rev-parse --short HEAD 2>/dev/null))
COMMIT := $(COMMIT)$(shell git diff-files --quiet || echo '-dirty')
COMMIT := $(if $(COMMIT),$(COMMIT),"Unknown")


GO_VERSION := 1.12.5
ARCH ?= $(shell go env GOARCH)
BuildDate = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
Commit = $(shell git rev-parse --short HEAD)
GOENV := GO111MODULE=on CGO_ENABLED=0 GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH)
GO := $(GOENV) go build -mod=vendor

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

.PHONY: build container push test clean

build:
$(GO) -v -o $(OUTPUT_DIR)/$(TARGETS) -ldflags "-s -w " .

mod-reset-vendor:
@$(shell [ -f go.mod ] && go mod vendor)

docker-build:
docker run --rm -v "$$PWD":/go/src/${ROOT} -w /go/src/${ROOT} \
hub.tencentyun.com/xkcp0324/golang:${GO_VERSION} make build

container:
@for target in $(TARGETS); do \
for registry in $(REGISTRIES); do \
image=$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX); \
docker build -t $${registry}$${image}:$(VERSION) \
--build-arg ROOT=$(ROOT) --build-arg TARGET=$${target} \
--build-arg CMD_DIR=$(CMD_DIR) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
-f $(DOCKER_DIR)/$${target}/Dockerfile .; \
done \
done

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

test:
@go test ./...

clean:
@rm -vrf ${OUTPUT_DIR}/*
Binary file added bin/sym-operator
Binary file not shown.
22 changes: 22 additions & 0 deletions charts/sym-operator/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions charts/sym-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "0.0.1"
description: The operator for symphony
name: sym-operator
version: 0.0.1
Empty file.
32 changes: 32 additions & 0 deletions charts/sym-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "sym-operator.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "sym-operator.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "sym-operator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
40 changes: 40 additions & 0 deletions charts/sym-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sym-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "sym-operator.name" . }}
helm.sh/chart: {{ include "sym-operator.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "sym-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "sym-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
serviceAccountName: {{ template "sym-operator.name" . }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
29 changes: 29 additions & 0 deletions charts/sym-operator/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if .Values.rbac.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "sym-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "sym-operator.name" . }}
helm.sh/chart: {{ include "sym-operator.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/name: {{ include "sym-operator.name" . }}
helm.sh/chart: {{ include "sym-operator.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ template "sym-operator.fullname" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: {{ template "sym-operator.fullname" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
19 changes: 19 additions & 0 deletions charts/sym-operator/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "sym-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "sym-operator.name" . }}
helm.sh/chart: {{ include "sym-operator.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "sym-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
39 changes: 39 additions & 0 deletions charts/sym-operator/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Default values for sym-operator.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: hub.tencentyun.com/demo001/sym-operator
tag: v0.0.1
pullPolicy: IfNotPresent

nameOverride: ""
fullnameOverride: ""

service:
type: ClusterIP
port: 80

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

rbac:
create: true
serviceAccountName: default
13 changes: 13 additions & 0 deletions docker/sym-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.9
MAINTAINER yongzhi <[email protected]>

RUN apk add --no-cache tzdata curl busybox-extras && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai">>/etc/timezone

COPY bin/sym-operator /sym-operator

EXPOSE 8080

ENTRYPOINT ["/sym-operator"]

9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"flag"
"github.com/yangyongzhi/sym-operator/pkg/helm"
"k8s.io/client-go/rest"
"os"
"time"

Expand Down Expand Up @@ -47,8 +48,14 @@ func main() {

// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler()
var cfg *rest.Config
var err error
if kubeconfig != "" {
cfg, err = clientcmd.BuildConfigFromFlags(masterURL, kubeconfig) // out of cluster config
} else {
cfg, err = rest.InClusterConfig()
}

cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
if err != nil {
klog.Fatalf("Error building kubeconfig: %s", err.Error())
}
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/Azure/go-ansiterm/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/Azure/go-ansiterm/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 13cf089

Please sign in to comment.