|
|
@@ -29,7 +29,7 @@ public class NamespaceApiImpl implements NamespaceApi{
|
|
|
|
|
|
private Logger logger = LoggerUtil.getLogger(NamespaceApi.class);
|
|
|
|
|
|
- private static final String BACKGROUND_PROPAGATION_POLICY = "Background";
|
|
|
+ private static final String FOREGROUND_PROPAGATION_POLICY = "Foreground";
|
|
|
@Autowired
|
|
|
private CoreV1Api coreV1Api;
|
|
|
|
|
|
@@ -63,13 +63,16 @@ public class NamespaceApiImpl implements NamespaceApi{
|
|
|
try {
|
|
|
V1DeleteOptions v1DeleteOptions = new V1DeleteOptionsBuilder()
|
|
|
.withApiVersion(Namespace.VERSION)
|
|
|
- .withPropagationPolicy(BACKGROUND_PROPAGATION_POLICY)
|
|
|
+ .withPropagationPolicy(FOREGROUND_PROPAGATION_POLICY)
|
|
|
.build();
|
|
|
coreV1Api.deleteNamespace(name, v1DeleteOptions, PRETTY_FORMAT,
|
|
|
- null, null, BACKGROUND_PROPAGATION_POLICY);
|
|
|
+ null, null, FOREGROUND_PROPAGATION_POLICY);
|
|
|
} catch (ApiException e) {
|
|
|
LoggerUtil.error(logger, e, "Namespace删除失败,name={}, response={}", name , e.getResponseBody());
|
|
|
return new ApiResult<>(e.getCode(), e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LoggerUtil.warn(logger, e, "k8s swagger bug");
|
|
|
+ return new ApiResult<>(null);
|
|
|
}
|
|
|
return new ApiResult<>(null);
|
|
|
}
|
|
|
@@ -101,14 +104,38 @@ public class NamespaceApiImpl implements NamespaceApi{
|
|
|
@Override
|
|
|
public ApiResult<List<Namespace>> getByLabel(String key, String value) {
|
|
|
try {
|
|
|
- V1NamespaceList v1NamespaceList = coreV1Api.listNamespace(PRETTY_FORMAT, null, null, true,key+":"+value, null, null, null, null);
|
|
|
+ String labelSelector = buildLabelSelector(key, value);
|
|
|
+ V1NamespaceList v1NamespaceList = coreV1Api.listNamespace(
|
|
|
+ PRETTY_FORMAT,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ true,
|
|
|
+ labelSelector,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null);
|
|
|
List<Namespace> namespaces = v1NamespaceList.getItems().stream().map(Namespace::new).collect(Collectors.toList());
|
|
|
LoggerUtil.info(logger,"result={}", namespaces);
|
|
|
return new ApiResult<>(namespaces);
|
|
|
} catch (ApiException e) {
|
|
|
- LoggerUtil.error(logger, e, "根据标签获取Namespace异常, key={}, value={}", key, value);
|
|
|
+ LoggerUtil.error(logger, e, "根据标签获取Namespace异常, key={}, value={}, response={}", key, value, e.getResponseBody());
|
|
|
return new ApiResult<>(e.getCode(), e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String buildLabelSelector(String key, String value) {
|
|
|
+ return key + "=" + value;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildLabelSelector(Map<String, String> labels) {
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
+ for (Map.Entry<String, String> entry : labels.entrySet()) {
|
|
|
+ result.append(entry.getKey());
|
|
|
+ result.append("=");
|
|
|
+ result.append(entry.getValue());
|
|
|
+ result.append(",");
|
|
|
+ }
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
}
|