Skip to content

Commit a206033

Browse files
committed
支持一个容器的一次性日志输出
1 parent c73cdad commit a206033

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

pom.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.github.kubesys</groupId>
66
<artifactId>client-java</artifactId>
7-
<version>1.3.0</version>
7+
<version>1.3.1</version>
88
<packaging>jar</packaging>
99
<name>client-java</name>
1010
<url>http://maven.apache.org</url>
1111
<properties>
1212
<!-- project.version -->
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<!-- code -->
15-
<jackson.version>2.16.1</jackson.version>
15+
<jackson.version>2.17.1</jackson.version>
1616
<httpclient.version>5.3.1</httpclient.version>
17+
<commons.io.version>2.16.1</commons.io.version>
1718
<!-- test -->
1819
<junit.version>5.10.2</junit.version>
1920
<!-- build -->
@@ -34,6 +35,12 @@
3435
</license>
3536
</licenses>
3637
<dependencies>
38+
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
39+
<dependency>
40+
<groupId>commons-io</groupId>
41+
<artifactId>commons-io</artifactId>
42+
<version>${commons.io.version}</version>
43+
</dependency>
3744
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
3845
<dependency>
3946
<groupId>com.fasterxml.jackson.core</groupId>

src/main/java/io/github/kubesys/client/KubernetesClient.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Map;
2323
import java.util.logging.Logger;
2424

25+
import org.apache.commons.io.IOUtils;
2526
import org.apache.hc.client5.http.classic.methods.HttpDelete;
2627
import org.apache.hc.client5.http.classic.methods.HttpGet;
2728
import org.apache.hc.client5.http.classic.methods.HttpPost;
@@ -1297,6 +1298,31 @@ public KubernetesAdminConfig getKubernetesAdminConfig() {
12971298
return kubernetesAdminConfig;
12981299
}
12991300

1301+
/**
1302+
*
1303+
* @param pod pod
1304+
* @return json json from Kubernetes
1305+
* @throws Exception Kubernetes cannot parsing this jsonStr
1306+
*/
1307+
@Deprecated
1308+
public String getPodLog(String pod) throws Exception {
1309+
return getPodLog("default", pod);
1310+
}
1311+
1312+
/**
1313+
*
1314+
* @param namespace namespace
1315+
* @param pod pod
1316+
* @return json json from Kubernetes
1317+
* @throws Exception Kubernetes cannot parsing this jsonStr
1318+
*/
1319+
@Deprecated
1320+
public String getPodLog(String namespace, String pod) throws Exception {
1321+
final String uri = analyzer.getConvertor().getUrl("Pod", namespace, pod) + "/log";
1322+
HttpGet request = ReqUtil.get(kubernetesAdminConfig, uri);
1323+
return IOUtils.toString(httpClient.execute(request).getEntity().getContent());
1324+
}
1325+
13001326
/**
13011327
* create a new HttpCaller for each WatchResource or WatchResources API
13021328
*
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (2020, ) Institute of Software, Chinese Academy of Sciences
3+
*/
4+
package io.github.kubesys.client.examples;
5+
6+
import java.nio.charset.StandardCharsets;
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
9+
10+
import io.github.kubesys.client.KubernetesClient;
11+
12+
/**
13+
* @author wuheng@iscas.ac.cn
14+
* @since 2023.12.05
15+
*
16+
*/
17+
public class GetLogExample {
18+
19+
/**
20+
* see KubernetesCertClientExample or KubernetesTokenClientExample
21+
*/
22+
static KubernetesClient client = null;
23+
24+
public static void main(String[] args) throws Exception {
25+
System.out.print(client.getPodLog("kube-flannel", "kube-flannel-ds-cthfj"));
26+
}
27+
28+
}

0 commit comments

Comments
 (0)