Skip to content

Commit

Permalink
Merge pull request kubeflow#16 from kubeflow/master
Browse files Browse the repository at this point in the history
[pull] master from kubeflow:master
  • Loading branch information
openshift-merge-robot authored May 4, 2022
2 parents df7cdf5 + da6efb9 commit 3edd3a9
Show file tree
Hide file tree
Showing 34 changed files with 10,802 additions and 2,931 deletions.
2 changes: 1 addition & 1 deletion components/crud-web-apps/common/backend/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
REQUIRES = [
"Flask >= 1.1.1",
"Flask-API >= 2.0",
"kubernetes >= 11.0.1",
"kubernetes == 22.6.0",
"requests >= 2.22.0",
"urllib3 >= 1.25.7",
"Werkzeug >= 0.16.0",
Expand Down
5 changes: 5 additions & 0 deletions components/notebook-controller/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
.git
bin/
testbin/
6 changes: 3 additions & 3 deletions components/notebook-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# This is necessary because the Jupyter controller now depends on
# components/common
ARG GOLANG_VERSION=1.15
ARG GOLANG_VERSION=1.17
FROM golang:${GOLANG_VERSION} as builder

WORKDIR /workspace
Expand All @@ -23,9 +23,9 @@ WORKDIR /workspace/notebook-controller

# Build
RUN if [ "$(uname -m)" = "aarch64" ]; then \
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -a -o manager main.go; \
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -a -mod=mod -o manager main.go; \
else \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go; \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -mod=mod -o manager main.go; \
fi

# Use distroless as minimal base image to package the manager binary
Expand Down
173 changes: 108 additions & 65 deletions components/notebook-controller/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@

# Image URL to use all building/pushing image targets
IMG ?= gcr.io/kubeflow-images-public/notebook-controller
IMG ?= public.ecr.aws/j1r0q0g6/notebooks/notebook-controller
TAG ?= $(shell git describe --tags --always)
SHELL := /bin/bash
GOLANG_VERSION ?= 1.15

# Whether to use cached images with GCB
USE_IMAGE_CACHE ?= true

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"

# Based on recommendation https://sdk.operatorframework.io/docs/building-operators/golang/references/envtest-setup/
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand All @@ -21,77 +13,128 @@ else
GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: manager

# check license
check-license:
./third_party/check-license.sh
##@ General

# Run tests
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/a9bd9117a77a2f84bbc546e28991136fe0000dc0/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR);
go test ./api/... ./controllers/... -coverprofile cover.out
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

# Build manager binary
manager: generate fmt vet
go build -o bin/manager main.go
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet
go run ./main.go
##@ Development

# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crd/bases
.PHONY: check-license
check-license: ## Check third-party license
./third_party/check-license.sh

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
kubectl apply -f config/crd/bases
kustomize build config/default | kubectl apply -f -
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

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

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

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

##@ Build

# Build the docker image
docker-build: test
.PHONY: manager
manager: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
cd .. && docker build . -t ${IMG}:${TAG} -f ./notebook-controller/Dockerfile
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"${IMG}:${TAG}"'@' ./config/default/manager_image_patch.yaml

# Push the docker image
docker-push:
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
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/controller-gen@v0.2.0
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
.PHONY: image
image: docker-build docker-push ## Build and push docker image with the manager.

# TODO(jlewi): Can we get rid of this and just use skaffold?
build-gcr: test
docker build -t $(IMG):$(TAG) .
@echo Built $(IMG):$(TAG)
##@ Deployment

ifndef ignore-not-found
ignore-not-found = false
endif

push-gcr: build-gcr
docker push $(IMG):$(TAG)
@echo Pushed $(IMG):$(TAG)
.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
sed -i'' -e 's@newName: .*@newName: '"${IMG}"'@' ./config/base/kustomization.yaml
sed -i'' -e 's@newTag: .*@newTag: '"${TAG}"'@' ./config/base/kustomization.yaml
$(KUSTOMIZE) build config/base | kubectl apply -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/base | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/v3/cmd/kustomize@v3.2.0)

ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
31 changes: 24 additions & 7 deletions components/notebook-controller/PROJECT
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
version: "2"
domain: kubeflow.org
layout:
- go.kubebuilder.io/v3
projectName: notebook-controller
repo: github.com/kubeflow/kubeflow/components/notebook-controller
resources:
- group: kubeflow.org
version: v1alpha1
kind: Notebook
- group: kubeflow.org
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kubeflow.org
kind: Notebook
- group: kubeflow.org
path: github.com/kubeflow/kubeflow/components/notebook-controller/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
domain: kubeflow.org
kind: Notebook
path: github.com/kubeflow/kubeflow/components/notebook-controller/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: kubeflow.org
kind: Notebook
path: github.com/kubeflow/kubeflow/components/notebook-controller/api/v1beta1
version: v1beta1
version: "3"
Loading

0 comments on commit 3edd3a9

Please sign in to comment.