-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
315f486
commit 1d23d2b
Showing
10 changed files
with
443 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...s-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/V1FlowControlAPIGroupDSL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...s-client/src/main/java/io/fabric8/kubernetes/client/impl/V1FlowControlAPIGroupClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/V1FlowSchemaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.