Skip to content

Commit ff09717

Browse files
authored
Merge pull request #3 from takeshi-yoshimura/add-controller
add a controller and custom uploader Opened issues 4 and 5 to capture the agreed roll overs from this initial commit.
2 parents 38baa34 + 1e3bad7 commit ff09717

File tree

56 files changed

+3390
-657
lines changed

Some content is hidden

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

56 files changed

+3390
-657
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

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,33 @@ Cargo.lock
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
11+
12+
# Binaries for programs and plugins
13+
*.exe
14+
*.exe~
15+
*.dll
16+
*.so
17+
*.dylib
18+
bin
19+
testbin/*
20+
Dockerfile.cross
21+
22+
go.sum
23+
24+
# Test binary, build with `go test -c`
25+
*.test
26+
27+
# Output of the go coverage tool, specifically when used with LiteIDE
28+
*-cover.out
29+
*-cover.html
30+
31+
# Kubernetes Generated files - skip generated files, except for vendored files
32+
33+
!vendor/**/zz_generated.*
34+
35+
# editor and IDE paraphernalia
36+
.vscode
37+
.idea
38+
*.swp
39+
*.swo
40+
*~

Dockerfile

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
# Build the manager binary
2-
FROM quay.io/operator-framework/helm-operator:v1.7.2
2+
FROM golang:1.19 as builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
35

4-
ENV HOME=/opt/helm
5-
COPY watches.yaml ${HOME}/watches.yaml
6-
COPY helm-charts ${HOME}/helm-charts
7-
WORKDIR ${HOME}
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY main.go main.go
16+
COPY api/ api/
17+
COPY controllers/ controllers/
18+
19+
# Build
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
25+
26+
# Use distroless as minimal base image to package the manager binary
27+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28+
FROM gcr.io/distroless/static:nonroot
29+
WORKDIR /
30+
COPY --from=builder /workspace/manager .
31+
USER 65532:65532
32+
33+
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)