Skip to content

Commit

Permalink
feat (kubernetes-client-api) : Add DSL support for new resources in K…
Browse files Browse the repository at this point in the history
…ubernetes v1.27.0

Add DSL support and mock tests for the following Kubernetes resources to
KubernetesClient:
- `networking.k8s.io/v1alpha1` IPAddress
- `networking.k8s.io/v1alpha1` ClusterCIDR
- `certificates.k8s.io/v1alpha1` ClusterTrustBundle
- `authentication.k8s.io/v1beta1` SelfSubjectReview

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia authored and manusa committed Jul 14, 2023
1 parent 0b666f7 commit b421555
Show file tree
Hide file tree
Showing 18 changed files with 767 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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.networking.v1alpha1.ClusterCIDR;
import io.fabric8.kubernetes.api.model.networking.v1alpha1.ClusterCIDRList;
import io.fabric8.kubernetes.api.model.networking.v1alpha1.IPAddress;
import io.fabric8.kubernetes.api.model.networking.v1alpha1.IPAddressList;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;

public interface V1Alpha1NetworkAPIGroupDSL extends Client {
/**
* API entrypoint for networking.k8s.io/v1alpha1 IPAddress
* <br>
* IPAddress represents a single IP of a single IP Family. The object is designed to be used by APIs
* that operate on IP addresses. The object is used by the Service core API for allocation of IP addresses.
*
* @return {@link NonNamespaceOperation} for IPAddress
*/
NonNamespaceOperation<IPAddress, IPAddressList, Resource<IPAddress>> ipAddresses();

/**
* API entrypoint for networking.k8s.io/v1alpha1 ClusterCIDR
* <br>
* ClusterCIDR represents a single configuration for per-Node Pod CIDR
* allocations when the MultiCIDRRangeAllocator is enabled (see the config for
* kube-controller-manager). A cluster may have any number of ClusterCIDR
* resources, all of which will be considered when allocating a CIDR for a
* Node. A ClusterCIDR is eligible to be used for a given Node when the node
* selector matches the node in question and has free CIDRs to allocate. In
* case of multiple matching ClusterCIDR resources, the allocator will attempt
* to break ties using internal heuristics, but any ClusterCIDR whose node
* selector matches the Node may be used.
*
* @return {@link NonNamespaceOperation} for ClusterCIDR
*/
NonNamespaceOperation<ClusterCIDR, ClusterCIDRList, Resource<ClusterCIDR>> clusterCIDRs();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface AuthenticationAPIGroupDSL extends Client {
V1AuthenticationAPIGroupDSL v1();

V1Alpha1AuthenticationAPIGroupDSL v1alpha1();

V1Beta1AuthenticationAPIGroupDSL v1beta1();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public interface CertificatesAPIGroupDSL extends Client {
V1CertificatesAPIGroupDSL v1();

V1beta1CertificatesAPIGroupDSL v1beta1();

V1Alpha1CertificatesAPIGroupDSL v1alpha1();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress;
import io.fabric8.kubernetes.api.model.networking.v1beta1.IngressList;
import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.V1Alpha1NetworkAPIGroupDSL;
import io.fabric8.kubernetes.client.V1NetworkAPIGroupDSL;
import io.fabric8.kubernetes.client.V1beta1NetworkAPIGroupDSL;

Expand All @@ -28,6 +29,8 @@ public interface NetworkAPIGroupDSL extends Client {

V1beta1NetworkAPIGroupDSL v1beta1();

V1Alpha1NetworkAPIGroupDSL v1alpha1();

MixedOperation<NetworkPolicy, NetworkPolicyList, Resource<NetworkPolicy>> networkPolicies();

MixedOperation<Ingress, IngressList, Resource<Ingress>> ingress();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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.certificates.v1alpha1.ClusterTrustBundle;
import io.fabric8.kubernetes.api.model.certificates.v1alpha1.ClusterTrustBundleList;
import io.fabric8.kubernetes.client.Client;

public interface V1Alpha1CertificatesAPIGroupDSL extends Client {
/**
* API entrypoint for certificates.k8s.io/v1alpha1 ClusterTrustBundle
* <br>
* ClusterTrustBundle is a cluster-scoped container for X.509 trust anchors
* (root certificates).
* <br>
* ClusterTrustBundle objects are considered to be readable by any authenticated
* user in the cluster, because they can be mounted by pods using the
* `clusterTrustBundle` projection. All service accounts have read access to
* ClusterTrustBundles by default. Users who only have namespace-level access
* to a cluster can read ClusterTrustBundles by impersonating a serviceaccount
* that they have access to.
* <br>
* It can be optionally associated with a particular assigner, in which case it
* contains one valid set of trust anchors for that signer. Signers may have
* multiple associated ClusterTrustBundles; each is an independent set of trust
* anchors for that signer. Admission control is used to enforce that only users
* with permissions on the signer can create or modify the corresponding bundle.
*
* @return {@link NonNamespaceOperation} for ClusterTrustBundle
*/
NonNamespaceOperation<ClusterTrustBundle, ClusterTrustBundleList, Resource<ClusterTrustBundle>> clusterTrustBundles();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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.authentication.v1beta1.SelfSubjectReview;
import io.fabric8.kubernetes.client.Client;

public interface V1Beta1AuthenticationAPIGroupDSL extends Client {
/**
* API for creating authentication.k8s.io/v1beta1 SelfSubjectReview.
* <br>
* SelfSubjectReview contains the user information that the kube-apiserver has about the user making this request.
* When using impersonation, users will receive the user info of the user being impersonated. If impersonation or
* request header authentication is used, any extra keys will have their case ignored and returned as lowercase.
*
* @return InOutCreateable instance for creating SelfSubjectReview object
*/
InOutCreateable<SelfSubjectReview, SelfSubjectReview> selfSubjectReview();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.fabric8.kubernetes.client.V1AuthenticationAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.AuthenticationAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1Alpha1AuthenticationAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1Beta1AuthenticationAPIGroupDSL;
import io.fabric8.kubernetes.client.extension.ClientAdapter;

public class AuthenticationAPIGroupClient extends ClientAdapter<AuthenticationAPIGroupClient>
Expand All @@ -29,7 +30,12 @@ public V1AuthenticationAPIGroupDSL v1() {

@Override
public V1Alpha1AuthenticationAPIGroupDSL v1alpha1() {
return adapt(V1Alpha1AuthenticationAPIGroupDSL.class);
return adapt(V1Alpha1AuthenticationAPIGroupClient.class);
}

@Override
public V1Beta1AuthenticationAPIGroupDSL v1beta1() {
return adapt(V1Beta1AuthenticationAPIGroupClient.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.fabric8.kubernetes.client.impl;

import io.fabric8.kubernetes.client.dsl.CertificatesAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1Alpha1CertificatesAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1CertificatesAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1beta1CertificatesAPIGroupDSL;
import io.fabric8.kubernetes.client.extension.ClientAdapter;
Expand All @@ -32,6 +33,11 @@ public V1beta1CertificatesAPIGroupDSL v1beta1() {
return adapt(V1beta1CertificatesAPIGroupClient.class);
}

@Override
public V1Alpha1CertificatesAPIGroupDSL v1alpha1() {
return adapt(V1Alpha1CertificatesAPIGroupClient.class);
}

@Override
public CertificatesAPIGroupClient newInstance() {
return new CertificatesAPIGroupClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import io.fabric8.kubernetes.client.RequestConfig;
import io.fabric8.kubernetes.client.V1AdmissionRegistrationAPIGroupDSL;
import io.fabric8.kubernetes.client.V1Alpha1AdmissionRegistrationAPIGroupDSL;
import io.fabric8.kubernetes.client.V1Alpha1NetworkAPIGroupDSL;
import io.fabric8.kubernetes.client.V1Alpha2DynamicResourceAllocationAPIGroupDSL;
import io.fabric8.kubernetes.client.V1ApiextensionAPIGroupDSL;
import io.fabric8.kubernetes.client.V1AuthenticationAPIGroupDSL;
Expand Down Expand Up @@ -126,7 +127,9 @@
import io.fabric8.kubernetes.client.dsl.StorageAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1APIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1Alpha1AuthenticationAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1Alpha1CertificatesAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1BatchAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1Beta1AuthenticationAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1CertificatesAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1DiscoveryAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.V1EventingAPIGroupDSL;
Expand Down Expand Up @@ -253,8 +256,10 @@ protected void registerDefaultAdapters() {
adapters.registerClient(V1beta1AuthorizationAPIGroupDSL.class, new V1beta1AuthorizationAPIGroupClient());
adapters.registerClient(V1AuthenticationAPIGroupDSL.class, new V1AuthenticationAPIGroupClient());
adapters.registerClient(V1Alpha1AuthenticationAPIGroupDSL.class, new V1Alpha1AuthenticationAPIGroupClient());
adapters.registerClient(V1Beta1AuthenticationAPIGroupDSL.class, new V1Beta1AuthenticationAPIGroupClient());
adapters.registerClient(V1NetworkAPIGroupDSL.class, new V1NetworkAPIGroupClient());
adapters.registerClient(V1beta1NetworkAPIGroupDSL.class, new V1beta1NetworkAPIGroupClient());
adapters.registerClient(V1Alpha1NetworkAPIGroupDSL.class, new V1Alpha1NetworkAPIGroupClient());
adapters.registerClient(DiscoveryAPIGroupDSL.class, new DiscoveryAPIGroupClient());
adapters.registerClient(V1beta1DiscoveryAPIGroupDSL.class, new V1beta1DiscoveryAPIGroupClient());
adapters.registerClient(V1DiscoveryAPIGroupDSL.class, new V1DiscoveryAPIGroupClient());
Expand All @@ -265,6 +270,7 @@ protected void registerDefaultAdapters() {
adapters.registerClient(CertificatesAPIGroupDSL.class, new CertificatesAPIGroupClient());
adapters.registerClient(V1CertificatesAPIGroupDSL.class, new V1CertificatesAPIGroupClient());
adapters.registerClient(V1beta1CertificatesAPIGroupDSL.class, new V1beta1CertificatesAPIGroupClient());
adapters.registerClient(V1Alpha1CertificatesAPIGroupDSL.class, new V1Alpha1CertificatesAPIGroupClient());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyList;
import io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress;
import io.fabric8.kubernetes.api.model.networking.v1beta1.IngressList;
import io.fabric8.kubernetes.client.V1Alpha1NetworkAPIGroupDSL;
import io.fabric8.kubernetes.client.V1NetworkAPIGroupDSL;
import io.fabric8.kubernetes.client.V1beta1NetworkAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
Expand All @@ -38,6 +39,11 @@ public V1beta1NetworkAPIGroupDSL v1beta1() {
return adapt(V1beta1NetworkAPIGroupClient.class);
}

@Override
public V1Alpha1NetworkAPIGroupDSL v1alpha1() {
return adapt(V1Alpha1NetworkAPIGroupClient.class);
}

@Override
public MixedOperation<NetworkPolicy, NetworkPolicyList, Resource<NetworkPolicy>> networkPolicies() {
return resources(NetworkPolicy.class, NetworkPolicyList.class);
Expand Down
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.impl;

import io.fabric8.kubernetes.api.model.certificates.v1alpha1.ClusterTrustBundle;
import io.fabric8.kubernetes.api.model.certificates.v1alpha1.ClusterTrustBundleList;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.V1Alpha1CertificatesAPIGroupDSL;
import io.fabric8.kubernetes.client.extension.ClientAdapter;

public class V1Alpha1CertificatesAPIGroupClient extends ClientAdapter<V1Alpha1CertificatesAPIGroupClient>
implements V1Alpha1CertificatesAPIGroupDSL {
@Override
public NonNamespaceOperation<ClusterTrustBundle, ClusterTrustBundleList, Resource<ClusterTrustBundle>> clusterTrustBundles() {
return resources(ClusterTrustBundle.class, ClusterTrustBundleList.class);
}

@Override
public V1Alpha1CertificatesAPIGroupClient newInstance() {
return new V1Alpha1CertificatesAPIGroupClient();
}
}
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.networking.v1alpha1.ClusterCIDR;
import io.fabric8.kubernetes.api.model.networking.v1alpha1.ClusterCIDRList;
import io.fabric8.kubernetes.api.model.networking.v1alpha1.IPAddress;
import io.fabric8.kubernetes.api.model.networking.v1alpha1.IPAddressList;
import io.fabric8.kubernetes.client.V1Alpha1NetworkAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.extension.ClientAdapter;

public class V1Alpha1NetworkAPIGroupClient extends ClientAdapter<V1Alpha1NetworkAPIGroupClient>
implements V1Alpha1NetworkAPIGroupDSL {
@Override
public NonNamespaceOperation<IPAddress, IPAddressList, Resource<IPAddress>> ipAddresses() {
return resources(IPAddress.class, IPAddressList.class);
}

@Override
public NonNamespaceOperation<ClusterCIDR, ClusterCIDRList, Resource<ClusterCIDR>> clusterCIDRs() {
return resources(ClusterCIDR.class, ClusterCIDRList.class);
}

@Override
public V1Alpha1NetworkAPIGroupClient newInstance() {
return new V1Alpha1NetworkAPIGroupClient();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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.authentication.v1beta1.SelfSubjectReview;
import io.fabric8.kubernetes.client.dsl.InOutCreateable;
import io.fabric8.kubernetes.client.dsl.V1Beta1AuthenticationAPIGroupDSL;
import io.fabric8.kubernetes.client.extension.ClientAdapter;

public class V1Beta1AuthenticationAPIGroupClient extends ClientAdapter<V1Beta1AuthenticationAPIGroupClient>
implements V1Beta1AuthenticationAPIGroupDSL {
@Override
public InOutCreateable<SelfSubjectReview, SelfSubjectReview> selfSubjectReview() {
return getClient().adapt(BaseClient.class).getHandlers().getNonListingOperation(SelfSubjectReview.class, this);
}

@Override
public V1Beta1AuthenticationAPIGroupClient newInstance() {
return new V1Beta1AuthenticationAPIGroupClient();
}
}
Loading

0 comments on commit b421555

Please sign in to comment.