-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore : add example for getting logs of controller via microservice name
Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
f3d639d
commit 6633abd
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/io/fabric8/ControllerGetLogsFilterLabel.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.fabric8; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodList; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClientBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ControllerGetLogsFilterLabel { | ||
private static final Logger logger = LoggerFactory.getLogger(ControllerGetLogsFilterLabel.class.getSimpleName()); | ||
public static void main(String[] args) { | ||
try (KubernetesClient client = new KubernetesClientBuilder().build()) { | ||
// This microservice is already deployed using Kubernetes maven plugin | ||
PodList podList = client.pods() | ||
.inNamespace("default") | ||
.withLabel("app", "random-generator") | ||
.list(); | ||
if (podList.getItems().isEmpty()) { | ||
logger.info("No pod with provided label found in cluster"); | ||
} else { | ||
Pod pod = podList.getItems().get(0); | ||
String log = client.pods().inNamespace("default") | ||
.resource(pod) | ||
.getLog(); | ||
logger.info(log); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.fabric8; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodList; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClientBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DeploymentGetLogs { | ||
private static final Logger logger = LoggerFactory.getLogger(DeploymentGetLogs.class.getSimpleName()); | ||
public static void main(String[] args) { | ||
try (KubernetesClient client = new KubernetesClientBuilder().build()) { | ||
// This microservice is already deployed using Kubernetes maven plugin | ||
String log = client.apps().deployments().inNamespace("default") | ||
.withName("random-generator") | ||
.getLog(); | ||
logger.info(log); | ||
} | ||
} | ||
} |