From b957a9872cda4401e243ea95940733b7eae4d662 Mon Sep 17 00:00:00 2001 From: jingzhang36 Date: Thu, 4 Jul 2019 02:39:40 +0800 Subject: [PATCH] Viewer CRD controller running under namespace (#1562) * Viewer CRD controller running under namespace * Change docker file and add manifest deployment yaml to support the new flag namespace * Change docker file to support new flag namespace for viewer crd controller * Modify kustomization.yaml and namespaced-install.yaml * Change file name from ml-pipeline-viewer-crd-deployment to ml-pipeline-viewer-crd-deployment-patch * Fix typo * Remove some duplicate configs in namespaced-install --- backend/Dockerfile.viewercontroller | 3 ++- backend/src/crd/controller/viewer/BUILD.bazel | 1 + backend/src/crd/controller/viewer/main.go | 12 +++++++++++- manifests/namespaced-install.yaml | 2 ++ manifests/namespaced-install/kustomization.yaml | 1 + .../ml-pipeline-viewer-crd-deployment-patch.yaml | 12 ++++++++++++ 6 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 manifests/namespaced-install/ml-pipeline-viewer-crd-deployment-patch.yaml diff --git a/backend/Dockerfile.viewercontroller b/backend/Dockerfile.viewercontroller index fac487fb416..9f4ff561ac9 100644 --- a/backend/Dockerfile.viewercontroller +++ b/backend/Dockerfile.viewercontroller @@ -20,5 +20,6 @@ COPY --from=builder /src/github.com/kubeflow/pipelines/third_party/license.txt / RUN chmod +x /bin/controller ENV MAX_NUM_VIEWERS "50" +ENV NAMESPACE "kubeflow" -CMD /bin/controller -alsologtostderr=true -max_num_viewers=${MAX_NUM_VIEWERS} \ No newline at end of file +CMD /bin/controller -alsologtostderr=true -max_num_viewers=${MAX_NUM_VIEWERS} --namespace=${NAMESPACE} \ No newline at end of file diff --git a/backend/src/crd/controller/viewer/BUILD.bazel b/backend/src/crd/controller/viewer/BUILD.bazel index cc7371d9037..b7041c6121f 100644 --- a/backend/src/crd/controller/viewer/BUILD.bazel +++ b/backend/src/crd/controller/viewer/BUILD.bazel @@ -17,6 +17,7 @@ go_library( "@io_k8s_client_go//tools/clientcmd:go_default_library", "@io_k8s_sigs_controller_runtime//pkg/builder:go_default_library", "@io_k8s_sigs_controller_runtime//pkg/client:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/manager:go_default_library", ], ) diff --git a/backend/src/crd/controller/viewer/main.go b/backend/src/crd/controller/viewer/main.go index 853c9917d06..afa29d496c0 100644 --- a/backend/src/crd/controller/viewer/main.go +++ b/backend/src/crd/controller/viewer/main.go @@ -32,6 +32,7 @@ import ( "k8s.io/client-go/tools/clientcmd" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/manager" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // Needed for GCP authentication. ) @@ -42,6 +43,9 @@ var ( maxNumViewers = flag.Int("max_num_viewers", 50, "Maximum number of viewer instances allowed within "+ "the cluster before the controller starts deleting the oldest one.") + namespace = flag.String("namespace", "kubeflow", + "Namespace within which CRD controller is running. Default is "+ + "kubeflow.") ) func main() { @@ -67,7 +71,13 @@ func main() { // Create a controller that is in charge of Viewer types, and also responds to // changes to any deployment and services that is owned by any Viewer instance. - mgr, err := builder.SimpleController(). + mgr, err := manager.New(cfg, manager.Options{Namespace: *namespace}) + if err != nil { + log.Fatal(err) + } + + _, err = builder.SimpleController(). + WithManager(mgr). ForType(&viewerV1beta1.Viewer{}). Owns(&appsv1.Deployment{}). Owns(&corev1.Service{}). diff --git a/manifests/namespaced-install.yaml b/manifests/namespaced-install.yaml index 07932dc3849..b75a9851ecd 100644 --- a/manifests/namespaced-install.yaml +++ b/manifests/namespaced-install.yaml @@ -759,6 +759,8 @@ spec: - env: - name: MAX_NUM_VIEWERS value: "50" + - name: NAMESPACE + value: kubeflow image: gcr.io/ml-pipeline/viewer-crd-controller:0.1.23 imagePullPolicy: Always name: ml-pipeline-viewer-crd diff --git a/manifests/namespaced-install/kustomization.yaml b/manifests/namespaced-install/kustomization.yaml index 8ea6d113513..e9ff73c78c7 100644 --- a/manifests/namespaced-install/kustomization.yaml +++ b/manifests/namespaced-install/kustomization.yaml @@ -13,6 +13,7 @@ patchesStrategicMerge: - workflow-controller-configmap.yaml - ml-pipeline-persistenceagent-deployment-patch.yaml - ml-pipeline-scheduledworkflow-deployment-patch.yaml +- ml-pipeline-viewer-crd-deployment-patch.yaml - ml-pipeline-ui-deployment-patch.yaml vars: diff --git a/manifests/namespaced-install/ml-pipeline-viewer-crd-deployment-patch.yaml b/manifests/namespaced-install/ml-pipeline-viewer-crd-deployment-patch.yaml new file mode 100644 index 00000000000..848134f1fbc --- /dev/null +++ b/manifests/namespaced-install/ml-pipeline-viewer-crd-deployment-patch.yaml @@ -0,0 +1,12 @@ +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: ml-pipeline-viewer-crd +spec: + template: + spec: + containers: + - name: ml-pipeline-viewer-crd + env: + - name: NAMESPACE + value: $(NAMESPACE)