Skip to content

Commit b9a7cd2

Browse files
authored
Merge pull request #49 from mumoshu/k8s-1.23
Various improvements to bump CRD to v1 for K8s 1.22 support
2 parents 1b85804 + 815c05a commit b9a7cd2

29 files changed

+1861
-1447
lines changed

.github/workflows/go.yaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,25 @@ jobs:
77
steps:
88
- uses: actions/checkout@v2
99
- name: Setup Go
10-
uses: actions/setup-go@v1
10+
uses: actions/setup-go@v3
1111
with:
12-
go-version: 1.14.4
13-
- uses: actions/cache@v1
12+
go-version: '^1.17.7'
13+
- uses: actions/cache@v3
1414
with:
1515
path: ~/go/pkg/mod
1616
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
1717
restore-keys: |
1818
${{ runner.os }}-go-
19-
- name: Download Modules
20-
if: steps.cache.outputs.cache-hit != 'true'
21-
run: go mod download
2219
- name: Build
23-
run: go build ./cmd/manager/
20+
run: make build
21+
- name: Install kubebuilder
22+
run: |
23+
curl -L -O https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.2/kubebuilder_2.3.2_linux_amd64.tar.gz
24+
tar zxvf kubebuilder_2.3.2_linux_amd64.tar.gz
25+
sudo mv kubebuilder_2.3.2_linux_amd64 /usr/local/kubebuilder
26+
- name: Test
27+
run: go test ./...
28+
env:
29+
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
30+
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
31+
AWS_REGION: ${{secrets.AWS_REGION}}

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Build the manager binary
2+
FROM golang:1.17 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY cmd/ cmd/
15+
COPY api/ api/
16+
COPY controllers/ controllers/
17+
18+
# Build
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
20+
21+
# Use distroless as minimal base image to package the manager binary
22+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
23+
FROM gcr.io/distroless/static:nonroot
24+
WORKDIR /
25+
COPY --from=builder /workspace/manager .
26+
USER 65532:65532
27+
28+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
VERSION ?= canary
22
REPO ?= mumoshu/aws-secret-operator
33
IMAGE ?= $(REPO):$(VERSION)
4-
GO ?= go1.14.4
4+
GO ?= go
55

66
.PHONY: build
77
build:
8-
go build -o bin/aws-secret-operator ./cmd/manager
8+
$(GO) build -o bin/aws-secret-operator .
99

1010
.PHONY: image
1111
image:
12-
DOCKERFILE_PATH=./build/Dockerfile IMAGE_NAME=$(IMAGE) REPO=$(REPO) hooks/build
12+
docker build -t $(IMAGE) .
1313

14+
.PHONY: push
1415
publish:
15-
operator-sdk build $(IMAGE) && docker push $(IMAGE)
16+
docker push $(IMAGE)
1617

17-
install-tools:
18-
go get github.com/aws/[email protected]
19-
go get github.com/aws/aws-sdk-go/aws/session
20-
go get github.com/aws/aws-sdk-go/service/secretsmanager
21-
go get github.com/pkg/errors
18+
crds: controller-gen
19+
$(CONTROLLER_GEN) crd rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=deploy/crds
2220

23-
.PHONY: e2e
24-
e2e:
25-
kubectl create namespace operator-test || true
26-
$(GO) run github.com/operator-framework/operator-sdk/cmd/operator-sdk test local ./test/e2e --operator-namespace operator-test --up-local
21+
# Generate code
22+
generate: controller-gen
23+
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
24+
25+
# Find or download controller-gen
26+
#
27+
# Note that controller-gen newer than 0.4.1 is needed for https://github.com/kubernetes-sigs/controller-tools/issues/444#issuecomment-680168439
28+
# Otherwise we get errors like the below:
29+
# Error: failed to install CRD crds/actions.summerwind.dev_runnersets.yaml: CustomResourceDefinition.apiextensions.k8s.io "runnersets.actions.summerwind.dev" is invalid: [spec.validation.openAPIV3Schema.properties[spec].properties[template].properties[spec].properties[containers].items.properties[ports].items.properties[protocol].default: Required value: this property is in x-kubernetes-list-map-keys, so it must have a default or be a required property, spec.validation.openAPIV3Schema.properties[spec].properties[template].properties[spec].properties[initContainers].items.properties[ports].items.properties[protocol].default: Required value: this property is in x-kubernetes-list-map-keys, so it must have a default or be a required property]
30+
#
31+
# Note that controller-gen newer than 0.6.0 is needed due to https://github.com/kubernetes-sigs/controller-tools/issues/448
32+
# Otherwise ObjectMeta embedded in Spec results in empty on the storage.
33+
controller-gen:
34+
ifeq (, $(shell which controller-gen))
35+
ifeq (, $(wildcard $(GOBIN)/controller-gen))
36+
@{ \
37+
set -e ;\
38+
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
39+
cd $$CONTROLLER_GEN_TMP_DIR ;\
40+
$(GO) mod init tmp ;\
41+
$(GO) get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
42+
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
43+
}
44+
endif
45+
CONTROLLER_GEN=$(GOBIN)/controller-gen
46+
else
47+
CONTROLLER_GEN=$(shell which controller-gen)
48+
endif

pkg/apis/addtoscheme_mumoshu_v1alpha1.go renamed to api/addtoscheme_mumoshu_v1alpha1.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package apis
1+
package api
22

33
import (
4-
"github.com/mumoshu/aws-secret-operator/pkg/apis/mumoshu/v1alpha1"
4+
"github.com/mumoshu/aws-secret-operator/api/mumoshu/v1alpha1"
55
)
66

77
func init() {

pkg/apis/apis.go renamed to api/apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package apis
1+
package api
22

33
import (
44
"k8s.io/apimachinery/pkg/runtime"
File renamed without changes.

api/mumoshu/v1alpha1/register.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// NOTE: Boilerplate only. Ignore this file.
2+
3+
// Package v1alpha1 contains API Schema definitions for the mumoshu v1alpha1 API group
4+
// +k8s:deepcopy-gen=package,register
5+
// +groupName=mumoshu.github.io
6+
package v1alpha1
7+
8+
import (
9+
"k8s.io/apimachinery/pkg/runtime/schema"
10+
"sigs.k8s.io/controller-runtime/pkg/scheme"
11+
)
12+
13+
var (
14+
// GroupVersion is group version used to register these objects
15+
GroupVersion = schema.GroupVersion{Group: "mumoshu.github.io", Version: "v1alpha1"}
16+
17+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
18+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
19+
20+
// AddToScheme adds the types in this group-version to the given scheme.
21+
AddToScheme = SchemeBuilder.AddToScheme
22+
)

pkg/apis/mumoshu/v1alpha1/zz_generated.deepcopy.go renamed to api/mumoshu/v1alpha1/zz_generated.deepcopy.go

Lines changed: 18 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/manager/main.go

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

0 commit comments

Comments
 (0)