Skip to content

Commit 59c2c5d

Browse files
committed
throw Exception for KubernetesClient
1 parent 7aab6da commit 59c2c5d

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>io.github.kubesys</groupId>
77
<artifactId>client-java</artifactId>
8-
<version>0.9.0</version>
8+
<version>0.9.1</version>
99
<packaging>jar</packaging>
1010

1111
<name>client-java</name>
@@ -60,7 +60,6 @@
6060
<groupId>org.junit.jupiter</groupId>
6161
<artifactId>junit-jupiter-api</artifactId>
6262
<version>${junit.version}</version>
63-
<scope>test</scope>
6463
</dependency>
6564

6665
</dependencies>

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ public class KubernetesClient {
8484
* it is used for sending requests to Kuberenetes kube-apiserver,
8585
* and then receiving response from it.
8686
*/
87-
protected final KubeBaseRequest requester;
87+
protected KubeBaseRequest requester;
8888

8989
/**
9090
* it is used for getting the metadata of all kinds in Kubernetes according
9191
* to [Kubernetes API pattern]
9292
* (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/)
9393
*/
94-
protected final KubernetesAnalyzer analyzer;
94+
protected KubernetesAnalyzer analyzer;
9595

9696
/**
9797
* for the Pods running on the leader nodes
9898
*
9999
* @throws Exception exception
100100
*/
101-
public KubernetesClient() throws Exception {
101+
public KubernetesClient() {
102102
this(new File(KubernetesConstants.KUBE_CONFIG));
103103
}
104104

@@ -108,7 +108,7 @@ public KubernetesClient() throws Exception {
108108
* @param file such as $HOME$/.kube/conf
109109
* @throws Exception exception
110110
*/
111-
public KubernetesClient(File file) throws Exception {
111+
public KubernetesClient(File file) {
112112
this(file, new KubernetesAnalyzer());
113113
}
114114

@@ -120,11 +120,15 @@ public KubernetesClient(File file) throws Exception {
120120
* @param analyzer it is used for getting the metadata for each Kubernetes kind.
121121
* @throws Exception exception
122122
*/
123-
public KubernetesClient(File file, KubernetesAnalyzer analyzer) throws Exception {
124-
this.requester = new KubeBaseRequest(new YAMLMapper().readTree(file));
125-
this.analyzer = analyzer.initIfNeed(this);
123+
public KubernetesClient(File file, KubernetesAnalyzer analyzer) {
124+
try {
125+
this.requester = new KubeBaseRequest(new YAMLMapper().readTree(file));
126+
this.analyzer = analyzer.initIfNeed(this);
127+
} catch (Exception e) {
128+
m_logger.severe("无法连接到Kubernetes,退出");
129+
System.exit(1);
130+
}
126131
}
127-
128132

129133
/**
130134
* invoke Kubernetes using token,see
@@ -135,7 +139,7 @@ public KubernetesClient(File file, KubernetesAnalyzer analyzer) throws Exception
135139
* ClusterRoleBinding
136140
* @throws Exception exception
137141
*/
138-
public KubernetesClient(String url, String token) throws Exception {
142+
public KubernetesClient(String url, String token) {
139143
this(url, token, new KubernetesAnalyzer());
140144
}
141145

@@ -149,9 +153,14 @@ public KubernetesClient(String url, String token) throws Exception {
149153
* @param analyzer it is used for getting the metadata for each Kubernetes kind.
150154
* @throws Exception exception
151155
*/
152-
public KubernetesClient(String url, String token, KubernetesAnalyzer analyzer) throws Exception {
153-
this.requester = new KubeBaseRequest(url, token);
154-
this.analyzer = analyzer.initIfNeed(this);
156+
public KubernetesClient(String url, String token, KubernetesAnalyzer analyzer) {
157+
try {
158+
this.requester = new KubeBaseRequest(url, token);
159+
this.analyzer = analyzer.initIfNeed(this);
160+
} catch (Exception e) {
161+
m_logger.severe("无法连接到Kubernetes,退出");
162+
System.exit(1);
163+
}
155164
}
156165

157166

0 commit comments

Comments
 (0)