Skip to content

Commit

Permalink
refactor: replace operator-sdk with kubebuilder, use k3d instead of k…
Browse files Browse the repository at this point in the history
…ind for testing (#11)

* refactor: replace operator-sdk with kubebuilder, use k3d instead of kind for testing, update readmes, update charts
  • Loading branch information
isindir authored Jul 25, 2020
1 parent 221e0a6 commit 4ef6e3b
Show file tree
Hide file tree
Showing 85 changed files with 1,470 additions and 2,297 deletions.
179 changes: 101 additions & 78 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ jobs:
image: ubuntu-1604:202004-01
environment:
GOLANG_VERSION: 1.14.4
# https://github.com/operator-framework/operator-sdk/releases
OPERATOR_SDK_VERSION: v0.18.2
# https://github.com/kubernetes-sigs/kubebuilder/releases
KUBEBUILDER_VERSION: 2.3.1
# https://github.com/kubernetes-sigs/kustomize/releases
KUSTOMIZE_VERSION: v3.8.1
# https://github.com/github/hub/releases
HUB_VERSION: 2.14.2
# https://github.com/git-chglog/git-chglog/releases
GIT_CHGLOG_VERSION: 0.9.1

GOPATH: /home/circleci/gogo
GOROOT: /usr/local/go
GO111MODULE: "on"
GO15VENDOREXPERIMENT: 1
steps:
- checkout
- run:
name: install golang
name: install kubebuilder
command: |
sudo rm -fr /usr/local/go
curl -sSLO https://dl.google.com/go/go${GOLANG_VERSION}.linux-amd64.tar.gz
tar -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz
sudo mv go /usr/local
rm -fr go${GOLANG_VERSION}.linux-amd64.tar.gz
mkdir -p $GOPATH/{src/github.com/isindir,bin,pkg}
go get -u golang.org/x/lint/golint
go version
go env
- restore-cache:
keys:
- v2-modules-{{ .Branch }}-{{ checksum "go.sum" }}
- v2-modules-{{ .Branch }}-
- v2-modules-
curl -sSLO https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KUBEBUILDER_VERSION}/kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64.tar.gz
tar -xzf kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64.tar.gz
chmod +x kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64/bin/{etcd,kube-apiserver,kubebuilder,kubectl}
sudo mv kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64/bin/{etcd,kube-apiserver,kubebuilder,kubectl} /usr/local/bin/
background: true
- run:
name: install operator-sdk
name: install kustomize
command: |
curl -sSLo operator-sdk https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu
chmod +x operator-sdk
sudo mv operator-sdk /usr/local/bin/
curl -sSLO https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz
tar -xzf kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz
chmod +x kustomize
sudo mv kustomize /usr/local/bin/
background: true
- run:
name: install git-chglog
command: |
Expand All @@ -54,14 +54,24 @@ jobs:
tar -xzf hub-linux-amd64-${HUB_VERSION}.tgz
chmod +x hub-linux-amd64-${HUB_VERSION}/bin/hub
sudo mv hub-linux-amd64-${HUB_VERSION}/bin/hub /usr/local/bin/
background: true
- run:
name: Fetch Go dependencies
command: |
make mod
- run:
name: Build
name: install golang
command: |
make build
sudo rm -fr /usr/local/go
curl -sSLO https://dl.google.com/go/go${GOLANG_VERSION}.linux-amd64.tar.gz
tar -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz
sudo mv go /usr/local
rm -fr go${GOLANG_VERSION}.linux-amd64.tar.gz
mkdir -p $GOPATH/{src/github.com/isindir,bin,pkg}
go get -u golang.org/x/lint/golint
go version
go env
- restore-cache:
keys:
- v2-modules-{{ .Branch }}-{{ checksum "go.sum" }}
- v2-modules-{{ .Branch }}-
- v2-modules-
- run:
name: release
command: |
Expand All @@ -76,16 +86,20 @@ jobs:
image: ubuntu-1604:202004-01
environment:
# https://github.com/kubernetes/kubernetes/releases
K8S_VERSION: v1.18.3
K8S_VERSION: v1.18.2
# https://github.com/kubernetes-sigs/kind/releases
KIND_VERSION: v0.8.1
# https://github.com/rancher/k3d/releases
K3D_VERSION: v3.0.0
# https://github.com/helm/helm/releases
HELM_VERSION: v3.2.4
GOLANG_VERSION: 1.14.4
# https://github.com/operator-framework/operator-sdk/releases
OPERATOR_SDK_VERSION: v0.18.2
# https://github.com/kubernetes-sigs/kubebuilder/releases
KUBEBUILDER_VERSION: 2.3.1
# https://github.com/mozilla/sops/releases
SOPS_VERSION: v3.5.0
SOPS_VERSION: v3.6.0
# https://github.com/kubernetes-sigs/kustomize/releases
KUSTOMIZE_VERSION: v3.8.1

