Skip to content

Commit 5dc514a

Browse files
Donatien26Eneman Donatien
authored andcommitted
move to operator sdk v4 + refacto + add unitest
1 parent 7e47a67 commit 5dc514a

Some content is hidden

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

75 files changed

+3273
-1744
lines changed

.github/workflows/ci-chart.yaml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
name: Release Helm
1+
name: Helm CI
22

33
on:
44
push:
55
branches:
6-
- main
6+
- "**"
7+
paths-ignore:
8+
- 'docs/**'
9+
tags:
10+
- "*"
11+
pull_request:
12+
paths-ignore:
13+
- 'docs/**'
714

815
jobs:
9-
release_helm:
16+
17+
helm-lint:
1018
runs-on: ubuntu-latest
1119
steps:
1220
- name: Checkout
@@ -17,6 +25,26 @@ jobs:
1725

1826
- name: Lint Chart
1927
run: helm lint .
28+
29+
helm-unitest:
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Install Helm on Runner
35+
uses: azure/[email protected]
36+
37+
- name: Lint Chart
38+
run: echo "TODO"
39+
40+
release_helm:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
46+
- name: Install Helm on Runner
47+
uses: azure/[email protected]
2048

2149
- name: Configure Git
2250
run: |
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,67 @@
1-
name: build
2-
3-
on: [push]
4-
5-
jobs:
6-
build:
7-
outputs:
8-
version: ${{ steps.get_version.outputs.VERSION }}
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Checkout code
12-
uses: actions/checkout@v4
13-
14-
- name: Docker meta
15-
id: docker_meta
16-
uses: crazy-max/[email protected]
17-
with:
18-
images: inseefrlab/s3-operator # list of Docker images to use as base name for tags
19-
20-
- name: Set up QEMU
21-
uses: docker/setup-qemu-action@v3
22-
23-
- name: Set up Docker Buildx
24-
uses: docker/setup-buildx-action@v3
25-
26-
- name: Login to DockerHub
27-
if: github.event_name != 'pull_request'
28-
uses: docker/login-action@v3
29-
with:
30-
username: ${{ secrets.DOCKERHUB_USERNAME }}
31-
password: ${{ secrets.DOCKERHUB_TOKEN }}
32-
33-
- name: Build and push
34-
uses: docker/build-push-action@v5
35-
with:
36-
context: .
37-
file: ./Dockerfile
38-
push: ${{ github.event_name != 'pull_request' }}
39-
# Use tags computed before and also latest if on master
40-
tags: |
41-
${{ steps.docker_meta.outputs.tags }}
42-
${{ github.ref == 'refs/heads/main' && 'inseefrlab/s3-operator:latest' || '' }}
43-
labels: ${{ steps.docker_meta.outputs.labels }}
44-
platforms: linux/amd64,linux/arm64
45-
46-
- name: Image digest
47-
run: echo ${{ steps.docker_build.outputs.digest }}
1+
name: Docker CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
paths-ignore:
8+
- 'docs/**'
9+
tags:
10+
- "*"
11+
pull_request:
12+
paths-ignore:
13+
- 'docs/**'
14+
15+
jobs:
16+
17+
lint-docker:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
- uses: hadolint/[email protected]
23+
with:
24+
dockerfile: Dockerfile
25+
26+
build-docker:
27+
outputs:
28+
version: ${{ steps.get_version.outputs.VERSION }}
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Docker meta
35+
id: docker_meta
36+
uses: crazy-max/[email protected]
37+
with:
38+
images: inseefrlab/s3-operator # list of Docker images to use as base name for tags
39+
40+
- name: Set up QEMU
41+
uses: docker/setup-qemu-action@v3
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v3
45+
46+
- name: Login to DockerHub
47+
if: github.event_name != 'pull_request'
48+
uses: docker/login-action@v3
49+
with:
50+
username: ${{ secrets.DOCKERHUB_USERNAME }}
51+
password: ${{ secrets.DOCKERHUB_TOKEN }}
52+
53+
- name: Build and push
54+
uses: docker/build-push-action@v5
55+
with:
56+
context: .
57+
file: ./Dockerfile
58+
push: ${{ github.event_name != 'pull_request' }}
59+
# Use tags computed before and also latest if on master
60+
tags: |
61+
${{ steps.docker_meta.outputs.tags }}
62+
${{ github.ref == 'refs/heads/main' && 'inseefrlab/s3-operator:latest' || '' }}
63+
labels: ${{ steps.docker_meta.outputs.labels }}
64+
platforms: linux/amd64,linux/arm64
65+
66+
- name: Image digest
67+
run: echo ${{ steps.docker_build.outputs.digest }}

