Skip to content

Commit 3898a15

Browse files
committed
Introduce Taskfile to describe developer and CI tasks
Signed-off-by: Joe Lanford <[email protected]>
1 parent 79f406d commit 3898a15

15 files changed

+431
-95
lines changed

.github/workflows/e2e.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ jobs:
2626
with:
2727
go-version-file: "go.mod"
2828

29+
- uses: actions/cache@v3
30+
with:
31+
path: |
32+
~/.cache/go-build
33+
~/go/pkg/mod
34+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
35+
restore-keys: |
36+
${{ runner.os }}-go-
37+
2938
- name: Docker Login
3039
if: ${{ github.event_name != 'pull_request' }}
3140
uses: docker/login-action@v1
@@ -52,12 +61,10 @@ jobs:
5261
echo IMAGE_TAG="$(git describe --tags --always)" >> $GITHUB_ENV
5362
fi
5463
55-
- name: Generate the operator-controller release manifests
56-
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
57-
run: |
58-
make quickstart VERSION=${GITHUB_REF#refs/tags/}
64+
- name: Install Task
65+
run: go install github.com/go-task/task/v3/cmd/task@latest
5966

6067
- name: Run goreleaser
61-
run: make release
68+
run: task release
6269
env:
6370
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/test.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: test
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
test: [ sanity, unit, e2e ]
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- uses: actions/setup-go@v3
20+
with:
21+
go-version-file: go.mod
22+
23+
- uses: actions/cache@v3
24+
with:
25+
path: |
26+
~/.cache/go-build
27+
~/go/pkg/mod
28+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
29+
restore-keys: |
30+
${{ runner.os }}-go-
31+
32+
- name: Install Task
33+
run: go install github.com/go-task/task/v3/cmd/task@latest
34+
35+
- name: Run ${{matrix.test}} test
36+
run: |
37+
task test:${{matrix.test}}

.github/workflows/unit-test.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.gitignore

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,21 @@ vendor
66
*.dll
77
*.so
88
*.dylib
9-
bin/*
10-
testbin/*
11-
Dockerfile.cross
9+
**/bin/*
1210

1311
# Test binary, build with `go test -c`
1412
*.test
1513

1614
# Output of the go coverage tool, specifically when used with LiteIDE
17-
*.out
15+
cover.out
1816

1917
# Release output
20-
dist/**
21-
operator-controller.yaml
22-
install.sh
23-
24-
# Kubernetes Generated files - skip generated files, except for vendored files
25-
26-
!vendor/**/zz_generated.*
18+
/dist/**
19+
/install.sh
20+
/operator-controller.yaml
2721

2822
# editor and IDE paraphernalia
2923
.idea
3024
*.swp
3125
*.swo
3226
*~
33-
34-
# TODO dfranz remove this line and the bin folder when tools binaries are moved to their own folder
35-
!bin/.dockerignore

.goreleaser.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ builds:
1010
- id: operator-controller
1111
main: ./
1212
binary: bin/manager
13-
tags: $GO_BUILD_TAGS
13+
tags: upstream
1414
goos:
1515
- linux
1616
goarch:
@@ -22,7 +22,7 @@ builds:
2222
- -X main.Version={{ .Version }}
2323
dockers:
2424
- image_templates:
25-
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
25+
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
2626
dockerfile: Dockerfile
2727
goos: linux
2828
goarch: amd64
@@ -58,11 +58,12 @@ changelog:
5858
release:
5959
disable: '{{ ne .Env.ENABLE_RELEASE_PIPELINE "true" }}'
6060
extra_files:
61+
- glob: 'install.sh'
6162
- glob: 'operator-controller.yaml'
6263
- glob: 'install.sh'
6364
header: |
6465
## Installation
6566
6667
```bash
67-
curl -L -s https://github.com/operator-framework/operator-controller/releases/download/{{ .Tag }}/install.sh | bash -s
68+
curl -sSL https://github.com/operator-framework/operator-controller/releases/download/{{ .Env.IMAGE_TAG }}/install.sh | bash -s
6869
```

.taskfile.build.yaml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
version: '3'
2+
3+
includes:
4+
tools:
5+
taskfile: .taskfile.tools.yaml
6+
internal: true
7+
8+
vars:
9+
BIN: "{{.ROOT_DIR}}/bin"
10+
OPERATOR_CONTROLLER_MANIFEST: ./operator-controller.yaml
11+
12+
OLMV0_VERSION: v0.24.0
13+
CERT_MANAGER_VERSION: v1.9.0
14+
RUKPAK_VERSION: v0.11.0
15+
16+
env:
17+
IMAGE_REPO: quay.io/operator-framework/operator-controller
18+
IMAGE_TAG: devel
19+
20+
tasks:
21+
generate:
22+
desc: "Run code generation"
23+
summary: |
24+
This task runs go generate and controller-gen to generate code, CRDs,
25+
webhook configurations, and RBAC manifests.
26+
cmds:
27+
- go generate ./...
28+
- "{{.TOOLSBIN}}/controller-gen object:headerFile=hack/boilerplate.go.txt paths=./..."
29+
- "{{.TOOLSBIN}}/controller-gen rbac:roleName=manager-role crd webhook paths=./... output:crd:artifacts:config=config/crd/bases"
30+
deps: [tools:controller-gen]
31+
32+
binary:
33+
desc: "Build the binaries for the current OS"
34+
summary: |
35+
This task uses goreleaser to build the operator binary based on GOOS and GOARCH.
36+
By default, the binary is created at ./bin/manager.
37+
38+
To generate the binary for a different OS, set the GOOS task variable accordingly.
39+
cmds:
40+
- mkdir -p {{.BIN}}
41+
- GOOS={{.GOOS}} {{.TOOLSBIN}}/goreleaser build --single-target --snapshot --clean --output {{.BIN}}/manager
42+
deps: [tools:goreleaser, generate]
43+
44+
docker:
45+
desc: "Build the docker image"
46+
summary: |
47+
This task builds the operator's linux binary in {{.BIN}}/linux and then uses
48+
the Dockerfile to build the docker image in {{.BIN}}/linux.
49+
50+
GOARCH is taken from the environment to ensure a binary that will run on the local
51+
machine. GOOS is always set to `linux` for the docker build.
52+
53+
By default, the image is tagged as quay.io/operator-framework/operator-controller:devel.
54+
You can control the image repo and tag by setting the IMAGE_REPO and IMAGE_TAG
55+
environment variables.
56+
cmds:
57+
- docker build -f Dockerfile -t $IMAGE_REPO:$IMAGE_TAG bin/linux
58+
deps:
59+
- task: binary
60+
vars:
61+
BIN: "{{.ROOT_DIR}}/bin/linux"
62+
GOOS: linux
63+
64+
manifest:
65+
desc: "Generate the operator manifest"
66+
summary: |
67+
This task uses kustomize to generate the operator manifest.
68+
69+
The operator manifest is generated by combining the CRD and default manifests
70+
with the controller image set to the IMAGE_REPO and IMAGE_TAG environment variables.
71+
cmds:
72+
- cd config/manager && {{.TOOLSBIN}}/kustomize edit set image controller=$IMAGE_REPO:$IMAGE_TAG
73+
- "{{.TOOLSBIN}}/kustomize build config/default > ./operator-controller.yaml"
74+
deps: [tools:kustomize, generate]
75+
76+
install-script:
77+
desc: "Generate the install script"
78+
summary: |
79+
This task generates the install script that can be used to install the operator.
80+
81+
The OPERATOR_CONTROLLER_MANIFEST task variable is used to set the location that
82+
will be used to `kubectl apply -f` the operator-controller manifest. By default,
83+
this is set to `./operator-controller.yaml`. However this can be overridden during
84+
a release to reference the release manifest URL that is uploaded to GitHub during
85+
the release.
86+
silent: true
87+
cmds:
88+
- |
89+
cat << EOF > ./install.sh
90+
#!/usr/bin/env bash
91+
set -o pipefail -o errexit -o nounset
92+
93+
# Install OLMv0
94+
curl -L -s https://github.com/operator-framework/operator-lifecycle-manager/releases/download/{{.OLMV0_VERSION}}/install.sh | bash -s {{.OLMV0_VERSION}}
95+
96+
# Install cert-manager
97+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/{{.CERT_MANAGER_VERSION}}/cert-manager.yaml
98+
kubectl wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-webhook --timeout=60s
99+
100+
# Install rukpak
101+
kubectl apply -f https://github.com/operator-framework/rukpak/releases/download/{{.RUKPAK_VERSION}}/rukpak.yaml
102+
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/core --timeout=60s
103+
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/helm-provisioner --timeout=60s
104+
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/rukpak-webhooks --timeout=60s
105+
kubectl wait --for=condition=Available --namespace=crdvalidator-system deployment/crd-validation-webhook --timeout=60s
106+
107+
# Install operator-controller
108+
kubectl apply -f {{.OPERATOR_CONTROLLER_MANIFEST}}
109+
kubectl wait --for=condition=Available --namespace=operator-controller-system deployment/operator-controller-controller-manager --timeout=60s
110+
EOF
111+
- chmod +x ./install.sh

.taskfile.deploy.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '3'
2+
3+
includes:
4+
build:
5+
taskfile: .taskfile.build.yaml
6+
internal: true
7+
kind:
8+
taskfile: .taskfile.kind.yaml
9+
internal: true
10+
11+
tasks:
12+
kind:
13+
cmds:
14+
- task: kind:load-image
15+
vars:
16+
IMAGE: "$IMAGE_REPO:$IMAGE_TAG"
17+
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}"
18+
- ./install.sh
19+
deps:
20+
- task: build:docker
21+
- task: build:manifest
22+
- task: build:install-script
23+
- task: kind:create
24+
vars:
25+
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}"
26+
desc: "Run the operator in a fresh kind cluster"

.taskfile.kind.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
3+
vars:
4+
KIND_CLUSTER_NAME: "operator-controller"
5+
6+
includes:
7+
tools:
8+
taskfile: .taskfile.tools.yaml
9+
internal: true
10+
11+
tasks:
12+
create:
13+
desc: "Create a fresh kind cluster"
14+
cmds:
15+
- "{{.TOOLSBIN}}/kind create cluster --name {{.KIND_CLUSTER_NAME}}"
16+
deps:
17+
- tools:kind
18+
- task: delete
19+
vars:
20+
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}"
21+
22+
delete:
23+
desc: "Delete a kind cluster"
24+
cmds:
25+
- "{{.TOOLSBIN}}/kind delete cluster --name {{.KIND_CLUSTER_NAME}}"
26+
deps: [tools:kind]
27+
28+
load-image:
29+
desc: "Load the image into the kind cluster"
30+
cmds:
31+
- "{{.TOOLSBIN}}/kind load docker-image {{.IMAGE}} --name {{.KIND_CLUSTER_NAME}}"
32+
deps: [tools:kind]

.taskfile.style.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
3+
tasks:
4+
default:
5+
deps: [ fmt, vet, tidy ]
6+
7+
fmt:
8+
cmds:
9+
- go fmt ./...
10+
vet:
11+
cmds:
12+
- go vet ./...
13+
tidy:
14+
cmds:
15+
- go mod tidy
16+

0 commit comments

Comments
 (0)