Skip to content

Commit a8499d5

Browse files
committed
Treat blank CA Cert data as null
The Kubernetes Client appears to treat these differently. If using a null cert it appears it willm either fall back to trusting all certs or (more likely) using an auto-configured cert it finds within the pod from the service account auto mount files. Currently there are weird inconsistencies as after you edit the config or restart the server it can set an empty string which starts causing validation failures talking to the API.
1 parent e73f7d1 commit a8499d5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/cd/go/contrib/elasticagent/PluginSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public String getClusterUrl() {
108108
}
109109

110110
public String getCaCertData() {
111-
return clusterCACertData;
111+
return isBlank(clusterCACertData) ? null : clusterCACertData;
112112
}
113113

114114
public Integer getClusterRequestTimeout() {

src/test/java/cd/go/contrib/elasticagent/PluginSettingsTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,14 @@ public void shouldConsiderBlankStringAsNull() {
9898

9999
assertThat(pluginSettings.getNamespace()).isEqualTo("default");
100100
}
101+
102+
@Test
103+
public void shouldConsiderBlankCertAsNull() {
104+
final Map<String, Object> pluginSettingsMap = new HashMap<>();
105+
pluginSettingsMap.put("kubernetes_cluster_ca_cert", " ");
106+
107+
PluginSettings pluginSettings = PluginSettings.fromJSON(new Gson().toJson(pluginSettingsMap));
108+
109+
assertThat(pluginSettings.getCaCertData()).isNull();
110+
}
101111
}

0 commit comments

Comments
 (0)