Skip to content

Commit

Permalink
Merge pull request #72 from Vlatombe/update-dependencies
Browse files Browse the repository at this point in the history
Compatibility with kubernetes-client 6.x
  • Loading branch information
jtnord authored Jun 13, 2023
2 parents c236af5 + 4ced973 commit fe5fd18
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 104 deletions.
91 changes: 11 additions & 80 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.39</version>
<version>4.50</version>
<relativePath />
</parent>

Expand All @@ -45,8 +45,8 @@
<properties>
<revision>1</revision>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.303.3</jenkins.version>
<java.level>8</java.level>
<jenkins.version>2.332.4</jenkins.version>
<bom>2.332.x</bom>
<junit5.version>5.7.2</junit5.version>
</properties>

Expand Down Expand Up @@ -78,60 +78,22 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>symbol-annotation</artifactId>
<version>1.22</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>trilead-ssh2</artifactId>
<version>build-217-jenkins-16</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.3.15</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
<version>1.24</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.22</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.23</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plain-credentials</artifactId>
<version>1.7</version>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${bom}</artifactId>
<version>1706.vc166d5f429f8</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>aws-credentials</artifactId>
<version>1.26</version>
<version>1.33</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>docker-commons</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-extensions</artifactId>
<version>1.3.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>openstack-cloud</artifactId>
Expand All @@ -147,16 +109,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-credentials</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>variant</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-branch-source</artifactId>
Expand All @@ -167,40 +119,19 @@
<artifactId>hashicorp-vault-plugin</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.ui</groupId>
<artifactId>jquery-detached</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
<version>2.13.0-230.v59243c64b0a5</version>

</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>
<version>1.21</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>kubernetes-client-api</artifactId>
<version>5.12.1-187.v577c3e368fb_6</version>
<version>6.3.1-206.v76d3b_6b_14db_b</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -283,7 +214,7 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
<version>5.12.1</version>
<version>6.3.1</version>
<scope>test</scope>
<exclusions>
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
*/
package com.cloudbees.jenkins.plugins.kubernetes_credentials_provider;

import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.WatcherException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
Expand All @@ -45,7 +44,6 @@
import io.fabric8.kubernetes.api.model.SecretList;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
Expand Down Expand Up @@ -101,7 +99,7 @@ KubernetesClient getKubernetesClient() {
Config config = cb.build();
// TODO post 2.362 use jenkins.util.SetContextClassLoader
try (WithContextClassLoader ignored = new WithContextClassLoader(getClass().getClassLoader())) {
client = new DefaultKubernetesClient(config);
client = new KubernetesClientBuilder().withConfig(config).build();
}
}
return client;
Expand Down Expand Up @@ -134,20 +132,7 @@ public void startWatchingForSecrets() {
LOG.log(Level.FINER, "registering watch");
// XXX https://github.com/fabric8io/kubernetes-client/issues/1014
// watch(resourceVersion, watcher) is deprecated but there is nothing to say why?
try {
watch = _client.secrets().withLabelSelector(selector).withLabel(SecretUtils.JENKINS_IO_CREDENTIALS_TYPE_LABEL).watch(list.getMetadata().getResourceVersion(), this);
} catch (NoSuchMethodError e) {
// TODO monkey patching for kubernetes-client 6.x as they broke binary compatibility; Remove once this plugin depends on kubernetes-client 6.x at compilation time.
Object o = _client.secrets().withLabelSelector(selector).withLabel(SecretUtils.JENKINS_IO_CREDENTIALS_TYPE_LABEL);
try {
Method watchMethod = o.getClass().getMethod("watch", String.class, Watcher.class);
watch = (Watch) watchMethod.invoke(o, list.getMetadata().getResourceVersion(), this);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
RuntimeException runtimeException = new RuntimeException(ex);
runtimeException.addSuppressed(e);
throw runtimeException;
}
}
watch = _client.secrets().withLabelSelector(selector).withLabel(SecretUtils.JENKINS_IO_CREDENTIALS_TYPE_LABEL).watch(list.getMetadata().getResourceVersion(), this);
LOG.log(Level.FINER, "registered watch, retrieving secrets");

// successfully initialized, clear any previous monitors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
@RunWith(MockitoJUnitRunner.class)
public class KubernetesCredentialsProviderTest {

private static final Long EVENT_WAIT_PERIOD_MS = 10L;

public @Rule KubernetesServer server = new KubernetesServer();
private @Mock ScheduledExecutorService jenkinsTimer;

Expand Down Expand Up @@ -96,12 +98,15 @@ public void startWatchingForSecrets() {
.once();

// expect the s2 will get dropped when the credentials map is reset to the full list
server.expect().withPath("/api/v1/namespaces/test/secrets?labelSelector=jenkins.io%2Fcredentials-type&watch=true")
.andReturnChunked(200, new WatchEvent(s1, "ADDED"), new WatchEvent(s2, "ADDED"))
server.expect().withPath("/api/v1/namespaces/test/secrets?labelSelector=jenkins.io%2Fcredentials-type&resourceVersion=1&allowWatchBookmarks=true&watch=true")
.andUpgradeToWebSocket()
.open()
.waitFor(EVENT_WAIT_PERIOD_MS)
.andEmit(new WatchEvent(s1, "ADDED"))
.waitFor(EVENT_WAIT_PERIOD_MS)
.andEmit(new WatchEvent(s2, "ADDED"))
.done()
.once();
server.expect().withPath("/api/v1/namespaces/test/secrets?labelSelector=jenkins.io%2Fcredentials-type&watch=true")
.andReturn(200, null)
.always();

KubernetesCredentialProvider provider = new MockedKubernetesCredentialProvider();
provider.startWatchingForSecrets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void getNonNullSecretDataWithNoData() {
SecretUtils.getNonNullSecretData(s, "some-key", "oops");
fail();
} catch (CredentialsConvertionException cce) {
assertThat(cce.getMessage(), is("oops"));
assertThat(cce.getMessage(), is("oops (mapped to some-key)"));
}
}

Expand Down

0 comments on commit fe5fd18

Please sign in to comment.