Skip to content

Commit dbf1afd

Browse files
rohanKanojiamanusa
authored andcommitted
feat (openshift-client-api) : Add DSL for new OpenShift 4.13.12 resources to OpenShiftClient (#5286)
Add DSL support for the following endpoints: - openShiftClient.metal3RemediationTemplates() - openShiftClient.metal3Remediations() - openShiftClient.projectHelmChartRepositories() - openShiftClient.operatorHub().olmConfigs() - openShiftClient.config().imageTagMirrorSets() - openShiftClient.config().imageDigestMirrorSets() - openShiftClient.machine().controlPlaneMachineSets() Signed-off-by: Rohan Kumar <[email protected]>
1 parent dbbdc5d commit dbf1afd

16 files changed

+934
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.openshift.client.server.mock;
17+
18+
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
19+
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
20+
import io.fabric8.openshift.api.model.machine.v1.ControlPlaneMachineSet;
21+
import io.fabric8.openshift.api.model.machine.v1.ControlPlaneMachineSetBuilder;
22+
import io.fabric8.openshift.api.model.machine.v1.ControlPlaneMachineSetList;
23+
import io.fabric8.openshift.api.model.machine.v1.ControlPlaneMachineSetListBuilder;
24+
import io.fabric8.openshift.client.OpenShiftClient;
25+
import org.junit.jupiter.api.Test;
26+
27+
import java.net.HttpURLConnection;
28+
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertNotNull;
31+
import static org.junit.jupiter.api.Assertions.assertTrue;
32+
33+
@EnableKubernetesMockClient
34+
class ControlPlaneMachineSetTest {
35+
KubernetesMockServer server;
36+
OpenShiftClient client;
37+
38+
@Test
39+
void create() {
40+
// Given
41+
ControlPlaneMachineSet controlPlaneMachineSet = getControlPlaneMachineSet();
42+
server.expect().post()
43+
.withPath("/apis/machine.openshift.io/v1/namespaces/ns1/controlplanemachinesets")
44+
.andReturn(HttpURLConnection.HTTP_OK, controlPlaneMachineSet)
45+
.once();
46+
47+
// When
48+
controlPlaneMachineSet = client.machine().controlPlaneMachineSets().inNamespace("ns1").resource(controlPlaneMachineSet)
49+
.create();
50+
51+
// Then
52+
assertNotNull(controlPlaneMachineSet);
53+
assertEquals("cluster", controlPlaneMachineSet.getMetadata().getName());
54+
}
55+
56+
@Test
57+
void get() {
58+
// Given
59+
server.expect().get()
60+
.withPath("/apis/machine.openshift.io/v1/namespaces/ns1/controlplanemachinesets/cluster")
61+
.andReturn(HttpURLConnection.HTTP_OK, getControlPlaneMachineSet())
62+
.once();
63+
64+
// When
65+
ControlPlaneMachineSet controlPlaneMachineSet = client.machine().controlPlaneMachineSets().inNamespace("ns1")
66+
.withName("cluster").get();
67+
68+
// Then
69+
assertNotNull(controlPlaneMachineSet);
70+
assertEquals("cluster", controlPlaneMachineSet.getMetadata().getName());
71+
}
72+
73+
@Test
74+
void list() {
75+
// Given
76+
server.expect().get()
77+
.withPath("/apis/machine.openshift.io/v1/namespaces/ns1/controlplanemachinesets")
78+
.andReturn(HttpURLConnection.HTTP_OK,
79+
new ControlPlaneMachineSetListBuilder().withItems(getControlPlaneMachineSet()).build())
80+
.once();
81+
82+
// When
83+
ControlPlaneMachineSetList controlPlaneMachineSetList = client.machine().controlPlaneMachineSets().inNamespace("ns1")
84+
.list();
85+
86+
// Then
87+
assertNotNull(controlPlaneMachineSetList);
88+
assertNotNull(controlPlaneMachineSetList.getItems());
89+
assertEquals(1, controlPlaneMachineSetList.getItems().size());
90+
}
91+
92+
@Test
93+
void delete() {
94+
// Given
95+
server.expect().delete()
96+
.withPath("/apis/machine.openshift.io/v1/namespaces/ns1/controlplanemachinesets/cluster")
97+
.andReturn(HttpURLConnection.HTTP_OK, getControlPlaneMachineSet())
98+
.once();
99+
100+
// When
101+
boolean deleted = client.machine().controlPlaneMachineSets().inNamespace("ns1").withName("cluster").delete().size() == 1;
102+
103+
// Then
104+
assertTrue(deleted);
105+
}
106+
107+
private ControlPlaneMachineSet getControlPlaneMachineSet() {
108+
return new ControlPlaneMachineSetBuilder()
109+
.withNewMetadata()
110+
.withName("cluster")
111+
.endMetadata()
112+
.withNewSpec()
113+
.withReplicas(3)
114+
.withState("Active")
115+
.withNewStrategy().withType("RollingUpdate").endStrategy()
116+
.withNewSelector()
117+
.addToMatchLabels("machine.openshift.io/cluster-api-machine-role", "master")
118+
.addToMatchLabels("machine.openshift.io/cluster-api-machine-type", "master")
119+
.endSelector()
120+
.withNewTemplate()
121+
.withMachineType("machines_v1beta1_machine_openshift_io")
122+
.withNewMachinesV1beta1MachineOpenshiftIo()
123+
.withNewMetadata()
124+
.addToLabels("machine.openshift.io/cluster-api-machine-role", "master")
125+
.addToLabels("machine.openshift.io/cluster-api-machine-type", "master")
126+
.addToLabels("machine.openshift.io/cluster-api-cluster", "cluster")
127+
.endMetadata()
128+
.withNewSpec()
129+
.withNewProviderSpec()
130+
.endProviderSpec()
131+
.endSpec()
132+
.endMachinesV1beta1MachineOpenshiftIo()
133+
.endTemplate()
134+
.endSpec()
135+
.build();
136+
}
137+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.openshift.client.server.mock;
17+
18+
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
19+
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
20+
import io.fabric8.openshift.api.model.config.v1.ImageDigestMirrorSet;
21+
import io.fabric8.openshift.api.model.config.v1.ImageDigestMirrorSetBuilder;
22+
import io.fabric8.openshift.api.model.config.v1.ImageDigestMirrorSetList;
23+
import io.fabric8.openshift.api.model.config.v1.ImageDigestMirrorSetListBuilder;
24+
import io.fabric8.openshift.client.OpenShiftClient;
25+
import org.junit.jupiter.api.Test;
26+
27+
import java.net.HttpURLConnection;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
@EnableKubernetesMockClient
32+
class ImageDigestMirrorSetTest {
33+
private OpenShiftClient client;
34+
private KubernetesMockServer server;
35+
36+
@Test
37+
void get() {
38+
// Given
39+
server.expect().get().withPath("/apis/config.openshift.io/v1/imagedigestmirrorsets/test-get")
40+
.andReturn(HttpURLConnection.HTTP_OK, createNewImageDigestMirrorSet("test-get"))
41+
.once();
42+
43+
// When
44+
ImageDigestMirrorSet imageDigestMirrorSet = client.config().imageDigestMirrorSets().withName("test-get").get();
45+
46+
// Then
47+
assertThat(imageDigestMirrorSet)
48+
.isNotNull()
49+
.hasFieldOrPropertyWithValue("metadata.name", "test-get");
50+
}
51+
52+
@Test
53+
void list() {
54+
// Given
55+
server.expect().get().withPath("/apis/config.openshift.io/v1/imagedigestmirrorsets")
56+
.andReturn(HttpURLConnection.HTTP_OK, new ImageDigestMirrorSetListBuilder()
57+
.addToItems(createNewImageDigestMirrorSet("test-list"))
58+
.build())
59+
.once();
60+
61+
// When
62+
ImageDigestMirrorSetList imageDigestMirrorSetList = client.config().imageDigestMirrorSets().list();
63+
64+
// Then
65+
assertThat(imageDigestMirrorSetList).isNotNull();
66+
assertThat(imageDigestMirrorSetList.getItems()).hasSize(1);
67+
assertThat(imageDigestMirrorSetList.getItems().get(0))
68+
.hasFieldOrPropertyWithValue("metadata.name", "test-list");
69+
}
70+
71+
@Test
72+
void delete() {
73+
// Given
74+
server.expect().delete().withPath("/apis/config.openshift.io/v1/imagedigestmirrorsets/cluster")
75+
.andReturn(HttpURLConnection.HTTP_OK, createNewImageDigestMirrorSet("cluster"))
76+
.once();
77+
78+
// When
79+
boolean isDeleted = client.config().imageDigestMirrorSets().withName("cluster").delete().size() == 1;
80+
81+
// Then
82+
assertThat(isDeleted).isTrue();
83+
}
84+
85+
private ImageDigestMirrorSet createNewImageDigestMirrorSet(String name) {
86+
return new ImageDigestMirrorSetBuilder()
87+
.withNewMetadata()
88+
.withName(name)
89+
.endMetadata()
90+
.withNewSpec()
91+
.addNewImageDigestMirror()
92+
.withMirrors("example.com/example/ubi-minimal")
93+
.withSource("registry.access.redhat.com/ubi9/ubi-minimal")
94+
.withMirrorSourcePolicy("AllowContactingSource")
95+
.endImageDigestMirror()
96+
.endSpec()
97+
.build();
98+
}
99+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.openshift.client.server.mock;
17+
18+
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
19+
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
20+
import io.fabric8.openshift.api.model.config.v1.ImageTagMirrorSet;
21+
import io.fabric8.openshift.api.model.config.v1.ImageTagMirrorSetBuilder;
22+
import io.fabric8.openshift.api.model.config.v1.ImageTagMirrorSetList;
23+
import io.fabric8.openshift.api.model.config.v1.ImageTagMirrorSetListBuilder;
24+
import io.fabric8.openshift.client.OpenShiftClient;
25+
import org.junit.jupiter.api.Test;
26+
27+
import java.net.HttpURLConnection;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
@EnableKubernetesMockClient
32+
class ImageTagMirrorSetTest {
33+
private OpenShiftClient client;
34+
private KubernetesMockServer server;
35+
36+
@Test
37+
void get() {
38+
// Given
39+
server.expect().get().withPath("/apis/config.openshift.io/v1/imagetagmirrorsets/test-get")
40+
.andReturn(HttpURLConnection.HTTP_OK, createNewImageTagMirrorSet("test-get"))
41+
.once();
42+
43+
// When
44+
ImageTagMirrorSet imageTagMirrorSet = client.config().imageTagMirrorSets().withName("test-get").get();
45+
46+
// Then
47+
assertThat(imageTagMirrorSet)
48+
.isNotNull()
49+
.hasFieldOrPropertyWithValue("metadata.name", "test-get");
50+
}
51+
52+
@Test
53+
void list() {
54+
// Given
55+
server.expect().get().withPath("/apis/config.openshift.io/v1/imagetagmirrorsets")
56+
.andReturn(HttpURLConnection.HTTP_OK, new ImageTagMirrorSetListBuilder()
57+
.addToItems(createNewImageTagMirrorSet("test-list"))
58+
.build())
59+
.once();
60+
61+
// When
62+
ImageTagMirrorSetList imageTagMirrorSetList = client.config().imageTagMirrorSets().list();
63+
64+
// Then
65+
assertThat(imageTagMirrorSetList).isNotNull();
66+
assertThat(imageTagMirrorSetList.getItems()).hasSize(1);
67+
assertThat(imageTagMirrorSetList.getItems().get(0))
68+
.hasFieldOrPropertyWithValue("metadata.name", "test-list");
69+
}
70+
71+
@Test
72+
void delete() {
73+
// Given
74+
server.expect().delete().withPath("/apis/config.openshift.io/v1/imagetagmirrorsets/cluster")
75+
.andReturn(HttpURLConnection.HTTP_OK, createNewImageTagMirrorSet("cluster"))
76+
.once();
77+
78+
// When
79+
boolean isDeleted = client.config().imageTagMirrorSets().withName("cluster").delete().size() == 1;
80+
81+
// Then
82+
assertThat(isDeleted).isTrue();
83+
}
84+
85+
private ImageTagMirrorSet createNewImageTagMirrorSet(String name) {
86+
return new ImageTagMirrorSetBuilder()
87+
.withNewMetadata()
88+
.withName(name)
89+
.endMetadata()
90+
.withNewSpec()
91+
.addNewImageTagMirror()
92+
.withMirrors("example.com/example/ubi-minimal")
93+
.withSource("registry.access.redhat.com/ubi9/ubi-minimal")
94+
.withMirrorSourcePolicy("AllowContactingSource")
95+
.endImageTagMirror()
96+
.endSpec()
97+
.build();
98+
}
99+
}

0 commit comments

Comments
 (0)