Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,23 @@
@Introspected
public abstract class KubernetesObject {

private String kind;
private Metadata metadata;

/**
* @return The Kind
*/
public String getKind() {
return kind;
}

/**
* @param kind The Kind
*/
public void setKind(String kind) {
this.kind = kind;
}

/**
* @return The Metadata
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
public class ConfigMap extends KubernetesObject {

private Map<String, String> data = new HashMap<>();
private String status;
private String message;
private String reason;
private int code;

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

/**
* @return The Status
*/
public String getStatus() {
return status;
}

/**
* @param status The Status
*/
public void setStatus(String status) {
this.status = status;
}

/**
* @return The Message
*/
public String getMessage() {
return message;
}

/**
* @param message The Message
*/
public void setMessage(String message) {
this.message = message;
}

/**
* @return The Reason
*/
public String getReason() {
return reason;
}

/**
* @param reason The Reason
*/

public void setReason(String reason) {
this.reason = reason;
}

/**
* @return The Code
*/
public int getCode() {
return code;
}

/**
* @param code The Code
*/
public void setCode(int code) {
this.code = code;
}

@Override
public String toString() {
return "ConfigMap{" +
"metadata=" + getMetadata() +
", data=" + data +
", status='" + status + '\'' +
", message='" + message + '\'' +
", reason='" + reason + '\'' +
", code=" + code +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import static io.micronaut.kubernetes.configuration.KubernetesConfigurationClient.KUBERNETES_CONFIG_MAP_NAME_SUFFIX;
import static io.micronaut.kubernetes.util.KubernetesUtils.computePodLabelSelector;
import static java.net.HttpURLConnection.HTTP_GONE;

/**
* Watches for ConfigMap changes and makes the appropriate changes to the {@link Environment} by adding or removing
Expand Down Expand Up @@ -94,9 +95,11 @@ public void onApplicationEvent(ServiceReadyEvent event) {
LOG.trace("Received ConfigMap watch event: {}", e);
}
})
.doOnError(throwable -> LOG.error("Error while watching ConfigMap events", throwable))
.onErrorReturn(throwable -> {
LOG.error("Error while watching ConfigMap events", throwable);
return new ConfigMapWatchEvent(ConfigMapWatchEvent.EventType.ERROR);
})
.subscribeOn(Schedulers.from(this.executorService))
.onErrorReturnItem(new ConfigMapWatchEvent(ConfigMapWatchEvent.EventType.ERROR))
.subscribe(this::processEvent);
}

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

private void processConfigMapErrored(ConfigMapWatchEvent event) {
LOG.error("Kubernetes API returned an error for a ConfigMap watch event: {}", event.toString());
if (event.getObject().getCode() == HTTP_GONE) {
/*"kind":"Status",
"apiVersion":"v1",
"metadata":{},
"status":"Failure",
"message":"too old resource version: 1770726893 (1771132522)",
"reason":"Expired",
"code":410}}*/
this.environment.getPropertySources().forEach(src -> LOG.warn("WTF: src={}", src));
this.environment = environment.refresh();
onApplicationEvent(null);
}
}

private boolean passesIncludesExcludesLabelsFilters(ConfigMap configMap) {
Expand Down

0 comments on commit 67a42be

Please sign in to comment.