Skip to content

Commit

Permalink
fix: adding a method to inline creating / editing the config
Browse files Browse the repository at this point in the history
closes #5353

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
  • Loading branch information
shawkins authored and manusa committed Jan 23, 2024
1 parent 99f0846 commit 947d1fa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#### Improvements
* Fix #5701: Owner reference validity check regarding scope and namespace
* Fix #5353: added KubernetesClientBuilder.editOrNewConfig

#### Dependency Upgrade

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,23 @@ public KubernetesClientBuilder withHttpClientBuilderConsumer(Consumer<HttpClient
return this;
}

public class ConfigNested extends ConfigFluent<ConfigNested> {

private ConfigBuilder builder;

private ConfigNested() {
this.builder = new ConfigBuilder(this, config);
}

public KubernetesClientBuilder endConfig() {
config = this.builder.build();
return KubernetesClientBuilder.this;
}

}

public ConfigNested editOrNewConfig() {
return new ConfigNested();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.fabric8.kubernetes.client;

import io.fabric8.kubernetes.client.KubernetesClientBuilder.ConfigNested;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.http.HttpClient.Factory;
import org.junit.jupiter.api.Test;
Expand All @@ -37,6 +38,16 @@ void testHttpClientConfiguration() {
Mockito.verify(mockBuilder).proxyAuthorization("something");
}

@Test
void testConfigNested() {
KubernetesClientBuilder builder = new KubernetesClientBuilder(null);
builder.withConfig(new ConfigBuilder().withWatchReconnectLimit(600).build());
builder.editOrNewConfig().withApiVersion("x.y").endConfig();
ConfigNested configNested = builder.editOrNewConfig();
assertEquals("x.y", configNested.getApiVersion());
assertEquals(600, configNested.getWatchReconnectLimit());
}

/**
* This test is only to check null returned by Thread.currentThread().getContextClassLoader would be handled properly.
* For this unit test, since io.fabric8.kubernetes.client.impl.KubernetesClientImpl is not loaded in the class path,
Expand Down

0 comments on commit 947d1fa

Please sign in to comment.