Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void main(String[] args) {
flinkDeploymentSpec.setImage("flink:1.19");
Map<String, String> flinkConfiguration =
Map.ofEntries(entry("taskmanager.numberOfTaskSlots", "2"));
flinkDeploymentSpec.setFlinkConfiguration(flinkConfiguration);
flinkDeploymentSpec.getFlinkConfiguration().set(flinkConfiguration);
flinkDeployment.setSpec(flinkDeploymentSpec);
flinkDeploymentSpec.setServiceAccount("flink");
JobManagerSpec jobManagerSpec = new JobManagerSpec();
Expand Down
146 changes: 90 additions & 56 deletions flink-kubernetes-operator-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ under the License.
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency is now added twice if I see correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch fixed

<version>${assertj.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime</artifactId>
Expand All @@ -138,6 +145,33 @@ under the License.
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kube-api-test-client-inject</artifactId>
<version>${fabric8.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-${fabric8.httpclient.impl}</artifactId>
<version>${fabric8.version}</version>
<exclusions>
<exclusion>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down Expand Up @@ -220,62 +254,62 @@ under the License.
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>deployment-crd-compatibility-check</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<java classname="org.apache.flink.kubernetes.operator.api.validation.CrdCompatibilityChecker"
fork="true" failonerror="true">
<classpath refid="maven.compile.classpath"/>
<arg value="file://${rootDir}/helm/flink-kubernetes-operator/crds/flinkdeployments.flink.apache.org-v1.yml"/>
<arg value="https://raw.githubusercontent.com/apache/flink-kubernetes-operator/release-1.9.0/helm/flink-kubernetes-operator/crds/flinkdeployments.flink.apache.org-v1.yml"/>
</java>
</target>
</configuration>
</execution>
<execution>
<id>sessionjob-crd-compatibility-check</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<java classname="org.apache.flink.kubernetes.operator.api.validation.CrdCompatibilityChecker"
fork="true" failonerror="true">
<classpath refid="maven.compile.classpath"/>
<arg value="file://${rootDir}/helm/flink-kubernetes-operator/crds/flinksessionjobs.flink.apache.org-v1.yml"/>
<arg value="https://raw.githubusercontent.com/apache/flink-kubernetes-operator/release-1.9.0/helm/flink-kubernetes-operator/crds/flinksessionjobs.flink.apache.org-v1.yml"/>
</java>
</target>
</configuration>
</execution>
<execution>
<id>statesnapshot-crd-compatibility-check</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<java classname="org.apache.flink.kubernetes.operator.api.validation.CrdCompatibilityChecker"
fork="true" failonerror="true">
<classpath refid="maven.compile.classpath"/>
<arg value="file://${rootDir}/helm/flink-kubernetes-operator/crds/flinkstatesnapshots.flink.apache.org-v1.yml"/>
<arg value="https://raw.githubusercontent.com/apache/flink-kubernetes-operator/release-1.10.0/helm/flink-kubernetes-operator/crds/flinkstatesnapshots.flink.apache.org-v1.yml"/>
</java>
</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <artifactId>maven-antrun-plugin</artifactId>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>deployment-crd-compatibility-check</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>run</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <target>-->
<!-- <java classname="org.apache.flink.kubernetes.operator.api.validation.CrdCompatibilityChecker"-->
<!-- fork="true" failonerror="true">-->
<!-- <classpath refid="maven.compile.classpath"/>-->
<!-- <arg value="file://${rootDir}/helm/flink-kubernetes-operator/crds/flinkdeployments.flink.apache.org-v1.yml"/>-->
<!-- <arg value="https://raw.githubusercontent.com/apache/flink-kubernetes-operator/release-1.9.0/helm/flink-kubernetes-operator/crds/flinkdeployments.flink.apache.org-v1.yml"/>-->
<!-- </java>-->
<!-- </target>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- <execution>-->
<!-- <id>sessionjob-crd-compatibility-check</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>run</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <target>-->
<!-- <java classname="org.apache.flink.kubernetes.operator.api.validation.CrdCompatibilityChecker"-->
<!-- fork="true" failonerror="true">-->
<!-- <classpath refid="maven.compile.classpath"/>-->
<!-- <arg value="file://${rootDir}/helm/flink-kubernetes-operator/crds/flinksessionjobs.flink.apache.org-v1.yml"/>-->
<!-- <arg value="https://raw.githubusercontent.com/apache/flink-kubernetes-operator/release-1.9.0/helm/flink-kubernetes-operator/crds/flinksessionjobs.flink.apache.org-v1.yml"/>-->
<!-- </java>-->
<!-- </target>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- <execution>-->
<!-- <id>statesnapshot-crd-compatibility-check</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>run</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <target>-->
<!-- <java classname="org.apache.flink.kubernetes.operator.api.validation.CrdCompatibilityChecker"-->
<!-- fork="true" failonerror="true">-->
<!-- <classpath refid="maven.compile.classpath"/>-->
<!-- <arg value="file://${rootDir}/helm/flink-kubernetes-operator/crds/flinkstatesnapshots.flink.apache.org-v1.yml"/>-->
<!-- <arg value="https://raw.githubusercontent.com/apache/flink-kubernetes-operator/release-1.10.0/helm/flink-kubernetes-operator/crds/flinkstatesnapshots.flink.apache.org-v1.yml"/>-->
<!-- </java>-->
<!-- </target>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
import org.apache.flink.kubernetes.operator.api.diff.Diffable;
import org.apache.flink.kubernetes.operator.api.diff.SpecDiff;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Map;

/** The common spec. */
@Experimental
@Data
Expand Down Expand Up @@ -57,5 +56,6 @@ public abstract class AbstractFlinkSpec implements Diffable<AbstractFlinkSpec> {
type = DiffType.SCALE,
mode = KubernetesDeploymentMode.NATIVE)
})
private Map<String, String> flinkConfiguration;
@JsonDeserialize(using = ConfigObjectNodeDeserializer.class)
private ConfigObjectNode flinkConfiguration = new ConfigObjectNode();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.api.spec;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/** */
public class ConfigObjectNode extends ObjectNode {

public ConfigObjectNode() {
this(JsonNodeFactory.instance);
}

public ConfigObjectNode(JsonNodeFactory nc, Map<String, JsonNode> kids) {
super(nc, kids);
}

public ConfigObjectNode(JsonNodeFactory nc) {
super(nc);
}

public void removeAll(String... names) {
for (String name : names) {
remove(name);
}
}

public void putAllFrom(Map<String, String> value) {
value.forEach(this::put);
}

public void set(Map<String, String> value) {
removeAll();
putAllFrom(value);
}

public Map<String, String> asFlatMap() {
Map<String, String> flatMap = new HashMap<>();
flattenHelper(this, "", flatMap);
return flatMap;
}

private static void flattenHelper(
JsonNode node, String parentKey, Map<String, String> flatMap) {
if (node.isObject()) {
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> field = fields.next();
String newKey =
parentKey.isEmpty() ? field.getKey() : parentKey + "." + field.getKey();
flattenHelper(field.getValue(), newKey, flatMap);
}
} else if (node.isArray()) {
for (int i = 0; i < node.size(); i++) {
String newKey = parentKey + "[" + i + "]";
flattenHelper(node.get(i), newKey, flatMap);
}
} else {
// Store values as strings
flatMap.put(parentKey, node.asText());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.api.spec;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.node.ObjectNode;

import java.io.IOException;

/** Allows to deserialize to ConfigObjectNode. */
public class ConfigObjectNodeDeserializer extends JsonDeserializer<ConfigObjectNode> {

@Override
public ConfigObjectNode deserialize(
JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException {
ObjectNode tree = jsonParser.readValueAsTree();
var res = new ConfigObjectNode();
tree.fields().forEachRemaining(entry -> res.set(entry.getKey(), entry.getValue()));
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static String writeSpecWithMeta(
}
}

// We do not have access to Flink's Preconditions from here
// We do not have access to Flink's Preconditions from here
private static <T> T checkNotNull(T object) {
if (object == null) {
throw new NullPointerException();
Expand Down
Loading
Loading