Skip to content

Commit 1d23d2b

Browse files
rohanKanojiamanusa
authored andcommitted
feat (kubernetes-client-api) : Add DSL for flowcontrol.apiserver.k8s.io v1 apiVersion
Add the following DSL entrypoints for KubernetesClient: - `client.flowControl().v1().priorityLevelConfigurations()` - `client.flowControl().v1().flowSchema()` Signed-off-by: Rohan Kumar <[email protected]>
1 parent 315f486 commit 1d23d2b

File tree

10 files changed

+443
-0
lines changed

10 files changed

+443
-0
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@
1515
* Fix #5535: Add lombok and sundrio dependencies to the generated bom
1616

1717
#### Dependency Upgrade
18+
* Updated Kubernetes Model to Kubernetes `v1.29.0`
1819
* Updated okio to version 1.17.6 to avoid CVE-2023-3635
1920

2021
#### New Features
2122
* Fix #5608 Support authentication with certificate in exec-credentials
2223

2324
#### _**Note**_: Breaking changes
25+
- Deleted resources in Kubernetes 1.29.0 `flowcontrol.apiserver.k8s.io/v1alpha1`, please migrate to `flowcontrol.apiserver.k8s.io/v1` resources (available via `client.flowControl().v1()` DSL)
26+
- `io.fabric8.kubernetes.api.model.flowcontrol.v1alpha1.FlowSchema` removed
27+
- `io.fabric8.kubernetes.api.model.flowcontrol.v1alpha1.PriorityLevelConfiguration` removed
28+
- ClusterCIDR has been removed from Kubernetes 1.29.0 Networking Model
29+
- `io.fabric8.kubernetes.api.model.networking.v1alpha1.ClusterCIDR` removed
30+
- DSL entrypoint `client.network().v1alpha1().clusterCIDRs()` has been removed from KubernetesClient
2431

2532
### 6.9.2 (2023-11-02)
2633

kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/FlowControlAPIGroupDSL.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import io.fabric8.kubernetes.client.Client;
1919

