From 43796bec39378b3c342005e216297e20687db454 Mon Sep 17 00:00:00 2001 From: Kimonas Sotirchos Date: Mon, 17 Feb 2020 14:32:26 +0200 Subject: [PATCH] PVCViewers Controller: parameterize variables The controller will be also using an ENV Variable to check 1. what image to use for the pvc viewer pod. 2. what the will be the endpoint for a pvcviewer 3. what image pull policy to use (we want always when in dev mode) Signed-off-by: Kimonas Sotirchos Reviewed-by: Yannis Zarkadas Github-PR: #34 --- .../crd/bases/kubeflow.org_pvcviewers.yaml | 2 + .../config/manager/kustomization.yaml | 2 +- .../config/manager/manager.yaml | 39 +++++++++++-------- components/pvcviewer-controller/util/util.go | 39 +++++++++++++++---- 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/components/pvcviewer-controller/config/crd/bases/kubeflow.org_pvcviewers.yaml b/components/pvcviewer-controller/config/crd/bases/kubeflow.org_pvcviewers.yaml index cdd584cb27b..e5a42e09eeb 100644 --- a/components/pvcviewer-controller/config/crd/bases/kubeflow.org_pvcviewers.yaml +++ b/components/pvcviewer-controller/config/crd/bases/kubeflow.org_pvcviewers.yaml @@ -9,7 +9,9 @@ spec: group: kubeflow.org names: kind: PVCViewer + listKind: PVCViewerList plural: pvcviewers + singular: pvcviewer scope: "" subresources: status: {} diff --git a/components/pvcviewer-controller/config/manager/kustomization.yaml b/components/pvcviewer-controller/config/manager/kustomization.yaml index 308c70d1470..439619cb234 100644 --- a/components/pvcviewer-controller/config/manager/kustomization.yaml +++ b/components/pvcviewer-controller/config/manager/kustomization.yaml @@ -5,4 +5,4 @@ kind: Kustomization images: - name: controller newName: gcr.io/arrikto-playground/pvcviewer-controller - newTag: latest + newTag: v0.4.0-rc.1-925-g00d52d25 diff --git a/components/pvcviewer-controller/config/manager/manager.yaml b/components/pvcviewer-controller/config/manager/manager.yaml index 1a955c7c556..18af098970b 100644 --- a/components/pvcviewer-controller/config/manager/manager.yaml +++ b/components/pvcviewer-controller/config/manager/manager.yaml @@ -23,20 +23,27 @@ spec: control-plane: controller-manager spec: containers: - - command: - - /manager - args: - - --enable-leader-election - image: controller:latest - name: manager - env: - - name: ENABLE_CULLING - value: "true" - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 100m - memory: 20Mi + - command: + - /manager + args: + - --enable-leader-election + image: controller:latest + name: manager + imagePullPolicy: Always + env: + - name: ENABLE_CULLING + value: "true" + - name: VIEWER_URL + value: "/volume/browser/%s/%s" + - name: VIEWER_IMAGE + value: "coderaiser/cloudcmd" + - name: VIEWER_PULL_POLICY + value: "IfNotPresent" + resources: + limits: + cpu: 100m + memory: 30Mi + requests: + cpu: 100m + memory: 20Mi terminationGracePeriodSeconds: 10 diff --git a/components/pvcviewer-controller/util/util.go b/components/pvcviewer-controller/util/util.go index 4403cedbed1..fa71dcbf264 100644 --- a/components/pvcviewer-controller/util/util.go +++ b/components/pvcviewer-controller/util/util.go @@ -14,10 +14,18 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) -const DEFAULT_SERVING_PORT = 80 -const DEFAULT_CONTAINER_PORT = 8000 -const CONTAINER_NAME = "pvcviewer" -const PVC_VIEWER_LABEL = "pvcviewer.kubeflow.org/name" +const ( + DEFAULT_SERVING_PORT = 80 + DEFAULT_CONTAINER_PORT = 8000 + CONTAINER_NAME = "pvcviewer" + PVC_VIEWER_LABEL = "pvcviewer.kubeflow.org/name" +) + +var ( + VIEWER_URL = GetEnvDefault("VIEWER_URL", "/volume/browser/%s/%s") + VIEWER_IMAGE = GetEnvDefault("VIEWER_IMAGE", "coderaiser/cloudcmd") + VIEWER_PULL_POLICY = GetEnvDefault("VIEWER_PULL_POLICY", "IfNotPresent") +) func GetEnvDefault(variable string, defaultVal string) string { envVar, exists := os.LookupEnv(variable) @@ -36,10 +44,26 @@ func GetSvcName(instance *v1alpha1.PVCViewer) string { } func GetPrefix(instance *v1alpha1.PVCViewer) string { - return fmt.Sprintf("/devices/volumes/%s/%s", + return fmt.Sprintf(VIEWER_URL, instance.Namespace, instance.Spec.PVC) } +func getPullPolicy() corev1.PullPolicy { + if VIEWER_PULL_POLICY == "Always" { + return corev1.PullAlways + } + + if VIEWER_PULL_POLICY == "Never" { + return corev1.PullNever + } + + if VIEWER_PULL_POLICY == "IfNotPresent" { + return corev1.PullIfNotPresent + } + + return corev1.PullAlways +} + func GetMountNode(podList *corev1.PodList, pvcName string) string { // Iterate the Pods in the PVCViewer's Namespace // If we find a Pod that has this Pod mounted, get the Pod's Node @@ -71,14 +95,14 @@ func GeneratePod(instance *v1alpha1.PVCViewer) *corev1.Pod { Containers: []corev1.Container{ { Name: CONTAINER_NAME, - Image: "coderaiser/cloudcmd", + Image: VIEWER_IMAGE, Args: []string{ "--prefix=" + GetPrefix(instance), "--prefix-socket=" + GetPrefix(instance), "--one-file-panel", "--root=/" + instance.Spec.PVC, }, - ImagePullPolicy: "IfNotPresent", + ImagePullPolicy: getPullPolicy(), Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("0"), @@ -145,7 +169,6 @@ func GenerateVirtualService(instance *v1alpha1.PVCViewer) (*unstructured.Unstruc namespace := instance.Namespace prefix := GetPrefix(instance) service := fmt.Sprintf("%s.%s.svc.cluster.local", GetSvcName(instance), namespace) - DEFAULT_SERVING_PORT := 80 vsvc := &unstructured.Unstructured{} vsvc.SetAPIVersion("networking.istio.io/v1alpha3")