You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@streampark.apache.org by "wolfboys (via GitHub)" <gi...@apache.org> on 2023/05/12 15:29:30 UTC

[GitHub] [incubator-streampark] wolfboys commented on a diff in pull request #2741: [FIX]fix parse k8s version

wolfboys commented on code in PR #2741:
URL: https://github.com/apache/incubator-streampark/pull/2741#discussion_r1192514194


##########
streampark-flink/streampark-flink-kubernetes/src/main/scala/org/apache/streampark/flink/kubernetes/ingress/IngressStrategy.scala:
##########
@@ -26,13 +26,27 @@ import java.io.File
 
 trait IngressStrategy {
 
+  // splits a version string into numeric and "extra" parts
+  private val VERSION_MATCH_RE = "^\\s*v?([0-9]+(?:\\.[0-9]+)*)(.*)*$".r

Review Comment:
   `private[this] val GIT_VERSION_REGEXP = "^v(\\d+\\.\\d+)".r`



##########
streampark-flink/streampark-flink-kubernetes/src/main/scala/org/apache/streampark/flink/kubernetes/ingress/IngressController.scala:
##########
@@ -30,8 +30,7 @@ object IngressController extends Logger {
   private lazy val ingressStrategy: IngressStrategy = {
     using(new DefaultKubernetesClient()) {
       client =>
-        val versionInfo = client.getVersion
-        val version = s"${versionInfo.getMajor}.${versionInfo.getMinor}".toDouble
+        val version = ingressStrategy.parseSemantic(client.getVersion.getGitVersion)

Review Comment:
   val version = GIT_VERSION_REGEXP.findFirstIn(client.getVersion.getGitVersion).get.toDouble
   



##########
streampark-flink/streampark-flink-kubernetes/src/main/scala/org/apache/streampark/flink/kubernetes/ingress/IngressStrategy.scala:
##########
@@ -26,13 +26,27 @@ import java.io.File
 
 trait IngressStrategy {
 
+  // splits a version string into numeric and "extra" parts
+  private val VERSION_MATCH_RE = "^\\s*v?([0-9]+(?:\\.[0-9]+)*)(.*)*$".r
+
   def ingressUrlAddress(
       nameSpace: String,
       clusterId: String,
       clusterClient: ClusterClient[_]): String
 
   def configureIngress(domainName: String, clusterId: String, nameSpace: String): Unit
 
+  /**
+   * The version information of kubernetes is based on the gitVersion field ParseSemantic parses a
+   * version string that exactly obeys the syntax and semantics of the "Semantic Versioning"
+   * specification (http://semver.org/) (although it ignores leading and trailing whitespace, and
+   * allows the version to be preceded by "v").
+   */
+  def parseSemantic(getGitVersion: String): Double = {
+    val numbers = VERSION_MATCH_RE.findFirstMatchIn(getGitVersion).get.group(1).split('.')
+    s"${numbers(0)}.${numbers(1)}".toDouble
+  }

Review Comment:
   We can remove this method



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@streampark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org