private[utils] def buildSparkUIIngress()

in server/src/main/scala/org/apache/livy/utils/SparkKubernetesApp.scala [747:797]


    private[utils] def buildSparkUIIngress(
      app: KubernetesApplication, className: String, protocol: String, host: String,
      tlsSecretName: String, additionalConfSnippet: String, additionalAnnotations: (String, String)*
    ): Ingress = {
      val appTag = app.getApplicationTag
      val serviceHost = s"${getServiceName(app)}.${app.getApplicationNamespace}.svc.cluster.local"

      // Common annotations
      val annotations = Map(
        "nginx.ingress.kubernetes.io/rewrite-target" -> "/$1",
        "nginx.ingress.kubernetes.io/proxy-redirect-to" -> s"/$appTag/",
        "nginx.ingress.kubernetes.io/proxy-redirect-from" -> s"http://$serviceHost/",
        "nginx.ingress.kubernetes.io/upstream-vhost" -> s"$serviceHost",
        "nginx.ingress.kubernetes.io/service-upstream" -> "true",
        "nginx.ingress.kubernetes.io/x-forwarded-prefix" -> s"/$appTag",
        "nginx.ingress.kubernetes.io/configuration-snippet" ->
          NGINX_CONFIG_SNIPPET.concat(additionalConfSnippet)
      ) ++ additionalAnnotations

      val builder = new IngressBuilder()
        .withApiVersion("networking.k8s.io/v1")
        .withNewMetadata()
        .withName(getServiceName(app))
        .withNamespace(app.getApplicationNamespace)
        .addToAnnotations(annotations.asJava)
        .addToLabels(SPARK_APP_TAG_LABEL, appTag)
        .addToLabels(CREATED_BY_LIVY_LABEL.asJava)
        .endMetadata()
        .withNewSpec()
        .withIngressClassName(className)
        .addNewRule()
        .withHost(host)
        .withNewHttp()
        .addNewPath()
        .withPath(s"/$appTag/?(.*)")
        .withPathType("ImplementationSpecific")
        .withNewBackend()
        .withNewService()
        .withName(getServiceName(app))
        .withNewPort()
        .withName(SPARK_UI_PORT_NAME).endPort()
        .endService()
        .endBackend()
        .endPath()
        .endHttp()
        .endRule()
      if (protocol.endsWith("s") && tlsSecretName != null && tlsSecretName.nonEmpty) {
        builder.addNewTl().withSecretName(tlsSecretName).addToHosts(host).endTl()
      }
      builder.endSpec().build()
    }