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

[GitHub] [incubator-streampark] MonsterChenzhuo opened a new pull request, #2697: [Improve]Ingress uses different versions of API according to differen…

MonsterChenzhuo opened a new pull request, #2697:
URL: https://github.com/apache/incubator-streampark/pull/2697

   …t K8s versions.
   
   <!--
   Thank you for contributing to StreamPark! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   ## Contribution Checklist
   
     - If this is your first time, please read our contributor guidelines: [Submit Code](https://streampark.apache.org/community/submit_guide/submit_code).
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-streampark/issues).
   
     - Name the pull request in the form "[Feature] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
   
     - If the PR is unfinished, add `[WIP]` in your PR title, e.g., `[WIP][Feature] Title of the pull request`.
   
   -->
   
   ## What changes were proposed in this pull request
   
   Issue Number: close #xxx <!-- REMOVE this line if no issue to close -->
   
   <!--(For example: This pull request proposed to add checkstyle plugin).-->
   
   ## Brief change log
   
   <!--*(for example:)*
   - *Add maven-checkstyle-plugin to root pom.xml*
   -->
   
   ## Verifying this change
   
   <!--*(Please pick either of the following options)*-->
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   <!--*(example:)*
   - *Added integration tests for end-to-end.*
   - *Added *Test to verify the change.*
   - *Manually verified the change by testing locally.* -->
   
   ## Does this pull request potentially affect one of the following parts
    - Dependencies (does it add or upgrade a dependency): (yes / no)
   


-- 
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


[GitHub] [incubator-streampark] github-actions[bot] commented on a diff in pull request #2697: [Improve]Ingress uses different versions of API according to differen…

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #2697:
URL: https://github.com/apache/incubator-streampark/pull/2697#discussion_r1176175294


##########
streampark-flink/streampark-flink-kubernetes/src/test/scala/org/apache/streampark/flink/kubernetes/IngressMetaTestUtil.scala:
##########
@@ -0,0 +1,51 @@
+package org.apache.streampark.flink.kubernetes

Review Comment:
   ```suggestion
   /*
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance
    * with the License.  You may obtain a copy of the License at
    *
    *   http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an
    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    * KIND, either express or implied.  See the License for the
    * specific language governing permissions and limitations
    * under the License.
    */
   
   package org.apache.streampark.flink.kubernetes
   ```
   <!-- license-eye hidden identification -->



-- 
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


[GitHub] [incubator-streampark] github-actions[bot] commented on a diff in pull request #2697: [Improve]Ingress uses different versions of API according to differen…

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #2697:
URL: https://github.com/apache/incubator-streampark/pull/2697#discussion_r1176012735


##########
streampark-flink/streampark-flink-kubernetes/src/main/scala/org/apache/streampark/flink/kubernetes/ingress/IngressStrategyV1beta1.scala:
##########
@@ -0,0 +1,92 @@
+package org.apache.streampark.flink.kubernetes.ingress

Review Comment:
   ```suggestion
   /*
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance
    * with the License.  You may obtain a copy of the License at
    *
    *   http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an
    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    * KIND, either express or implied.  See the License for the
    * specific language governing permissions and limitations
    * under the License.
    */
   
   package org.apache.streampark.flink.kubernetes.ingress
   ```
   <!-- license-eye hidden identification -->



-- 
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


[GitHub] [incubator-streampark] senlizishi commented on pull request #2697: [Improve]Ingress uses different versions of API according to differen…

Posted by "senlizishi (via GitHub)" <gi...@apache.org>.
senlizishi commented on PR #2697:
URL: https://github.com/apache/incubator-streampark/pull/2697#issuecomment-1521518257

   LGTM


-- 
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


[GitHub] [incubator-streampark] wolfboys commented on a diff in pull request #2697: [Improve]Ingress uses different versions of API according to differen…

Posted by "wolfboys (via GitHub)" <gi...@apache.org>.
wolfboys commented on code in PR #2697:
URL: https://github.com/apache/incubator-streampark/pull/2697#discussion_r1176058673


