Skip to content

Commit 469d652

Browse files
authored
Merge branch 'master' into renovate/codecov-codecov-action-3.x
2 parents faa895b + 7c7fd9a commit 469d652

Some content is hidden

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

44 files changed

+3201
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*.dll
88
*.so
99
*.dylib
10+
# install makefile required bins in the bin/ dir
11+
bin
1012

1113
# Test binary, build with `go test -c`
1214
*.test

Makefile

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ endif
2323
# create a list of linker flags for building the golang application
2424
LD_FLAGS = -X github.com/go-vela/worker/version.Commit=${GITHUB_SHA} -X github.com/go-vela/worker/version.Date=${BUILD_DATE} -X github.com/go-vela/worker/version.Tag=${GITHUB_TAG}
2525

26+
# Misc settings for the generating the Kubernetes CRD for the Kubernetes Runtime
27+
K8S_CRD_OUTPUT_PKG=github.com/go-vela/worker/runtime/kubernetes/generated
28+
K8S_CRD_INPUT_PKG=github.com/go-vela/worker/runtime/kubernetes/apis
29+
K8S_CRD_CLIENTSET_PKG_NAME=clientset
30+
K8S_CRD_CLIENTSET_NAME_VERSIONED=versioned
31+
K8S_CRD_GROUP=vela
32+
K8S_CRD_VERSION=v1alpha1
33+
2634
# The `clean` target is intended to clean the workspace
2735
# and prepare the local changes for submission.
2836
#
@@ -311,3 +319,76 @@ spec-version-update:
311319
# Usage: `make spec`
312320
.PHONY: spec
313321
spec: spec-gen spec-version-update spec-validate
322+
323+
# The `crd-gen` target is intended to create a k8s CRD client
324+
# for the kubernetes runtime using k8s.io/code-generator
325+
#
326+
# Usage: `make crd-gen`
327+
.PHONY: crd-client-gen
328+
crd-client-gen: controller-gen client-gen
329+
$(eval TMP := $(shell mktemp -d))
330+
@echo
331+
@echo "### Generating CRD deepcopy funcs using sig.k8s.io/controller-tools"
332+
$(CONTROLLER_GEN) \
333+
object:headerFile="runtime/kubernetes/codegen/header.go.txt" \
334+
paths="${K8S_CRD_INPUT_PKG}/${K8S_CRD_GROUP}/${K8S_CRD_VERSION}"
335+
@echo "### Generating CRD clientset using k8s.io/code-generator"
336+
@echo "Generating clientset for ${K8S_CRD_GROUP}:${K8S_CRD_VERSION} at ${K8S_CRD_OUTPUT_PKG}/${K8S_CRD_CLIENTSET_PKG_NAME}"
337+
$(CLIENT_GEN) \
338+
--clientset-name "${K8S_CRD_CLIENTSET_NAME_VERSIONED}" \
339+
--input-base "" \
340+
--input \
341+
"${K8S_CRD_INPUT_PKG}/${K8S_CRD_GROUP}/${K8S_CRD_VERSION}" \
342+
--output-package \
343+
"${K8S_CRD_OUTPUT_PKG}/${K8S_CRD_CLIENTSET_PKG_NAME}" \
344+
--output-base "${TMP}" \
345+
--go-header-file runtime/kubernetes/codegen/header.go.txt
346+
@echo "### Copying generated files"
347+
rm -rf runtime/kubernetes/generated/clientset
348+
cp -r ${TMP}/github.com/go-vela/worker/runtime/kubernetes/* runtime/kubernetes/
349+
rm -rf $(TMP)
350+
@echo "### CRD clientset created successfully"
351+
352+
# The `crd-manifest` target will call crd-gen to create a k8s crd
353+
# for the kubernetes runtime.
354+
#
355+
# Usage: `make crd`
356+
.PHONY: crd-manifest
357+
crd-manifest: controller-gen ## Generate CustomResourceDefinition object.
358+
@echo
359+
@echo "### Generating CRD manifest using sig.k8s.io/controller-tools"
360+
@echo "Generating CRD manifest in runtime/kubernetes/generated"
361+
$(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=runtime/kubernetes/generated
362+
@echo "### CRD manifest created successfully"
363+
364+
# The `crd` target will call crd-client-gen and crd-manifest
365+
# to create a k8s CRD for the kubernetes runtime.
366+
#
367+
# Usage: `make crd`
368+
.PHONY: crd
369+
crd: crd-client-gen crd-manifest
370+
371+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
372+
.PHONY: controller-gen
373+
controller-gen: ## Download controller-gen locally if necessary.
374+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
375+
376+
CLIENT_GEN = $(shell pwd)/bin/client-gen
377+
.PHONY: client-gen
378+
client-gen: ## Download client-gen locally if necessary.
379+
$(eval K8S_LIB_VERSION := $(shell go mod graph | grep 'github.com/go-vela/worker k8s.io/client-go@' | sed 's/.*@//'))
380+
$(call go-get-tool,$(CLIENT_GEN),k8s.io/code-generator/cmd/client-gen@$(K8S_LIB_VERSION))
381+
382+
# go-get-tool will 'go get' any package $2 and install it to $1.
383+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
384+
define go-get-tool
385+
@[ -f $(1) ] || { \
386+
set -e ;\
387+
TMP_DIR=$$(mktemp -d) ;\
388+
cd $$TMP_DIR ;\
389+
go mod init tmp ;\
390+
echo "Downloading $(2)" ;\
391+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
392+
rm -rf $$TMP_DIR ;\
393+
}
394+
endef

PROJECT

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
# This file is used in generating code for the Kubernetes Runtime.
3+
# Look in runtime/kubernetes/apis/ and runtime/kubernetes/generated/
4+
# for the code that is used or generated by the code generators.
5+
#
6+
# For more about this file see:
7+
# https://book.kubebuilder.io/reference/project-config.html
8+
domain: go-vela.github.io
9+
layout:
10+
- go.kubebuilder.io/v3
11+
projectName: worker
12+
repo: github.com/go-vela/worker
13+
resources:
14+
- api:
15+
crdVersion: v1
16+
namespaced: true
17+
domain: go-vela.github.io
18+
kind: PipelinePodsTemplate
19+
path: pkg/runtime/kubernetes/apis/vela/v1alpha1
20+
version: v1alpha1
21+
version: "3"

cmd/vela-worker/exec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (w *Worker) exec(index int) error {
5656
ConfigFile: w.Config.Runtime.ConfigFile,
5757
HostVolumes: w.Config.Runtime.HostVolumes,
5858
Namespace: w.Config.Runtime.Namespace,
59+
PodsTemplateName: w.Config.Runtime.PodsTemplateName,
60+
PodsTemplateFile: w.Config.Runtime.PodsTemplateFile,
5961
PrivilegedImages: w.Config.Runtime.PrivilegedImages,
6062
})
6163
if err != nil {

cmd/vela-worker/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ func run(c *cli.Context) error {
107107
Driver: c.String("runtime.driver"),
108108
ConfigFile: c.String("runtime.config"),
109109
Namespace: c.String("runtime.namespace"),
110+
PodsTemplateName: c.String("runtime.pods-template-name"),
111+
PodsTemplateFile: c.Path("runtime.pods-template-file"),
110112
HostVolumes: c.StringSlice("runtime.volumes"),
111113
PrivilegedImages: c.StringSlice("runtime.privileged-images"),
112114
},

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.17
44

55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
7-
github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3
87
github.com/docker/distribution v2.8.1+incompatible
98
github.com/docker/docker v20.10.10+incompatible
109
github.com/docker/go-units v0.4.0
@@ -23,6 +22,7 @@ require (
2322
k8s.io/api v0.23.5
2423
k8s.io/apimachinery v0.23.5
2524
k8s.io/client-go v0.23.5
25+
sigs.k8s.io/yaml v1.2.0
2626
)
2727

2828
require (
@@ -34,6 +34,7 @@ require (
3434
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
3535
github.com/alicebob/miniredis/v2 v2.19.0 // indirect
3636
github.com/beorn7/perks v1.0.1 // indirect
37+
github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 // indirect
3738
github.com/cespare/xxhash/v2 v2.1.2 // indirect
3839
github.com/containerd/containerd v1.4.13 // indirect
3940
github.com/coreos/go-semver v0.3.0 // indirect
@@ -107,5 +108,4 @@ require (
107108
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
108109
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
109110
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
110-
sigs.k8s.io/yaml v1.2.0 // indirect
111111
)

runtime/docker/opts_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
package docker
66

77
import (
8-
"github.com/sirupsen/logrus"
98
"reflect"
109
"testing"
10+
11+
"github.com/sirupsen/logrus"
1112
)
1213

1314
func TestDocker_ClientOpt_WithPrivilegedImages(t *testing.T) {

runtime/flags.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ var Flags = []cli.Flag{
3636
Name: "runtime.namespace",
3737
Usage: "namespace to use for the runtime (only used by kubernetes)",
3838
},
39+
&cli.StringFlag{
40+
EnvVars: []string{"VELA_RUNTIME_PODS_TEMPLATE_NAME", "RUNTIME_PODS_TEMPLATE_NAME"},
41+
FilePath: "/vela/runtime/pods_template_name",
42+
Name: "runtime.pods-template-name",
43+
Usage: "name of the PipelinePodsTemplate to retrieve from the runtime.namespace (only used by kubernetes)",
44+
},
45+
&cli.PathFlag{
46+
EnvVars: []string{"VELA_RUNTIME_PODS_TEMPLATE_FILE", "RUNTIME_PODS_TEMPLATE_FILE"},
47+
FilePath: "/vela/runtime/pods_template_file",
48+
Name: "runtime.pods-template-file",
49+
Usage: "path to local fallback file containing a PipelinePodsTemplate in YAML (only used by kubernetes; only used if runtime.pods-template-name is not defined)",
50+
},
3951
&cli.StringSliceFlag{
4052
EnvVars: []string{"VELA_RUNTIME_PRIVILEGED_IMAGES", "RUNTIME_PRIVILEGED_IMAGES"},
4153
FilePath: "/vela/runtime/privileged_images",

runtime/kubernetes/apis/doc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
2+
//
3+
// Use of this source code is governed by the LICENSE file in this repository.
4+
5+
// Package apis defines the worker-config CRD and related utilities.
6+
//
7+
// Usage:
8+
//
9+
// import "github.com/go-vela/worker/runtime/kubernetes/apis"
10+
package apis
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
2+
//
3+
// Use of this source code is governed by the LICENSE file in this repository.
4+
5+
package vela
6+
7+
const (
8+
// GroupName is the group name used in this package.
9+
GroupName = "go-vela.github.io"
10+
)

0 commit comments

Comments
 (0)