Skip to content

Commit 69b28e6

Browse files
committed
Minor tidies to location of the config
- Also correct the optionality from the view/form perspective
1 parent 89c89c0 commit 69b28e6

File tree

9 files changed

+51
-53
lines changed

9 files changed

+51
-53
lines changed

docs/configure_cluster_profile.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@
1313

1414
1. Optionally specify `Agent auto-register timeout (in minutes)`. This defaults to 10 (minutes) if not provided.
1515

16-
2. Optionally specify `The cluster request timeout`. This defaults to 10000 (milliseconds) if not provided.
16+
1. Optionally specify `Maximum pending pods`. This defaults to 10 (pods) if not provided.
1717

18-
3. Optionally Specify `Maximum pending pods`. This defaults to 10 (pods) if not provided.
18+
1. Specify `Cluster URL`.
1919

20-
4. Specify `Cluster URL`.
21-
22-
5. Optionally specify `Namespace`. If not provided, the plugin will launch GoCD
20+
1. Optionally specify `Namespace`. If not provided, the plugin will launch GoCD
2321
agent pods in the default Kubernetes namespace. Note: If you have multiple
2422
GoCD servers with cluster profiles pointing to the same Kubernetes cluster,
2523
make sure that the namespace used by each GoCD server is different.
2624
Otherwise, the plugin of one GoCD server will end up terminating pods
2725
started by the plugin in the other GoCD servers.
2826

29-
6. Specify `Security token`. This should be a Kubernetes API token with the
27+
1. Specify `Security token`. This should be a Kubernetes API token with the
3028
following permissions:
3129

