You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/06/11 01:24:23 UTC

[GitHub] [flink-kubernetes-operator] Aitozi opened a new pull request, #265: [FLINK-27613] Add label for the session job to help list the session …

Aitozi opened a new pull request, #265:
URL: https://github.com/apache/flink-kubernetes-operator/pull/265

   …jobs in the same session cluster
   
   This PR is based on https://github.com/apache/flink-kubernetes-operator/pull/215 but use the mutator webhook to do the same thing


-- 
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@flink.apache.org

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


[GitHub] [flink-kubernetes-operator] Aitozi commented on a diff in pull request #265: [FLINK-27613] Add label for the session job to help list the session …

Posted by GitBox <gi...@apache.org>.
Aitozi commented on code in PR #265:
URL: https://github.com/apache/flink-kubernetes-operator/pull/265#discussion_r895810978


##########
flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/Utils.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.flink.kubernetes.operator.admission;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.fabric8.kubernetes.api.model.HasMetadata;
+
+/** Admission utils. */
+public class Utils {
+
+    private static final ObjectMapper mapper = new ObjectMapper();
+
+    public static <T> T convertToTargetType(HasMetadata resource, Class<T> targetType)

Review Comment:
   👍🏻, Fixed



-- 
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@flink.apache.org

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


[GitHub] [flink-kubernetes-operator] Aitozi commented on a diff in pull request #265: [FLINK-27613] Add label for the session job to help list the session …

Posted by GitBox <gi...@apache.org>.
Aitozi commented on code in PR #265:
URL: https://github.com/apache/flink-kubernetes-operator/pull/265#discussion_r895817521


##########
helm/flink-kubernetes-operator/templates/webhook.yaml:
##########
@@ -109,4 +109,36 @@ webhooks:
         operator: In
         values: [{{- range .Values.watchNamespaces }}{{ . | quote }},{{- end}}]
   {{- end }}
-  {{- end }}
+---

Review Comment:
   Agree, will do it 



-- 
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@flink.apache.org

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


[GitHub] [flink-kubernetes-operator] gyfora commented on a diff in pull request #265: [FLINK-27613] Add label for the session job to help list the session …

Posted by GitBox <gi...@apache.org>.
gyfora commented on code in PR #265:
URL: https://github.com/apache/flink-kubernetes-operator/pull/265#discussion_r895714062


##########
flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/mutator/FlinkMutator.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.flink.kubernetes.operator.admission.mutator;
+
+import org.apache.flink.kubernetes.operator.admission.Utils;
+import org.apache.flink.kubernetes.operator.crd.CrdConstants;
+import org.apache.flink.kubernetes.operator.crd.FlinkSessionJob;
+
+import io.fabric8.kubernetes.api.model.HasMetadata;
+import io.javaoperatorsdk.admissioncontroller.NotAllowedException;
+import io.javaoperatorsdk.admissioncontroller.Operation;
+import io.javaoperatorsdk.admissioncontroller.mutation.Mutator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+
+/** The default mutator. */
+public class FlinkMutator implements Mutator<HasMetadata> {
+    private static final Logger LOG = LoggerFactory.getLogger(FlinkMutator.class);
+
+    @Override
+    public HasMetadata mutate(HasMetadata resource, Operation operation)
+            throws NotAllowedException {
+        if (operation == Operation.CREATE) {
+            LOG.debug("Mutating resource {}", resource);
+
+            if (CrdConstants.KIND_SESSION_JOB.equals(resource.getKind())) {
+                try {
+                    var sessionJob = Utils.convertToTargetType(resource, FlinkSessionJob.class);
+                    patchInternalLabel(sessionJob);
+                    return sessionJob;
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+        return resource;
+    }
+
+    private void patchInternalLabel(FlinkSessionJob flinkSessionJob) {

Review Comment:
   I think it would be clearer to call it simply `setSessionTargetLabel`



##########
helm/flink-kubernetes-operator/templates/webhook.yaml:
##########
@@ -109,4 +109,36 @@ webhooks:
         operator: In
         values: [{{- range .Values.watchNamespaces }}{{ . | quote }},{{- end}}]
   {{- end }}
-  {{- end }}
+---

Review Comment:
   I think we should have a separate config flag to enable this. We should handle the validating and mutating webhooks independently of each other as some envs might want one but not the other.



##########
flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/Utils.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.flink.kubernetes.operator.admission;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.fabric8.kubernetes.api.model.HasMetadata;
+
+/** Admission utils. */
+public class Utils {
+
+    private static final ObjectMapper mapper = new ObjectMapper();
+
+    public static <T> T convertToTargetType(HasMetadata resource, Class<T> targetType)

Review Comment:
   I think we don’t need this utility class, ObjectMapper already has a convertValue method that does exactly this.



-- 
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@flink.apache.org

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


[GitHub] [flink-kubernetes-operator] Aitozi commented on a diff in pull request #265: [FLINK-27613] Add label for the session job to help list the session …

Posted by GitBox <gi...@apache.org>.
Aitozi commented on code in PR #265:
URL: https://github.com/apache/flink-kubernetes-operator/pull/265#discussion_r895841739


##########
helm/flink-kubernetes-operator/templates/webhook.yaml:
##########
@@ -109,4 +109,36 @@ webhooks:
         operator: In
         values: [{{- range .Values.watchNamespaces }}{{ . | quote }},{{- end}}]
   {{- end }}
-  {{- end }}
+---

Review Comment:
   Fixed



-- 
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@flink.apache.org

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


[GitHub] [flink-kubernetes-operator] gyfora merged pull request #265: [FLINK-27613] Add label for the session job to help list the session …

Posted by GitBox <gi...@apache.org>.
gyfora merged PR #265:
URL: https://github.com/apache/flink-kubernetes-operator/pull/265


-- 
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@flink.apache.org

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