From afc3d7afc355c177125ddb9dbc83fde563f0f2bd Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Mon, 24 Oct 2022 12:12:06 +1000 Subject: [PATCH 1/2] [JENKINS-69927] Display only one monitor instead of duplicates when initializing watcher --- .../KubernetesCredentialProvider.java | 4 ++++ .../KubernetesCredentialsProviderTest.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialProvider.java b/src/main/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialProvider.java index 6e1bc484..44c6bb00 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialProvider.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialProvider.java @@ -136,11 +136,15 @@ public void startWatchingForSecrets() { if (reconnectClientOnException) { reconnectLater(); } + // Only report the latest failure + clearAdminMonitors(initAdminMonitorId); new AdministrativeError(initAdminMonitorId, "Failed to initialize Kubernetes secret provider", "Credentials from Kubernetes Secrets will not be available.", kex); } catch (LabelSelectorParseException lex) { LOG.log(Level.SEVERE, "Failed to initialise k8s secret provider, secrets from Kubernetes will not be available", lex); + // Only report the latest failure + clearAdminMonitors(labelSelectorAdminMonitorId); new AdministrativeError(labelSelectorAdminMonitorId, "Failed to parse Kubernetes secret label selector", "Failed to parse Kubernetes secret label selector " + diff --git a/src/test/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsProviderTest.java b/src/test/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsProviderTest.java index 8873fc0c..c8a26d70 100644 --- a/src/test/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsProviderTest.java +++ b/src/test/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsProviderTest.java @@ -121,6 +121,8 @@ public void startWatchingForSecretsKubernetesClientException() throws IOExceptio KubernetesCredentialProvider provider = new MockedKubernetesCredentialProvider(); provider.startWatchingForSecrets(); assertEquals("expect administrative error", 1, getInitAdministrativeMonitorCount()); + provider.startWatchingForSecrets(); + assertEquals("expect at most 1 administrative error", 1, getInitAdministrativeMonitorCount()); // enable default responses defaultMockKubernetesResponses(); From b9926c97204cba654a7cc3d6797af99df023edea Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Mon, 24 Oct 2022 12:33:47 +1000 Subject: [PATCH 2/2] [JENKINS-69927] Adapt test --- .../KubernetesCredentialsProviderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsProviderTest.java b/src/test/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsProviderTest.java index c8a26d70..e68b016e 100644 --- a/src/test/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsProviderTest.java +++ b/src/test/java/com/cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsProviderTest.java @@ -130,7 +130,7 @@ public void startWatchingForSecretsKubernetesClientException() throws IOExceptio provider.startWatchingForSecrets(); // verify we schedule reconnect task ArgumentCaptor reconnectTask = ArgumentCaptor.forClass(Runnable.class); - verify(jenkinsTimer).schedule(reconnectTask.capture(), eq(5L), eq(TimeUnit.MINUTES)); + verify(jenkinsTimer, times(2)).schedule(reconnectTask.capture(), eq(5L), eq(TimeUnit.MINUTES)); reconnectTask.getValue().run(); assertEquals("expect administrative error to be cleared", 0, getInitAdministrativeMonitorCount()); }