Skip to content

Commit 666e2a2

Browse files
committed
SecretHelper should not log warnings on repeated ReadHealthState attempts
1 parent 628f2e5 commit 666e2a2

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import oracle.kubernetes.operator.helpers.ServiceHelper;
3636
import oracle.kubernetes.operator.logging.LoggingFacade;
3737
import oracle.kubernetes.operator.logging.LoggingFactory;
38+
import oracle.kubernetes.operator.logging.LoggingFilter;
3839
import oracle.kubernetes.operator.logging.MessageKeys;
3940
import oracle.kubernetes.operator.steps.BeforeAdminServiceStep;
4041
import oracle.kubernetes.operator.steps.DeleteDomainStep;
@@ -290,6 +291,7 @@ public void dispatchDomainWatch(Watch.Response<Domain> item) {
290291

291292
private void scheduleDomainStatusUpdating(DomainPresenceInfo info) {
292293
AtomicInteger unchangedCount = new AtomicInteger(0);
294+
final LoggingFilter loggingFilter = new LoggingFilter();
293295
Runnable command =
294296
new Runnable() {
295297
public void run() {
@@ -301,6 +303,7 @@ public void run() {
301303
.put(
302304
ProcessingConstants.DOMAIN_COMPONENT_NAME,
303305
Component.createFor(info, delegate.getVersion()));
306+
packet.put(ProcessingConstants.LOGGING_FILTER, loggingFilter);
304307
MainTuning main = TuningParameters.getInstance().getMainTuning();
305308
Step strategy =
306309
DomainStatusUpdater.createStatusStep(main.statusUpdateTimeoutSeconds, null);
@@ -312,6 +315,11 @@ public void run() {
312315
new CompletionCallback() {
313316
@Override
314317
public void onCompletion(Packet packet) {
318+
if (Boolean.TRUE.equals(packet.get(ProcessingConstants.SERVER_HEALTH_READ))) {
319+
loggingFilter.setCanLog(true);
320+
} else {
321+
loggingFilter.setCanLog(false);
322+
}
315323
Boolean isStatusUnchanged =
316324
(Boolean) packet.get(ProcessingConstants.STATUS_UNCHANGED);
317325
if (Boolean.TRUE.equals(isStatusUnchanged)) {
@@ -344,6 +352,7 @@ public void onCompletion(Packet packet) {
344352
@Override
345353
public void onThrowable(Packet packet, Throwable throwable) {
346354
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
355+
loggingFilter.setCanLog(false);
347356
// retry to trying after shorter delay because of exception
348357
unchangedCount.set(0);
349358
registerStatusUpdater(

operator/src/main/java/oracle/kubernetes/operator/ProcessingConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ public interface ProcessingConstants {
3333
public static final String DOMAIN_INTROSPECTOR_JOB = "domainIntrospectorJob";
3434
public static final String DOMAIN_INTROSPECTOR_LOG_RESULT = "domainIntrospectorLogResult";
3535
public static final String SIT_CONFIG_MAP = "sitConfigMap";
36+
37+
String LOGGING_FILTER = "optionalLogging";
38+
String SERVER_HEALTH_READ = "serverHealthRead";
3639
}

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import java.util.HashMap;
1010
import java.util.List;
1111
import java.util.Map;
12+
import oracle.kubernetes.operator.ProcessingConstants;
1213
import oracle.kubernetes.operator.logging.LoggingFacade;
1314
import oracle.kubernetes.operator.logging.LoggingFactory;
15+
import oracle.kubernetes.operator.logging.LoggingFilter;
1416
import oracle.kubernetes.operator.logging.MessageKeys;
1517
import oracle.kubernetes.operator.work.ContainerResolver;
1618
import oracle.kubernetes.operator.work.NextAction;
@@ -72,7 +74,7 @@ public Map<String, byte[]> getSecretData(SecretType secretType, String secretNam
7274
return null;
7375
}
7476

75-
return harvestAdminSecretData(secret);
77+
return harvestAdminSecretData(secret, null);
7678
} catch (Throwable e) {
7779
LOGGER.severe(MessageKeys.EXCEPTION, e);
7880
return null;
@@ -116,6 +118,7 @@ public NextAction apply(Packet packet) {
116118
}
117119

118120
LOGGER.fine(MessageKeys.RETRIEVING_SECRET, secretName);
121+
final LoggingFilter loggingFilter = packet.getValue(ProcessingConstants.LOGGING_FILTER);
119122
CallBuilderFactory factory =
120123
ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
121124
Step read =
@@ -132,7 +135,13 @@ public NextAction onFailure(
132135
int statusCode,
133136
Map<String, List<String>> responseHeaders) {
134137
if (statusCode == CallBuilder.NOT_FOUND) {
135-
LOGGER.warning(MessageKeys.SECRET_NOT_FOUND, secretName);
138+
if (LoggingFilter.canLog(loggingFilter)) {
139+
LOGGER.warning(
140+
MessageKeys.SECRET_NOT_FOUND,
141+
secretName
142+
+ ", LOGGING_FILTER: "
143+
+ packet.get(ProcessingConstants.LOGGING_FILTER));
144+
}
136145
return doNext(packet);
137146
}
138147
return super.onFailure(packet, e, statusCode, responseHeaders);
@@ -144,7 +153,7 @@ public NextAction onSuccess(
144153
V1Secret result,
145154
int statusCode,
146155
Map<String, List<String>> responseHeaders) {
147-
packet.put(SECRET_DATA_KEY, harvestAdminSecretData(result));
156+
packet.put(SECRET_DATA_KEY, harvestAdminSecretData(result, loggingFilter));
148157
return doNext(packet);
149158
}
150159
});
@@ -153,21 +162,26 @@ public NextAction onSuccess(
153162
}
154163
}
155164

156-
private static Map<String, byte[]> harvestAdminSecretData(V1Secret secret) {
165+
private static Map<String, byte[]> harvestAdminSecretData(
166+
V1Secret secret, LoggingFilter loggingFilter) {
157167
Map<String, byte[]> secretData = new HashMap<>();
158168
byte[] usernameBytes = secret.getData().get(ADMIN_SERVER_CREDENTIALS_USERNAME);
159169
byte[] passwordBytes = secret.getData().get(ADMIN_SERVER_CREDENTIALS_PASSWORD);
160170

161171
if (usernameBytes != null) {
162172
secretData.put(ADMIN_SERVER_CREDENTIALS_USERNAME, usernameBytes);
163173
} else {
164-
LOGGER.warning(MessageKeys.SECRET_DATA_NOT_FOUND, ADMIN_SERVER_CREDENTIALS_USERNAME);
174+
if (LoggingFilter.canLog(loggingFilter)) {
175+
LOGGER.warning(MessageKeys.SECRET_DATA_NOT_FOUND, ADMIN_SERVER_CREDENTIALS_USERNAME);
176+
}
165177
}
166178

167179
if (passwordBytes != null) {
168180
secretData.put(ADMIN_SERVER_CREDENTIALS_PASSWORD, passwordBytes);
169181
} else {
170-
LOGGER.warning(MessageKeys.SECRET_DATA_NOT_FOUND, ADMIN_SERVER_CREDENTIALS_PASSWORD);
182+
if (LoggingFilter.canLog(loggingFilter)) {
183+
LOGGER.warning(MessageKeys.SECRET_DATA_NOT_FOUND, ADMIN_SERVER_CREDENTIALS_PASSWORD);
184+
}
171185
}
172186
return secretData;
173187
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,15 @@ public NextAction apply(Packet packet) {
196196
if (secretData != null) {
197197
username = secretData.get(SecretHelper.ADMIN_SERVER_CREDENTIALS_USERNAME);
198198
password = secretData.get(SecretHelper.ADMIN_SERVER_CREDENTIALS_PASSWORD);
199-
}
200-
packet.put(KEY, createAuthenticatedClient(username, password));
199+
packet.put(KEY, createAuthenticatedClient(username, password));
201200

202-
Arrays.fill(username, (byte) 0);
203-
Arrays.fill(password, (byte) 0);
201+
if (username != null) {
202+
Arrays.fill(username, (byte) 0);
203+
}
204+
if (password != null) {
205+
Arrays.fill(password, (byte) 0);
206+
}
207+
}
204208
return doNext(packet);
205209
}
206210
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator.logging;
6+
7+
public class LoggingFilter {
8+
9+
volatile boolean loggingAllowed;
10+
11+
public void setCanLog(boolean canLog) {
12+
loggingAllowed = canLog;
13+
}
14+
15+
public boolean canLog() {
16+
return loggingAllowed;
17+
}
18+
19+
public static boolean canLog(LoggingFilter loggingFilter) {
20+
if (loggingFilter == null) {
21+
return true;
22+
}
23+
return loggingFilter.canLog();
24+
}
25+
}

operator/src/main/java/oracle/kubernetes/operator/steps/ReadHealthStep.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public NextAction apply(Packet packet) {
9292
try {
9393
HttpClient httpClient = (HttpClient) packet.get(HttpClient.KEY);
9494

95+
if (httpClient == null) {
96+
return doNext(packet);
97+
}
98+
9599
String serviceURL = HttpClient.getServiceURL(service);
96100
if (serviceURL != null) {
97101
String jsonResult =
@@ -149,6 +153,7 @@ public NextAction apply(Packet packet) {
149153
(ConcurrentMap<String, ServerHealth>)
150154
packet.get(ProcessingConstants.SERVER_HEALTH_MAP);
151155
serverHealthMap.put((String) packet.get(ProcessingConstants.SERVER_NAME), health);
156+
packet.put(ProcessingConstants.SERVER_HEALTH_READ, Boolean.TRUE);
152157
}
153158
return doNext(packet);
154159
} catch (Throwable t) {

0 commit comments

Comments
 (0)