forked from Gitlink/microservices
fix(运维监控):修复应用Pod列表找不到的问题
调整 podSelector 的匹配规则,不再仅依赖选择器的 Key 部分,而是保存并使用 POD 的完整选择器字段(如 "app=nginx")。在获取应用的 Labels 列表时,将该完整选择器通过 = 拆分为 Key 和 Value,再分别与 POD 的 Labels 进行精确匹配,从而提升选择器匹配的准确性与灵活性。
This commit is contained in:
parent
66e1b9aca6
commit
12eecde9c4
|
|
@ -35,6 +35,9 @@ public class K8sApplication {
|
|||
@ApiModelProperty(value = "Pod选择器")
|
||||
private String podSelector;
|
||||
|
||||
@ApiModelProperty(value = "Docker镜像")
|
||||
private String dockerImage;
|
||||
|
||||
@ApiModelProperty(value = "运行状态")
|
||||
private K8sApplicationState state;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ public class RancherApplicationVo {
|
|||
RancherMetadataVo metadata;
|
||||
// 状态
|
||||
RancherApplicationStateVo status;
|
||||
// 规格
|
||||
JSONObject spec;
|
||||
|
||||
|
||||
public K8sApplication toK8sApplication() {
|
||||
|
|
@ -36,6 +38,22 @@ public class RancherApplicationVo {
|
|||
target.setReadyReplicas(status.getReadyReplicas());
|
||||
}
|
||||
|
||||
if (spec != null) {
|
||||
JSONObject templateObj = spec.getJSONObject("template");
|
||||
if (templateObj != null) {
|
||||
JSONObject specObj = templateObj.getJSONObject("spec");
|
||||
if (specObj != null) {
|
||||
JSONArray containersArray = specObj.getJSONArray("containers");
|
||||
if (containersArray != null && !containersArray.isEmpty()) {
|
||||
JSONObject firstContainer = containersArray.getJSONObject(0);
|
||||
if (firstContainer != null && firstContainer.containsKey("image")) {
|
||||
target.setDockerImage(firstContainer.getString("image"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata.getAnnotations() != null && metadata.getAnnotations().containsKey("mon-name")) {
|
||||
target.setAlias(metadata.getAnnotations().getString("mon-name"));
|
||||
}
|
||||
|
|
@ -51,10 +69,10 @@ public class RancherApplicationVo {
|
|||
JSONObject relationship = relationships.getJSONObject(i);
|
||||
if (relationship.containsKey("toType") && "pod".equals(relationship.getString("toType"))) {
|
||||
String selector = relationship.getString("selector");
|
||||
if (StringUtils.isNotEmpty(selector) && selector.contains("app=")) {
|
||||
String appName = selector.substring(selector.indexOf("=") + 1);
|
||||
target.setPodSelector(appName);
|
||||
if (StringUtils.isNotEmpty(selector) && selector.contains("=") && selector.split("=").length >= 2) {
|
||||
target.setPodSelector(selector);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return target;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ public class RancherServiceVo {
|
|||
String id;
|
||||
// 元数据
|
||||
RancherMetadataVo metadata;
|
||||
// 状态
|
||||
// 规格
|
||||
RancherServiceSpecVo spec;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue