Skip to content

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

kubernetes-discovery-client/src/main/java/io/micronaut/kubernetes/client/v1/KubernetesObject.java

+15
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,23 @@
2626
@Introspected
2727
public abstract class KubernetesObject {
2828

29+
private String kind;
2930
private Metadata metadata;
3031

32+
/**
33+
* @return The Kind
34+
*/
35+
public String getKind() {
36+
return kind;
37+
}
38+
39+
/**
40+
* @param kind The Kind
41+
*/
42+
public void setKind(String kind) {
43+
this.kind = kind;
44+
}
45+
3146
/**
3247
* @return The Metadata
3348
*/

kubernetes-discovery-client/src/main/java/io/micronaut/kubernetes/client/v1/configmaps/ConfigMap.java

+65
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
public class ConfigMap extends KubernetesObject {
3232

3333
private Map<String, String> data = new HashMap<>();
34+
private String status;
35+
private String message;
36+
private String reason;
37+
private int code;
3438

3539
/**
3640
* @return A Map where the key is the file name, and the value is a string with all the properties
@@ -46,11 +50,72 @@ public void setData(Map<String, String> data) {
4650
this.data = data;
4751
}
4852

53+
/**
54+
* @return The Status
55+
*/
56+
public String getStatus() {
57+
return status;
58+
}
59+
60+
/**
61+
* @param status The Status
62+
*/
63+
public void setStatus(String status) {
64+
this.status = status;
65+
}
66+
67+
/**
68+
* @return The Message
69+
*/
70+
public String getMessage() {
71+
return message;
72+
}
73+
74+
/**
75+
* @param message The Message
76+
*/
77+
public void setMessage(String message) {
78+
this.message = message;
79+
}
80+
81+
/**
82+
* @return The Reason
83+
*/
84+
public String getReason() {
85+
return reason;
86+
}
87+
88+
/**
89+
* @param reason The Reason
90+
*/
91+
92+
public void setReason(String reason) {
93+
this.reason = reason;
94+
}
95+
96+
/**
97+
* @return The Code
98+
*/
99+
public int getCode() {
100+
return code;
101+
}
102+
103+
/**
104+
* @param code The Code
105+
*/
106+
public void setCode(int code) {
107+
this.code = code;
108+
}
109+
49110
@Override
50111
public String toString() {
51112
return "ConfigMap{" +
52113
"metadata=" + getMetadata() +
53114
", data=" + data +
115+
", status='" + status + '\'' +
116+
", message='" + message + '\'' +
117+
", reason='" + reason + '\'' +
118+
", code=" + code +
54119
'}';
55120
}
56121
}

kubernetes-discovery-client/src/main/java/io/micronaut/kubernetes/configuration/KubernetesConfigMapWatcher.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import static io.micronaut.kubernetes.configuration.KubernetesConfigurationClient.KUBERNETES_CONFIG_MAP_NAME_SUFFIX;
4141
import static io.micronaut.kubernetes.util.KubernetesUtils.computePodLabelSelector;
42+
import static java.net.HttpURLConnection.HTTP_GONE;
4243

4344
/**
4445
* Watches for ConfigMap changes and makes the appropriate changes to the {@link Environment} by adding or removing
@@ -94,9 +95,11 @@ public void onApplicationEvent(ServiceReadyEvent event) {
9495
LOG.trace("Received ConfigMap watch event: {}", e);
9596
}
9697
})
97-
.doOnError(throwable -> LOG.error("Error while watching ConfigMap events", throwable))
98+
.onErrorReturn(throwable -> {
99+
LOG.error("Error while watching ConfigMap events", throwable);
100+
return new ConfigMapWatchEvent(ConfigMapWatchEvent.EventType.ERROR);
101+
})
98102
.subscribeOn(Schedulers.from(this.executorService))
99-
.onErrorReturnItem(new ConfigMapWatchEvent(ConfigMapWatchEvent.EventType.ERROR))
100103
.subscribe(this::processEvent);
101104
}
102105

@@ -178,6 +181,18 @@ private void processConfigMapDeleted(ConfigMap configMap) {
178181

179182
private void processConfigMapErrored(ConfigMapWatchEvent event) {
180183
LOG.error("Kubernetes API returned an error for a ConfigMap watch event: {}", event.toString());
184+
if (event.getObject().getCode() == HTTP_GONE) {
185+
/*"kind":"Status",
186+
"apiVersion":"v1",
187+
"metadata":{},
188+
"status":"Failure",
189+
"message":"too old resource version: 1770726893 (1771132522)",
190+
"reason":"Expired",
191+
"code":410}}*/
192+
this.environment.getPropertySources().forEach(src -> LOG.warn("WTF: src={}", src));
193+
this.environment = environment.refresh();
194+
onApplicationEvent(null);
195+
}
181196
}
182197

183198
private boolean passesIncludesExcludesLabelsFilters(ConfigMap configMap) {

0 commit comments

Comments
 (0)