Skip to content

Commit

Permalink
feat(provider/kubernetes): return resource create time
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Wander committed Jan 4, 2018
1 parent 0af916d commit aa199c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
@Slf4j
public class KubernetesV2ServerGroup extends ManifestBasedModel implements ServerGroup {
Boolean disabled;
Long createdTime;
Set<String> zones = new HashSet<>();
Set<Instance> instances = new HashSet<>();
Set<String> loadBalancers = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifest;
import com.netflix.spinnaker.clouddriver.names.NamerRegistry;
import com.netflix.spinnaker.moniker.Moniker;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

@Slf4j
abstract public class ManifestBasedModel {
public String getName() {
return getManifest().getFullResourceName();
Expand Down Expand Up @@ -66,6 +74,19 @@ public String getAccount() {
return getAccountName();
}

public Long getCreatedTime() {
Map<String, String> metadata = (Map<String, String>) getManifest().getOrDefault("metadata", new HashMap<>());
String timestamp = metadata.get("creationTimestamp");
try {
return StringUtils.isNotEmpty(timestamp) ?
(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(timestamp)).getTime() :
null;
} catch (ParseException e) {
log.warn("Failed to parse timestamp: ", e);
return null;
}
}

abstract protected KubernetesManifest getManifest();
abstract protected Keys.InfrastructureCacheKey getKey();
}

0 comments on commit aa199c7

Please sign in to comment.