Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Dockerfile for each component + helm for executor #37

Merged
merged 19 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5309100
Adding test dockerfile
JamesMurkin Jul 29, 2019
ad4faf8
Building dockerfile in circleci
JamesMurkin Jul 29, 2019
8991952
Setting docker to ON in cirlcleci
JamesMurkin Jul 29, 2019
8e1aef9
Add Dockerfile for Armada and Dockerfiles to use multistage build
JamesMurkin Jul 30, 2019
7ef3507
Allowing users to specify the location of their configuration file
JamesMurkin Jul 30, 2019
2ebd83c
Allowing kubernetes connection config location to be specified in the…
JamesMurkin Jul 30, 2019
75ca6b7
Adding git hash as docker image tag
JamesMurkin Jul 30, 2019
5cce24d
Setting working_directory to something sensible
JamesMurkin Jul 30, 2019
ebc4a87
Renaming executor config configLocation to kubernetesConfigLocation t…
JamesMurkin Jul 30, 2019
e3508a1
Making working_directory set from CIRCLE CI values
JamesMurkin Jul 30, 2019
b9592e9
Removing circleci variables from working_directory
JamesMurkin Jul 30, 2019
3a4c665
Setting entrypoint rather than cmd in dockerfiles
JamesMurkin Jul 31, 2019
f13de3f
Simplifying LoadConfig to use full path of overrideConfig
JamesMurkin Jul 31, 2019
b01085a
Adding helm chart for executor component
JamesMurkin Jul 31, 2019
57ea8a3
Setting default helm chart applicationConfig to blank
JamesMurkin Jul 31, 2019
07c53ba
Merge branch 'master' into dockerfile-test
JamesMurkin Aug 1, 2019
38f51be
Moving inCluster and kubeConfigPath to command line flags rather than…
JamesMurkin Aug 1, 2019
7e68874
Setting executor helm to run in inCluster mode
JamesMurkin Aug 1, 2019
7bd40aa
Renaming executor helm chart to just be "executor" rather than "armad…
JamesMurkin Aug 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ jobs:
#### expecting it in the form of
#### /go/src/github.com/circleci/go-tool
#### /go/src/bitbucket.org/circleci/go-tool
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
working_directory: /go/src/github.com/G-Research/k8s-batch
steps:
- checkout
- setup_remote_docker

# specify any bash command here prefixed with `run: `
- run: go get -v -d ./...
- run: go test -v ./...
- run: exit $(gofmt -l . | wc -l)
- run: docker build -t executor:${CIRCLE_SHA1} -f ./build/executor/Dockerfile .
19 changes: 19 additions & 0 deletions build/armada/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.12.6 as builder

RUN mkdir /app

ADD . /app

WORKDIR /app

RUN env GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -o main cmd/armada/main.go

FROM alpine:3.10

COPY --from=builder /app/main /app/

COPY --from=builder /app/config /app/config

WORKDIR /app

ENTRYPOINT ["./main"]
19 changes: 19 additions & 0 deletions build/executor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.12.6 as builder

RUN mkdir /app

ADD . /app

WORKDIR /app

RUN env GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -o main cmd/executor/main.go

FROM alpine:3.10

COPY --from=builder /app/main /app/

COPY --from=builder /app/config /app/config

WORKDIR /app

ENTRYPOINT ["./main"]
15 changes: 13 additions & 2 deletions cmd/armada/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ import (
"github.com/G-Research/k8s-batch/internal/armada/configuration"
"github.com/G-Research/k8s-batch/internal/common"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"os"
"os/signal"
"syscall"
)