.github/workflows/ci-go.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Golang CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
paths-ignore:
8+
- 'docs/**'
9+
tags:
10+
- "*"
11+
pull_request:
12+
paths-ignore:
13+
- 'docs/**'
14+
15+
jobs:
16+
17+
go:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
- name: Setup Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: '1.23.x'
26+
- name: Install dependencies
27+
run: go mod download
28+
- uses: brian-pickens/go-test-report@v1
29+
with:
30+
packages: "./..."
31+
reports-only: "false"
32+
summary: "true"
33+
GO111MODULE: "auto"
34+
- name: Build
35+
run: go build -v ./...
36+
- name: 'Upload Artifact'
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: manager
40+
path: bin/manager
41+
retention-days: 5

.github/workflows/release.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
on:
2+
push:
3+
# Sequence of patterns matched against refs/tags
4+
tags:
5+
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
6+
7+
name: Upload Release Asset
8+
9+
jobs:
10+
upload-release-assets:
11+
name: Upload Release Asset
12+
needs: build-go
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
- name: Download a single artifact
18+
uses: actions/download-artifact@v4
19+
with:
20+
name: manager
21+
- name: Create Release
22+
id: create_release
23+
uses: actions/create-release@v1
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
with:
27+
tag_name: ${{ github.ref }}
28+
release_name: Release ${{ github.ref }}
29+
draft: false
30+
prerelease: false
31+
- name: Upload Release Asset
32+
id: upload-release-asset
33+
uses: actions/upload-release-asset@v1
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
with:
37+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
38+
asset_path: bin/manager
39+
asset_name: s3-operator
40+
asset_content_type: application/x-executable

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ COPY go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY cmd/main.go main.go
15+
COPY cmd/main.go cmd/main.go
1616
COPY api/ api/
17-
COPY controllers/ controllers/
1817
COPY internal/ internal/
1918

2019

@@ -23,7 +22,7 @@ COPY internal/ internal/
2322
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2423
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2524
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
26-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
2726

2827
# Use distroless as minimal base image to package the manager binary
2928
# Refer to https://github.com/GoogleContainerTools/distroless for more details

LICENSE

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
MIT License
1+
Copyright 2023.
22

3-
Copyright (c) 2023 InseeFrLab
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
46

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
7+
http://www.apache.org/licenses/LICENSE-2.0
118

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ endif
4848

4949
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5050
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51-
OPERATOR_SDK_VERSION ?= v1.32.0
51+
OPERATOR_SDK_VERSION ?= v1.39.1
5252

5353
# Image URL to use all building/pushing image targets
5454
IMG ?= controller:latest
5555
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
56-
ENVTEST_K8S_VERSION = 1.26.0
56+
ENVTEST_K8S_VERSION = 1.32.0
5757

5858
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5959
ifeq (,$(shell go env GOBIN))
@@ -113,11 +113,11 @@ test: manifests generate fmt vet envtest ## Run tests.
113113

114114
.PHONY: build
115115
build: manifests generate fmt vet ## Build manager binary.
116-
go build -o bin/manager main.go
116+
go build -o bin/manager cmd/main.go
117117

118118
.PHONY: run
119119
run: manifests generate fmt vet ## Run a controller from your host.
120-
go run ./main.go
120+
go run ./cmd/main.go
121121

122122
# If you wish built the manager image targeting other platforms you can use the --platform flag.
123123
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
@@ -184,7 +184,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
184184

185185
## Tool Versions
186186
KUSTOMIZE_VERSION ?= v3.8.7
187-
CONTROLLER_TOOLS_VERSION ?= v0.11.1
187+
CONTROLLER_TOOLS_VERSION ?= v0.17.1
188188

189189
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
190190
.PHONY: kustomize
@@ -279,3 +279,7 @@ catalog-build: opm ## Build a catalog image.
279279
.PHONY: catalog-push
280280
catalog-push: ## Push a catalog image.
281281
$(MAKE) docker-push IMG=$(CATALOG_IMG)
282+
283+
.PHONY: go-unittest
284+
go-unittest: ## Build the bundle image.
285+
go test -v ./...

0 commit comments

Comments
 (0)