Skip to content

Commit

Permalink
PVCViewers Controller: parameterize variables
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Yannis Zarkadas <[email protected]>
Github-PR: kubeflow#34
  • Loading branch information
kimwnasptd committed Apr 19, 2021
1 parent a63318d commit 43796be
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ spec:
group: kubeflow.org
names:
kind: PVCViewer
listKind: PVCViewerList
plural: pvcviewers
singular: pvcviewer
scope: ""
subresources:
status: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 23 additions & 16 deletions components/pvcviewer-controller/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 31 additions & 8 deletions components/pvcviewer-controller/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 43796be

Please sign in to comment.