3230
| Resource | Actions |
@@ -44,10 +42,13 @@
4442
If you are comfortable with cluster-wide permissions you can refer to the [example within the GoCD official helm
4543
chart](https://github.com/gocd/helm-chart/blob/master/gocd/templates/gocd-cluster-role.yaml).
4644

47-
7. Specify `Cluster CA certificate data`. This should be the base-64-encoded certificate
45+
1. Specify `Cluster CA certificate data`. This should be the base-64-encoded certificate
4846
of the Kubernetes API server. It can be omitted in the rare case that the Kubernetes API
4947
is configured to serve plain HTTP.
5048

49+
1. Optionally specify the `Cluster request timeout` (in milliseconds).
50+
51+
5152
!["Kubernetes Cluster Profile"][1]
5253

5354

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ private void clearOutClientOnTimer() {
7676
private KubernetesClient createClientFor(PluginSettings pluginSettings) {
7777
final ConfigBuilder configBuilder = new ConfigBuilder()
7878
.withAutoConfigure(false)
79-
.withRequestTimeout(pluginSettings.getClusterRequestTimeout())
80-
.withOauthToken(pluginSettings.getSecurityToken())
8179
.withMasterUrl(pluginSettings.getClusterUrl())
80+
.withNamespace(pluginSettings.getNamespace())
81+
.withOauthToken(pluginSettings.getSecurityToken())
8282
.withCaCertData(pluginSettings.getCaCertData())
83-
.withNamespace(pluginSettings.getNamespace());
83+
.withRequestTimeout(pluginSettings.getClusterRequestTimeout());
8484

8585
return new KubernetesClientBuilder().withConfig(configBuilder.build()).build();
8686
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public GoPluginApiResponse handle(GoPluginApiRequest request) {
113113
}
114114
} catch (Exception e) {
115115
LOG.error("Failed to handle request " + request.requestName(), e);
116-
117116
return DefaultGoPluginApiResponse.error("Failed to handle request " + request.requestName());
118117
}
119118
}

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public class PluginSettings {
4040
@SerializedName("pending_pods_count")
4141
private String maxPendingPods;
4242

43-
@Expose
44-
@SerializedName("cluster_request_timeout")
45-
private String clusterRequestTimeout;
46-
4743
@Expose
4844
@SerializedName("kubernetes_cluster_url")
4945
private String clusterUrl;
@@ -60,6 +56,10 @@ public class PluginSettings {
6056
@SerializedName("namespace")
6157
private String namespace;
6258

59+
@Expose
60+
@SerializedName("cluster_request_timeout")
61+
private String clusterRequestTimeout;
62+
6363
private Duration autoRegisterPeriod;
6464

6565
public PluginSettings() {
@@ -86,20 +86,13 @@ public Duration getAutoRegisterPeriod() {
8686
}
8787

8888
Integer getAutoRegisterTimeout() {
89-
Integer autoRegisterTimeoutInt = !isBlank(autoRegisterTimeout) ? Integer.valueOf(autoRegisterTimeout) : null;
90-
return getOrDefault(autoRegisterTimeoutInt, 10);
89+
Integer value = !isBlank(autoRegisterTimeout) ? Integer.valueOf(autoRegisterTimeout) : null;
90+
return getOrDefault(value, 10);
9191
}
9292

9393
public Integer getMaxPendingPods() {
94-
Integer maximumPendingPodsInt = !isBlank(this.maxPendingPods) ? Integer.valueOf(this.maxPendingPods) : null;
95-
return getOrDefault(maximumPendingPodsInt, 10);
96-
}
97-
98-
public Integer getClusterRequestTimeout() {
99-
Integer maximumPendingPodsInt = !isBlank(this.clusterRequestTimeout)
100-
? Integer.valueOf(this.clusterRequestTimeout)
101-
: null;
102-
return getOrDefault(maximumPendingPodsInt, 10000);
94+
Integer value = !isBlank(this.maxPendingPods) ? Integer.valueOf(this.maxPendingPods) : null;
95+
return getOrDefault(value, 10);
10396
}
10497

10598
public String getGoServerUrl() {
@@ -118,6 +111,11 @@ public String getCaCertData() {
118111
return clusterCACertData;
119112
}
120113

114+
public Integer getClusterRequestTimeout() {
115+
Integer value = !isBlank(this.clusterRequestTimeout) ? Integer.valueOf(this.clusterRequestTimeout) : null;
116+
return getOrDefault(value, 10000);
117+
}
118+
121119
public String getNamespace() {
122120
return getOrDefault(this.namespace, "default");
123121
}
@@ -147,14 +145,14 @@ public boolean equals(Object o) {
147145
return false;
148146
if (maxPendingPods != null ? !maxPendingPods.equals(that.maxPendingPods) : that.maxPendingPods != null)
149147
return false;
150-
if (clusterRequestTimeout != null ? !clusterRequestTimeout.equals(that.clusterRequestTimeout) : that.clusterRequestTimeout != null)
151-
return false;
152148
if (clusterUrl != null ? !clusterUrl.equals(that.clusterUrl) : that.clusterUrl != null)
153149
return false;
154150
if (securityToken != null ? !securityToken.equals(that.securityToken) : that.securityToken != null)
155151
return false;
156152
if (clusterCACertData != null ? !clusterCACertData.equals(that.clusterCACertData) : that.clusterCACertData != null)
157153
return false;
154+
if (clusterRequestTimeout != null ? !clusterRequestTimeout.equals(that.clusterRequestTimeout) : that.clusterRequestTimeout != null)
155+
return false;
158156
return namespace != null ? namespace.equals(that.namespace) : that.namespace == null;
159157
}
160158

@@ -163,10 +161,10 @@ public int hashCode() {
163161
int result = goServerUrl != null ? goServerUrl.hashCode() : 0;
164162
result = 31 * result + (autoRegisterTimeout != null ? autoRegisterTimeout.hashCode() : 0);
165163
result = 31 * result + (maxPendingPods != null ? maxPendingPods.hashCode() : 0);
166-
result = 31 * result + (clusterRequestTimeout != null ? clusterRequestTimeout.hashCode() : 0);
167164
result = 31 * result + (clusterUrl != null ? clusterUrl.hashCode() : 0);
168165
result = 31 * result + (securityToken != null ? securityToken.hashCode() : 0);
169166
result = 31 * result + (clusterCACertData != null ? clusterCACertData.hashCode() : 0);
167+
result = 31 * result + (clusterRequestTimeout != null ? clusterRequestTimeout.hashCode() : 0);
170168
result = 31 * result + (namespace != null ? namespace.hashCode() : 0);
171169
return result;
172170
}
@@ -177,10 +175,10 @@ public String toString() {
177175
"goServerUrl='" + goServerUrl + '\'' +
178176
", autoRegisterTimeout=" + autoRegisterTimeout +
179177
", maxPendingPods=" + maxPendingPods +
180-
", clusterRequestTimeout=" + clusterRequestTimeout +
181178
", clusterUrl='" + clusterUrl + '\'' +
182179
", securityToken='" + securityToken + '\'' +
183180
", clusterCACertData='" + clusterCACertData + '\'' +
181+
", clusterRequestTimeout=" + clusterRequestTimeout +
184182
", namespace='" + namespace + '\'' +
185183
", autoRegisterPeriod=" + autoRegisterPeriod +
186184
'}';

src/main/java/cd/go/contrib/elasticagent/executors/GetClusterProfileMetadataExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ public class GetClusterProfileMetadataExecutor implements RequestExecutor {
3333
public static final Metadata GO_SERVER_URL = new GoServerURLMetadata();
3434
public static final Metadata AUTO_REGISTER_TIMEOUT = new Metadata("auto_register_timeout", false, false);
3535
public static final Metadata MAX_PENDING_PODS = new Metadata("pending_pods_count", false, false);
36-
public static final Metadata CLUSTER_REQUEST_TIMEOUT = new Metadata("cluster_request_timeout", false, false);
3736
public static final Metadata CLUSTER_URL = new Metadata("kubernetes_cluster_url", true, false);
3837
public static final Metadata NAMESPACE = new Metadata("namespace", false, false);
3938
public static final Metadata SECURITY_TOKEN = new Metadata("security_token", true, true);
4039
public static final Metadata CLUSTER_CA_CERT = new Metadata("kubernetes_cluster_ca_cert", false, true);
40+
public static final Metadata CLUSTER_REQUEST_TIMEOUT = new Metadata("cluster_request_timeout", false, false);
4141

4242
public static final List<Metadata> FIELDS = new ArrayList<>();
4343

4444
static {
4545
FIELDS.add(GO_SERVER_URL);
4646
FIELDS.add(AUTO_REGISTER_TIMEOUT);
4747
FIELDS.add(MAX_PENDING_PODS);
48-
FIELDS.add(CLUSTER_REQUEST_TIMEOUT);
4948
FIELDS.add(CLUSTER_URL);
5049
FIELDS.add(NAMESPACE);
5150
FIELDS.add(SECURITY_TOKEN);
5251
FIELDS.add(CLUSTER_CA_CERT);
52+
FIELDS.add(CLUSTER_REQUEST_TIMEOUT);
5353
}
5454

5555
@Override

src/main/resources/plugin-settings.template.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@
8484
<label class="form-help-content">Defaults to <code>10 minutes</code>.</label>
8585
</div>
8686

87-
<div class="row">
88-
<label>The cluster request timeout(in milliseconds)</label>
89-
<input type="text" ng-model="cluster_request_timeout" ng-required="true"/>
90-
<span class="form_error" ng-show="GOINPUTNAME[cluster_request_timeout].$error.server">{{GOINPUTNAME[cluster_request_timeout].$error.server}}</span>
91-
<label class="form-help-content">Defaults to <code>10000 milliseconds</code>.</label>
92-
</div>
93-
9487
<div class="row">
9588
<label>Maximum pending pods</label>
9689
<input type="text" ng-model="pending_pods_count" ng-required="true"/>
@@ -138,5 +131,12 @@
138131
Kubernetes cluster CA certificate data. Include the entire PEM contents, including <code> -----BEGIN * </code> and <code> -----END * </code>.
139132
</label>
140133
</div>
134+
135+
<div class="row">
136+
<label>Cluster request timeout (in milliseconds)</label>
137+
<input type="text" ng-model="cluster_request_timeout"/>
138+
<span class="form_error" ng-show="GOINPUTNAME[cluster_request_timeout].$error.server">{{GOINPUTNAME[cluster_request_timeout].$error.server}}</span>
139+
<label class="form-help-content">Defaults to <code>10000 milliseconds</code>.</label>
140+
</div>
141141
</fieldset>
142142
</div>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public void setUp() throws Exception {
4242
pluginSettingsMap.put("go_server_url", "https://foo.go.cd/go");
4343
pluginSettingsMap.put("auto_register_timeout", "13");
4444
pluginSettingsMap.put("pending_pods_count", "14");
45-
pluginSettingsMap.put("cluster_request_timeout", "10000");
4645
pluginSettingsMap.put("kubernetes_cluster_url", "https://cloud.example.com");
4746
pluginSettingsMap.put("security_token", "foo-token");
4847
pluginSettingsMap.put("namespace", "gocd");
48+
pluginSettingsMap.put("cluster_request_timeout", "10000");
4949

5050
clock = new Clock.TestClock();
5151
factory = new KubernetesClientFactory(clock);
@@ -54,7 +54,7 @@ public void setUp() throws Exception {
5454

5555
@Test
5656
public void shouldInitializeClient() {
57-
KubernetesClient client = factory.client(pluginSettings);
57+
factory.client(pluginSettings);
5858
}
5959

6060
@Test

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ public void shouldDeserializeFromJSON() {
3333
pluginSettingsMap.put("go_server_url", "https://foo.go.cd/go");
3434
pluginSettingsMap.put("auto_register_timeout", "13");
3535
pluginSettingsMap.put("pending_pods_count", "14");
36-
pluginSettingsMap.put("cluster_request_timeout", "60000");
3736
pluginSettingsMap.put("kubernetes_cluster_url", "https://cloud.example.com");
3837
pluginSettingsMap.put("security_token", "foo-token");
3938
pluginSettingsMap.put("kubernetes_cluster_ca_cert", "foo-ca-certs");
4039
pluginSettingsMap.put("namespace", "gocd");
40+
pluginSettingsMap.put("cluster_request_timeout", "60000");
4141

4242
PluginSettings pluginSettings = PluginSettings.fromJSON(new Gson().toJson(pluginSettingsMap));
4343

4444
assertThat(pluginSettings.getGoServerUrl()).isEqualTo("https://foo.go.cd/go");
4545
assertThat(pluginSettings.getAutoRegisterTimeout()).isEqualTo(13);
4646
assertThat(pluginSettings.getMaxPendingPods()).isEqualTo(14);
47-
assertThat(pluginSettings.getClusterRequestTimeout()).isEqualTo(60000);
4847
assertThat(pluginSettings.getClusterUrl()).isEqualTo("https://cloud.example.com");
4948
assertThat(pluginSettings.getCaCertData()).isEqualTo("foo-ca-certs");
5049
assertThat(pluginSettings.getSecurityToken()).isEqualTo("foo-token");
5150
assertThat(pluginSettings.getNamespace()).isEqualTo("gocd");
51+
assertThat(pluginSettings.getClusterRequestTimeout()).isEqualTo(60000);
5252

5353
}
5454

@@ -58,22 +58,22 @@ public void shouldHandleEmptyValuesForPendingPodsAndAutoRegisterTimeout() {
5858
pluginSettingsMap.put("go_server_url", "https://foo.go.cd/go");
5959
pluginSettingsMap.put("auto_register_timeout", "");
6060
pluginSettingsMap.put("pending_pods_count", null);
61-
pluginSettingsMap.put("cluster_request_timeout", null);
6261
pluginSettingsMap.put("kubernetes_cluster_url", "https://cloud.example.com");
6362
pluginSettingsMap.put("security_token", "foo-token");
6463
pluginSettingsMap.put("kubernetes_cluster_ca_cert", "foo-ca-certs");
6564
pluginSettingsMap.put("namespace", "gocd");
65+
pluginSettingsMap.put("cluster_request_timeout", null);
6666

6767
PluginSettings pluginSettings = PluginSettings.fromJSON(new Gson().toJson(pluginSettingsMap));
6868

6969
assertThat(pluginSettings.getGoServerUrl()).isEqualTo("https://foo.go.cd/go");
7070
assertThat(pluginSettings.getAutoRegisterTimeout()).isEqualTo(10);
7171
assertThat(pluginSettings.getMaxPendingPods()).isEqualTo(10);
72-
assertThat(pluginSettings.getClusterRequestTimeout()).isEqualTo(10000);
7372
assertThat(pluginSettings.getClusterUrl()).isEqualTo("https://cloud.example.com");
7473
assertThat(pluginSettings.getCaCertData()).isEqualTo("foo-ca-certs");
7574
assertThat(pluginSettings.getSecurityToken()).isEqualTo("foo-token");
7675
assertThat(pluginSettings.getNamespace()).isEqualTo("gocd");
76+
assertThat(pluginSettings.getClusterRequestTimeout()).isEqualTo(10000);
7777
}
7878

7979
@Test
@@ -83,10 +83,10 @@ public void shouldHaveDefaultValueAfterDeSerialization() {
8383
assertNull(pluginSettings.getGoServerUrl());
8484
assertThat(pluginSettings.getAutoRegisterTimeout()).isEqualTo(10);
8585
assertThat(pluginSettings.getMaxPendingPods()).isEqualTo(10);
86-
assertThat(pluginSettings.getClusterRequestTimeout()).isEqualTo(10000);
8786
assertThat(pluginSettings.getNamespace()).isEqualTo("default");
8887
assertNull(pluginSettings.getClusterUrl());
8988
assertNull(pluginSettings.getCaCertData());
89+
assertThat(pluginSettings.getClusterRequestTimeout()).isEqualTo(10000);
9090
}
9191

9292
@Test

src/test/java/cd/go/contrib/elasticagent/executors/GetClusterProfileMetadataExecutorTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ public void assertJsonStructure() throws Exception {
6565
" }\n" +
6666
" },\n" +
6767
" {\n" +
68-
" \"key\": \"cluster_request_timeout\",\n" +
69-
" \"metadata\": {\n" +
70-
" \"required\": false,\n" +
71-
" \"secure\": false\n" +
72-
" }\n" +
73-
" },\n" +
74-
" {\n" +
7568
" \"key\": \"kubernetes_cluster_url\",\n" +
7669
" \"metadata\": {\n" +
7770
" \"required\": true,\n" +
@@ -98,6 +91,13 @@ public void assertJsonStructure() throws Exception {
9891
" \"required\": false,\n" +
9992
" \"secure\": true\n" +
10093
" }\n" +
94+
" },\n" +
95+
" {\n" +
96+
" \"key\": \"cluster_request_timeout\",\n" +
97+
" \"metadata\": {\n" +
98+
" \"required\": false,\n" +
99+
" \"secure\": false\n" +
100+
" }\n" +
101101
" }\n" +
102102
"]";
103103

0 commit comments

Comments
 (0)