From a6b2ca8d1f4b6902f6b8543c2db9181e451909a5 Mon Sep 17 00:00:00 2001 From: wind57 Date: Wed, 20 Sep 2023 11:15:01 +0300 Subject: [PATCH 1/2] fix issue --- ...rnetesClientDiscoveryHealthITDelegate.java | 69 ++++++++++--------- .../it/DiscoveryClientFilterNamespaceIT.java | 7 +- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/src/test/java/org/springframework/cloud/kubernetes/client/discovery/it/KubernetesClientDiscoveryHealthITDelegate.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/src/test/java/org/springframework/cloud/kubernetes/client/discovery/it/KubernetesClientDiscoveryHealthITDelegate.java index ee03815f27..f11fb27899 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/src/test/java/org/springframework/cloud/kubernetes/client/discovery/it/KubernetesClientDiscoveryHealthITDelegate.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/src/test/java/org/springframework/cloud/kubernetes/client/discovery/it/KubernetesClientDiscoveryHealthITDelegate.java @@ -156,8 +156,8 @@ void testDefaultConfiguration(K3sContainer container) { String healthResult = healthClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class) .retryWhen(retrySpec()).block(); - String infoResult = infoClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class) - .retryWhen(retrySpec()).block(); + String infoResult = infoClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec()) + .block(); Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) .extractingJsonPathStringValue("$.components.discoveryComposite.status").isEqualTo("UP"); @@ -188,55 +188,56 @@ void testDefaultConfiguration(K3sContainer container) { } private void assertHealth(String healthResult) { - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue( - "$.components.kubernetes.status").isEqualTo("UP"); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathStringValue("$.components.kubernetes.status").isEqualTo("UP"); - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue( - "$.components.kubernetes.details.hostIp").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathStringValue("$.components.kubernetes.details.hostIp").isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathBooleanValue( - "$.components.kubernetes.details.inside").isEqualTo(true); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathBooleanValue("$.components.kubernetes.details.inside").isEqualTo(true); - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue( - "$.components.kubernetes.details.labels.app").isEqualTo("spring-cloud-kubernetes-client-discovery-it"); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathStringValue("$.components.kubernetes.details.labels.app") + .isEqualTo("spring-cloud-kubernetes-client-discovery-it"); - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue( - "$.components.kubernetes.details.namespace").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathStringValue("$.components.kubernetes.details.namespace").isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue( - "$.components.kubernetes.details.nodeName").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathStringValue("$.components.kubernetes.details.nodeName").isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue( - "$.components.kubernetes.details.podIp").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathStringValue("$.components.kubernetes.details.podIp").isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue( - "$.components.kubernetes.details.podName").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathStringValue("$.components.kubernetes.details.podName").isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue( - "$.components.kubernetes.details.serviceAccount").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)) + .extractingJsonPathStringValue("$.components.kubernetes.details.serviceAccount").isNotEmpty(); } private void assertInfo(String infoResult) { - Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue( - "$.kubernetes.hostIp").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue("$.kubernetes.hostIp") + .isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathBooleanValue( - "$.kubernetes.inside").isEqualTo(true); + Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathBooleanValue("$.kubernetes.inside") + .isEqualTo(true); - Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue( - "$.kubernetes.namespace").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)) + .extractingJsonPathStringValue("$.kubernetes.namespace").isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue( - "$.kubernetes.nodeName").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue("$.kubernetes.nodeName") + .isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue( - "$.kubernetes.podIp").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue("$.kubernetes.podIp") + .isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue( - "$.kubernetes.podName").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue("$.kubernetes.podName") + .isNotEmpty(); - Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue( - "$.kubernetes.serviceAccount").isNotEmpty(); + Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)) + .extractingJsonPathStringValue("$.kubernetes.serviceAccount").isNotEmpty(); } private WebClient.Builder builder() { diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java index 65491ee126..3d42774cdc 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java @@ -71,6 +71,8 @@ class DiscoveryClientFilterNamespaceIT { private static RbacAuthorizationV1Api rbacApi; + private static V1ClusterRoleBinding clusterRole; + @BeforeAll static void beforeAll() throws Exception { K3S.start(); @@ -83,18 +85,19 @@ static void beforeAll() throws Exception { util = new Util(K3S); rbacApi = new RbacAuthorizationV1Api(); + clusterRole = (V1ClusterRoleBinding) util + .yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml"); util.createNamespace(NAMESPACE_LEFT); util.createNamespace(NAMESPACE_RIGHT); util.setUp(NAMESPACE); - V1ClusterRoleBinding clusterRole = (V1ClusterRoleBinding) util - .yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml"); rbacApi.createClusterRoleBinding(clusterRole, null, null, null, null); discoveryServer(Phase.CREATE); } @AfterAll static void afterAll() throws Exception { + rbacApi.deleteClusterRoleBinding(clusterRole.getMetadata().getName(), null, null, null, null, null, null); Commons.cleanUp(DISCOVERY_SERVER_APP_NAME, K3S); Commons.cleanUp(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S); discoveryServer(Phase.DELETE); From 3ed982ac5035dc2ebfea0b49d4d50e6353d8ad62 Mon Sep 17 00:00:00 2001 From: wind57 Date: Wed, 20 Sep 2023 12:42:06 +0300 Subject: [PATCH 2/2] fix issue --- .../it/DiscoveryClientFilterNamespaceIT.java | 9 +++++---- .../discoveryclient/it/DiscoveryClientIT.java | 12 +++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java index 3d42774cdc..fe10560904 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java @@ -71,7 +71,7 @@ class DiscoveryClientFilterNamespaceIT { private static RbacAuthorizationV1Api rbacApi; - private static V1ClusterRoleBinding clusterRole; + private static V1ClusterRoleBinding clusterRoleBinding; @BeforeAll static void beforeAll() throws Exception { @@ -85,19 +85,20 @@ static void beforeAll() throws Exception { util = new Util(K3S); rbacApi = new RbacAuthorizationV1Api(); - clusterRole = (V1ClusterRoleBinding) util + clusterRoleBinding = (V1ClusterRoleBinding) util .yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml"); util.createNamespace(NAMESPACE_LEFT); util.createNamespace(NAMESPACE_RIGHT); util.setUp(NAMESPACE); - rbacApi.createClusterRoleBinding(clusterRole, null, null, null, null); + rbacApi.createClusterRoleBinding(clusterRoleBinding, null, null, null, null); discoveryServer(Phase.CREATE); } @AfterAll static void afterAll() throws Exception { - rbacApi.deleteClusterRoleBinding(clusterRole.getMetadata().getName(), null, null, null, null, null, null); + rbacApi.deleteClusterRoleBinding(clusterRoleBinding.getMetadata().getName(), null, null, null, null, null, + null); Commons.cleanUp(DISCOVERY_SERVER_APP_NAME, K3S); Commons.cleanUp(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S); discoveryServer(Phase.DELETE); diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientIT.java index 7f4903717e..e3ca48a385 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientIT.java @@ -113,6 +113,10 @@ class DiscoveryClientIT { private static Util util; + private static RbacAuthorizationV1Api rbacApi; + + private static V1ClusterRoleBinding clusterRoleBinding; + @BeforeAll static void beforeAll() throws Exception { K3S.start(); @@ -124,15 +128,15 @@ static void beforeAll() throws Exception { Commons.loadSpringCloudKubernetesImage(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S); util = new Util(K3S); + rbacApi = new RbacAuthorizationV1Api(); util.setUp(NAMESPACE); util.createNamespace(NAMESPACE_LEFT); util.createNamespace(NAMESPACE_RIGHT); - RbacAuthorizationV1Api rbacApi = new RbacAuthorizationV1Api(); - V1ClusterRoleBinding clusterRole = (V1ClusterRoleBinding) util + clusterRoleBinding = (V1ClusterRoleBinding) util .yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml"); - rbacApi.createClusterRoleBinding(clusterRole, null, null, null, null); + rbacApi.createClusterRoleBinding(clusterRoleBinding, null, null, null, null); util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.CREATE, false); util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.CREATE, false); @@ -143,6 +147,8 @@ static void beforeAll() throws Exception { @AfterAll static void afterAll() throws Exception { + rbacApi.deleteClusterRoleBinding(clusterRoleBinding.getMetadata().getName(), null, null, null, null, null, + null); Commons.cleanUp(DISCOVERY_SERVER_APP_NAME, K3S); Commons.cleanUp(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S);