Skip to content

Commit aa2333a

Browse files
committed
Catch up to master
2 parents c190e72 + 966fc19 commit aa2333a

35 files changed

+249
-203
lines changed

operator/src/main/java/oracle/kubernetes/operator/authentication/Authenticator.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public class Authenticator {
3232

3333
private final String _SERVICE_HOST = "KUBERNETES_SERVICE_HOST";
3434
private final String _SERVICE_PORT = "KUBERNETES_SERVICE_PORT";
35-
private final String _TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
36-
private final String _CACERT_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt";
35+
//private final String _TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
36+
//private final String _CACERT_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt";
3737
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
3838

3939
/**
@@ -46,7 +46,6 @@ public class Authenticator {
4646
public Authenticator() throws IOException {
4747
this.apiClient = Config.defaultClient();
4848
this.helper = new Helpers(this);
49-
SecretHelper.addCustomGsonToClient(this.apiClient);
5049
}
5150

5251
/**
@@ -167,7 +166,6 @@ private ApiClient authenticateByServiceAccount(V1ServiceAccount serviceAccount)
167166
newClient.setBasePath(serviceUrl);
168167
newClient.setApiKey("Bearer " + token);
169168
newClient.setSslCaCert(new ByteArrayInputStream(caCert));
170-
SecretHelper.addCustomGsonToClient(newClient);
171169

172170
LOGGER.exiting(newClient);
173171
return newClient;

operator/src/main/java/oracle/kubernetes/operator/authentication/Helpers.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
public class Helpers {
2626

27+
@SuppressWarnings("unused")
2728
private final Authenticator authenticator;
2829
private final ApiClient apiClient;
2930
private final CoreV1Api coreApi;

operator/src/main/java/oracle/kubernetes/operator/builders/UncheckedApiException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* An exception used to bypass functional programming incompatability with checked exceptions. This is thrown
1010
* by a function object and the underlying ApiException is then rethrown by the caller of the function object.
1111
*/
12+
@SuppressWarnings("serial")
1213
class UncheckedApiException extends RuntimeException {
1314
UncheckedApiException(ApiException e) {
1415
super(e);

operator/src/main/java/oracle/kubernetes/operator/builders/WatchBuilder.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.lang.reflect.Type;
2828
import java.util.function.BiFunction;
2929

30-
@SuppressWarnings("WeakerAccess")
3130
public class WatchBuilder {
3231
/** Always true for watches. */
3332
private static final boolean WATCH = true;
@@ -244,10 +243,6 @@ public WatchBuilder withLabelSelectors(String... labelSelectors) {
244243
return this;
245244
}
246245

247-
private String asList(String... selectors) {
248-
return String.join(",", selectors);
249-
}
250-
251246
public WatchBuilder withLimit(Integer limit) {
252247
callParams.setLimit(limit);
253248
return this;

operator/src/main/java/oracle/kubernetes/operator/helpers/ClientPool.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ private ApiClient getApiClient() {
4646
}
4747
LOGGER.info(MessageKeys.K8S_MASTER_URL, client != null ? client.getBasePath() : null);
4848

49-
// Temporarily set a custom Gson for secret support
50-
// TODO:
51-
SecretHelper.addCustomGsonToClient(client);
52-
53-
// TEST
49+
// Ensure that client doesn't time out before call or watch
5450
client.getHttpClient().setReadTimeout(5, TimeUnit.MINUTES);
5551

5652
LOGGER.exiting(client);

operator/src/main/java/oracle/kubernetes/operator/helpers/SecretHelper.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,7 @@
33

44
package oracle.kubernetes.operator.helpers;
55

6-
import com.google.gson.Gson;
7-
import com.google.gson.GsonBuilder;
8-
import com.google.gson.JsonDeserializationContext;
9-
import com.google.gson.JsonDeserializer;
10-
import com.google.gson.JsonElement;
11-
import com.google.gson.JsonParseException;
12-
import com.google.gson.JsonPrimitive;
13-
import com.google.gson.JsonSerializationContext;
14-
import com.google.gson.JsonSerializer;
15-
import io.kubernetes.client.ApiClient;
166
import io.kubernetes.client.ApiException;
17-
import io.kubernetes.client.JSON;
187
import io.kubernetes.client.models.V1Secret;
198
import oracle.kubernetes.operator.logging.LoggingFacade;
209
import oracle.kubernetes.operator.logging.LoggingFactory;
@@ -24,11 +13,6 @@
2413
import oracle.kubernetes.operator.work.Packet;
2514
import oracle.kubernetes.operator.work.Step;
2615

27-
import org.joda.time.DateTime;
28-
29-
import java.lang.reflect.Type;
30-
import java.util.Base64;
31-
import java.util.Date;
3216
import java.util.HashMap;
3317
import java.util.List;
3418
import java.util.Map;
@@ -174,43 +158,4 @@ private static Map<String, byte[]> harvestAdminSecretData(V1Secret secret) {
174158
return secretData;
175159
}
176160

177-
// Due to issue with kubernetes-client/java (com.google.gson.JsonSyntaxException when deserialize V1Secret)
178-
// Issue #131
179-
// Add a custom Gson to the client so secrets can be decoded.
180-
181-
/**
182-
* Add custom Gson to client
183-
* @param apiClient API client
184-
*/
185-
public static void addCustomGsonToClient(ApiClient apiClient) {
186-
187-
LOGGER.entering();
188-
189-
JSON.DateTypeAdapter dateTypeAdapter = new JSON.DateTypeAdapter();
190-
JSON.SqlDateTypeAdapter sqlDateTypeAdapter = new JSON.SqlDateTypeAdapter();
191-
JSON.DateTimeTypeAdapter dateTimeTypeAdapter = new JSON.DateTimeTypeAdapter();
192-
193-
Gson customGson =
194-
(new GsonBuilder()).registerTypeAdapter(
195-
Date.class, dateTypeAdapter).registerTypeAdapter(
196-
java.sql.Date.class, sqlDateTypeAdapter).registerTypeAdapter(
197-
DateTime.class, dateTimeTypeAdapter).registerTypeAdapter(
198-
byte[].class, new ByteArrayBase64StringTypeAdapter()).create();
199-
200-
apiClient.getJSON().setGson(customGson);
201-
202-
LOGGER.exiting();
203-
}
204-
205-
private static class ByteArrayBase64StringTypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
206-
207-
public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
208-
return Base64.getUrlDecoder().decode(json.getAsString());
209-
}
210-
211-
public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) {
212-
return new JsonPrimitive(Base64.getUrlEncoder().encodeToString(src));
213-
}
214-
}
215-
216161
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.operator.http;
5+
6+
/**
7+
* Exception when a HTTP status code is received that indicates the request was not successful
8+
*/
9+
public class HTTPException extends Exception {
10+
11+
final int statusCode;
12+
13+
public HTTPException(int statusCode) {
14+
super("status code: " + statusCode);
15+
this.statusCode = statusCode;
16+
}
17+
18+
public int getStatusCode() {
19+
return statusCode;
20+
}
21+
}

operator/src/main/java/oracle/kubernetes/operator/http/HttpClient.java

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,97 @@ private HttpClient(Client httpClient, String principal, String encodedCredential
4949
this.encodedCredentials = encodedCredentials;
5050
}
5151

52-
public String executeGetOnServiceClusterIP(String requestUrl, String serviceName, String namespace) {
53-
String serviceURL = SERVICE_URL == null ? getServiceURL(principal, serviceName, namespace) : SERVICE_URL;
52+
/**
53+
* Constructs a URL using the provided service URL and request URL, and use the resulting URL to issue a HTTP GET request
54+
*
55+
* @param requestUrl The request URL containing the request of the REST call
56+
* @param serviceURL The service URL containing the host and port of the server where the HTTP
57+
* request is to be sent to
58+
*
59+
* @return A Result object containing the respond from the REST call
60+
*/
61+
public Result executeGetOnServiceClusterIP(String requestUrl, String serviceURL) {
5462
String url = serviceURL + requestUrl;
5563
WebTarget target = httpClient.target(url);
5664
Invocation.Builder invocationBuilder = target.request().accept("application/json")
5765
.header("Authorization", "Basic " + encodedCredentials);
5866
Response response = invocationBuilder.get();
67+
String responseString = null;
68+
int status = response.getStatus();
69+
boolean successful = false;
5970
if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
71+
successful = true;
6072
if (response.hasEntity()) {
61-
return String.valueOf(response.readEntity(String.class));
73+
responseString = String.valueOf(response.readEntity(String.class));
6274
}
6375
} else {
6476
LOGGER.warning(MessageKeys.HTTP_METHOD_FAILED, "GET", url, response.getStatus());
6577
}
66-
return null;
78+
return new Result(responseString, status, successful);
6779
}
6880

69-
public String executePostUrlOnServiceClusterIP(String requestUrl, String serviceURL, String namespace, String payload) {
81+
/**
82+
* Constructs a URL using the provided service URL and request URL, and use the resulting URL and the
83+
* payload provided to issue a HTTP POST request.
84+
* This method does not throw HTTPException if the HTTP request returns failure status code
85+
*
86+
* @param requestUrl The request URL containing the request of the REST call
87+
* @param serviceURL The service URL containing the host and port of the server where the HTTP
88+
* request is to be sent to
89+
* @param payload The payload to be used in the HTTP POST request
90+
*
91+
* @return A Result object containing the respond from the REST call
92+
* @throws HTTPException if throwOnFailure is true and the status of the HTTP response indicates the request was not
93+
* successful
94+
*/ public Result executePostUrlOnServiceClusterIP(String requestUrl, String serviceURL, String payload) {
95+
Result result = null;
96+
try {
97+
result = executePostUrlOnServiceClusterIP(requestUrl, serviceURL, payload, false);
98+
} catch (HTTPException httpException) {
99+
// ignore as executePostUrlOnServiceClusterIP only throw HTTPException if throwOnFailure is true
100+
}
101+
return result;
102+
}
103+
104+
/**
105+
* Constructs a URL using the provided service URL and request URL, and use the resulting URL and the
106+
* payload provided to issue a HTTP POST request
107+
*
108+
* @param requestUrl The request URL containing the request of the REST call
109+
* @param serviceURL The service URL containing the host and port of the server where the HTTP
110+
* request is to be sent to
111+
* @param payload The payload to be used in the HTTP POST request
112+
* @param throwOnFailure Throws HTTPException if the status code in the HTTP response indicates any error
113+
*
114+
* @return A Result object containing the respond from the REST call
115+
* @throws HTTPException if throwOnFailure is true and the status of the HTTP response indicates the request was not
116+
* successful
117+
*/
118+
public Result executePostUrlOnServiceClusterIP(String requestUrl, String serviceURL, String payload,
119+
boolean throwOnFailure) throws HTTPException {
120+
70121
String url = serviceURL + requestUrl;
71122
WebTarget target = httpClient.target(url);
72123
Invocation.Builder invocationBuilder = target.request().accept("application/json")
73124
.header("Authorization", "Basic " + encodedCredentials)
74125
.header("X-Requested-By", "WebLogicOperator");
75126
Response response = invocationBuilder.post(Entity.json(payload));
76127
LOGGER.finer("Response is " + response.getStatusInfo());
128+
String responseString = null;
129+
int status = response.getStatus();
130+
boolean successful = false;
77131
if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
132+
successful = true;
78133
if (response.hasEntity()) {
79-
return String.valueOf(response.readEntity(String.class));
134+
responseString = String.valueOf(response.readEntity(String.class));
80135
}
81136
} else {
82137
LOGGER.warning(MessageKeys.HTTP_METHOD_FAILED, "POST", url, response.getStatus());
138+
if (throwOnFailure) {
139+
throw new HTTPException(status);
140+
}
83141
}
84-
return null;
142+
return new Result(responseString, status, successful);
85143
}
86144

87145
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.operator.http;
5+
6+
/**
7+
* Holder of response received from REST requests invoked using methods in {@link HttpClient} class
8+
*/
9+
public class Result {
10+
11+
final String response;
12+
final int status;
13+
final boolean successful;
14+
15+
public Result(String response, int status, boolean successful) {
16+
this.response = response;
17+
this.status = status;
18+
this.successful = successful;
19+
}
20+
21+
/**
22+
*
23+
* @return The String response received from the REST request
24+
*/
25+
public String getResponse() {
26+
return response;
27+
}
28+
29+
/**
30+
*
31+
* @return HTTP status code from the REST request
32+
*/
33+
public int getStatus() {
34+
return status;
35+
}
36+
37+
/**
38+
*
39+
* @return True if the REST request returns a status code that indicates successful request, false otherwise
40+
*/
41+
public boolean isSuccessful() {
42+
return successful;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "Result{" +
48+
"response='" + response + '\'' +
49+
", status=" + status +
50+
", successful=" + successful +
51+
'}';
52+
}
53+
}

operator/src/main/java/oracle/kubernetes/operator/logging/MessageKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,6 @@ private MessageKeys() {}
134134
public static final String CLUSTER_SERVICE_DELETED = "WLSKO-0124";
135135
public static final String INGRESS_DELETED = "WLSKO-0125";
136136
public static final String TUNING_PARAMETERS = "WLSKO-0126";
137+
public static final String WLS_HEALTH_READ_FAILED = "WLSKO-0127";
137138

138139
}

0 commit comments

Comments
 (0)