Skip to content

Commit 5d7ed5d

Browse files
committed
*: separate base image code and build from example
1 parent d146814 commit 5d7ed5d

Some content is hidden

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

54 files changed

+479
-396
lines changed

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager
1818

1919
# Use distroless as minimal base image to package the manager binary
2020
# Refer to https://github.com/GoogleContainerTools/distroless for more details
21-
FROM alpine
21+
FROM gcr.io/distroless/static:nonroot
2222
WORKDIR /
23-
COPY helm-charts/ helm-charts/
24-
COPY watches.yaml watches.yaml
2523
COPY --from=builder /workspace/manager .
24+
USER nonroot:nonroot
2625

2726
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
# Image URL to use all building/pushing image targets
3-
IMG ?= controller:latest
4-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5-
CRD_OPTIONS ?= "crd:trivialVersions=true"
3+
IMG ?= quay.io/joelanford/helm-operator
64

75
SHELL=/bin/bash
86
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
@@ -15,34 +13,13 @@ endif
1513
all: manager
1614

1715
# Run tests
18-
test: generate fmt vet manifests testbin
16+
test: generate fmt vet testbin
1917
go test -race -covermode atomic -coverprofile cover.out ./...
2018

2119
# Build manager binary
2220
manager: generate fmt vet
2321
go build -o bin/manager main.go
2422

25-
# Run against the configured Kubernetes cluster in ~/.kube/config
26-
run: generate fmt vet manifests
27-
go run ./main.go
28-
29-
# Install CRDs into a cluster
30-
install: manifests
31-
kustomize build config/crd | kubectl apply -f -
32-
33-
# Uninstall CRDs from a cluster
34-
uninstall: manifests
35-
kustomize build config/crd | kubectl delete -f -
36-
37-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
38-
deploy: manifests
39-
cd config/manager && kustomize edit set image controller=${IMG}
40-
kustomize build config/default | kubectl apply -f -
41-
42-
# Generate manifests e.g. CRD, RBAC etc.
43-
manifests: controller-gen
44-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
45-
4623
# Run go fmt against code
4724
fmt:
4825
go fmt ./...

config/manager/kustomization.yaml

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

example/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM quay.io/joelanford/helm-operator:latest
2+
3+
ENV HOME=/opt/helm
4+
COPY watches.yaml ${HOME}/watches.yaml
5+
COPY helm-charts ${HOME}/helm-charts
6+
WORKDIR ${HOME}

example/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= quay.io/joelanford/nginx-operator
4+
5+
all: docker-build
6+
7+
# Run against the configured Kubernetes cluster in ~/.kube/config
8+
run:
9+
go run ../main.go
10+
11+
# Install CRDs into a cluster
12+
install:
13+
kustomize build config/crd | kubectl apply -f -
14+
15+
# Uninstall CRDs from a cluster
16+
uninstall:
17+
kustomize build config/crd | kubectl delete -f -
18+
19+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
20+
deploy:
21+
cd config/manager && kustomize edit set image controller=${IMG}
22+
kustomize build config/default | kubectl apply -f -
23+
24+
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
25+
undeploy:
26+
cd config/manager && kustomize edit set image controller=${IMG}
27+
kustomize build config/default | kubectl delete -f -
28+
29+
# Build the docker image
30+
docker-build:
31+
docker build . -t ${IMG}
32+
33+
# Push the docker image
34+
docker-push:
35+
docker push ${IMG}

config/crd/bases/apache.sdk.operatorframework.io_tomcats.yaml renamed to example/config/crd/bases/helm.sdk.operatorframework.io_nginxes.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ metadata:
66
annotations:
77
controller-gen.kubebuilder.io/version: v0.2.4
88
creationTimestamp: null
9-
name: tomcats.apache.sdk.operatorframework.io
9+
name: nginxes.helm.sdk.operatorframework.io
1010
spec:
11-
group: apache.sdk.operatorframework.io
11+
group: helm.sdk.operatorframework.io
1212
names:
13-
kind: Tomcat
14-
listKind: TomcatList
15-
plural: tomcats
16-
singular: tomcat
13+
kind: Nginx
14+
listKind: NginxList
15+
plural: nginxes
16+
singular: nginx
1717
scope: Namespaced
1818
versions:
1919
- name: v1
2020
schema:
2121
openAPIV3Schema:
22-
description: Tomcat is the Schema for the tomcats API
22+
description: Nginx is the Schema for the nginxes API
2323
properties:
2424
apiVersion:
2525
description: 'APIVersion defines the versioned schema of this representation
@@ -34,10 +34,10 @@ spec:
3434
metadata:
3535
type: object
3636
spec:
37-
description: TomcatSpec defines the desired state of Tomcat
37+
description: NginxSpec defines the desired state of Nginx
3838
type: object
3939
status:
40-
description: TomcatStatus defines the observed state of Tomcat
40+
description: NginxStatus defines the observed state of Nginx
4141
type: object
4242
type: object
4343
served: true

config/crd/kustomization.yaml renamed to example/config/crd/kustomization.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
44
resources:
5-
- bases/apache.sdk.operatorframework.io_tomcats.yaml
5+
- bases/helm.sdk.operatorframework.io_nginxes.yaml
66
# +kubebuilder:scaffold:crdkustomizeresource
77

88
patchesStrategicMerge:
99
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1010
# patches here are for enabling the conversion webhook for each CRD
11-
#- patches/webhook_in_tomcats.yaml
11+
#- patches/webhook_in_nginxes.yaml
1212
# +kubebuilder:scaffold:crdkustomizewebhookpatch
1313

1414
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
1515
# patches here are for enabling the CA injection for each CRD
16-
#- patches/cainjection_in_tomcats.yaml
16+
#- patches/cainjection_in_nginxes.yaml
1717
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
1818

1919
# the following config is for teaching kustomize how to do kustomization for CRDs.

0 commit comments

Comments
 (0)