Skip to content

Commit 1e3bad7

Browse files
add workflows for image builds and unittest
Signed-off-by: Takeshi Yoshimura <[email protected]>
1 parent fd329cc commit 1e3bad7

File tree

6 files changed

+209
-5
lines changed

6 files changed

+209
-5
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Build and push images
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- api/**
9+
- cmd/**
10+
- controllers/**
11+
- ./main.go
12+
- ./go.mod
13+
- ./go.sum
14+
- config/**
15+
- ./Dockerfile
16+
- ./Makefile
17+
workflow_dispatch:
18+
19+
env:
20+
VERSION: '0.0.1'
21+
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
22+
23+
jobs:
24+
build-push-bundle:
25+
runs-on: ubuntu-latest
26+
needs: build-push-controller
27+
env:
28+
IMAGE_NAME: ghcr.io/${{ github.repository }}/core-dump-operator
29+
BUNDLE_IMAGE_NAME: ghcr.io/${{ github.repository }}/core-dump-operator-bundle
30+
CHANNELS: stable
31+
DEFAULT_CHANNEL: stable
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: actions/setup-go@v2
35+
with:
36+
go-version: '1.19.2'
37+
- name: set ARCH and OD
38+
run: |
39+
echo "ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)" >> $GITHUB_ENV
40+
echo "OS=$(uname | awk '{print tolower($0)}')" >> $GITHUB_ENV
41+
echo "OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.31.0" >> $GITHUB_ENV
42+
- name: download operator-sdk
43+
run: curl -LO ${{ env.OPERATOR_SDK_DL_URL }}/operator-sdk_${{ env.OS }}_${{ env.ARCH }}
44+
- name: move operator-sdk to binary path
45+
run: chmod +x operator-sdk_${{ env.OS }}_${{ env.ARCH }} && sudo mv operator-sdk_${{ env.OS }}_${{ env.ARCH }} /usr/local/bin/operator-sdk
46+
- name: Tidy
47+
run: |
48+
go mod tidy
49+
- name: Make bundle
50+
run: make bundle IMG=${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
51+
- name: Set up Docker
52+
uses: docker/setup-buildx-action@v1
53+
- name: Login to Docker
54+
uses: docker/login-action@v1
55+
with:
56+
registry: ghcr.io
57+
username: ${{ secrets.GH_USERNAME }}
58+
password: ${{ secrets.GH_TOKEN }}
59+
- name: Build and push bundle
60+
uses: docker/build-push-action@v2
61+
with:
62+
context: .
63+
push: true
64+
tags: |
65+
${{ env.BUNDLE_IMAGE_NAME }}:latest
66+
${{ env.BUNDLE_IMAGE_NAME }}:v${{ env.VERSION }}
67+
file: ./bundle.Dockerfile
68+
69+
build-push-controller:
70+
runs-on: ubuntu-latest
71+
env:
72+
IMAGE_NAME: ghcr.io/${{ github.repository }}/core-dump-operator
73+
steps:
74+
- uses: actions/checkout@v2
75+
- uses: actions/setup-go@v2
76+
with:
77+
go-version: '1.19.2'
78+
- name: Tidy
79+
run: |
80+
go mod tidy
81+
make generate fmt vet
82+
- name: Set up Docker
83+
uses: docker/setup-buildx-action@v1
84+
- name: Login to Docker
85+
uses: docker/login-action@v1
86+
with:
87+
registry: ghcr.io
88+
username: ${{ secrets.GH_USERNAME }}
89+
password: ${{ secrets.GH_TOKEN }}
90+
- name: Build and push controller
91+
uses: docker/build-push-action@v2
92+
with:
93+
context: .
94+
push: true
95+
tags: |
96+
${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ github.run_number }}
97+
${{ env.IMAGE_NAME }}:latest
98+
${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
99+
file: ./Dockerfile
100+
101+
build-push-uploader:
102+
runs-on: ubuntu-latest
103+
env:
104+
IMAGE_NAME: ghcr.io/${{ github.repository }}/core-dump-uploader
105+
CGO_ENABLED: 0
106+
GOOS: linux
107+
steps:
108+
- uses: actions/checkout@v2
109+
- uses: actions/setup-go@v2
110+
with:
111+
go-version: '1.19.2'
112+
- name: Tidy
113+
run: |
114+
go mod tidy
115+
- name: Set up Docker
116+
uses: docker/setup-buildx-action@v1
117+
- name: Login to Docker
118+
uses: docker/login-action@v1
119+
with:
120+
registry: ghcr.io
121+
username: ${{ secrets.GH_USERNAME }}
122+
password: ${{ secrets.GH_TOKEN }}
123+
- name: Build
124+
run: |
125+
go build -v -a -ldflags '-extldflags "-static"' -gcflags="all=-N -l" -o ./bin/core-dump-uploader ./cmd/core-dump-uploader/
126+
cp /etc/ssl/certs/ca-certificates.crt bin/
127+
- name: Build and push controller
128+
uses: docker/build-push-action@v2
129+
with:
130+
context: ./bin/
131+
push: true
132+
tags: |
133+
${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ github.run_number }}
134+
${{ env.IMAGE_NAME }}:latest
135+
${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
136+
file: ./cmd/core-dump-uploader/Dockerfile

.github/workflows/unittest.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Perform unittest
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
operator-test:
9+
env:
10+
CLUSTER_ID: default
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-go@v2
15+
with:
16+
go-version: '1.19.2'
17+
- name: set ARCH and OD
18+
run: |
19+
echo "ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)" >> $GITHUB_ENV
20+
echo "OS=$(uname | awk '{print tolower($0)}')" >> $GITHUB_ENV
21+
echo "OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.23.0" >> $GITHUB_ENV
22+
- name: download operator-sdk
23+
run: curl -LO ${{ env.OPERATOR_SDK_DL_URL }}/operator-sdk_${{ env.OS }}_${{ env.ARCH }}
24+
- name: move operator-sdk to binary path
25+
run: chmod +x operator-sdk_${{ env.OS }}_${{ env.ARCH }} && sudo mv operator-sdk_${{ env.OS }}_${{ env.ARCH }} /usr/local/bin/operator-sdk
26+
- name: Tidy
27+
run: |
28+
go mod tidy
29+
- name: Make bundle
30+
run: make bundle
31+
- name: Test Controller
32+
run: make operator-test
33+
uploader-test:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v2
37+
- uses: actions/setup-go@v2
38+
with:
39+
go-version: '1.19.2'
40+
- name: Tidy
41+
run: |
42+
go mod tidy
43+
- name: Make generate
44+
run: make generate
45+
- name: Test Uploader
46+
run: make uploader-test

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
3232
#
3333
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
3434
# ibm.com/core-dump-operator-bundle:$VERSION and ibm.com/core-dump-operator-catalog:$VERSION.
35-
IMAGE_TAG_BASE ?= quay.io/number9/core-dump-operator
35+
IMAGE_TAG_BASE ?= ghcr.io/core-dump-operator/core-dump-operator
3636

3737
# BUNDLE_IMG defines the image:tag used for the bundle.
3838
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
@@ -282,4 +282,3 @@ uploader-push: uploader-cbuild
282282
uploader-test: fmt vet envtest ## Run tests.
283283
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./cmd/... -coverprofile uploader-cover.out
284284
go tool cover -html=uploader-cover.out -o uploader-cover.html
285-

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ An **experimental** operator for https://github.com/IBM/core-dump-handler.
44
This repository contains a special uploader to enable multi-tenant core-dump collection per namespace.
55
The custom uploader searches and uses a secret with `type: core-dump-handler` in the namespace that runs a core-dumper process.
66

7+
## install with public images
8+
9+
Create a namespace for the operator
10+
```
11+
oc create namespace core-dump-handler
12+
```
13+
14+
Label the namespace
15+
```
16+
oc label namespace core-dump-handler core-dump-handler=enabled"
17+
```
18+
19+
Run bundle command to deploy the operator
20+
```
21+
operator-sdk run bundle ghcr.io/ibm/core-dump-operator/core-dump-operator-bundle:v0.0.1 --namespace core-dump-handler
22+
```
23+
24+
Update the S3 values in the `config/samples/secrets.yaml` and deploy a sample daemonset with it.
25+
```
26+
kubectl apply -f config/samples/secrets.yaml \
27+
-f config/samples/charts_v1alpha1_coredumphandler.yaml
28+
```
29+
730
## install from commandline
831

932
```

api/v1alpha1/coredumpoperator_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type CoreDumpHandlerSpec struct {
3232
HandlerImage string `json:"handlerImage,omitempty"`
3333

3434
// UploaderImage is the image for core-dump-uploader to upload zip files generated by handlerImage containers
35-
//+kubebuilder:default="ghcr.io/ibm/core-dump-operator/core-dump-uploader:0.0.1"
35+
//+kubebuilder:default="ghcr.io/ibm/core-dump-operator/core-dump-uploader:v0.0.1"
3636
UploaderImage string `json:"uploaderImage,omitempty"`
3737

3838
// ImagePullSecret is used to download uploaderImage

config/samples/charts_v1alpha1_coredumphandler.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ metadata:
66
spec:
77
serviceAccount: core-dump-operator-uploader-sa # Uploader requires a service account with a secret and namespace reader role (see `config/rbac/uploader_sa_rbac.yaml`).
88
namespaceLabelSelector:
9-
"kubernetes.io/metadata.name": "core-dump-handler"
10-
openShift: true
9+
"core-dump-handler": "enabled"
10+
openShift: true

0 commit comments

Comments
 (0)