KUBECONFIG: /home/circleci/.kube/config

Expand All @@ -112,51 +126,37 @@ jobs:
go get -u golang.org/x/lint/golint
go version
go env
background: true
- run:
name: install gpg2
command: |
sudo apt update
sudo apt install -f
sudo apt-get install gnupg2 -y
- run:
name: install kubectl
command: |
curl -sSLo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
mkdir -p ${HOME}/.kube
touch ${HOME}/.kube/config
background: true
- run:
name: install sops
command: |
curl -sSLo sops https://github.com/mozilla/sops/releases/download/${SOPS_VERSION}/sops-${SOPS_VERSION}.linux
chmod +x sops
sudo mv sops /usr/local/bin/
background: true
- run:
name: install operator-sdk
name: install kubebuilder
command: |
curl -sSLo operator-sdk https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu
chmod +x operator-sdk
sudo mv operator-sdk /usr/local/bin/
curl -sSLO https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KUBEBUILDER_VERSION}/kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64.tar.gz
tar -xzf kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64.tar.gz
chmod +x kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64/bin/{etcd,kube-apiserver,kubebuilder,kubectl}
sudo mv kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64/bin/{etcd,kube-apiserver,kubebuilder,kubectl} /usr/local/bin/
background: true
- run:
name: install kind
name: install kustomize
command: |
curl -sSLo kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64
chmod +x kind
sudo mv kind /usr/local/bin/
- run:
name: start kind
command: |
kind create cluster --quiet --name operator
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}';
until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do
sleep 1;
done
# Dump cluster info
kubectl cluster-info
kubectl version
kubectl describe node operator-control-plane
curl -sSLO https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz
tar -xzf kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz
chmod +x kustomize
sudo mv kustomize /usr/local/bin/
background: true
- run:
name: install helm
command: |
Expand All @@ -166,15 +166,39 @@ jobs:
sudo mv linux-amd64/helm /usr/local/bin/
rm -fr linux-amd64
helm version
# build starts here
background: true
- run:
name: install kubectl
command: |
curl -sSLo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
mkdir -p ${HOME}/.kube
touch ${HOME}/.kube/config
- run:
name: Fetch Go dependencies
name: install k3d
command: |
make mod
curl -sSLo k3d https://github.com/rancher/k3d/releases/download/${K3D_VERSION}/k3d-linux-amd64
chmod +x k3d
sudo mv k3d /usr/local/bin/
- run:
name: Build
name: start k3d
command: |
make build
k3d cluster create operator --agents 1
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}';
until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do
sleep 1;
done
# Dump cluster info
kubectl cluster-info
kubectl version
kubectl describe node k3d-operator-server-0
kubectl describe node k3d-operator-agent-0
- run:
name: Run Tests
command: |
make docker-build
- save_cache:
key: v2-modules-{{ .Branch }}-{{ checksum "go.sum" }}
paths:
Expand Down Expand Up @@ -206,15 +230,19 @@ jobs:
# Run k8s related commands
kubectl create namespace sops
kubectl apply -f deploy/crds/isindir_v1alpha1_sopssecret_crd.yaml
make install
sleep 3
sops -e -p $FP \
--encrypted-suffix='_templates' \
deploy/crds/00init.yaml \
> 00init.enc.yaml
kubectl apply -f 00init.enc.yaml --namespace sops
sops -e -p $FP \
--encrypted-suffix='Templates' \
config/samples/isindir_v1alpha2_sopssecret.yaml \
> config/samples/isindir_v1alpha2_sopssecret.enc.yaml
file config/samples/isindir_v1alpha2_sopssecret.enc.yaml
echo "====================================="
cat config/samples/isindir_v1alpha2_sopssecret.enc.yaml
echo "====================================="
kubectl apply -f config/samples/isindir_v1alpha2_sopssecret.enc.yaml --namespace sops
sleep 3
nohup make run/local &
nohup make run &
sleep 150
kubectl get sops --namespace sops
echo
Expand All @@ -229,7 +257,7 @@ jobs:
exit 1
fi
# Delete to check GC works
kubectl delete -f 00init.enc.yaml --namespace sops
kubectl delete -f config/samples/isindir_v1alpha2_sopssecret.enc.yaml --namespace sops
sleep 15
kubectl get sops --namespace sops
echo
Expand All @@ -243,11 +271,6 @@ jobs:
exit 1
fi
rm -fr $GNUPGHOME
- run:
name: Run Tests
command: |
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
make test
workflows:
version: 2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/manager
keys.tar.gz
keys
1.yaml
Expand Down
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Build the manager binary
FROM golang:1.14.4 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go

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

RUN apt-get -y update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends gnupg2 \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/bin
COPY --from=builder /workspace/manager .

RUN useradd --create-home --user-group nonroot
USER nonroot:nonroot

ENTRYPOINT ["/usr/local/bin/manager"]
Loading

0 comments on commit 4ef6e3b

Please sign in to comment.