Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (kubernetes-client-api) : Add DSL for flowcontrol.apiserver.k8s.io v1 apiVersion #5688

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
* Fix #5535: Add lombok and sundrio dependencies to the generated bom

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

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

#### _**Note**_: Breaking changes
- 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)
- `io.fabric8.kubernetes.api.model.flowcontrol.v1alpha1.FlowSchema` removed
- `io.fabric8.kubernetes.api.model.flowcontrol.v1alpha1.PriorityLevelConfiguration` removed
- ClusterCIDR has been removed from Kubernetes 1.29.0 Networking Model
- `io.fabric8.kubernetes.api.model.networking.v1alpha1.ClusterCIDR` removed
- DSL entrypoint `client.network().v1alpha1().clusterCIDRs()` has been removed from KubernetesClient

### 6.9.2 (2023-11-02)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.fabric8.kubernetes.client.Client;

public interface FlowControlAPIGroupDSL extends Client {
V1FlowControlAPIGroupDSL v1();

V1beta1FlowControlAPIGroupDSL v1beta1();

V1beta2FlowControlAPIGroupDSL v1beta2();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed 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 io.fabric8.kubernetes.client.dsl;

import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchema;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaList;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.PriorityLevelConfiguration;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.PriorityLevelConfigurationList;
import io.fabric8.kubernetes.client.Client;

public interface V1FlowControlAPIGroupDSL extends Client {
/**
* DSL entrypoint for flowcontrol.apiserver.k8s.io/v1 FlowSchema
*
* @return {@link NonNamespaceOperation} for FlowSchema resource
*/
NonNamespaceOperation<FlowSchema, FlowSchemaList, Resource<FlowSchema>> flowSchema();

/**
* DSL entrypoint for flowcontrol.apiserver.k8s.io/v1 PriorityLevelConfiguration
*
* @return {@link NonNamespaceOperation} for PriorityLevelConfiguration resource
*/
NonNamespaceOperation<PriorityLevelConfiguration, PriorityLevelConfigurationList, Resource<PriorityLevelConfiguration>> priorityLevelConfigurations();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
package io.fabric8.kubernetes.client.impl;

import io.fabric8.kubernetes.client.dsl.FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1beta1FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1beta2FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1beta3FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.extension.ClientAdapter;

public class FlowControlAPIGroupClient extends ClientAdapter<FlowControlAPIGroupClient> implements FlowControlAPIGroupDSL {

@Override
public V1FlowControlAPIGroupDSL v1() {
return adapt(V1FlowControlAPIGroupClient.class);
}

@Override
public V1beta1FlowControlAPIGroupDSL v1beta1() {
return adapt(V1beta1FlowControlAPIGroupClient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
import io.fabric8.kubernetes.client.dsl.V1CertificatesAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1DiscoveryAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1EventingAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1PolicyAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1SchedulingAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1beta1BatchAPIGroupDSL;
Expand Down Expand Up @@ -234,6 +235,7 @@ protected void registerDefaultAdapters() {
adapters.registerClient(V1EventingAPIGroupDSL.class, new V1EventingAPIGroupClient());
adapters.registerClient(V1beta1EventingAPIGroupDSL.class, new V1beta1EventingAPIGroupClient());
adapters.registerClient(FlowControlAPIGroupDSL.class, new FlowControlAPIGroupClient());
adapters.registerClient(V1FlowControlAPIGroupDSL.class, new V1FlowControlAPIGroupClient());
adapters.registerClient(V1beta1FlowControlAPIGroupDSL.class, new V1beta1FlowControlAPIGroupClient());
adapters.registerClient(V1beta2FlowControlAPIGroupDSL.class, new V1beta2FlowControlAPIGroupClient());
adapters.registerClient(V1beta3FlowControlAPIGroupDSL.class, new V1beta3FlowControlAPIGroupClient());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed 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 io.fabric8.kubernetes.client.impl;

import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchema;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaList;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.PriorityLevelConfiguration;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.PriorityLevelConfigurationList;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.extension.ClientAdapter;

public class V1FlowControlAPIGroupClient extends ClientAdapter<V1FlowControlAPIGroupClient>
implements V1FlowControlAPIGroupDSL {
@Override
public NonNamespaceOperation<FlowSchema, FlowSchemaList, Resource<FlowSchema>> flowSchema() {
return resources(FlowSchema.class, FlowSchemaList.class);
}

@Override
public NonNamespaceOperation<PriorityLevelConfiguration, PriorityLevelConfigurationList, Resource<PriorityLevelConfiguration>> priorityLevelConfigurations() {
return resources(PriorityLevelConfiguration.class, PriorityLevelConfigurationList.class);
}

@Override
public V1FlowControlAPIGroupClient newInstance() {
return new V1FlowControlAPIGroupClient();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed 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 io.fabric8.kubernetes.client.mock;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchema;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaBuilder;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaList;
import io.fabric8.kubernetes.api.model.flowcontrol.v1.FlowSchemaListBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import org.assertj.core.api.AssertionsForClassTypes;
import org.junit.jupiter.api.Test;

import java.net.HttpURLConnection;
import java.util.List;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

@EnableKubernetesMockClient
class V1FlowSchemaTest {
private KubernetesMockServer server;
private KubernetesClient client;

@Test
void load() {
List<HasMetadata> items = client.load(getClass().getResourceAsStream("/v1-flowschema.yaml")).items();
assertThat(items).isNotNull().hasSize(1);
AssertionsForClassTypes.assertThat(items.get(0))
.isInstanceOf(FlowSchema.class)
.hasFieldOrPropertyWithValue("metadata.name", "health-for-strangers");
}

@Test
void get() {
// Given
server.expect().get().withPath("/apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/exempt")
.andReturn(HttpURLConnection.HTTP_OK, createFlowSchema("exempt"))
.once();

// When
FlowSchema flowSchema = client.flowControl().v1().flowSchema().withName("exempt").get();

// Then
AssertionsForClassTypes.assertThat(flowSchema)
.isNotNull()
.hasFieldOrPropertyWithValue("metadata.name", "exempt");
}

@Test
void list() {
// Given
server.expect().get().withPath("/apis/flowcontrol.apiserver.k8s.io/v1/flowschemas")
.andReturn(HttpURLConnection.HTTP_OK, new FlowSchemaListBuilder()
.addToItems(createFlowSchema("exempt"))
.build())
.once();

// When
FlowSchemaList flowSchemas = client.flowControl().v1().flowSchema().list();

// Then
AssertionsForClassTypes.assertThat(flowSchemas).isNotNull();
assertThat(flowSchemas.getItems()).hasSize(1);
AssertionsForClassTypes.assertThat(flowSchemas.getItems().get(0))
.hasFieldOrPropertyWithValue("metadata.name", "exempt");
}

@Test
void create() {
// Given
FlowSchema flowSchema = createFlowSchema("flowschema1");
server.expect().post().withPath("/apis/flowcontrol.apiserver.k8s.io/v1/flowschemas")
.andReturn(HttpURLConnection.HTTP_OK, flowSchema)
.once();

// When
FlowSchema createdFlowSchema = client.flowControl().v1().flowSchema().resource(flowSchema).create();

// Then
AssertionsForClassTypes.assertThat(createdFlowSchema).isNotNull();
AssertionsForClassTypes.assertThat(createdFlowSchema)
.hasFieldOrPropertyWithValue("metadata.name", "flowschema1");
}

@Test
void delete() {
// Given
FlowSchema flowSchema = createFlowSchema("flowschema1");
server.expect().delete().withPath("/apis/flowcontrol.apiserver.k8s.io/v1/flowschemas/flowschema1")
.andReturn(HttpURLConnection.HTTP_OK, flowSchema)
.once();

// When
boolean isDeleted = client.flowControl().v1().flowSchema().withName("flowschema1").delete().size() == 1;

// Then
AssertionsForClassTypes.assertThat(isDeleted).isTrue();
}

private FlowSchema createFlowSchema(String name) {
return new FlowSchemaBuilder()
.withNewMetadata().withName(name).endMetadata()
.withNewSpec()
.withMatchingPrecedence(1)
.withNewPriorityLevelConfiguration()
.withName(name)
.endPriorityLevelConfiguration()
.addNewRule()
.addNewNonResourceRule()
.addToNonResourceURLs("*")
.addToVerbs("*")
.endNonResourceRule()
.addNewResourceRule()
.addToApiGroups("*")
.endResourceRule()
.addNewSubject()
.withNewGroup()
.withName("system:masters")
.endGroup()
.withKind("Group")
.endSubject()
.endRule()
.endSpec()
.build();
}
}
Loading
Loading