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

Merge with native kubernetes executor #1

Merged
merged 28 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
503cf27
build(deps): bump terser from 4.8.0 to 4.8.1 in /webdash (#677)
dependabot[bot] May 11, 2023
cfc7221
build(deps): bump minimist from 1.2.5 to 1.2.8 in /webdash (#676)
dependabot[bot] May 11, 2023
af6254f
build(deps): bump golang.org/x/crypto (#675)
dependabot[bot] May 11, 2023
e5e5af7
build(deps): bump github.com/prometheus/client_golang (#673)
dependabot[bot] May 11, 2023
c295d2e
build(deps): bump github.com/aws/aws-sdk-go from 1.13.54 to 1.34.0 (#…
dependabot[bot] May 11, 2023
9bdc529
build(deps): bump k8s.io/client-go from 0.17.0 to 0.20.0 (#670)
dependabot[bot] May 11, 2023
22d6e18
build(deps): bump github.com/docker/docker (#695)
dependabot[bot] May 11, 2023
29cb2ef
build(deps): bump github.com/docker/distribution (#694)
dependabot[bot] May 11, 2023
de7325a
build(deps): bump golang.org/x/crypto (#696)
dependabot[bot] May 11, 2023
fbe75d4
build(deps): bump json5 from 1.0.1 to 1.0.2 in /webdash (#678)
dependabot[bot] May 11, 2023
f009843
build(deps): bump decode-uri-component from 0.2.0 to 0.2.2 in /webdas…
dependabot[bot] May 11, 2023
05a527d
build(deps): bump ua-parser-js from 0.7.28 to 0.7.35 in /webdash (#697)
dependabot[bot] May 11, 2023
baf83cc
Revert dependabot updates to go.sum and go.mod
lbeckman314 May 15, 2023
7eca441
Create dependabot.yml (#724)
lbeckman314 Nov 7, 2023
444d181
build(deps): bump tough-cookie from 4.0.0 to 4.1.3 in /webdash (#717)
dependabot[bot] Nov 7, 2023
07b90c7
build(deps): bump semver from 5.7.1 to 5.7.2 in /webdash (#719)
dependabot[bot] Nov 8, 2023
db8fe44
build(deps): bump word-wrap from 1.2.3 to 1.2.4 in /webdash (#720)
dependabot[bot] Nov 8, 2023
e6a5ef9
build(deps): bump golang.org/x/net (#731)
dependabot[bot] Nov 8, 2023
937d279
build(deps): bump browserify-sign from 4.2.1 to 4.2.2 in /webdash (#732)
dependabot[bot] Nov 8, 2023
7663804
build(deps): bump @babel/traverse from 7.15.0 to 7.23.2 in /webdash (…
dependabot[bot] Nov 8, 2023
a299356
build(deps): bump github.com/docker/docker (#733)
dependabot[bot] Nov 8, 2023
d8d0454
build(deps): bump google.golang.org/grpc from 1.27.1 to 1.56.3 (#734)
dependabot[bot] Nov 8, 2023
4b127af
Upgrade kubernetes client library version to v0.28.4
KrKOo Dec 5, 2023
6dc4216
Upgrade golang version in Dockerfiles to 1.21.4
KrKOo Dec 5, 2023
c81be57
Add build and dependency caching to Dockerfiles
KrKOo Dec 11, 2023
f9b831c
Add native kubernetes task execution support
KrKOo Dec 11, 2023
ef5764d
Remove useless methods from KubernetesCommand
KrKOo Dec 12, 2023
29da010
Update Docker.ContainerStop() call after docker library update
KrKOo Jan 19, 2024
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
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
# Raise pull requests for version updates against the `develop` branch
target-branch: "develop"
24 changes: 12 additions & 12 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ on: [ pull_request ]
jobs:

lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Lint dependencies
run: make lint-depends

- name: Lint
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make lint
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
args: --timeout 3m --verbose

build:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
go-version: ^1.18

- name: Check out code
uses: actions/checkout@v2
Expand All @@ -44,7 +44,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
go-version: ^1.18
- name: Check out code
uses: actions/checkout@v2
- name: Unit Tests
Expand Down
16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# build stage
FROM golang:1.13.8-alpine AS build-env
FROM golang:1.21.4-alpine AS build-env
RUN apk add make git bash build-base
ENV GOPATH=/go
ENV PATH="/go/bin:${PATH}"
ADD ./ /go/src/github.com/ohsu-comp-bio/funnel
RUN cd /go/src/github.com/ohsu-comp-bio/funnel && make build

WORKDIR /go/src/github.com/ohsu-comp-bio/funnel
COPY go.* .
RUN go mod download
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build make build

# final stage
FROM debian
RUN apt-get update && apt-get install -y --no-install-recommends curl python3-pip && pip3 install htsget --break-system-packages && rm -rf ~/.cache
WORKDIR /opt/funnel
VOLUME /opt/funnel/funnel-work-dir
EXPOSE 8000 9090
ENV PATH="/app:${PATH}"
COPY --from=build-env /go/src/github.com/ohsu-comp-bio/funnel/funnel /app/
RUN apt-get update && apt-get install -y --no-install-recommends podman curl python3-pip && pip3 install htsget && rm -rf ~/.cache
ADD https://raw.githubusercontent.com/containers/libpod/master/contrib/podmanimage/stable/containers.conf /etc/containers/containers.conf
RUN ln -s /usr/bin/podman /usr/bin/docker

ENTRYPOINT [ "/app/funnel" ]
22 changes: 22 additions & 0 deletions Dockerfile.dind
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# build stage
FROM golang:1.21.4-alpine AS build-env
RUN apk add make git bash build-base
ENV GOPATH=/go
ENV PATH="/go/bin:${PATH}"

WORKDIR /go/src/github.com/ohsu-comp-bio/funnel
COPY go.* .
RUN go mod download
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build make build

# final stage
FROM docker:stable-dind
WORKDIR /opt/funnel
VOLUME /opt/funnel/funnel-work-dir
EXPOSE 8000 9090
ENV PATH="/app:${PATH}"
COPY --from=build-env /go/src/github.com/ohsu-comp-bio/funnel/funnel /app/
ADD ./deployments/kubernetes/dind/entrypoint.sh /usr/local/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]
22 changes: 22 additions & 0 deletions Dockerfile.dind-rootless
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# build stage
FROM golang:1.21.4-alpine AS build-env
RUN apk add make git bash build-base
ENV GOPATH=/go
ENV PATH="/go/bin:${PATH}"

WORKDIR /go/src/github.com/ohsu-comp-bio/funnel
COPY go.* .
RUN go mod download
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build make build

# final stage
FROM docker:stable-dind-rootless
WORKDIR /opt/funnel
VOLUME /opt/funnel/funnel-work-dir
EXPOSE 8000 9090
ENV PATH="/app:${PATH}"
COPY --from=build-env /go/src/github.com/ohsu-comp-bio/funnel/funnel /app/
ADD ./deployments/kubernetes/dind-rootless/entrypoint.sh /usr/local/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]
2 changes: 2 additions & 0 deletions cmd/util/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ func computeFlags(flagConf *config.Config) *pflag.FlagSet {
f.Var(&flagConf.Scheduler.NodeDeadTimeout, "Scheduler.NodeDeadTimeout", "How long to wait before deleting a dead node from the DB")

// Kubernetes
f.StringVar(&flagConf.Kubernetes.Executor, "Kubernetes.Executor", flagConf.Kubernetes.Executor, "Executor to use for executing tasks (docker or kubernetes)")
f.StringVar(&flagConf.Kubernetes.ExecutorTemplateFile, "Kubernetes.ExecutorTemplateFile", flagConf.Kubernetes.ExecutorTemplateFile, "Path to executor job template file")
f.StringVar(&flagConf.Kubernetes.TemplateFile, "Kubernetes.TemplateFile", flagConf.Kubernetes.TemplateFile, "Path to job template file")
f.StringVar(&flagConf.Kubernetes.Namespace, "Kubernetes.Namespace", flagConf.Kubernetes.Namespace, "Namespace to spawn jobs within")
f.StringVar(&flagConf.Kubernetes.ConfigFile, "Kubernetes.ConfigFile", flagConf.Kubernetes.ConfigFile, "Path to kubernetes config file")
Expand Down
29 changes: 25 additions & 4 deletions cmd/worker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package worker
import (
"context"
"fmt"
"io/ioutil"
"strings"

"github.com/ohsu-comp-bio/funnel/config"
Expand Down Expand Up @@ -70,11 +71,31 @@ func NewWorker(ctx context.Context, conf config.Config, log *logger.Logger, opts
}
store.AttachLogger(log)

if conf.Kubernetes.ExecutorTemplateFile != "" {
content, err := ioutil.ReadFile(conf.Kubernetes.ExecutorTemplateFile)
if err != nil {
return nil, fmt.Errorf("reading template: %v", err)
}
conf.Kubernetes.ExecutorTemplate = string(content)
}

// The executor always defaults to docker, unless explicitly set to kubernetes.
var executor = worker.Executor{
Backend: "docker",
}

if conf.Kubernetes.Executor == "kubernetes" {
executor.Backend = "kubernetes"
executor.Template = conf.Kubernetes.ExecutorTemplate
executor.Namespace = conf.Kubernetes.Namespace
}

return &worker.DefaultWorker{
Conf: conf.Worker,
Store: store,
TaskReader: reader,
EventWriter: writer,
Executor: executor,
Conf: conf.Worker,
Store: store,
TaskReader: reader,
EventWriter: writer,
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions compute/kubernetes/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (b *Backend) Submit(task *tes.Task) error {
if err != nil {
return fmt.Errorf("creating job spec: %v", err)
}
_, err = b.client.Create(job)
_, err = b.client.Create(context.TODO(), job, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("creating job: %v", err)
}
Expand All @@ -163,7 +163,7 @@ func (b *Backend) Submit(task *tes.Task) error {
func (b *Backend) deleteJob(taskID string) error {
var gracePeriod int64 = 0
var prop metav1.DeletionPropagation = metav1.DeletePropagationForeground
err := b.client.Delete(taskID, &metav1.DeleteOptions{
err := b.client.Delete(context.TODO(), taskID, metav1.DeleteOptions{
GracePeriodSeconds: &gracePeriod,
PropagationPolicy: &prop,
})
Expand Down Expand Up @@ -215,7 +215,7 @@ ReconcileLoop:
case <-ctx.Done():
return
case <-ticker.C:
jobs, err := b.client.List(metav1.ListOptions{})
jobs, err := b.client.List(context.TODO() ,metav1.ListOptions{})
if err != nil {
b.log.Error("reconcile: listing jobs", err)
continue ReconcileLoop
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ func (h HTSGETStorage) Valid() bool {

// Kubernetes describes the configuration for the Kubernetes compute backend.
type Kubernetes struct {
// The executor used to execute tasks. Available executors: docker, kubernetes
Executor string
// Turn off task state reconciler. When enabled, Funnel communicates with Kuberenetes
// to find tasks that are stuck in a queued state or errored and updates the task state
// accordingly.
Expand All @@ -411,6 +413,10 @@ type Kubernetes struct {
Template string
// TemplateFile is the path to the job template.
TemplateFile string
// Job template used for executing the tasks.
ExecutorTemplate string
// ExecutorTemplateFile is the path to the executor template.
ExecutorTemplateFile string
// Path to the Kubernetes configuration file, otherwise assumes the Funnel server is running in a pod and
// attempts to use https://godoc.org/k8s.io/client-go/rest#InClusterConfig to infer configuration.
ConfigFile string
Expand Down
23 changes: 16 additions & 7 deletions config/default-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Compute: local

# The name of the active event writer backend(s).
# Available backends: log, boltdb, badger, datastore, dynamodb, elastic, mongodb, kafka
EventWriters:
EventWriters:
- boltdb
- log

Expand Down Expand Up @@ -42,7 +42,7 @@ Server:
DisableHTTPCache: true

RPCClient:
# RPC server address
# RPC server address
ServerAddress: localhost:9090

# Credentials for Basic authentication for the server APIs using a password.
Expand All @@ -59,7 +59,7 @@ RPCClient:
# up to 1 minute
MaxRetries: 10

# The scheduler is used for the Manual compute backend.
# The scheduler is used for the Manual compute backend.
Scheduler:
# How often to run a scheduler iteration.
ScheduleRate: 1s
Expand All @@ -78,7 +78,7 @@ Node:
# -1 means there is no timeout. 0 means timeout immediately after the first task.
Timeout: -1s

# A Node will automatically try to detect what resources are available to it.
# A Node will automatically try to detect what resources are available to it.
# Defining Resources in the Node configuration overrides this behavior.
Resources:
# CPUs available.
Expand Down Expand Up @@ -149,7 +149,7 @@ Datastore:
# Optional. If possible, credentials will be automatically discovered
# from the environment.
CredentialsFile: ""

MongoDB:
# Addrs holds the addresses for the seed servers.
Addrs:
Expand Down Expand Up @@ -298,6 +298,8 @@ AWSBatch:

# Kubernetes describes the configuration for the Kubernetes compute backend.
Kubernetes:
# The executor used to execute tasks. Available executors: docker, kubernetes
Executor: "docker"
# Turn off task state reconciler. When enabled, Funnel communicates with Kubernetes
# to find tasks that are stuck in a queued state or errored and
# updates the task state accordingly.
Expand All @@ -307,11 +309,18 @@ Kubernetes:
ReconcileRate: 10m
# Kubernetes Namespace to spawn jobs within
Namespace: ""
# Batch job template. See: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#job-v1-batch
# Master batch job template. See: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#job-v1-batch
Template: ""
# TemplateFile is the path to the job template.
# TemplateFile is the path to the master job template.
TemplateFile: ""

# Configuration of the Kubernetes executor.

# Job template used for executing the tasks.
ExecutorTemplate: ""
# ExecutorTemplateFile is the path to the executor template.
ExecutorTemplateFile: ""

#-------------------------------------------------------------------------------
# Storage
#-------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func DefaultConfig() Config {
c.AWSBatch.ReconcileRate = reconcile
c.AWSBatch.DisableReconciler = true

kubernetesTemplate := intern.MustAsset("config/kubernetes-template.yaml")
executorTemplate := intern.MustAsset("config/kubernetes-executor-template.yaml")
c.Kubernetes.Executor = "docker"
c.Kubernetes.Template = string(kubernetesTemplate)
c.Kubernetes.ExecutorTemplate = string(executorTemplate)
c.Kubernetes.ReconcileRate = reconcile

return c
Expand Down
Loading
Loading