Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: pvcviewer-controller and PVCViewer pod #5783

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions components/pvcviewer-controller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
35 changes: 35 additions & 0 deletions components/pvcviewer-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Build the manager binary
# The Docker context is expected to be:
#
# ${PATH_TO_KUBEFLOW/KUBEFLOW repo}/components
#
# This is necessary because the Jupyter controller now depends on
# components/common
FROM golang:1.16.2 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
# Copy the Go Modules manifests
COPY pvcviewer-controller /workspace/pvcviewer-controller
COPY common /workspace/common
# 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 cd /workspace/pvcviewer-controller && go mod download

WORKDIR /workspace/pvcviewer-controller

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

# 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/pvcviewer-controller/manager .
USER nonroot:nonroot

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

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# 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
go run ./main.go

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

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

# 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
docker-build: test
cd .. && docker build -f pvcviewer-controller/Dockerfile . -t ${IMG}

# Push the docker image
docker-push:
docker push ${IMG}

# 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.1
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
5 changes: 5 additions & 0 deletions components/pvcviewer-controller/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
approvers:
- elikatsis
- DavidSpek
- kimwnasptd
reviewers:
7 changes: 7 additions & 0 deletions components/pvcviewer-controller/PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "2"
domain: kubeflow.org
repo: pvcviewer-controller
resources:
- group: pvcviewer
version: v1alpha1
kind: pvcviewer
61 changes: 61 additions & 0 deletions components/pvcviewer-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# GSoC 2020 - TENSORBOARD CONTROLLER

### Related Closed Issues

- [Extend Tensorboard Controller to Support PVCs #5039](https://github.com/kubeflow/kubeflow/issues/5039)

- [Tensorboard controller creates servers that always mount user-gcp-sa secret #5065](https://github.com/kubeflow/kubeflow/issues/5065)

- [Tensorboard CR doesn't contain information about the Tensorboard Server being ready or not #5166](https://github.com/kubeflow/kubeflow/issues/5166)

### Related Pull Requests

- [Mount GCP secret only when accessing Google storage #5069](https://github.com/kubeflow/kubeflow/pull/5069)

- [Add scheduling functionality for Tensorboard servers that use RWO PVCs as log storages #5218](https://github.com/kubeflow/kubeflow/pull/5218)

- [Add functionality to inform TWA frontend about the status of Tensorboard servers #5259](https://github.com/kubeflow/kubeflow/pull/5259)

Prequisites to build and run the controller:

1. GO

2. Docker

3. kustomize

4. kubectl

## RUN TENSORBOARD CONTROLLER LOCALLY

Steps:


1. Clone the repository

2. Change directories to `components/tensorboard-controller`

3. Generate and install manifests and build the controller: `make install`

4. Run the controller locally: `make run`

If you want to enable the scheduling functionality for Tensorboard servers that use ReadWriteOnce PVCs as log storages, then set the `RWO_PVC_SCHEDULING` to `true` and run: `RWO_PVC_SCHEDULING="true" make run`

## BUILD TENSORBOARD CONTROLLER IMAGE AND DEPLOY TO CLUSTER

1. Clone the repository

2. Change directories to `components/tensorboard-controller`

3. Generate and install manifests and build the controller: `make manifests`

4. Build and push the docker image: `make docker-build docker-push IMG=YOUR_IMAGE_NAME`

5. Deploy the Tensorboard controller: `make deploy IMG=YOUR_IMAGE_NAME`

If you want to enable the scheduling functionality for Tensorboard servers that use ReadWriteOnce PVCs as log storages, then:

1. Change directories to `components/tensorboard-controller/config/manager`
2. Modify the `manager.yaml` file by navigating to the `deployment.spec.template.spec` field and manually setting the value of the `RWO_PVC_SCHEDULING` env var to `"true"` in the manager container.

3. Run: `make deploy IMG=YOUR_IMAGE_NAME`
35 changes: 35 additions & 0 deletions components/pvcviewer-controller/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the pvcviewer v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=pvcviewer.kubeflow.org
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "pvcviewer.kubeflow.org", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
78 changes: 78 additions & 0 deletions components/pvcviewer-controller/api/v1alpha1/pvcviewer_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// PVCViewerSpec defines the desired state of PVCViewer
type PVCViewerSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
PVCName string `json:"pvcname"`
ViewerImage string `json:"viewerimage"`
}

// PVCViewerCondition defines the observed state of PVCViewer
type PVCViewerCondition struct {
// Deployment status, 'Available', 'Progressing', 'ReplicaFailure' .
DeploymentState appsv1.DeploymentConditionType `json:"deploymentState"`

// Last time we probed the condition.
LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"`
}

// PVCViewerStatus defines the observed state of PVCViewer
type PVCViewerStatus struct {
// Conditions is an array of current conditions
Conditions []PVCViewerCondition `json:"conditions"`
// ReadyReplicas defines the number of PVCViewer Servers
// that are available to connect. The value of ReadyReplicas
// can be either 0 or 1
ReadyReplicas int32 `json:"readyReplicas"`
Ready bool `json:"ready"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=pvcviewers,scope=Namespaced
// +kubebuilder:subresource:status

// PVCViewer is the Schema for the pvcviewers API
type PVCViewer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec PVCViewerSpec `json:"spec,omitempty"`
Status PVCViewerStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// PVCViewerList contains a list of PVCViewer
type PVCViewerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []PVCViewer `json:"items"`
}

func init() {
SchemeBuilder.Register(&PVCViewer{}, &PVCViewerList{})
}