Skip to content

Commit

Permalink
fix #4496: removing list handling from watching
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins authored and manusa committed Oct 19, 2022
1 parent f8dd11b commit b025aef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@
* Fix #4478: Removing the resourceVersion bump with null status
* Fix #4482: Fixing blocking behavior of okhttp log watch
* Fix #4487: Schema for multimaps is now generated correctly
* Fix #4496: Removing watch handling of lists

#### Improvements
* Fix #4471: Adding KubernetesClientBuilder.withHttpClientBuilderConsumer to further customize the HttpClient for any implementation.
Expand Down
Expand Up @@ -20,7 +20,6 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesResource;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.ListOptions;
import io.fabric8.kubernetes.api.model.Status;
import io.fabric8.kubernetes.api.model.WatchEvent;
Expand All @@ -39,7 +38,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -250,33 +248,9 @@ private WatchEvent contextAwareWatchEventDeserializer(String messageSource)
}
}

protected WatchEvent readWatchEvent(String messageSource) throws JsonProcessingException {
WatchEvent event = contextAwareWatchEventDeserializer(messageSource);
KubernetesResource object = null;
if (event != null) {
object = event.getObject();
}
// when watching API Groups we don't get a WatchEvent resource
// so the object will be null
// so lets try parse the message as a KubernetesResource
// as it will probably be a list of resources like a BuildList
if (object == null) {
object = Serialization.unmarshal(messageSource, KubernetesResource.class);
if (event == null) {
event = new WatchEvent(object, "MODIFIED");
} else {
event.setObject(object);
}
}
if (event.getType() == null) {
event.setType("MODIFIED");
}
return event;
}

protected void onMessage(String message) {
try {
WatchEvent event = readWatchEvent(message);
WatchEvent event = contextAwareWatchEventDeserializer(message);
Object object = event.getObject();
Action action = Action.valueOf(event.getType());
if (action == Action.ERROR) {
Expand All @@ -291,21 +265,7 @@ protected void onMessage(String message) {
} else if (object instanceof HasMetadata) {
HasMetadata hasMetadata = (HasMetadata) object;
updateResourceVersion(hasMetadata.getMetadata().getResourceVersion());

if (object instanceof KubernetesResourceList) {
// Dirty cast - should always be valid though
@SuppressWarnings({ "rawtypes" })
KubernetesResourceList list = (KubernetesResourceList) hasMetadata;
@SuppressWarnings("unchecked")
List<HasMetadata> items = list.getItems();
if (items != null) {
for (HasMetadata item : items) {
eventReceived(action, item);
}
}
} else {
eventReceived(action, hasMetadata);
}
eventReceived(action, hasMetadata);
} else {
final String msg = String.format("Invalid object received: %s", message);
close(new WatcherException(msg, null, message));
Expand Down

0 comments on commit b025aef

Please sign in to comment.