2020
public interface FlowControlAPIGroupDSL extends Client {
21+
V1FlowControlAPIGroupDSL v1();
22+
2123
V1beta1FlowControlAPIGroupDSL v1beta1();
2224

2325
V1beta2FlowControlAPIGroupDSL v1beta2();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.kubernetes.client.dsl;
17+
18+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchema;
19+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaList;
20+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.PriorityLevelConfiguration;
21+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.PriorityLevelConfigurationList;
22+
import io.fabric8.kubernetes.client.Client;
23+
24+
public interface V1FlowControlAPIGroupDSL extends Client {
25+
/**
26+
* DSL entrypoint for flowcontrol.apiserver.k8s.io/v1 FlowSchema
27+
*
28+
* @return {@link NonNamespaceOperation} for FlowSchema resource
29+
*/
30+
NonNamespaceOperation<FlowSchema, FlowSchemaList, Resource<FlowSchema>> flowSchema();
31+
32+
/**
33+
* DSL entrypoint for flowcontrol.apiserver.k8s.io/v1 PriorityLevelConfiguration
34+
*
35+
* @return {@link NonNamespaceOperation} for PriorityLevelConfiguration resource
36+
*/
37+
NonNamespaceOperation<PriorityLevelConfiguration, PriorityLevelConfigurationList, Resource<PriorityLevelConfiguration>> priorityLevelConfigurations();
38+
}

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/impl/FlowControlAPIGroupClient.java

+6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
package io.fabric8.kubernetes.client.impl;
1717

1818
import io.fabric8.kubernetes.client.dsl.FlowControlAPIGroupDSL;
19+
import io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL;
1920
import io.fabric8.kubernetes.client.dsl.V1beta1FlowControlAPIGroupDSL;
2021
import io.fabric8.kubernetes.client.dsl.V1beta2FlowControlAPIGroupDSL;
2122
import io.fabric8.kubernetes.client.dsl.V1beta3FlowControlAPIGroupDSL;
2223
import io.fabric8.kubernetes.client.extension.ClientAdapter;
2324

2425
public class FlowControlAPIGroupClient extends ClientAdapter<FlowControlAPIGroupClient> implements FlowControlAPIGroupDSL {
2526

27+
@Override
28+
public V1FlowControlAPIGroupDSL v1() {
29+
return adapt(V1FlowControlAPIGroupClient.class);
30+
}
31+
2632
@Override
2733
public V1beta1FlowControlAPIGroupDSL v1beta1() {
2834
return adapt(V1beta1FlowControlAPIGroupClient.class);

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/impl/KubernetesClientImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
import io.fabric8.kubernetes.client.dsl.V1CertificatesAPIGroupDSL;
134134
import io.fabric8.kubernetes.client.dsl.V1DiscoveryAPIGroupDSL;
135135
import io.fabric8.kubernetes.client.dsl.V1EventingAPIGroupDSL;
136+
import io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL;
136137
import io.fabric8.kubernetes.client.dsl.V1PolicyAPIGroupDSL;
137138
import io.fabric8.kubernetes.client.dsl.V1SchedulingAPIGroupDSL;
138139
import io.fabric8.kubernetes.client.dsl.V1beta1BatchAPIGroupDSL;
@@ -234,6 +235,7 @@ protected void registerDefaultAdapters() {
234235
adapters.registerClient(V1EventingAPIGroupDSL.class, new V1EventingAPIGroupClient());
235236
adapters.registerClient(V1beta1EventingAPIGroupDSL.class, new V1beta1EventingAPIGroupClient());
236237
adapters.registerClient(FlowControlAPIGroupDSL.class, new FlowControlAPIGroupClient());
238+
adapters.registerClient(V1FlowControlAPIGroupDSL.class, new V1FlowControlAPIGroupClient());
237239
adapters.registerClient(V1beta1FlowControlAPIGroupDSL.class, new V1beta1FlowControlAPIGroupClient());
238240
adapters.registerClient(V1beta2FlowControlAPIGroupDSL.class, new V1beta2FlowControlAPIGroupClient());
239241
adapters.registerClient(V1beta3FlowControlAPIGroupDSL.class, new V1beta3FlowControlAPIGroupClient());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.kubernetes.client.impl;
17+
18+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchema;
19+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaList;
20+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.PriorityLevelConfiguration;
21+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.PriorityLevelConfigurationList;
22+
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
23+
import io.fabric8.kubernetes.client.dsl.Resource;
24+
import io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL;
25+
import io.fabric8.kubernetes.client.extension.ClientAdapter;
26+
27+
public class V1FlowControlAPIGroupClient extends ClientAdapter<V1FlowControlAPIGroupClient>
28+
implements V1FlowControlAPIGroupDSL {
29+
@Override
30+
public NonNamespaceOperation<FlowSchema, FlowSchemaList, Resource<FlowSchema>> flowSchema() {
31+
return resources(FlowSchema.class, FlowSchemaList.class);
32+
}
33+
34+
@Override
35+
public NonNamespaceOperation<PriorityLevelConfiguration, PriorityLevelConfigurationList, Resource<PriorityLevelConfiguration>> priorityLevelConfigurations() {
36+
return resources(PriorityLevelConfiguration.class, PriorityLevelConfigurationList.class);
37+
}
38+
39+
@Override
40+
public V1FlowControlAPIGroupClient newInstance() {
41+
return new V1FlowControlAPIGroupClient();
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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.kubernetes.client.mock;
17+
18+
import io.fabric8.kubernetes.api.model.HasMetadata;
19+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchema;
20+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaBuilder;
21+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaList;
22+
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaListBuilder;
23+
import io.fabric8.kubernetes.client.KubernetesClient;
24+
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
25+
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
26+
import org.assertj.core.api.AssertionsForClassTypes;
27+
import org.junit.jupiter.api.Test;
28+
29+
import java.net.HttpURLConnection;
30+
import java.util.List;
31+
32+
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
33+
34+
@EnableKubernetesMockClient
35+
class V1FlowSchemaTest {
36+
private KubernetesMockServer server;
37+
private KubernetesClient client;
38+
39+
@Test
40+
void load() {
41+
List<HasMetadata> items = client.load(getClass().getResourceAsStream("/v1-flowschema.yaml")).items();
42+
assertThat(items).isNotNull().hasSize(1);
43+
AssertionsForClassTypes.assertThat(items.get(0))
44+
.isInstanceOf(FlowSchema.class)
45+
.hasFieldOrPropertyWithValue("metadata.name", "health-for-strangers");
46+
}
47+
48+
@Test
49+
void get() {
50+
// Given
51+
server.expect().get().withPath("/apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/exempt")
52+
.andReturn(HttpURLConnection.HTTP_OK, createFlowSchema("exempt"))
53+
.once();
54+
55+
// When
56+
FlowSchema flowSchema = client.flowControl().v1().flowSchema().withName("exempt").get();
57+
58+
// Then
59+
AssertionsForClassTypes.assertThat(flowSchema)
60+
.isNotNull()
61+
.hasFieldOrPropertyWithValue("metadata.name", "exempt");
62+
}
63+
64+
@Test
65+
void list() {
66+
// Given
67+
server.expect().get().withPath("/apis/flowcontrol.apiserver.k8s.io/v1/flowschemas")
68+
.andReturn(HttpURLConnection.HTTP_OK, new FlowSchemaListBuilder()
69+
.addToItems(createFlowSchema("exempt"))
70+
.build())
71+
.once();
72+
73+
// When
74+
FlowSchemaList flowSchemas = client.flowControl().v1().flowSchema().list();
75+
76+
// Then
77+
AssertionsForClassTypes.assertThat(flowSchemas).isNotNull();
78+
assertThat(flowSchemas.getItems()).hasSize(1);
79+
AssertionsForClassTypes.assertThat(flowSchemas.getItems().get(0))
80+
.hasFieldOrPropertyWithValue("metadata.name", "exempt");
81+
}
82+
83+
@Test
84+
void create() {
85+
// Given
86+
FlowSchema flowSchema = createFlowSchema("flowschema1");
87+
server.expect().post().withPath("/apis/flowcontrol.apiserver.k8s.io/v1/flowschemas")
88+
.andReturn(HttpURLConnection.HTTP_OK, flowSchema)
89+
.once();
90+
91+
// When
92+
FlowSchema createdFlowSchema = client.flowControl().v1().flowSchema().resource(flowSchema).create();
93+
94+
// Then
95+
AssertionsForClassTypes.assertThat(createdFlowSchema).isNotNull();
96+
AssertionsForClassTypes.assertThat(createdFlowSchema)
97+
.hasFieldOrPropertyWithValue("metadata.name", "flowschema1");
98+
}
99+
100+
@Test
101+
void delete() {
102+
// Given
103+
FlowSchema flowSchema = createFlowSchema("flowschema1");
104+
server.expect().delete().withPath("/apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/flowschema1")
105+
.andReturn(HttpURLConnection.HTTP_OK, flowSchema)
106+
.once();
107+
108+
// When
109+
boolean isDeleted = client.flowControl().v1().flowSchema().withName("flowschema1").delete().size() == 1;
110+
111+
// Then
112+
AssertionsForClassTypes.assertThat(isDeleted).isTrue();
113+
}
114+
115+
private FlowSchema createFlowSchema(String name) {
116+
return new FlowSchemaBuilder()
117+
.withNewMetadata().withName(name).endMetadata()
118+
.withNewSpec()
119+
.withMatchingPrecedence(1)
120+
.withNewPriorityLevelConfiguration()
121+
.withName(name)
122+
.endPriorityLevelConfiguration()
123+
.addNewRule()
124+
.addNewNonResourceRule()
125+
.addToNonResourceURLs("*")
126+
.addToVerbs("*")
127+
.endNonResourceRule()
128+
.addNewResourceRule()
129+
.addToApiGroups("*")
130+
.endResourceRule()
131+
.addNewSubject()
132+
.withNewGroup()
133+
.withName("system:masters")
134+
.endGroup()
135+
.withKind("Group")
136+
.endSubject()
137+
.endRule()
138+
.endSpec()
139+
.build();
140+
}
141+
}

0 commit comments

Comments
 (0)