Skip to content

Commit

Permalink
PVCViewers Controller: {Make,Docker}files
Browse files Browse the repository at this point in the history
Signed-off-by: Kimonas Sotirchos <[email protected]>
Reviewed-by: Yannis Zarkadas <[email protected]>
Github-PR: kubeflow#34
  • Loading branch information
kimwnasptd committed Sep 2, 2021
1 parent f9707af commit 7758f42
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
28 changes: 28 additions & 0 deletions components/pvcviewer-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Build the manager binary
FROM golang:1.12.5 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 util/ util/
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 gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER nonroot:nonroot

ENTRYPOINT ["/manager"]
105 changes: 105 additions & 0 deletions components/pvcviewer-controller/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

# Image URL to use all building/pushing image targets
IMG ?= gcr.io/arrikto-playground/pvcviewer-controller
TAG ?= $(shell git describe --tags)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

all: manager

# Run tests
test: generate fmt vet manifests
go test ./... -coverprofile cover.out

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

#
#
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
ENABLE_CULLING=false \
go run ./main.go

# Run the controller with culling enabled
# Will need to port-forward the prometheus service to 9090
# run `make proxy-prometheus` first
run-culling: generate fmt vet manifests
ENABLE_CULLING=true \
PROMETHEUS_SVC=localhost:9090 \
CLUSTER_DOMAIN=cluster.local \
IDLE_TIME=2 \
CULLING_CHECK_PERIOD=1 \
go run ./main.go

proxy-prometheus:
kubectl port-forward -n istio-system svc/prometheus 9090:9090

# Install CRDs into a cluster
install-crd: manifests
kustomize build config/crd | kubectl apply -f -

uninstall-crd: manifests
kustomize build config/crd | kubectl delete -f -

# Deploy basic CRs for testing
install-crs:
kubectl apply -f config/samples

uninstall-crs:
kubectl delete -f config/samples

#
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: docker-build docker-push manifests
cd config/manager && kustomize edit set image controller=$(IMG):$(TAG)
kustomize build config/default | kubectl apply -f -

destroy: manifests
cd config/manager && kustomize edit set image controller=$(IMG):$(TAG)
kustomize build config/default | kubectl delete -f -

delete-namespace:
kubectl delete namespace pvc-viewer-controller-system

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

# Run go fmt against code
fmt:
go fmt ./...

# Run go vet against code
vet:
go vet ./...

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."

# Build the docker image (should add some tests)
docker-build:
docker build . -t $(IMG):$(TAG)

# Push the docker image
docker-push:
docker push $(IMG):$(TAG)

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/[email protected]
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

0 comments on commit 7758f42

Please sign in to comment.