Skip to content

Commit 6a89134

Browse files
committed
CRD update in helm chart, add migration test
Signed-off-by: Attila Mészáros <[email protected]>
1 parent a9ee837 commit 6a89134

File tree

7 files changed

+11109
-6
lines changed

7 files changed

+11109
-6
lines changed

flink-kubernetes-operator-api/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ under the License.
152152
<version>${assertj.version}</version>
153153
<scope>test</scope>
154154
</dependency>
155+
156+
<dependency>
157+
<groupId>io.fabric8</groupId>
158+
<artifactId>kube-api-test-client-inject</artifactId>
159+
<version>${fabric8.version}</version>
160+
<scope>test</scope>
161+
</dependency>
162+
163+
<dependency>
164+
<groupId>io.fabric8</groupId>
165+
<artifactId>kubernetes-httpclient-${fabric8.httpclient.impl}</artifactId>
166+
<version>${fabric8.version}</version>
167+
<exclusions>
168+
<exclusion>
169+
<groupId>com.squareup.okhttp3</groupId>
170+
<artifactId>okhttp</artifactId>
171+
</exclusion>
172+
</exclusions>
173+
<scope>test</scope>
174+
</dependency>
155175
</dependencies>
156176

157177
<profiles>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.kubernetes.operator.api;
19+
20+
import org.apache.flink.kubernetes.operator.api.utils.SpecUtils;
21+
22+
import com.fasterxml.jackson.databind.ObjectMapper;
23+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
24+
import io.fabric8.kubeapitest.junit.EnableKubeAPIServer;
25+
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
26+
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition;
27+
import io.fabric8.kubernetes.client.KubernetesClient;
28+
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation;
29+
import org.junit.jupiter.api.Test;
30+
31+
import java.io.File;
32+
import java.io.IOException;
33+
34+
import static org.assertj.core.api.Assertions.assertThat;
35+
36+
@EnableKubeAPIServer
37+
class FlinkConfigurationYamlSupportTest {
38+
39+
private static final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
40+
public static final String OLD_CRD_PATH =
41+
"src/test/resources/pre-flink-configuration-yaml-crd.yml";
42+
public static final String NEW_CRD_PATH =
43+
"../helm/flink-kubernetes-operator/crds/flinkdeployments.flink.apache.org-v1.yml";
44+
45+
static KubernetesClient client;
46+
47+
@Test
48+
void upgradeCRDToYamlFlinkConfiguration() {
49+
applyCRD(OLD_CRD_PATH);
50+
51+
applyResource("src/test/resources/test-deployment-key-value-configuration.yaml");
52+
53+
var deployment =
54+
client.resources(FlinkDeployment.class)
55+
.inNamespace("default")
56+
.withName("basic-example")
57+
.get();
58+
assertThat(deployment.getSpec().getFlinkConfiguration()).hasSize(5);
59+
60+
applyCRD(NEW_CRD_PATH);
61+
62+
applyResource("src/test/resources/test-deployment-yaml-configuration.yaml");
63+
64+
deployment =
65+
client.resources(FlinkDeployment.class)
66+
.inNamespace("default")
67+
.withName("basic-example")
68+
.get();
69+
assertThat(deployment.getSpec().getFlinkConfiguration()).hasSize(3);
70+
assertThat(SpecUtils.toStringMap(deployment.getSpec().getFlinkConfiguration())).hasSize(5);
71+
}
72+
73+
private GenericKubernetesResource applyResource(String path) {
74+
try {
75+
GenericKubernetesResource d =
76+
objectMapper.readValue(new File(path), GenericKubernetesResource.class);
77+
78+
return client.resource(d).createOr(NonDeletingOperation::update);
79+
} catch (IOException e) {
80+
throw new RuntimeException(e);
81+
}
82+
}
83+
84+
private CustomResourceDefinition applyCRD(String path) {
85+
try {
86+
var crd = objectMapper.readValue(new File(path), CustomResourceDefinition.class);
87+
88+
var res = client.resource(crd).createOr(NonDeletingOperation::update);
89+
Thread.sleep(1000);
90+
return res;
91+
} catch (IOException | InterruptedException e) {
92+
throw new RuntimeException(e);
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)