Commit ffc1f8fe authored by 黎博's avatar 黎博

获取namespace列表时间转换

parent e8c84f52
...@@ -12,6 +12,7 @@ import io.fabric8.kubernetes.client.Config; ...@@ -12,6 +12,7 @@ import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.DefaultKubernetesClient; import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -19,10 +20,8 @@ import java.io.BufferedReader; ...@@ -19,10 +20,8 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
@Slf4j @Slf4j
@Component @Component
...@@ -113,12 +112,20 @@ public class K8sService { ...@@ -113,12 +112,20 @@ public class K8sService {
List<Namespace> namespaceList = kubernetesClient.namespaces().list().getItems(); List<Namespace> namespaceList = kubernetesClient.namespaces().list().getItems();
for (Namespace namespace : namespaceList) { for (Namespace namespace : namespaceList) {
if (namespace.getMetadata().getAnnotations() != null && namespace.getMetadata().getAnnotations().get("description").equals(env)) { if (namespace.getMetadata().getAnnotations() != null && namespace.getMetadata().getAnnotations().get("description").equals(env)) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("name", namespace.getMetadata().getName()); map.put("name", namespace.getMetadata().getName());
map.put("description", namespace.getMetadata().getAnnotations().get("description")); map.put("description", namespace.getMetadata().getAnnotations().get("description"));
map.put("owner", namespace.getMetadata().getAnnotations().get("owner")); map.put("owner", namespace.getMetadata().getAnnotations().get("owner"));
map.put("status", namespace.getStatus().getPhase()); map.put("status", namespace.getStatus().getPhase());
try {
map.put("createdAt", df.parse(namespace.getMetadata().getCreationTimestamp()));
} catch (Exception e) {
log.info("时间解析异常!");
e.printStackTrace();
map.put("createdAt", namespace.getMetadata().getCreationTimestamp()); map.put("createdAt", namespace.getMetadata().getCreationTimestamp());
}
resultList.add(map); resultList.add(map);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment