Skip to content

Commit

Permalink
Merge pull request #101 from jenkinsci/use-bom-versions
Browse files Browse the repository at this point in the history
Use versions from BOM
  • Loading branch information
jtnord authored Jan 14, 2025
2 parents 61aa684 + 0e62e6d commit 15e69b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
13 changes: 1 addition & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>aws-credentials</artifactId>
<version>189.v3551d5642995</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>docker-commons</artifactId>
<version>419.v8e3cd84ef49c</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>openstack-cloud</artifactId>
Expand Down Expand Up @@ -141,7 +131,6 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>kubernetes-client-api</artifactId>
<version>6.8.1-224.vd388fca_4db_3b_</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -221,7 +210,7 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
<version>6.7.1</version>
<version>6.10.0</version>
<scope>test</scope>
<exclusions>
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import hudson.triggers.SafeTimerTask;
import hudson.util.AdministrativeError;
import io.fabric8.kubernetes.api.model.LabelSelector;
import io.fabric8.kubernetes.api.model.ListOptionsBuilder;
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.SecretList;
import io.fabric8.kubernetes.client.Config;
Expand Down Expand Up @@ -132,7 +133,9 @@ 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?
watch = _client.secrets().withLabelSelector(selector).withLabel(SecretUtils.JENKINS_IO_CREDENTIALS_TYPE_LABEL).watch(list.getMetadata().getResourceVersion(), this);
ListOptionsBuilder lob = new ListOptionsBuilder();
lob.withResourceVersion(list.getMetadata().getResourceVersion());
watch = _client.secrets().withLabelSelector(selector).withLabel(SecretUtils.JENKINS_IO_CREDENTIALS_TYPE_LABEL).watch(lob.build(), 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 @@ -57,7 +57,7 @@ public class KubernetesCredentialsProviderTest {

private @Mock(answer = Answers.CALLS_REAL_METHODS) MockedStatic<ExtensionList> extensionList;
private @Mock MockedStatic<Timer> timer;

@Before
public void setUp() {
// mocked to validate add/remove of administrative errors
Expand All @@ -75,13 +75,15 @@ private void defaultMockKubernetesResponses() {
}

private void mockKubernetesResponses(String labelSelector) {
// initial request without resourceVersion
server.expect().withPath("/api/v1/namespaces/test/secrets?labelSelector=" + labelSelector)
.andReturn(200, new SecretListBuilder()
.withNewMetadata()
.withResourceVersion("1")
.endMetadata()
.build()).always();
server.expect().withPath("/api/v1/namespaces/test/secrets?labelSelector=" + labelSelector + "&resourceVersion=1&allowWatchBookmarks=true&watch=true")
// subsequent requests resourceVersion after the first list (we do not modify things, so return null)
server.expect().withPath("/api/v1/namespaces/test/secrets?allowWatchBookmarks=true&labelSelector=" + labelSelector + "&resourceVersion=1&watch=true")
.andReturn(200, null).always();
}

Expand All @@ -100,6 +102,10 @@ public void startWatchingForSecrets_Scoped() throws IOException {
.build())
.once();

// subsequent requests resourceVersion after the first list (we do not modify things, so return null)
server.expect().withPath("/api/v1/namespaces/test/secrets?allowWatchBookmarks=true&labelSelector=jenkins.io%2Fcredentials-type&resourceVersion=1&watch=true")
.andReturn(200, null).always();

KubernetesCredentialProvider provider = new MockedKubernetesCredentialProvider();
provider.startWatchingForSecrets();

Expand Down Expand Up @@ -128,7 +134,7 @@ 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&resourceVersion=1&allowWatchBookmarks=true&watch=true")
server.expect().withPath("/api/v1/namespaces/test/secrets?allowWatchBookmarks=true&labelSelector=jenkins.io%2Fcredentials-type&resourceVersion=1&watch=true")
.andUpgradeToWebSocket()
.open()
.waitFor(EVENT_WAIT_PERIOD_MS)
Expand Down Expand Up @@ -165,7 +171,7 @@ public void credentialScope() {
.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")
server.expect().withPath("/api/v1/namespaces/test/secrets?allowWatchBookmarks=true&labelSelector=jenkins.io%2Fcredentials-type&resourceVersion=1&watch=true")
.andReturnChunked(200, new WatchEvent(s1, "ADDED"), new WatchEvent(s2, "ADDED"))
.once();
server.expect().withPath("/api/v1/namespaces/test/secrets?labelSelector=jenkins.io%2Fcredentials-type&watch=true")
Expand All @@ -174,7 +180,6 @@ public void credentialScope() {

KubernetesCredentialProvider provider = new MockedKubernetesCredentialProvider();
provider.startWatchingForSecrets();

List<UsernamePasswordCredentials> credentials;

credentials = provider.getCredentials(UsernamePasswordCredentials.class, (ItemGroup) null, ACL.SYSTEM);
Expand Down Expand Up @@ -281,7 +286,7 @@ public void startWatchingWithCustomLabelSelectors() throws InterruptedException
provider.startWatchingForSecrets();

assertRequestCount("/api/v1/namespaces/test/secrets?labelSelector=jenkins.io%2Fcredentials-type%2Cenv%20in%20%28iat%20uat%29", 1);
assertRequestCountAtLeast("/api/v1/namespaces/test/secrets?labelSelector=jenkins.io%2Fcredentials-type%2Cenv%20in%20%28iat%20uat%29&resourceVersion=1&allowWatchBookmarks=true&watch=true", 1);
assertRequestCountAtLeast("/api/v1/namespaces/test/secrets?allowWatchBookmarks=true&labelSelector=jenkins.io%2Fcredentials-type%2Cenv%20in%20%28iat%20uat%29&resourceVersion=1&watch=true", 1);
} finally {
System.clearProperty(KubernetesCredentialProvider.LABEL_SELECTOR);
}
Expand Down Expand Up @@ -330,7 +335,7 @@ private List<RecordedRequest> getRequests() throws InterruptedException {
int count = server.getKubernetesMockServer().getRequestCount();
List<RecordedRequest> requests = new LinkedList<>();
while (count-- > 0) {
requests.add(server.getKubernetesMockServer().takeRequest());
requests.add(server.getKubernetesMockServer().takeRequest(30L, TimeUnit.SECONDS));
}
return requests;
}
Expand Down

0 comments on commit 15e69b5

Please sign in to comment.