mirror of
https://github.com/labring/sealos.git
synced 2026-09-21 05:44:43 +08:00
add logs for CheckPodConsistency. (#5035)
* add log to debug. Signed-off-by: yy <lingdie.yy@outlook.com> * add log to debug. Signed-off-by: yy <lingdie.yy@outlook.com> * add log to debug. Signed-off-by: yy <lingdie.yy@outlook.com> --------- Signed-off-by: yy <lingdie.yy@outlook.com>
This commit is contained in:
@@ -263,11 +263,17 @@ func (r *DevboxReconciler) syncPod(ctx context.Context, devbox *devboxv1alpha1.D
|
||||
return r.updateDevboxCommitHistory(ctx, devbox, &podList.Items[0])
|
||||
}
|
||||
if !helper.CheckPodConsistency(expectPod, &podList.Items[0]) {
|
||||
logger.Info("pod is pending, but pod spec is not consistent, delete pod")
|
||||
logger.Info("pod", "pod", podList.Items[0].Name, "pod spec", podList.Items[0].Spec)
|
||||
logger.Info("expect pod", "pod", expectPod.Name, "pod spec", expectPod.Spec)
|
||||
_ = r.Delete(ctx, &podList.Items[0])
|
||||
}
|
||||
case corev1.PodRunning:
|
||||
//if pod is running,check pod need restart
|
||||
if !helper.CheckPodConsistency(expectPod, &podList.Items[0]) {
|
||||
logger.Info("pod is running, but pod spec is not consistent, delete pod")
|
||||
logger.Info("pod", "pod", podList.Items[0].Name, "pod spec", podList.Items[0].Spec)
|
||||
logger.Info("expect pod", "pod", expectPod.Name, "pod spec", expectPod.Spec)
|
||||
_ = r.Delete(ctx, &podList.Items[0])
|
||||
}
|
||||
return r.updateDevboxCommitHistory(ctx, devbox, &podList.Items[0])
|
||||
|
||||
@@ -16,6 +16,7 @@ package helper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
@@ -106,6 +107,7 @@ func GenerateSSHKeyPair() ([]byte, []byte, error) {
|
||||
|
||||
func CheckPodConsistency(expectPod *corev1.Pod, pod *corev1.Pod) bool {
|
||||
if len(pod.Spec.Containers) == 0 {
|
||||
slog.Info("Pod has no containers")
|
||||
return false
|
||||
}
|
||||
container := pod.Spec.Containers[0]
|
||||
@@ -113,9 +115,11 @@ func CheckPodConsistency(expectPod *corev1.Pod, pod *corev1.Pod) bool {
|
||||
|
||||
// Check CPU and memory limits
|
||||
if container.Resources.Limits.Cpu().Cmp(*expectContainer.Resources.Limits.Cpu()) != 0 {
|
||||
slog.Info("CPU limits are not equal")
|
||||
return false
|
||||
}
|
||||
if container.Resources.Limits.Memory().Cmp(*expectContainer.Resources.Limits.Memory()) != 0 {
|
||||
slog.Info("Memory limits are not equal")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -126,12 +130,17 @@ func CheckPodConsistency(expectPod *corev1.Pod, pod *corev1.Pod) bool {
|
||||
for _, env := range container.Env {
|
||||
found := false
|
||||
for _, expectEnv := range expectContainer.Env {
|
||||
if env.Name == "SEALOS_COMMIT_IMAGE_NAME" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
if env.Name == expectEnv.Name && env.Value == expectEnv.Value {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
slog.Info("Environment variables are not equal", "env not found", env.Name, "env value", env.Value)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -149,6 +158,7 @@ func CheckPodConsistency(expectPod *corev1.Pod, pod *corev1.Pod) bool {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
slog.Info("Ports are not equal")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user