Reputation: 221
What type of edits will change a ReplicaSet and StatefulSet AGE(CreationTimeStamp)?
I'm asking this because I noticed that
So, what is the best way to verify if there were recent updates to a Deployment/ReplicaSet and StatefulSet?
So far, I'm using client-go to check these resources ages:
func statefulsetCheck(namespace string, clientset *kubernetes.Clientset) bool {
// get the statefulsets in the namespace
statefulsets, err := clientset.AppsV1().StatefulSets(namespace).List(context.TODO(), metav1.ListOptions{})
if errors.IsNotFound(err) {
log.Fatal("\nNo statefulsets in the namespace", err)
} else if err != nil {
log.Fatal("\nFailed to fetch statefulsets in the namespace: ", err)
}
var stsNames []string
for _, sts := range statefulsets.Items {
stsNames = append(stsNames, sts.Name)
}
fmt.Printf("\nStatefulsets in the namespace: %v", stsNames)
// check if the statefulsets are older than the 9 days
for _, sts := range statefulsets.Items {
stsAge := time.Since(sts.CreationTimestamp.Time)
fmt.Printf("\nStatefulset %v age: %v", sts.Name, stsAge)
if stsAge.Minutes() < 5 {
fmt.Printf("\nStatefulset %v had recent updates. Skipping...", sts.Name)
return true
}
}
return false
}
func replicasetCheck(namespace string, clientset *kubernetes.Clientset) bool {
// get the replicasets in the namespace
replicasets, err := clientset.AppsV1().ReplicaSets(namespace).List(context.TODO(), metav1.ListOptions{})
if errors.IsNotFound(err) {
log.Fatal("\nNo replicasets in the namespace", err)
} else if err != nil {
log.Fatal("\nFailed to fetch replicasets in the namespace", err)
}
var rpsNames []string
for _, rps := range replicasets.Items {
rpsNames = append(rpsNames, rps.Name)
}
fmt.Printf("\nReplicasets in the namespace: %v", rpsNames)
// check if the replicasets have recent updates
for _, rps := range replicasets.Items {
rpsAge := time.Since(rps.CreationTimestamp.Time)
fmt.Printf("\nReplicaset %v age: %v", rps.Name, rpsAge)
if rpsAge.Minutes() < 5 {
fmt.Printf("\nReplicaset %v had recent updates...", rps.Name)
return true
}
}
return false
}
Upvotes: 2
Views: 176
Reputation: 128797
AGE(CreationTimeStamp)
A resource's CreationTimeStamp
(and thereby its age) is set when a resource is created. E.g. to change it, you must delete the resource and create it again.
Upvotes: 1