Skip to content

Commit e7b1edc

Browse files
authored
Add web UI configurations when enabling UI service and ingress (#2599)
Signed-off-by: Yi Chen <[email protected]>
1 parent b27a1f2 commit e7b1edc

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

internal/controller/sparkapplication/controller.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,6 @@ func (r *Reconciler) reconcileSubmittedSparkApplication(ctx context.Context, req
318318
if err != nil {
319319
return fmt.Errorf("failed to get ingress url: %v", err)
320320
}
321-
// need to ensure the spark.ui variables are configured correctly if a subPath is used.
322-
if ingressURL.Path != "" {
323-
if app.Spec.SparkConf == nil {
324-
app.Spec.SparkConf = make(map[string]string)
325-
}
326-
app.Spec.SparkConf[common.SparkUIProxyBase] = ingressURL.Path
327-
app.Spec.SparkConf[common.SparkUIProxyRedirectURI] = "/"
328-
}
329321
ingress, err := r.createWebUIIngress(ctx, app, *service, ingressURL, r.options.IngressClassName, r.options.IngressTLS, r.options.IngressAnnotations)
330322
if err != nil {
331323
return fmt.Errorf("failed to create web UI ingress: %v", err)
@@ -739,6 +731,10 @@ func (r *Reconciler) submitSparkApplication(ctx context.Context, app *v1beta2.Sp
739731
r.recordSparkApplicationEvent(app)
740732
}()
741733

734+
if err := r.configWebUI(ctx, app); err != nil {
735+
return fmt.Errorf("failed to configure web UI: %v", err)
736+
}
737+
742738
if util.PrometheusMonitoringEnabled(app) {
743739
logger.Info("Configure Prometheus monitoring for SparkApplication")
744740
if err := configPrometheusMonitoring(ctx, app, r.client); err != nil {

internal/controller/sparkapplication/web_ui.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ import (
2929
"github.com/kubeflow/spark-operator/v2/pkg/util"
3030
)
3131

32+
func (r *Reconciler) configWebUI(_ context.Context, app *v1beta2.SparkApplication) error {
33+
if !r.options.EnableUIService || r.options.IngressURLFormat == "" {
34+
return nil
35+
}
36+
37+
ingressURL, err := getDriverIngressURL(r.options.IngressURLFormat, app)
38+
if err != nil {
39+
return fmt.Errorf("failed to get ingress url: %v", err)
40+
}
41+
if ingressURL.Path == "" {
42+
return nil
43+
}
44+
45+
if app.Spec.SparkConf == nil {
46+
app.Spec.SparkConf = make(map[string]string)
47+
}
48+
util.SetIfNotExists(app.Spec.SparkConf, common.SparkUIProxyBase, ingressURL.Path)
49+
util.SetIfNotExists(app.Spec.SparkConf, common.SparkUIProxyRedirectURI, "/")
50+
return nil
51+
}
52+
3253
func (r *Reconciler) createWebUIService(ctx context.Context, app *v1beta2.SparkApplication) (*SparkService, error) {
3354
portName := getWebUIServicePortName(app)
3455
port, err := getWebUIServicePort(app)

pkg/util/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,13 @@ func ConvertJavaMemoryStringToK8sMemoryString(memory string) string {
150150
// return original memory value if no conversion is needed
151151
return memory
152152
}
153+
154+
func SetIfNotExists[K comparable, V any](m map[K]V, key K, value V) {
155+
if m == nil {
156+
return
157+
}
158+
159+
if _, ok := m[key]; !ok {
160+
m[key] = value
161+
}
162+
}

0 commit comments

Comments
 (0)