Created
August 20, 2021 05:25
-
-
Save sandipchitale/3f2c10ef7f79a9287043d3086ed59fc9 to your computer and use it in GitHub Desktop.
Gradle farbick8 #gradle #kubernetes #fabrick8
This file contains hidden or 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
buildscript { | |
repositories { | |
mavenCentral(); | |
} | |
dependencies { | |
classpath group: 'io.fabric8', name: 'kubernetes-client', version: '4.10.3' | |
} | |
} | |
import io.fabric8.kubernetes.api.model.Pod; | |
import io.fabric8.kubernetes.client.Config; | |
import io.fabric8.kubernetes.client.ConfigBuilder; | |
import io.fabric8.kubernetes.client.DefaultKubernetesClient; | |
import io.fabric8.kubernetes.client.KubernetesClient; | |
import io.fabric8.kubernetes.client.KubernetesClientException; | |
import io.fabric8.kubernetes.client.Watcher; | |
task pods { | |
doLast { | |
Config config = new ConfigBuilder().build(); | |
try { | |
KubernetesClient client = null; | |
client = new DefaultKubernetesClient(config); | |
client.pods().watch(new Watcher() { | |
@Override | |
public void eventReceived(Action action, Object resource) { | |
if (resource instanceof Pod) { | |
System.out.println(action.name() + "\t" + ((Pod)resource).getMetadata().getName()); | |
} | |
} | |
@Override | |
public void onClose(KubernetesClientException cause) { | |
System.err.println(cause); | |
} | |
}); | |
Thread.sleep(100000); | |
} catch (KubernetesClientException ex) { | |
// Handle exception | |
ex.printStackTrace(); | |
} finally { | |
if (client != null) { | |
client.close(); | |
} | |
} | |
} | |
} | |
defaultTasks 'pods' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment