Created
February 2, 2021 13:30
-
-
Save enp/9c52e8cd182003f38b053cd8be0bbd2f to your computer and use it in GitHub Desktop.
Watch k8s events in groovy script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
@Grab('org.slf4j:slf4j-simple:[1,)') | |
import groovy.util.logging.* | |
@Grab('io.fabric8:kubernetes-client:[4,)') | |
import io.fabric8.kubernetes.client.* | |
import io.fabric8.kubernetes.api.model.* | |
@Slf4j | |
class WatchApp { | |
def client = new DefaultKubernetesClient() | |
WatchApp() { | |
client.events().inAnyNamespace().watch(new Watcher<Event>() { | |
public void eventReceived(Action action, Event resource) { | |
log.info("EVENT : {} : {}", action, resource.message) | |
} | |
public void onClose(WatcherException e) { | |
if (e != null) { | |
e.printStackTrace(); | |
log.error(e.getMessage(), e); | |
} | |
} | |
}) | |
} | |
} | |
new WatchApp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment