Skip to content

Commit

Permalink
[Bug] nginx ingress class bug fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfboys committed Nov 15, 2023
1 parent 8f1cf35 commit e2e8327
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ object FileUtils {
s"[StreamPark] Failed to create directory within $TEMP_DIR_ATTEMPTS attempts (tried $baseName 0 to $baseName ${TEMP_DIR_ATTEMPTS - 1})")
}

def mkdir(dir: File) = {
if (dir.exists && !dir.isDirectory) {
throw new IOException(s"File $dir exists and is not a directory. Unable to create directory.")
} else if (!dir.mkdirs) {
// Double-check that some other thread or process hasn't made
if (!dir.isDirectory) {
throw new IOException(s"Unable to create directory $dir")
}
}
}

def getPathFromEnv(env: String): String = {
val path = Option(System.getenv(env)).getOrElse(System.getProperty(env))
require(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package org.apache.streampark.flink.kubernetes.ingress

import org.apache.streampark.common.conf.{ConfigKeys, InternalConfigHolder, K8sFlinkConfig}
import org.apache.streampark.common.util.FileUtils

import io.fabric8.kubernetes.api.model.{OwnerReference, OwnerReferenceBuilder}
import io.fabric8.kubernetes.client.DefaultKubernetesClient
import org.apache.commons.io.FileUtils
import org.apache.flink.client.program.ClusterClient

import java.io.File
Expand All @@ -36,26 +36,26 @@ trait IngressStrategy {
def configureIngress(domainName: String, clusterId: String, nameSpace: String): Unit

def prepareIngressTemplateFiles(buildWorkspace: String, ingressTemplates: String): String = {
val workspaceDir = new File(buildWorkspace)
if (!workspaceDir.exists) workspaceDir.mkdir
if (ingressTemplates.isEmpty) null
else {
val workspaceDir = new File(buildWorkspace)
FileUtils.mkdir(workspaceDir)
val outputPath = buildWorkspace + "/ingress.yaml"
val outputFile = new File(outputPath)
FileUtils.write(outputFile, ingressTemplates, "UTF-8")
FileUtils.writeFile(ingressTemplates, outputFile)
outputPath
}
}

def buildIngressAnnotations(clusterId: String, namespace: String): Map[String, String] = {
val annotations = Map(
var annotations = Map(
"nginx.ingress.kubernetes.io/rewrite-target" -> "/$2",
"nginx.ingress.kubernetes.io/proxy-body-size" -> "1024m",
"nginx.ingress.kubernetes.io/configuration-snippet" -> s"""rewrite ^(/$clusterId)$$ $$1/ permanent; sub_filter '<base href="./">' '<base href="/$namespace/$clusterId/">'; sub_filter_once off;"""
)
val ingressClass = InternalConfigHolder.get[String](K8sFlinkConfig.ingressClass)
if (ingressClass.nonEmpty) {
annotations + ("kubernetes.io/ingress.class" -> ingressClass)
annotations += ("kubernetes.io/ingress.class" -> ingressClass)
}
annotations
}
Expand Down

0 comments on commit e2e8327

Please sign in to comment.