英文:
What type of edits will change a ReplicaSet and StatefulSet AGE?
问题
更改 ReplicaSet 和 StatefulSet 的哪些编辑会改变 AGE(CreationTimeStamp)?
我之所以问这个问题,是因为我注意到:
1)如果我更改 Deployment 的镜像,将创建一个新的 ReplicaSet。
2)旧的 ReplicaSet 仍然存在,DESIRED 设置为 0。
3)如果我切换回先前的容器镜像,这两个 ReplicaSet 的年龄不会改变,也不会重新创建。
那么,验证 Deployment/ReplicaSet 和 StatefulSet 是否有最近的更新的最佳方法是什么?
到目前为止,我使用 client-go 检查这些资源的年龄:
func statefulsetCheck(namespace string, clientset *kubernetes.Clientset) bool {
// 获取命名空间中的 StatefulSet
statefulsets, err := clientset.AppsV1().StatefulSets(namespace).List(context.TODO(), metav1.ListOptions{})
if errors.IsNotFound(err) {
log.Fatal("\n命名空间中没有 StatefulSet", err)
} else if err != nil {
log.Fatal("\n获取命名空间中的 StatefulSet 失败:", err)
}
var stsNames []string
for _, sts := range statefulsets.Items {
stsNames = append(stsNames, sts.Name)
}
fmt.Printf("\n命名空间中的 StatefulSet:%v", stsNames)
// 检查 StatefulSet 是否超过 9 天
for _, sts := range statefulsets.Items {
stsAge := time.Since(sts.CreationTimestamp.Time)
fmt.Printf("\nStatefulSet %v 的年龄:%v", sts.Name, stsAge)
if stsAge.Minutes() < 5 {
fmt.Printf("\nStatefulSet %v 有最近的更新。跳过...", sts.Name)
return true
}
}
return false
}
func replicasetCheck(namespace string, clientset *kubernetes.Clientset) bool {
// 获取命名空间中的 ReplicaSet
replicasets, err := clientset.AppsV1().ReplicaSets(namespace).List(context.TODO(), metav1.ListOptions{})
if errors.IsNotFound(err) {
log.Fatal("\n命名空间中没有 ReplicaSet", err)
} else if err != nil {
log.Fatal("\n获取命名空间中的 ReplicaSet 失败", err)
}
var rpsNames []string
for _, rps := range replicasets.Items {
rpsNames = append(rpsNames, rps.Name)
}
fmt.Printf("\n命名空间中的 ReplicaSet:%v", rpsNames)
// 检查 ReplicaSet 是否有最近的更新
for _, rps := range replicasets.Items {
rpsAge := time.Since(rps.CreationTimestamp.Time)
fmt.Printf("\nReplicaSet %v 的年龄:%v", rps.Name, rpsAge)
if rpsAge.Minutes() < 5 {
fmt.Printf("\nReplicaSet %v 有最近的更新...", rps.Name)
return true
}
}
return false
}
以上是要翻译的内容。
英文:
What type of edits will change a ReplicaSet and StatefulSet AGE(CreationTimeStamp)?
I'm asking this because I noticed that
- If I change a Deployment image, a new ReplicaSet will be created.
- The old ReplicaSet continues to exist with DESIRED set to 0.
- If I change back to the previous container image, the 2 ReplicaSets don't change their age nor are recreated.
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
}
答案1
得分: 1
"AGE(CreationTimeStamp)"
资源的CreationTimeStamp
(即其年龄)在资源被创建时设置。例如,要更改它,您必须删除该资源并重新创建。
英文:
>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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论