func main() {
const CustomConfigLocation string = "config"

func init() {
pflag.String(CustomConfigLocation, "", "Fully qualified path to application configuration file")
pflag.Parse()
}

func main() {
common.ConfigureLogging()
common.BindCommandlineArguments()

var config configuration.ArmadaConfig
common.LoadConfig(&config, "./config/armada")
userSpecifiedConfig := viper.GetString(CustomConfigLocation)
common.LoadConfig(&config, "./config/armada", userSpecifiedConfig)

log.Info("Starting...")

Expand Down
33 changes: 30 additions & 3 deletions cmd/executor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@ import (
"github.com/G-Research/k8s-batch/internal/common"
"github.com/G-Research/k8s-batch/internal/executor"
"github.com/G-Research/k8s-batch/internal/executor/configuration"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"os"
"os/signal"
"syscall"
)

func main() {
const CustomConfigLocation string = "config"
const InCluster string = "inCluster"
const KubeConfig string = "kubeConfigPath"

func init() {
pflag.String(CustomConfigLocation, "", "Fully qualified path to application configuration file")
pflag.Bool(InCluster, false, "When set executor will run using in cluster client connection details")
pflag.String(KubeConfig, "", "Fully qualified path to custom kube config file")
pflag.Parse()
}

func main() {
common.ConfigureLogging()
var config configuration.ExecutorConfiguration
common.LoadConfig(&config, "./config/executor")
common.BindCommandlineArguments()
config := loadConfig()

shutdownChannel := make(chan os.Signal, 1)
signal.Notify(shutdownChannel, syscall.SIGINT, syscall.SIGTERM)
Expand All @@ -25,3 +37,18 @@ func main() {
}()
wg.Wait()
}

func loadConfig() configuration.ExecutorConfiguration {
var config configuration.ExecutorConfiguration
userSpecifiedConfig := viper.GetString(CustomConfigLocation)
common.LoadConfig(&config, "./config/executor", userSpecifiedConfig)

inClusterDeployment := viper.GetBool(InCluster)
customKubeConfigLocation := viper.GetString(KubeConfig)

config.Kubernetes = configuration.KubernetesConfiguration{
InClusterDeployment: inClusterDeployment,
KubernetesConfigLocation: customKubeConfigLocation,
}
return config
}
1 change: 0 additions & 1 deletion config/executor/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
application:
clusterId : "Cluster1"
inClusterDeployment: false
task:
utilisationReportingInterval: 10s
missingJobEventReconciliationInterval: 10s
Expand Down
4 changes: 4 additions & 0 deletions deployment/executor/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
appVersion : v1
description: A helm chart for armada-executor component
name: executor
version: 0.0.1
35 changes: 35 additions & 0 deletions deployment/executor/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

{{- define "executor.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "executor.config.name" -}}
{{- printf "%s-%s" ( include "executor.name" .) "config" -}}
{{- end }}

{{- define "executor.application.config.filename" -}}
{{- printf "%s%s" ( include "executor.config.name" .) ".yaml" -}}
{{- end }}


{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "executor.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "executor.labels.identity" -}}
app: {{ include "executor.name" . }}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "executor.labels.all" -}}
{{ include "executor.labels.identity" . }}
chart: {{ include "executor.chart" . }}
release: {{ .Release.Name }}
{{- end -}}


29 changes: 29 additions & 0 deletions deployment/executor/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "executor.name" . }}
labels:
{{ include "executor.labels.all" . | indent 4 }}
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
- create
- delete
- deletecollection
- patch
- update
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch

15 changes: 15 additions & 0 deletions deployment/executor/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "executor.name" . }}
labels:
{{ include "executor.labels.all" . | indent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "executor.name" . }}
subjects:
- kind: ServiceAccount
name: {{ include "executor.name" . }}
namespace: {{ .Release.Namespace }}

