From 949afa9a2e0971f0c3f7835fb3142db11273253f Mon Sep 17 00:00:00 2001 From: Sairaman Kumar Date: Sun, 16 May 2021 11:58:13 +0530 Subject: [PATCH 1/3] Added enable-ui-service flag to disable UI service --- main.go | 3 +- pkg/controller/sparkapplication/controller.go | 42 +++++++++++-------- .../sparkapplication/controller_test.go | 2 +- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 4ac6234a8..4076fda07 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,7 @@ var ( enableWebhook = flag.Bool("enable-webhook", false, "Whether to enable the mutating admission webhook for admitting and patching Spark pods.") enableResourceQuotaEnforcement = flag.Bool("enable-resource-quota-enforcement", false, "Whether to enable ResourceQuota enforcement for SparkApplication resources. Requires the webhook to be enabled.") ingressURLFormat = flag.String("ingress-url-format", "", "Ingress URL format.") + enableUIService = flag.Bool("enable-ui-service", true, "Enable Spark service UI.") enableLeaderElection = flag.Bool("leader-election", false, "Enable Spark operator leader election.") leaderElectionLockNamespace = flag.String("leader-election-lock-namespace", "spark-operator", "Namespace in which to create the ConfigMap for leader election.") leaderElectionLockName = flag.String("leader-election-lock-name", "spark-operator-lock", "Name of the ConfigMap for leader election.") @@ -178,7 +179,7 @@ func main() { } applicationController := sparkapplication.NewController( - crClient, kubeClient, crInformerFactory, podInformerFactory, metricConfig, *namespace, *ingressURLFormat, batchSchedulerMgr) + crClient, kubeClient, crInformerFactory, podInformerFactory, metricConfig, *namespace, *ingressURLFormat, batchSchedulerMgr, *enableUIService) scheduledApplicationController := scheduledsparkapplication.NewController( crClient, kubeClient, apiExtensionsClient, crInformerFactory, clock.RealClock{}) diff --git a/pkg/controller/sparkapplication/controller.go b/pkg/controller/sparkapplication/controller.go index 8c3bc553e..1fc7e6994 100644 --- a/pkg/controller/sparkapplication/controller.go +++ b/pkg/controller/sparkapplication/controller.go @@ -77,6 +77,7 @@ type Controller struct { podLister v1.PodLister ingressURLFormat string batchSchedulerMgr *batchscheduler.SchedulerManager + enableUIService bool } // NewController creates a new Controller. @@ -88,7 +89,8 @@ func NewController( metricsConfig *util.MetricConfig, namespace string, ingressURLFormat string, - batchSchedulerMgr *batchscheduler.SchedulerManager) *Controller { + batchSchedulerMgr *batchscheduler.SchedulerManager, + enableUIService bool) *Controller { crdscheme.AddToScheme(scheme.Scheme) eventBroadcaster := record.NewBroadcaster() @@ -98,7 +100,7 @@ func NewController( }) recorder := eventBroadcaster.NewRecorder(scheme.Scheme, apiv1.EventSource{Component: "spark-operator"}) - return newSparkApplicationController(crdClient, kubeClient, crdInformerFactory, podInformerFactory, recorder, metricsConfig, ingressURLFormat, batchSchedulerMgr) + return newSparkApplicationController(crdClient, kubeClient, crdInformerFactory, podInformerFactory, recorder, metricsConfig, ingressURLFormat, batchSchedulerMgr, enableUIService) } func newSparkApplicationController( @@ -109,7 +111,8 @@ func newSparkApplicationController( eventRecorder record.EventRecorder, metricsConfig *util.MetricConfig, ingressURLFormat string, - batchSchedulerMgr *batchscheduler.SchedulerManager) *Controller { + batchSchedulerMgr *batchscheduler.SchedulerManager, + enableUIService bool) *Controller { queue := workqueue.NewNamedRateLimitingQueue(&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(queueTokenRefillRate), queueTokenBucketSize)}, "spark-application-controller") @@ -120,6 +123,7 @@ func newSparkApplicationController( queue: queue, ingressURLFormat: ingressURLFormat, batchSchedulerMgr: batchSchedulerMgr, + enableUIService: enableUIService, } if metricsConfig != nil { @@ -699,21 +703,23 @@ func (c *Controller) submitSparkApplication(app *v1beta2.SparkApplication) *v1be } c.recordSparkApplicationEvent(app) - service, err := createSparkUIService(app, c.kubeClient) - if err != nil { - glog.Errorf("failed to create UI service for SparkApplication %s/%s: %v", app.Namespace, app.Name, err) - } else { - app.Status.DriverInfo.WebUIServiceName = service.serviceName - app.Status.DriverInfo.WebUIPort = service.servicePort - app.Status.DriverInfo.WebUIAddress = fmt.Sprintf("%s:%d", service.serviceIP, app.Status.DriverInfo.WebUIPort) - // Create UI Ingress if ingress-format is set. - if c.ingressURLFormat != "" { - ingress, err := createSparkUIIngress(app, *service, c.ingressURLFormat, c.kubeClient) - if err != nil { - glog.Errorf("failed to create UI Ingress for SparkApplication %s/%s: %v", app.Namespace, app.Name, err) - } else { - app.Status.DriverInfo.WebUIIngressAddress = ingress.ingressURL - app.Status.DriverInfo.WebUIIngressName = ingress.ingressName + if c.enableUIService { + service, err := createSparkUIService(app, c.kubeClient) + if err != nil { + glog.Errorf("failed to create UI service for SparkApplication %s/%s: %v", app.Namespace, app.Name, err) + } else { + app.Status.DriverInfo.WebUIServiceName = service.serviceName + app.Status.DriverInfo.WebUIPort = service.servicePort + app.Status.DriverInfo.WebUIAddress = fmt.Sprintf("%s:%d", service.serviceIP, app.Status.DriverInfo.WebUIPort) + // Create UI Ingress if ingress-format is set. + if c.ingressURLFormat != "" { + ingress, err := createSparkUIIngress(app, *service, c.ingressURLFormat, c.kubeClient) + if err != nil { + glog.Errorf("failed to create UI Ingress for SparkApplication %s/%s: %v", app.Namespace, app.Name, err) + } else { + app.Status.DriverInfo.WebUIIngressAddress = ingress.ingressURL + app.Status.DriverInfo.WebUIIngressName = ingress.ingressName + } } } } diff --git a/pkg/controller/sparkapplication/controller_test.go b/pkg/controller/sparkapplication/controller_test.go index c891444a4..bb6b19510 100644 --- a/pkg/controller/sparkapplication/controller_test.go +++ b/pkg/controller/sparkapplication/controller_test.go @@ -67,7 +67,7 @@ func newFakeController(app *v1beta2.SparkApplication, pods ...*apiv1.Pod) (*Cont podInformerFactory := informers.NewSharedInformerFactory(kubeClient, 0*time.Second) controller := newSparkApplicationController(crdClient, kubeClient, informerFactory, podInformerFactory, recorder, - &util.MetricConfig{}, "", nil) + &util.MetricConfig{}, "", nil, true) informer := informerFactory.Sparkoperator().V1beta2().SparkApplications().Informer() if app != nil { From 7173bef562fee971e299e70783a9fad6cfeed4e4 Mon Sep 17 00:00:00 2001 From: Sairaman Kumar Date: Sun, 16 May 2021 12:03:28 +0530 Subject: [PATCH 2/3] Added uiService.enable to helm charts --- charts/spark-operator-chart/README.md | 3 ++- charts/spark-operator-chart/templates/deployment.yaml | 1 + charts/spark-operator-chart/values.yaml | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/charts/spark-operator-chart/README.md b/charts/spark-operator-chart/README.md index 16c26c81d..64515f00d 100644 --- a/charts/spark-operator-chart/README.md +++ b/charts/spark-operator-chart/README.md @@ -87,7 +87,8 @@ All charts linted successfully | image.repository | string | `"gcr.io/spark-operator/spark-operator"` | Image repository | | image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion. | | imagePullSecrets | list | `[]` | Image pull secrets | -| ingressUrlFormat | string | `""` | Ingress URL format | +| uiService.enable | bool | `""` | Enable UI service creation for Spark application | +| ingressUrlFormat | string | `""` | Ingress URL format. Requires the UI service to be enabled by setting `uiService.enable` to true. | | istio.enabled | bool | `false` | When using `istio`, spark jobs need to run without a sidecar to properly terminate | | labelSelectorFilter | string | `""` | A comma-separated list of key=value, or key labels to filter resources during watch and list based on the specified labels. | | leaderElection.lockName | string | `"spark-operator-lock"` | Leader election lock name. Ref: https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/docs/user-guide.md#enabling-leader-election-for-high-availability. | diff --git a/charts/spark-operator-chart/templates/deployment.yaml b/charts/spark-operator-chart/templates/deployment.yaml index 952874c98..331ab3552 100644 --- a/charts/spark-operator-chart/templates/deployment.yaml +++ b/charts/spark-operator-chart/templates/deployment.yaml @@ -55,6 +55,7 @@ spec: - -v={{ .Values.logLevel }} - -logtostderr - -namespace={{ .Values.sparkJobNamespace }} + - -enable-ui-service={{ .Values.uiService.enable}} - -ingress-url-format={{ .Values.ingressUrlFormat }} - -controller-threads={{ .Values.controllerThreads }} - -resync-interval={{ .Values.resyncInterval }} diff --git a/charts/spark-operator-chart/values.yaml b/charts/spark-operator-chart/values.yaml index 2a735fc64..ca44f4288 100644 --- a/charts/spark-operator-chart/values.yaml +++ b/charts/spark-operator-chart/values.yaml @@ -53,7 +53,12 @@ controllerThreads: 10 # unrelated to this setting resyncInterval: 30 -# -- Ingress URL format +uiService: + # -- Enable UI service creation for Spark application + enable: true + +# -- Ingress URL format. +# Requires the UI service to be enabled by setting `uiService.enable` to true. ingressUrlFormat: "" # -- Set higher levels for more verbose logging From 94652e7490d3bed58d63c8c1554febb754ef369d Mon Sep 17 00:00:00 2001 From: Sairaman K Date: Mon, 17 May 2021 09:01:42 +0530 Subject: [PATCH 3/3] Updated the Chart version to 1.1.1 --- charts/spark-operator-chart/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/spark-operator-chart/Chart.yaml b/charts/spark-operator-chart/Chart.yaml index 21548cf60..0258a522c 100644 --- a/charts/spark-operator-chart/Chart.yaml +++ b/charts/spark-operator-chart/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: spark-operator description: A Helm chart for Spark on Kubernetes operator -version: 1.1.0 +version: 1.1.1 appVersion: v1beta2-1.2.3-3.1.1 keywords: - spark