我正在使用openshift 3.9,并尝试在我的命名空间中列出fabirc8 Kubernetes-client ( https://github.com/fabric8io/kubernetes-client )中的所有Pods。我使用的是Java8和openshift客户端的版本
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<version>4.1.0</version>
</dependency>在吊舱内部,我可以使用bash获得一张荚的列表。
# using TLS connection with crt file defined
curl --cacert $CERT \
-H "Authorization: Bearer $TOKEN" \
https://$ENDPOINT/api/v1/namespaces/$NAMESPACE/pods这意味着我的服务帐户有权在名称空间中列出豆荚。
使用java,我无法授权jet。
try (OpenShiftClient client = new DefaultOpenShiftClient()) {
System.out.println("Client opened is: " + client.getConfiguration().getOauthToken());
client.pods().list().getItems().stream().forEach(
p -> System.out.println("pod: " + p));
}即使我使用builderConfig显式地指定了客户机,错误也如下所示:
线程"OkHttp Dispatcher“中对授权请求的意外响应(401未经授权)中的异常。丢失标题:位置!在io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor.authorize(OpenShiftOAuthInterceptor.java:128) at io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor.intercept(OpenShiftOAuthInterceptor.java:63) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:129) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java。util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
在第132行中,没有设置令牌的位置,因此无法找到令牌。我一个人解决不了这个问题。也许我必须设置标题授权:独自携带。
发布于 2022-09-19 16:29:30
try creating client this way
private OpenShiftClient buildClient(String namespace) {
logger.info("OpenShiftClient buildClient:" + openshiftConfig);
return new DefaultOpenShiftClient(new ConfigBuilder().withMasterUrl(clusterUrl))
.withNamespace(namespace)
.withTrustCerts(true)
.withDisableHostnameVerification(true)
.withUsername(openshiftConfig.getUsername()).withPassword( Password).withTrustCerts(true).build());
}https://stackoverflow.com/questions/53803629
复制相似问题