##########
streampark-flink/streampark-flink-kubernetes/src/main/scala/org/apache/streampark/flink/kubernetes/ingress/IngressController.scala:
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.flink.kubernetes.ingress
+
+import org.apache.streampark.common.util.Logger
+
+import io.fabric8.kubernetes.client.DefaultKubernetesClient
+import org.apache.flink.client.program.ClusterClient
+
+import scala.language.postfixOps
+
+object IngressController extends Logger {
+
+  val ingressStrategy: IngressStrategy = {

Review Comment:
   ``` 
    private lazy val ingressStrategy: IngressStrategy = {
       val client = new DefaultKubernetesClient()
       val versionInfo = client.getVersion
       val version = s"${versionInfo.getMajor}.${versionInfo.getMajor}".toDouble
       if (version >= 1.19) {
         new IngressStrategyV1()
       } else {
         new IngressStrategyV1beta1()
       }
     }
   ```



##########
streampark-flink/streampark-flink-kubernetes/src/main/scala/org/apache/streampark/flink/kubernetes/ingress/BaseIngressStrategy.scala:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.flink.kubernetes.ingress
+
+import org.apache.streampark.common.util.Utils._
+
+import io.fabric8.kubernetes.client.DefaultKubernetesClient
+import org.apache.commons.io.FileUtils
+import org.apache.flink.client.program.ClusterClient
+import org.json4s.{DefaultFormats, JArray}
+import org.json4s.jackson.JsonMethods.parse
+
+import java.io.File
+import java.nio.file.{Files, Paths}
+
+import scala.language.postfixOps
+import scala.util.{Failure, Success, Try}
+
+abstract class BaseIngressStrategy extends IngressStrategy {
+  override def ingressUrlAddress(

Review Comment:
   This method is not suitable for writing here, should be subclasses(IngressStrategyV1 | IngressStrategyV1beta1) to implement



##########
streampark-flink/streampark-flink-kubernetes/src/main/scala/org/apache/streampark/flink/kubernetes/ingress/IngressController.scala:
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.flink.kubernetes.ingress
+
+import org.apache.streampark.common.util.Logger
+
+import io.fabric8.kubernetes.client.DefaultKubernetesClient
+import org.apache.flink.client.program.ClusterClient
+
+import scala.language.postfixOps
+
+object IngressController extends Logger {
+
+  val ingressStrategy: IngressStrategy = {
+    if (getKubernetesVersion() >= 1.19) new IngressStrategyV1()
+    else new IngressStrategyV1beta1()
+  }
+
+  def configureIngress(domainName: String, clusterId: String, nameSpace: String): Unit = {
+    ingressStrategy.configureIngress(domainName, clusterId, nameSpace)
+  }
+
+  def ingressUrlAddress(
+      nameSpace: String,
+      clusterId: String,
+      clusterClient: ClusterClient[_]): String = {
+    ingressStrategy.ingressUrlAddress(nameSpace, clusterId, clusterClient)
+  }
+
+  def prepareIngressTemplateFiles(buildWorkspace: String, ingressTemplates: String): String = {
+    ingressStrategy.prepareIngressTemplateFiles(buildWorkspace, ingressTemplates)
+  }
+
+  def getKubernetesVersion(): Double = {

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


[GitHub] [incubator-streampark] wolfboys merged pull request #2697: [Improve]Ingress uses different versions of API according to differen…

Posted by "wolfboys (via GitHub)" <gi...@apache.org>.
wolfboys merged PR #2697:
URL: https://github.com/apache/incubator-streampark/pull/2697


-- 
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


[GitHub] [incubator-streampark] senlizishi commented on a diff in pull request #2697: [Improve]Ingress uses different versions of API according to differen…

Posted by "senlizishi (via GitHub)" <gi...@apache.org>.
senlizishi commented on code in PR #2697:
URL: https://github.com/apache/incubator-streampark/pull/2697#discussion_r1176058990


##########
streampark-flink/streampark-flink-kubernetes/src/main/scala/org/apache/streampark/flink/kubernetes/ingress/IngressStrategyV1beta1.scala:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.flink.kubernetes.ingress
+
+import io.fabric8.kubernetes.api.model.OwnerReferenceBuilder
+import io.fabric8.kubernetes.client.DefaultKubernetesClient
+
+import scala.collection.JavaConverters._
+import scala.language.postfixOps
+import scala.util.{Success, Try}
+
+class IngressStrategyV1beta1 extends BaseIngressStrategy {
+  override def configureIngress(domainName: String, clusterId: String, nameSpace: String): Unit = {
+    Try(new DefaultKubernetesClient) match {
+      case Success(client) =>
+        val annotMap = Map[String, String](
+          "nginx.ingress.kubernetes.io/rewrite-target" -> "/$2",
+          "nginx.ingress.kubernetes.io/proxy-body-size" -> "1024m",
+          "nginx.ingress.kubernetes.io/configuration-snippet" -> ("rewrite ^(/" + clusterId + ")$ $1/ permanent;")
+        )
+        val labelsMap = Map[String, String](
+          "app" -> clusterId,
+          "type" -> "flink-native-kubernetes",
+          "component" -> "ingress")
+
+        val deployment = client
+          .apps()
+          .deployments()
+          .inNamespace(nameSpace)
+          .withName(clusterId)
+          .get()
+
+        val deploymentUid = if (deployment != null) {
+          deployment.getMetadata.getUid
+        } else {
+          throw new RuntimeException(
+            s"Deployment with name $clusterId not found in namespace $nameSpace")
+        }
+
+        // Create OwnerReference object
+        val ownerReference = new OwnerReferenceBuilder()
+          .withApiVersion("apps/v1")
+          .withKind("Deployment")
+          .withName(clusterId)
+          .withUid(deploymentUid)
+          .withController(true)
+          .withBlockOwnerDeletion(true)
+          .build()
+
+        val ingress = new io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder()
+          .withNewMetadata()
+          .withName(clusterId)
+          .addToAnnotations(annotMap.asJava)
+          .addToLabels(labelsMap.asJava)
+          .addToOwnerReferences(ownerReference)
+          .endMetadata()
+          .withNewSpec()
+          .addNewRule()
+          .withHost(domainName)
+          .withNewHttp()
+          .addNewPath()
+          .withPath(s"/$nameSpace/$clusterId/")
+          .withPathType("ImplementationSpecific")
+          .withNewBackend()
+          .withNewService()
+          .withName(s"$clusterId-rest")
+          .withNewPort()
+          .withName("rest")
+          .endPort()
+          .endService()
+          .endBackend()
+          .endPath()
+          .addNewPath()
+          .withPath(s"/$nameSpace/$clusterId" + "(/|$)(.*)")
+          .withPathType("ImplementationSpecific")
+          .withNewBackend()
+          .withNewService()
+          .withName(s"$clusterId-rest")
+          .withNewPort()
+          .withName("rest")
+          .endPort()
+          .endService()
+          .endBackend()
+          .endPath()
+          .endHttp()
+          .endRule()
+          .endSpec()
+          .build()
+        client.network.v1.ingresses().inNamespace(nameSpace).create(ingress)

Review Comment:
   There seems to be a reversal here. This is IngressStrategyV1beta1.scala, but it uses the API of Ingress v1



-- 
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