gyfora commented on a change in pull request #1: URL: https://github.com/apache/flink-kubernetes-operator/pull/1#discussion_r806540896
########## File path: examples/basic-checkpoint-ha.yaml ########## @@ -0,0 +1,61 @@ +################################################################################ +# 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. +################################################################################ + +apiVersion: flink.apache.org/v1alpha1 +kind: FlinkDeployment +metadata: + namespace: default + name: basic-checkpoint-ha-example +spec: + image: flink:1.14.3 + flinkVersion: 1.14.3 + flinkConfiguration: + taskmanager.numberOfTaskSlots: "2" Review comment: Good catch, the config is definitely redundant here in the yamls and I will clean it up. In general for application clusters we would not even need this config in either place (TM or config) as it is automatically computed from the parallelism and number of TMs. For session clusters it is a very important config so I would still keep it under the taskManager section. What do you think? ########## File path: examples/basic-checkpoint-ha.yaml ########## @@ -0,0 +1,61 @@ +################################################################################ +# 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. +################################################################################ + +apiVersion: flink.apache.org/v1alpha1 +kind: FlinkDeployment +metadata: + namespace: default + name: basic-checkpoint-ha-example +spec: + image: flink:1.14.3 + flinkVersion: 1.14.3 + flinkConfiguration: + taskmanager.numberOfTaskSlots: "2" Review comment: Good catch, the config is definitely redundant here in the yamls and I will clean it up. ########## File path: pom.xml ########## @@ -0,0 +1,286 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.apache</groupId> + <artifactId>apache</artifactId> + <version>20</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.flink</groupId> + <artifactId>flink-kubernetes-operator-parent</artifactId> + <version>1.0-SNAPSHOT</version> + + <name>Flink Kubernetes: </name> + <packaging>pom</packaging> + <url>https://flink.apache.org</url> + <inceptionYear>2014</inceptionYear> + + <licenses> + <license> + <name>The Apache Software License, Version 2.0</name> + <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url> + <distribution>repo</distribution> + </license> + </licenses> + + <modules> + <module>flink-kubernetes-operator</module> + <module>flink-kubernetes-webhook</module> + </modules> + + <properties> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version> + <maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version> + <maven-failsafe-plugin.version>3.0.0-M4</maven-failsafe-plugin.version> + <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version> + + <operator.sdk.version>2.0.1</operator.sdk.version> + <fabric8.version>5.12.1</fabric8.version> + <lombok.version>1.18.22</lombok.version> + + <scala.version>2.12</scala.version> + <flink.version>1.14.3</flink.version> + <flink.shaded.version>15.0</flink.shaded.version> + + <slf4j.version>1.7.15</slf4j.version> + <log4j.version>2.17.1</log4j.version> + + <spotless.version>2.4.2</spotless.version> + <awaitility.version>4.1.0</awaitility.version> + <it.skip>true</it.skip> + <mockito.version>2.21.0</mockito.version> Review comment: Not sure but let's upgrade it, I agree :) ########## File path: pom.xml ########## @@ -0,0 +1,285 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.apache</groupId> + <artifactId>apache</artifactId> + <version>20</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.flink</groupId> + <artifactId>flink-kubernetes-operator-parent</artifactId> + <version>1.0-SNAPSHOT</version> + + <name>Flink Kubernetes: </name> + <packaging>pom</packaging> + <url>https://flink.apache.org</url> + <inceptionYear>2014</inceptionYear> + + <licenses> + <license> + <name>The Apache Software License, Version 2.0</name> + <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url> + <distribution>repo</distribution> + </license> + </licenses> + + <modules> + <module>flink-kubernetes-operator</module> + <module>flink-kubernetes-webhook</module> + </modules> + + <properties> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> + <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version> + <maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version> + <maven-failsafe-plugin.version>3.0.0-M4</maven-failsafe-plugin.version> + <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version> + + <operator.sdk.version>2.1.1</operator.sdk.version> + <fabric8.version>5.12.1</fabric8.version> + <lombok.version>1.18.22</lombok.version> + + <scala.version>2.12</scala.version> + <flink.version>1.14.3</flink.version> + <flink.shaded.version>15.0</flink.shaded.version> Review comment: Flink 1.15 already uses this version, I think by the time we have a first release here that is going to be the current version :) ########## File path: flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkUtils.java ########## @@ -0,0 +1,229 @@ +/* + * 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.utils; + +import org.apache.flink.configuration.ConfigConstants; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.CoreOptions; +import org.apache.flink.configuration.DeploymentOptions; +import org.apache.flink.configuration.GlobalConfiguration; +import org.apache.flink.configuration.JobManagerOptions; +import org.apache.flink.configuration.PipelineOptions; +import org.apache.flink.configuration.TaskManagerOptions; +import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions; +import org.apache.flink.kubernetes.configuration.KubernetesDeploymentTarget; +import org.apache.flink.kubernetes.operator.crd.FlinkDeployment; +import org.apache.flink.kubernetes.operator.crd.spec.FlinkDeploymentSpec; +import org.apache.flink.util.StringUtils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.internal.SerializationUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.util.Collections; +import java.util.Iterator; + +/** Flink Utility methods used by the operator. */ +public class FlinkUtils { + + private static final Logger LOG = LoggerFactory.getLogger(FlinkUtils.class); + private static final ObjectMapper MAPPER = new ObjectMapper(); + + public static Configuration getEffectiveConfig(FlinkDeployment flinkApp) { + String namespace = flinkApp.getMetadata().getNamespace(); + String clusterId = flinkApp.getMetadata().getName(); + FlinkDeploymentSpec spec = flinkApp.getSpec(); + + try { + String flinkConfDir = System.getenv().get(ConfigConstants.ENV_FLINK_CONF_DIR); + Configuration effectiveConfig = + flinkConfDir != null + ? GlobalConfiguration.loadConfiguration(flinkConfDir) + : new Configuration(); + + effectiveConfig.setString(KubernetesConfigOptions.NAMESPACE, namespace); + effectiveConfig.setString(KubernetesConfigOptions.CLUSTER_ID, clusterId); + + if (spec.getIngressDomain() != null) { + effectiveConfig.set( + KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE, + KubernetesConfigOptions.ServiceExposedType.ClusterIP); + } + + if (spec.getJob() != null) { + effectiveConfig.set( + DeploymentOptions.TARGET, KubernetesDeploymentTarget.APPLICATION.getName()); + } else { + effectiveConfig.set( + DeploymentOptions.TARGET, KubernetesDeploymentTarget.SESSION.getName()); + } + + if (!StringUtils.isNullOrWhitespaceOnly(spec.getImage())) { + effectiveConfig.set(KubernetesConfigOptions.CONTAINER_IMAGE, spec.getImage()); + } + + if (!StringUtils.isNullOrWhitespaceOnly(spec.getImagePullPolicy())) { + effectiveConfig.set( + KubernetesConfigOptions.CONTAINER_IMAGE_PULL_POLICY, + KubernetesConfigOptions.ImagePullPolicy.valueOf(spec.getImagePullPolicy())); + } + + if (spec.getFlinkConfiguration() != null && !spec.getFlinkConfiguration().isEmpty()) { + spec.getFlinkConfiguration().forEach(effectiveConfig::setString); + } + + // Pod template + if (spec.getPodTemplate() != null) { + effectiveConfig.set( + KubernetesConfigOptions.KUBERNETES_POD_TEMPLATE, + createTempFile(spec.getPodTemplate())); + } + + if (spec.getJobManager() != null) { + if (spec.getJobManager().getResource() != null) { + effectiveConfig.setString( + JobManagerOptions.TOTAL_PROCESS_MEMORY.key(), + spec.getJobManager().getResource().getMemory()); + effectiveConfig.set( + KubernetesConfigOptions.JOB_MANAGER_CPU, + spec.getJobManager().getResource().getCpu()); + } + + if (spec.getJobManager().getPodTemplate() != null) { + effectiveConfig.set( + KubernetesConfigOptions.JOB_MANAGER_POD_TEMPLATE, + createTempFile( + mergePodTemplates( + spec.getPodTemplate(), + spec.getJobManager().getPodTemplate()))); + } + } + + if (spec.getTaskManager() != null) { + if (spec.getTaskManager().getTaskSlots() > 0) { + effectiveConfig.set( + TaskManagerOptions.NUM_TASK_SLOTS, + spec.getTaskManager().getTaskSlots()); + } + + if (spec.getTaskManager().getResource() != null) { + effectiveConfig.setString( + TaskManagerOptions.TOTAL_PROCESS_MEMORY.key(), + spec.getTaskManager().getResource().getMemory()); + effectiveConfig.set( + KubernetesConfigOptions.TASK_MANAGER_CPU, + spec.getTaskManager().getResource().getCpu()); + } + + if (spec.getTaskManager().getPodTemplate() != null) { + effectiveConfig.set( + KubernetesConfigOptions.TASK_MANAGER_POD_TEMPLATE, + createTempFile( + mergePodTemplates( + spec.getPodTemplate(), + spec.getTaskManager().getPodTemplate()))); + } + } + + if (spec.getJob() != null) { + final URI uri = new URI(spec.getJob().getJarURI()); + effectiveConfig.set( + PipelineOptions.JARS, Collections.singletonList(uri.toString())); + + if (spec.getJob().getParallelism() > 0) { + effectiveConfig.set( + CoreOptions.DEFAULT_PARALLELISM, spec.getJob().getParallelism()); + } + } + + return effectiveConfig; + } catch (Exception e) { + throw new RuntimeException("Failed to load configuration", e); + } + } Review comment: I completely agree, I would not jump on this straight away but will add a ticket for this so we don't forget. ########## File path: pom.xml ########## @@ -0,0 +1,285 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.apache</groupId> + <artifactId>apache</artifactId> + <version>20</version> + </parent> Review comment: Does that mean that plugins, profiles etc defined in flink-parent are autmatically enabled here also? If that is the case that might make our life more difficult in the long run Looking at the statefun project that also does not use the flink parent: https://github.com/apache/flink-statefun/blob/master/pom.xml ########## File path: flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/reconciler/JobReconcilerTest.java ########## @@ -0,0 +1,100 @@ +/* + * 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.reconciler; + +import org.apache.flink.api.common.JobID; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.kubernetes.operator.TestUtils; +import org.apache.flink.kubernetes.operator.crd.FlinkDeployment; +import org.apache.flink.kubernetes.operator.crd.spec.UpgradeMode; +import org.apache.flink.kubernetes.operator.crd.status.JobStatus; +import org.apache.flink.kubernetes.operator.service.FlinkService; +import org.apache.flink.kubernetes.operator.utils.FlinkUtils; +import org.apache.flink.runtime.jobgraph.SavepointConfigOptions; + +import io.fabric8.kubernetes.client.KubernetesClient; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; + +/** @link JobStatusObserver unit tests */ +public class JobReconcilerTest { + + public static final String JOB_NAME = "test1"; + public static final String JOB_ID = "fd72014d4c864993a2e5a9287b4a9c5d"; + + private FlinkService flinkService = Mockito.mock(FlinkService.class); + + @Test + public void testUpgrade() throws Exception { + KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); + JobReconciler reconciler = new JobReconciler(kubernetesClient, flinkService); + FlinkDeployment deployment = TestUtils.buildApplicationCluster(); + Configuration config = FlinkUtils.getEffectiveConfig(deployment); + + reconciler.reconcile("test", deployment, config); + Mockito.verify(flinkService, times(1)).submitApplicationCluster(eq(deployment), eq(config)); + Mockito.clearInvocations(flinkService); + deployment.getStatus().setSpec(deployment.getSpec()); + + JobStatus jobStatus = new JobStatus(); + jobStatus.setJobName(JOB_NAME); + jobStatus.setJobId(JOB_ID); + jobStatus.setState("RUNNING"); + + deployment.getStatus().setJobStatus(jobStatus); + + // Test stateless upgrade + FlinkDeployment statelessUpgrade = TestUtils.clone(deployment); + statelessUpgrade.getSpec().getJob().setUpgradeMode(UpgradeMode.STATELESS); + statelessUpgrade.getSpec().getFlinkConfiguration().put("new", "conf"); + reconciler.reconcile("test", statelessUpgrade, config); + Mockito.verify(flinkService, times(1)) + .cancelJob(eq(JobID.fromHexString(JOB_ID)), eq(UpgradeMode.STATELESS), eq(config)); + + Mockito.verify(flinkService, times(1)) Review comment: That's a very good point, I think the codestyle definitely applies here as well. I will try to see how we can change those tests to not use mockito ########## File path: helm/flink-operator/templates/webhook.yaml ########## @@ -0,0 +1,103 @@ +################################################################################ +# 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. +################################################################################ +--- +{{- if .Values.webhook.create }} +--- +apiVersion: v1 +kind: Service +metadata: + name: flink-operator-webhook-service + namespace: {{ .Values.operatorNamespace.name }} +spec: + ports: + - port: 443 + targetPort: 9443 + selector: + app.kubernetes.io/name: {{ include "flink-operator.name" . }} +--- +{{- if .Values.webhook.keystore.useDefaultPassword }} +apiVersion: v1 +kind: Secret +metadata: + name: flink-operator-webhook-secret + namespace: {{ .Values.operatorNamespace.name }} +type: Opaque +data: + password: cGFzc3dvcmQxMjM0 +{{- end }} +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: flink-operator-serving-cert + namespace: {{ .Values.operatorNamespace.name }} +spec: + dnsNames: + - flink-operator-webhook-service.default.svc + - flink-operator-webhook-service.default.svc.cluster.local + keystores: + pkcs12: + create: true + passwordSecretRef: + {{- if .Values.webhook.keystore.useDefaultPassword }} + name: flink-operator-webhook-secret + key: password + {{- else }} + {{- with .Values.webhook.keystore.passwordSecretRef }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- end }} + issuerRef: + kind: Issuer + name: flink-operator-selfsigned-issuer + commonName: FlinkDeployment Validator + secretName: webhook-server-cert +--- +apiVersion: cert-manager.io/v1 +kind: Issuer +metadata: + name: flink-operator-selfsigned-issuer + namespace: {{ .Values.operatorNamespace.name }} +spec: + selfSigned: {} +--- +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingWebhookConfiguration +metadata: + annotations: + cert-manager.io/inject-ca-from: default/flink-operator-serving-cert + name: flink-operator-validating-webhook-configuration Review comment: The webhook config does not have a namespace (it's global), but you are absolutely right about the cert name, that is a mistake. Fixing now ########## File path: flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkUtils.java ########## @@ -0,0 +1,229 @@ +/* + * 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.utils; + +import org.apache.flink.configuration.ConfigConstants; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.CoreOptions; +import org.apache.flink.configuration.DeploymentOptions; +import org.apache.flink.configuration.GlobalConfiguration; +import org.apache.flink.configuration.JobManagerOptions; +import org.apache.flink.configuration.PipelineOptions; +import org.apache.flink.configuration.TaskManagerOptions; +import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions; +import org.apache.flink.kubernetes.configuration.KubernetesDeploymentTarget; +import org.apache.flink.kubernetes.operator.crd.FlinkDeployment; +import org.apache.flink.kubernetes.operator.crd.spec.FlinkDeploymentSpec; +import org.apache.flink.util.StringUtils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.internal.SerializationUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.util.Collections; +import java.util.Iterator; + +/** Flink Utility methods used by the operator. */ +public class FlinkUtils { + + private static final Logger LOG = LoggerFactory.getLogger(FlinkUtils.class); + private static final ObjectMapper MAPPER = new ObjectMapper(); + + public static Configuration getEffectiveConfig(FlinkDeployment flinkApp) { + String namespace = flinkApp.getMetadata().getNamespace(); + String clusterId = flinkApp.getMetadata().getName(); + FlinkDeploymentSpec spec = flinkApp.getSpec(); + + try { + String flinkConfDir = System.getenv().get(ConfigConstants.ENV_FLINK_CONF_DIR); + Configuration effectiveConfig = + flinkConfDir != null + ? GlobalConfiguration.loadConfiguration(flinkConfDir) + : new Configuration(); + + effectiveConfig.setString(KubernetesConfigOptions.NAMESPACE, namespace); + effectiveConfig.setString(KubernetesConfigOptions.CLUSTER_ID, clusterId); + + if (spec.getIngressDomain() != null) { + effectiveConfig.set( + KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE, + KubernetesConfigOptions.ServiceExposedType.ClusterIP); + } + + if (spec.getJob() != null) { + effectiveConfig.set( + DeploymentOptions.TARGET, KubernetesDeploymentTarget.APPLICATION.getName()); + } else { + effectiveConfig.set( + DeploymentOptions.TARGET, KubernetesDeploymentTarget.SESSION.getName()); + } + + if (!StringUtils.isNullOrWhitespaceOnly(spec.getImage())) { + effectiveConfig.set(KubernetesConfigOptions.CONTAINER_IMAGE, spec.getImage()); + } + + if (!StringUtils.isNullOrWhitespaceOnly(spec.getImagePullPolicy())) { + effectiveConfig.set( + KubernetesConfigOptions.CONTAINER_IMAGE_PULL_POLICY, + KubernetesConfigOptions.ImagePullPolicy.valueOf(spec.getImagePullPolicy())); + } + + if (spec.getFlinkConfiguration() != null && !spec.getFlinkConfiguration().isEmpty()) { + spec.getFlinkConfiguration().forEach(effectiveConfig::setString); + } + + // Pod template + if (spec.getPodTemplate() != null) { + effectiveConfig.set( + KubernetesConfigOptions.KUBERNETES_POD_TEMPLATE, + createTempFile(spec.getPodTemplate())); + } + + if (spec.getJobManager() != null) { + if (spec.getJobManager().getResource() != null) { + effectiveConfig.setString( + JobManagerOptions.TOTAL_PROCESS_MEMORY.key(), + spec.getJobManager().getResource().getMemory()); + effectiveConfig.set( + KubernetesConfigOptions.JOB_MANAGER_CPU, + spec.getJobManager().getResource().getCpu()); + } + + if (spec.getJobManager().getPodTemplate() != null) { + effectiveConfig.set( + KubernetesConfigOptions.JOB_MANAGER_POD_TEMPLATE, + createTempFile( + mergePodTemplates( + spec.getPodTemplate(), + spec.getJobManager().getPodTemplate()))); + } + } + + if (spec.getTaskManager() != null) { + if (spec.getTaskManager().getTaskSlots() > 0) { + effectiveConfig.set( + TaskManagerOptions.NUM_TASK_SLOTS, + spec.getTaskManager().getTaskSlots()); + } + + if (spec.getTaskManager().getResource() != null) { + effectiveConfig.setString( + TaskManagerOptions.TOTAL_PROCESS_MEMORY.key(), + spec.getTaskManager().getResource().getMemory()); + effectiveConfig.set( + KubernetesConfigOptions.TASK_MANAGER_CPU, + spec.getTaskManager().getResource().getCpu()); + } + + if (spec.getTaskManager().getPodTemplate() != null) { + effectiveConfig.set( + KubernetesConfigOptions.TASK_MANAGER_POD_TEMPLATE, + createTempFile( + mergePodTemplates( + spec.getPodTemplate(), + spec.getTaskManager().getPodTemplate()))); + } + } + + if (spec.getJob() != null) { + final URI uri = new URI(spec.getJob().getJarURI()); + effectiveConfig.set( + PipelineOptions.JARS, Collections.singletonList(uri.toString())); + + if (spec.getJob().getParallelism() > 0) { + effectiveConfig.set( + CoreOptions.DEFAULT_PARALLELISM, spec.getJob().getParallelism()); + } + } + + return effectiveConfig; + } catch (Exception e) { + throw new RuntimeException("Failed to load configuration", e); + } + } Review comment: https://issues.apache.org/jira/browse/FLINK-26163 ########## File path: helm/flink-operator/templates/webhook.yaml ########## @@ -0,0 +1,103 @@ +################################################################################ +# 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. +################################################################################ +--- +{{- if .Values.webhook.create }} +--- +apiVersion: v1 +kind: Service +metadata: + name: flink-operator-webhook-service + namespace: {{ .Values.operatorNamespace.name }} +spec: + ports: + - port: 443 + targetPort: 9443 + selector: + app.kubernetes.io/name: {{ include "flink-operator.name" . }} +--- +{{- if .Values.webhook.keystore.useDefaultPassword }} +apiVersion: v1 +kind: Secret +metadata: + name: flink-operator-webhook-secret + namespace: {{ .Values.operatorNamespace.name }} +type: Opaque +data: + password: cGFzc3dvcmQxMjM0 +{{- end }} +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: flink-operator-serving-cert + namespace: {{ .Values.operatorNamespace.name }} +spec: + dnsNames: + - flink-operator-webhook-service.default.svc + - flink-operator-webhook-service.default.svc.cluster.local Review comment: Good catch, fixed 👍 ########## File path: flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/crd/status/JobStatus.java ########## @@ -0,0 +1,36 @@ +/* + * 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.crd.status; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** Status of an individual job within the Flink deployment. */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class JobStatus { + private String jobName; + private String jobId; + private String state; Review comment: Good point, I think this could be mapped to the JobState enum, I will fix this tomorrow ########## File path: flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/crd/spec/JobSpec.java ########## @@ -0,0 +1,41 @@ +/* + * 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.crd.spec; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** Flink job spec. */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class JobSpec { + private String jarURI; + private int parallelism; + private String entryClass; Review comment: in the rest api it is simply called `entryClass` (https://nightlies.apache.org/flink/flink-docs-master/docs/ops/rest_api/#jars-jarid-run), if others also feel strongly about this we can change it, but if not I would prefer to keep it as is -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