12 changes: 12 additions & 0 deletions deployment/executor/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "executor.config.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "executor.labels.all" . | indent 4 }}
data:
{{ include "executor.application.config.filename" . }}: |
{{- if .Values.applicationConfig }}
{{ toYaml .Values.applicationConfig | indent 4 }}
{{- end }}
38 changes: 38 additions & 0 deletions deployment/executor/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "executor.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "executor.labels.all" . | indent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{ include "executor.labels.identity" . | indent 6 }}
template:
metadata:
name: {{ include "executor.name" . }}
labels:
{{ include "executor.labels.all" . | indent 8 }}
spec:
terminationGracePeriodSeconds: {{ .Values.executor.terminationGracePeriodSeconds }}
serviceAccountName: {{ include "executor.name" . }}
containers:
- name: executor
imagePullPolicy: IfNotPresent
image: {{ .Values.executor.image.repository }}:{{ required "A value is required for .Values.executor.image.tag" .Values.executor.image.tag }}
args:
- --config
- /config/application_config.yaml
- --inCluster
resources:
{{ toYaml .Values.executor.resources | indent 12 }}
volumeMounts:
- name: user-config
mountPath: /config/application_config.yaml
subPath: {{ include "executor.application.config.filename" . }}
volumes:
- name: user-config
configMap:
name: {{ include "executor.config.name" . }}
6 changes: 6 additions & 0 deletions deployment/executor/templates/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Namespace
apiVersion: v1
metadata:
name: {{ .Release.Namespace }}
labels:
{{ include "executor.labels.all" . | indent 4 }}
7 changes: 7 additions & 0 deletions deployment/executor/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "executor.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "executor.labels.all" . | indent 4 }}
14 changes: 14 additions & 0 deletions deployment/executor/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
executor:
image:
repository: executor-test
tag: latest
resources:
limits:
memory: 1Gi
cpu: 300m
requests:
memory: 512Mi
cpu: 200m
terminationGracePeriodSeconds: 0

applicationConfig:
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/kjk/betterguid v0.0.0-20170621091430-c442874ba63a
github.com/oklog/ulid v1.3.1
github.com/sirupsen/logrus v1.2.0
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.3.0
github.com/yuin/gopher-lua v0.0.0-20190514113301-1cd887cd7036 // indirect
Expand Down
24 changes: 22 additions & 2 deletions internal/common/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,37 @@ package common

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"os"
)

func LoadConfig(config interface{}, path string) {
func BindCommandlineArguments() {
err := viper.BindPFlags(pflag.CommandLine)
if err != nil {
log.Error()
os.Exit(-1)
}
}

func LoadConfig(config interface{}, defaultPath string, overrideConfig string) {
viper.SetConfigName("config")
viper.AddConfigPath(path)
viper.AddConfigPath(defaultPath)
if err := viper.ReadInConfig(); err != nil {
log.Error(err)
os.Exit(-1)
}

if overrideConfig != "" {
viper.SetConfigFile(overrideConfig)

err := viper.MergeInConfig()
if err != nil {
log.Error(err)
os.Exit(-1)
}
}

err := viper.Unmarshal(config)
if err != nil {
log.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/executor/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func StartUp(config configuration.ExecutorConfiguration) (func(), *sync.WaitGroup) {
kubernetesClient, err := CreateKubernetesClientWithDefaultConfig(config.Application.InClusterDeployment)
kubernetesClient, err := CreateKubernetesClient(&config.Kubernetes)
if err != nil {
log.Errorf("Failed to connect to kubernetes because %s", err)
os.Exit(-1)
Expand Down
9 changes: 7 additions & 2 deletions internal/executor/configuration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package configuration
import "time"

type ApplicationConfiguration struct {
ClusterId string
InClusterDeployment bool
ClusterId string
}

type KubernetesConfiguration struct {
InClusterDeployment bool
KubernetesConfigLocation string
}

type TaskConfiguration struct {
Expand All @@ -24,6 +28,7 @@ type EventsConfiguration struct {

type ExecutorConfiguration struct {
Application ApplicationConfiguration
Kubernetes KubernetesConfiguration
Task TaskConfiguration
Armada ArmadaConfiguration
Events EventsConfiguration
Expand Down
Loading