From 8ea185eff8f4d1f42b3cfedd7b54ac0c686ad712 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Sun, 27 Oct 2024 23:41:18 +0530 Subject: [PATCH 1/2] Removing getPluralFromKind and updating dependencies accordingly --- .../dsl/base/ResourceDefinitionContext.java | 2 +- .../kubernetes/client/utils/Utils.java | 11 --- .../kubernetes/client/internal/UtilsTest.java | 77 +------------------ 3 files changed, 2 insertions(+), 88 deletions(-) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/base/ResourceDefinitionContext.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/base/ResourceDefinitionContext.java index 67daa5eab40..ad546191bf1 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/base/ResourceDefinitionContext.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/base/ResourceDefinitionContext.java @@ -56,7 +56,7 @@ protected void validate() { if (kind == null) { throw new IllegalArgumentException("Neither kind nor plural was set, at least one is required"); } - plural = Utils.getPluralFromKind(kind); + plural = HasMetadata.getPlural(kind.getClass()); } } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/Utils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/Utils.java index 8c491c1158e..8a2d064f660 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/Utils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/Utils.java @@ -341,17 +341,6 @@ public static String toUrlEncoded(String str) { return null; } - /** - * - * @param kind - * @return - * @deprecated use {@link io.fabric8.kubernetes.api.model.HasMetadata#getPlural(Class)} - */ - @Deprecated - public static String getPluralFromKind(String kind) { - return Pluralize.toPlural(kind.toLowerCase(Locale.ROOT)); - } - /** * Reads @Namespaced annotation in resource class to check whether * resource is namespaced or not diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/UtilsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/UtilsTest.java index afe8fc7de32..ad29c3b2fcc 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/UtilsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/UtilsTest.java @@ -15,23 +15,7 @@ */ package io.fabric8.kubernetes.client.internal; -import io.fabric8.kubernetes.api.model.Binding; -import io.fabric8.kubernetes.api.model.ComponentStatus; -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.Endpoints; -import io.fabric8.kubernetes.api.model.Event; -import io.fabric8.kubernetes.api.model.LimitRange; -import io.fabric8.kubernetes.api.model.Namespace; -import io.fabric8.kubernetes.api.model.Node; -import io.fabric8.kubernetes.api.model.PersistentVolume; -import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.PodTemplate; -import io.fabric8.kubernetes.api.model.ReplicationController; -import io.fabric8.kubernetes.api.model.ResourceQuota; -import io.fabric8.kubernetes.api.model.Secret; -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.api.model.ServiceAccount; +import io.fabric8.kubernetes.api.model.*; import io.fabric8.kubernetes.api.model.admissionregistration.v1.MutatingWebhookConfiguration; import io.fabric8.kubernetes.api.model.admissionregistration.v1.ValidatingWebhookConfiguration; import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition; @@ -175,65 +159,6 @@ void interpolateStringWithParametersTest() { assertEquals("This is a \"template string\" and the following is code ${NOT_REPLACED}: '1' === '1'; /* END */", result); } - @Test - void testGetPluralFromKind() { - // Given - SortedMap pluralToKubernetesResourceMap = new TreeMap<>(); - pluralToKubernetesResourceMap.put("bindings", Binding.class); - pluralToKubernetesResourceMap.put("componentstatuses", ComponentStatus.class); - pluralToKubernetesResourceMap.put("configmaps", ConfigMap.class); - pluralToKubernetesResourceMap.put("endpoints", Endpoints.class); - pluralToKubernetesResourceMap.put("events", Event.class); - pluralToKubernetesResourceMap.put("limitranges", LimitRange.class); - pluralToKubernetesResourceMap.put("namespaces", Namespace.class); - pluralToKubernetesResourceMap.put("nodes", Node.class); - pluralToKubernetesResourceMap.put("persistentvolumeclaims", PersistentVolumeClaim.class); - pluralToKubernetesResourceMap.put("persistentvolumes", PersistentVolume.class); - pluralToKubernetesResourceMap.put("pods", Pod.class); - pluralToKubernetesResourceMap.put("podtemplates", PodTemplate.class); - pluralToKubernetesResourceMap.put("replicationcontrollers", ReplicationController.class); - pluralToKubernetesResourceMap.put("resourcequotas", ResourceQuota.class); - pluralToKubernetesResourceMap.put("secrets", Secret.class); - pluralToKubernetesResourceMap.put("serviceaccounts", ServiceAccount.class); - pluralToKubernetesResourceMap.put("services", Service.class); - pluralToKubernetesResourceMap.put("mutatingwebhookconfigurations", MutatingWebhookConfiguration.class); - pluralToKubernetesResourceMap.put("validatingwebhookconfigurations", ValidatingWebhookConfiguration.class); - pluralToKubernetesResourceMap.put("customresourcedefinitions", CustomResourceDefinition.class); - pluralToKubernetesResourceMap.put("controllerrevisions", ControllerRevision.class); - pluralToKubernetesResourceMap.put("daemonsets", DaemonSet.class); - pluralToKubernetesResourceMap.put("deployments", Deployment.class); - pluralToKubernetesResourceMap.put("replicasets", ReplicaSet.class); - pluralToKubernetesResourceMap.put("statefulsets", StatefulSet.class); - pluralToKubernetesResourceMap.put("tokenreviews", TokenReview.class); - pluralToKubernetesResourceMap.put("localsubjectaccessreviews", LocalSubjectAccessReview.class); - pluralToKubernetesResourceMap.put("selfsubjectaccessreviews", SelfSubjectAccessReview.class); - pluralToKubernetesResourceMap.put("selfsubjectrulesreviews", SelfSubjectRulesReview.class); - pluralToKubernetesResourceMap.put("subjectaccessreviews", SubjectAccessReview.class); - pluralToKubernetesResourceMap.put("horizontalpodautoscalers", HorizontalPodAutoscaler.class); - pluralToKubernetesResourceMap.put("cronjobs", CronJob.class); - pluralToKubernetesResourceMap.put("jobs", Job.class); - pluralToKubernetesResourceMap.put("certificatesigningrequests", CertificateSigningRequest.class); - pluralToKubernetesResourceMap.put("leases", Lease.class); - pluralToKubernetesResourceMap.put("endpointslices", EndpointSlice.class); - pluralToKubernetesResourceMap.put("ingresses", Ingress.class); - pluralToKubernetesResourceMap.put("networkpolicies", NetworkPolicy.class); - pluralToKubernetesResourceMap.put("poddisruptionbudgets", PodDisruptionBudget.class); - pluralToKubernetesResourceMap.put("podsecuritypolicies", PodSecurityPolicy.class); - pluralToKubernetesResourceMap.put("clusterrolebindings", ClusterRoleBinding.class); - pluralToKubernetesResourceMap.put("clusterroles", ClusterRole.class); - pluralToKubernetesResourceMap.put("rolebindings", RoleBinding.class); - pluralToKubernetesResourceMap.put("roles", Role.class); - pluralToKubernetesResourceMap.put("priorityclasses", PriorityClass.class); - pluralToKubernetesResourceMap.put("csidrivers", CSIDriver.class); - pluralToKubernetesResourceMap.put("csinodes", CSINode.class); - pluralToKubernetesResourceMap.put("storageclasses", StorageClass.class); - pluralToKubernetesResourceMap.put("volumeattachments", VolumeAttachment.class); - - // When & Then - pluralToKubernetesResourceMap.forEach( - (plural, kubernetesResource) -> assertEquals(plural, Utils.getPluralFromKind(kubernetesResource.getSimpleName()))); - } - @Test @DisplayName("Should test whether resource is namespaced or not") void testWhetherNamespacedOrNot() { From dad2061d892e106a8b3ecce213ce98ea2dd3c7fa Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Sun, 27 Oct 2024 23:47:36 +0530 Subject: [PATCH 2/2] Removing wildcard imports --- .../kubernetes/client/internal/UtilsTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/UtilsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/UtilsTest.java index ad29c3b2fcc..2aac809235d 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/UtilsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/UtilsTest.java @@ -15,7 +15,23 @@ */ package io.fabric8.kubernetes.client.internal; -import io.fabric8.kubernetes.api.model.*; +import io.fabric8.kubernetes.api.model.Binding; +import io.fabric8.kubernetes.api.model.ComponentStatus; +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.api.model.Endpoints; +import io.fabric8.kubernetes.api.model.Event; +import io.fabric8.kubernetes.api.model.LimitRange; +import io.fabric8.kubernetes.api.model.Namespace; +import io.fabric8.kubernetes.api.model.Node; +import io.fabric8.kubernetes.api.model.PersistentVolume; +import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.api.model.PodTemplate; +import io.fabric8.kubernetes.api.model.ReplicationController; +import io.fabric8.kubernetes.api.model.ResourceQuota; +import io.fabric8.kubernetes.api.model.Secret; +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceAccount; import io.fabric8.kubernetes.api.model.admissionregistration.v1.MutatingWebhookConfiguration; import io.fabric8.kubernetes.api.model.admissionregistration.v1.ValidatingWebhookConfiguration; import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;