From 9a8836d20c8b452e2a0140baa684725577575910 Mon Sep 17 00:00:00 2001 From: Max Shaposhnik Date: Thu, 2 Sep 2021 21:23:24 +0300 Subject: [PATCH] fix: Correct prervious roles validation fixup for minikube Signed-off-by: Max Shaposhnik --- .../AbstractWorkspaceServiceAccount.java | 20 +++++++++---------- ...KubernetesWorkspaceServiceAccountTest.java | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/AbstractWorkspaceServiceAccount.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/AbstractWorkspaceServiceAccount.java index 2a926e1da97..f2a14c188bd 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/AbstractWorkspaceServiceAccount.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/AbstractWorkspaceServiceAccount.java @@ -131,8 +131,8 @@ private void ensureImplicitRolesWithBindings(Client k8sClient) { serviceAccountName + "-view"); // metrics role - if (k8sClient.supportsApiPath("/apis/metrics.k8s.io")) { - try { + try { + if (k8sClient.supportsApiPath("/apis/metrics.k8s.io")) { ensureRoleWithBinding( k8sClient, buildRole( @@ -142,14 +142,14 @@ private void ensureImplicitRolesWithBindings(Client k8sClient) { singletonList("metrics.k8s.io"), Arrays.asList("list", "get", "watch")), serviceAccountName + "-metrics"); - } catch (KubernetesClientException e) { - // workaround to unblock workspace start if no permissions for metrics - if (e.getCode() == 403) { - LOG.warn( - "Unable to add metrics roles due to insufficient permissions. Workspace metrics will be disabled."); - } else { - throw e; - } + } + } catch (KubernetesClientException e) { + // workaround to unblock workspace start if no permissions for metrics + if (e.getCode() == 403) { + LOG.warn( + "Unable to add metrics roles due to insufficient permissions. Workspace metrics will be disabled."); + } else { + throw e; } } diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesWorkspaceServiceAccountTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesWorkspaceServiceAccountTest.java index 241c14b0d10..b6aa7a5cadd 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesWorkspaceServiceAccountTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesWorkspaceServiceAccountTest.java @@ -111,7 +111,7 @@ public void shouldCreateMetricsRoleIfAPIEnabledOnServer() throws Exception { } @Test - public void shouldNotCreateMetricsRoleIfAPIEnabledOnServer() throws Exception { + public void shouldNotCreateMetricsRoleIfAPINotEnabledOnServer() throws Exception { KubernetesClient localK8sClient = spy(serverMock.getClient()); when(localK8sClient.supportsApiPath(eq("/apis/metrics.k8s.io"))).thenReturn(false); when(clientFactory.create(anyString())).thenReturn(localK8sClient);