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

fix (kubernetes-model-generator) : Update Kubernetes Model to v1.25.0 (#4347) #4377

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
strategy:
fail-fast: false
matrix:
kubernetes: [v1.24.0,v1.23.3, v1.22.6, v1.20.15, v1.19.16, v1.12.10]
kubernetes: [v1.25.0, v1.24.0, v1.23.3, v1.22.6, v1.20.15, v1.19.16, v1.12.10]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Fix #4243: Update Tekton pipeline model to v0.39.0
* Fix #4243: Update Tekton triggers model to v0.20.2
* Fix #4383: bump snakeyaml from 1.30 to 1.31
* Fix #4347: Update Kubernetes Model to v1.25.0

#### New Features

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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;

import io.fabric8.kubernetes.api.model.autoscaling.v2.HorizontalPodAutoscaler;
import io.fabric8.kubernetes.api.model.autoscaling.v2.HorizontalPodAutoscalerList;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;

public interface V2AutoscalingAPIGroupDSL extends Client {
MixedOperation<HorizontalPodAutoscaler, HorizontalPodAutoscalerList, Resource<HorizontalPodAutoscaler>> horizontalPodAutoscalers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@

import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.V1AutoscalingAPIGroupDSL;
import io.fabric8.kubernetes.client.V2AutoscalingAPIGroupDSL;
import io.fabric8.kubernetes.client.V2beta1AutoscalingAPIGroupDSL;
import io.fabric8.kubernetes.client.V2beta2AutoscalingAPIGroupDSL;

public interface AutoscalingAPIGroupDSL extends Client {
V2AutoscalingAPIGroupDSL v2();

V1AutoscalingAPIGroupDSL v1();

V2beta1AutoscalingAPIGroupDSL v2beta1();

V2beta2AutoscalingAPIGroupDSL v2beta2();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@

public interface FlowControlAPIGroupDSL extends Client {
V1beta1FlowControlAPIGroupDSL v1beta1();

V1beta2FlowControlAPIGroupDSL v1beta2();
}
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.v1beta2.FlowSchema;
import io.fabric8.kubernetes.api.model.flowcontrol.v1beta2.FlowSchemaList;
import io.fabric8.kubernetes.api.model.flowcontrol.v1beta2.PriorityLevelConfiguration;
import io.fabric8.kubernetes.api.model.flowcontrol.v1beta2.PriorityLevelConfigurationList;
import io.fabric8.kubernetes.client.Client;

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

/**
* DSL entrypoint for flowcontrol.apiserver.k8s.io/v1beta2 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 @@ -20,6 +20,11 @@

public class AutoscalingAPIGroupClient extends ClientAdapter<AutoscalingAPIGroupClient> implements AutoscalingAPIGroupDSL {

@Override
public V2AutoscalingAPIGroupDSL v2() {
return adapt(V2AutoscalingAPIGroupClient.class);
}

@Override
public V1AutoscalingAPIGroupDSL v1() {
return adapt(V1AutoscalingAPIGroupClient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
import io.fabric8.kubernetes.client.dsl.V1beta1FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1beta1PolicyAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1beta1SchedulingAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1beta2FlowControlAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext;
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation;
import io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl;
Expand Down Expand Up @@ -179,6 +180,7 @@ public DefaultKubernetesClient(HttpClient httpClient, Config config, ExecutorSup
this.getAdapters().registerClient(ApiextensionsAPIGroupDSL.class, new ApiextensionsAPIGroupClient());
this.getAdapters().registerClient(AuthorizationAPIGroupDSL.class, new AuthorizationAPIGroupClient());
this.getAdapters().registerClient(V1AutoscalingAPIGroupDSL.class, new V1AutoscalingAPIGroupClient());
this.getAdapters().registerClient(V2AutoscalingAPIGroupDSL.class, new V2AutoscalingAPIGroupClient());
this.getAdapters().registerClient(V2beta1AutoscalingAPIGroupDSL.class, new V2beta1AutoscalingAPIGroupClient());
this.getAdapters().registerClient(V2beta2AutoscalingAPIGroupDSL.class, new V2beta2AutoscalingAPIGroupClient());
this.getAdapters().registerClient(BatchAPIGroupDSL.class, new BatchAPIGroupClient());
Expand All @@ -190,6 +192,7 @@ public DefaultKubernetesClient(HttpClient httpClient, Config config, ExecutorSup
this.getAdapters().registerClient(V1beta1EventingAPIGroupDSL.class, new V1beta1EventingAPIGroupClient());
this.getAdapters().registerClient(FlowControlAPIGroupDSL.class, new FlowControlAPIGroupClient());
this.getAdapters().registerClient(V1beta1FlowControlAPIGroupDSL.class, new V1beta1FlowControlAPIGroupClient());
this.getAdapters().registerClient(V1beta2FlowControlAPIGroupDSL.class, new V1beta2FlowControlAPIGroupClient());
this.getAdapters().registerClient(MetricAPIGroupDSL.class, new MetricAPIGroupClient());
this.getAdapters().registerClient(NetworkAPIGroupDSL.class, new NetworkAPIGroupClient());
this.getAdapters().registerClient(PolicyAPIGroupDSL.class, new PolicyAPIGroupClient());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

public class FlowControlAPIGroupClient extends ClientAdapter<FlowControlAPIGroupClient> implements FlowControlAPIGroupDSL {
Expand All @@ -26,6 +27,11 @@ public V1beta1FlowControlAPIGroupDSL v1beta1() {
return adapt(V1beta1FlowControlAPIGroupClient.class);
}

@Override
public V1beta2FlowControlAPIGroupDSL v1beta2() {
return adapt(V1beta2FlowControlAPIGroupClient.class);
}

@Override
public FlowControlAPIGroupClient newInstance() {
return new FlowControlAPIGroupClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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;

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

public class V1beta2FlowControlAPIGroupClient extends ClientAdapter<V1beta2FlowControlAPIGroupClient>
implements V1beta2FlowControlAPIGroupDSL {

@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 V1beta2FlowControlAPIGroupClient newInstance() {
return new V1beta2FlowControlAPIGroupClient();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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;

import io.fabric8.kubernetes.api.model.autoscaling.v2.HorizontalPodAutoscaler;
import io.fabric8.kubernetes.api.model.autoscaling.v2.HorizontalPodAutoscalerList;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.extension.ClientAdapter;

public class V2AutoscalingAPIGroupClient extends ClientAdapter<V2AutoscalingAPIGroupClient>
implements V2AutoscalingAPIGroupDSL {

@Override
public MixedOperation<HorizontalPodAutoscaler, HorizontalPodAutoscalerList, Resource<HorizontalPodAutoscaler>> horizontalPodAutoscalers() {
return resources(HorizontalPodAutoscaler.class, HorizontalPodAutoscalerList.class);
}

@Override
public V2AutoscalingAPIGroupClient newInstance() {
return new V2AutoscalingAPIGroupClient();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ void testCacheStore() {

cache.put(testPodObj);

// replace cached object with null value
String newClusterName = "test_cluster";
testPodObj.getMetadata().setClusterName(newClusterName);
// replace cached object with new value
String newGenerateName = "test-cluster";
testPodObj.getMetadata().setGenerateName(newGenerateName);
cache.put(testPodObj);

assertEquals(1, cache.list().size());
assertEquals(newClusterName, testPodObj.getMetadata().getClusterName());
assertEquals(newGenerateName, testPodObj.getMetadata().getGenerateName());
}

@Test
Expand Down Expand Up @@ -129,12 +129,12 @@ void testAddIndexers() {

Map<String, Function<Pod, List<String>>> indexers = new HashMap<>();
indexers.put(nodeIndex, pod -> Collections.singletonList(pod.getSpec().getNodeName()));
indexers.put(clusterIndex, pod -> Collections.singletonList(pod.getMetadata().getClusterName()));
indexers.put(clusterIndex, pod -> Collections.singletonList(pod.getMetadata().getGenerateName()));

podCache.addIndexers(indexers);

Pod testPod = new PodBuilder()
.withNewMetadata().withNamespace("test").withName("test-pod").withClusterName("test-cluster").endMetadata()
.withNewMetadata().withNamespace("test").withName("test-pod").withGenerateName("test-cluster").endMetadata()
.withNewSpec().withNodeName("test-node").endSpec()
.build();
podCache.put(testPod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.fabric8.kubernetes;

import io.fabric8.junit.jupiter.api.LoadKubernetesManifests;
import io.fabric8.junit.jupiter.api.RequireK8sSupport;
import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob;
import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobBuilder;
import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobList;
Expand All @@ -29,6 +30,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

@LoadKubernetesManifests("/cronjob-it.yml")
@RequireK8sSupport(CronJob.class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up update this test to use CronJob v1 instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created: #4434

class CronJobIT {

KubernetesClient client;
Expand Down
102 changes: 102 additions & 0 deletions kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodEvictIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* 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;

import io.fabric8.junit.jupiter.api.LoadKubernetesManifests;
import io.fabric8.junit.jupiter.api.RequireK8sSupport;
import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget;
import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudgetBuilder;
import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudgetSpecBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.readiness.Readiness;
import org.junit.jupiter.api.Test;

import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@LoadKubernetesManifests("/pod-evict-it.yml")
@RequireK8sSupport(PodDisruptionBudget.class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why this new test is based on v1beta1 of PodDisruptionBudget?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a new test. This was earlier part of PodIT . This test was breaking on Kubernetes 1.25 hence I moved it to separate class with a RequireK8sSupport condition

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up: update this test to use PodDisruptionBudget v1 instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created: #4436

class PodEvictIT {
private static final int POD_READY_WAIT_IN_SECONDS = 60;

KubernetesClient client;

@Test
void evict() {
Pod pod1 = client.pods().withName("pod-standard").get();
String pdbScope = pod1.getMetadata().getLabels().get("pdb-scope");
assertNotNull("pdb-scope label is null. is pod1 misconfigured?", pdbScope);

PodDisruptionBudget pdb = new PodDisruptionBudgetBuilder()
.withNewMetadata()
.withName("test-pdb")
.endMetadata()
.withSpec(
new PodDisruptionBudgetSpecBuilder()
.withMinAvailable(new IntOrString(1))
.withNewSelector()
.addToMatchLabels("pdb-scope", pdbScope)
.endSelector()
.build())
.build();

Pod pod2 = new PodBuilder()
.withNewMetadata()
.withName("pod2")
.addToLabels("pdb-scope", pdbScope)
.endMetadata()
.withSpec(pod1.getSpec())
.build();

Pod pod3 = new PodBuilder()
.withNewMetadata()
.withName("pod3")
.addToLabels("pdb-scope", pdbScope)
.endMetadata()
.withSpec(pod1.getSpec())
.build();

client.pods().resource(pod1).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS);

client.pods().resource(pod2).createOrReplace();
client.pods().resource(pod2).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS);

client.resource(pdb).createOrReplace();

// the server needs to process the pdb before the eviction can proceed, so we'll need to wait here
await().atMost(5, TimeUnit.MINUTES)
.until(() -> client.pods().withName(pod2.getMetadata().getName()).evict());

// cant evict because only one left
assertFalse(client.pods().resource(pod1).evict());
// ensure it really is still up
assertTrue(Readiness.getInstance().isReady(client.pods().resource(pod1).fromServer().get()));

// create another pod to satisfy PDB
client.pods().resource(pod3).createOrReplace();
client.pods().resource(pod3).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS);

// can now evict
assertTrue(client.pods().resource(pod3).evict());
}
}