fix(kubernetes): replace getCreatedTime in KubernetesResource interface
We [removed](https://github.com/spinnaker/clouddriver/pull/4769) getCreatedTime from the shared interface extended by Kubernetes resource types and pushed it down to KubernetesServerGroup only, but it turns out that Deck expects all resources to have this field.
MODIFY
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesResource.java
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesResource.java
@@ -32,4 +32,6 @@ public interface KubernetesResource {
KubernetesApiVersion getApiVersion();
String getNamespace();
+
+ Long getCreatedTime();
}

MODIFY
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2Instance.java
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2Instance.java
@@ -56,6 +56,7 @@ public final class KubernetesV2Instance implements Instance, KubernetesResource
private final KubernetesKind kind;
private final Map<String, String> labels;
private final Moniker moniker;
+ private final Long createdTime;
@Null
@Override
@@ -73,6 +74,7 @@ public final class KubernetesV2Instance implements Instance, KubernetesResource
this.kind = manifest.getKind();
this.labels = ImmutableMap.copyOf(manifest.getLabels());
this.moniker = moniker;
+ this.createdTime = manifest.getFormattedCreationTimestamp();
this.health = new ArrayList<>();
V1PodStatus status =

MODIFY
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2LoadBalancer.java
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2LoadBalancer.java
@@ -49,6 +49,7 @@ public final class KubernetesV2LoadBalancer
private final KubernetesKind kind;
private final Map<String, String> labels;
private final Moniker moniker;
+ private final Long createdTime;
private KubernetesV2LoadBalancer(
KubernetesManifest manifest,
@@ -64,6 +65,7 @@ public final class KubernetesV2LoadBalancer
this.labels = ImmutableMap.copyOf(manifest.getLabels());
this.moniker = moniker;
this.serverGroups = serverGroups;
+ this.createdTime = manifest.getFormattedCreationTimestamp();
}
@Nullable

MODIFY
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2SecurityGroup.java
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2SecurityGroup.java
@@ -71,6 +71,7 @@ public final class KubernetesV2SecurityGroup implements KubernetesResource, Secu
private final KubernetesKind kind;
private final Map<String, String> labels;
private final Moniker moniker;
+ private final Long createdTime;
private final Set<Rule> inboundRules;
private final Set<Rule> outboundRules;
@@ -104,6 +105,7 @@ public final class KubernetesV2SecurityGroup implements KubernetesResource, Secu
this.namespace = manifest.getNamespace();
this.labels = ImmutableMap.copyOf(manifest.getLabels());
this.moniker = moniker;
+ this.createdTime = manifest.getFormattedCreationTimestamp();
this.inboundRules = inboundRules;
this.outboundRules = outboundRules;

MODIFY
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2ServerGroup.java
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2ServerGroup.java
@@ -20,7 +20,6 @@ package com.netflix.spinnaker.clouddriver.kubernetes.caching.view.model;
import static com.google.common.collect.ImmutableList.toImmutableList;
import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -43,8 +42,6 @@ import com.netflix.spinnaker.clouddriver.model.ServerGroup;
import com.netflix.spinnaker.clouddriver.model.ServerGroupManager.ServerGroupManagerSummary;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import com.netflix.spinnaker.moniker.Moniker;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -135,7 +132,7 @@ public final class KubernetesV2ServerGroup implements KubernetesResource, Server
this.displayName = manifest.getName();
this.labels = ImmutableMap.copyOf(manifest.getLabels());
this.moniker = moniker;
- this.createdTime = getCreatedTime(manifest);
+ this.createdTime = manifest.getFormattedCreationTimestamp();
this.buildInfo =
ImmutableMap.of(
"images",
@@ -269,21 +266,6 @@ public final class KubernetesV2ServerGroup implements KubernetesResource, Server
.build());
}
- private static Long getCreatedTime(KubernetesManifest manifest) {
- Map<String, String> metadata =
- (Map<String, String>) manifest.getOrDefault("metadata", new HashMap<>());
- String timestamp = metadata.get("creationTimestamp");
- try {
- if (!Strings.isNullOrEmpty(timestamp)) {
- return (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(timestamp)).getTime();
- }
- } catch (ParseException e) {
- log.warn("Failed to parse timestamp: ", e);
- }
-
- return null;
- }
-
@Override
public String getType() {
return KubernetesCloudProvider.ID;

MODIFY
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2ServerGroupManager.java
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/caching/view/model/KubernetesV2ServerGroupManager.java
@@ -49,6 +49,7 @@ public final class KubernetesV2ServerGroupManager
private final KubernetesKind kind;
private final Map<String, String> labels;
private final Moniker moniker;
+ private final Long createdTime;
private KubernetesV2ServerGroupManager(
KubernetesManifest manifest,
@@ -64,6 +65,7 @@ public final class KubernetesV2ServerGroupManager
this.labels = ImmutableMap.copyOf(manifest.getLabels());
this.moniker = moniker;
this.serverGroups = serverGroups;
+ this.createdTime = manifest.getFormattedCreationTimestamp();
}
public static KubernetesV2ServerGroupManager fromCacheData(

MODIFY
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/description/manifest/KubernetesManifest.java
clouddriver-kubernetes/src/main/java/com/netflix/spinnaker/clouddriver/kubernetes/description/manifest/KubernetesManifest.java
@@ -22,6 +22,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -29,9 +31,11 @@ import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
+@Slf4j
public class KubernetesManifest extends HashMap<String, Object> {
private static final ObjectMapper mapper = new ObjectMapper();
@@ -151,6 +155,21 @@ public class KubernetesManifest extends HashMap<String, Object> {
: "";
}
+ @JsonIgnore
+ @Nullable
+ public Long getFormattedCreationTimestamp() {
+ String timestamp = getCreationTimestamp();
+ try {
+ if (!Strings.isNullOrEmpty(timestamp)) {
+ return (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(timestamp)).getTime();
+ }
+ } catch (ParseException e) {
+ log.warn("Failed to parse timestamp: ", e);
+ }
+
+ return null;
+ }
+
@JsonIgnore
@Nonnull
public List<OwnerReference> getOwnerReferences() {

fix(kubernetes): replace getCreatedTime in KubernetesResource interface (#4791)

We [removed](https://github.com/spinnaker/clouddriver/pull/4769) getCreatedTime from the shared interface extended by Kubernetes resource types and pushed it down to KubernetesServerGroup only, but it turns out that Deck expects all resources to have this field.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>