From 7d882d0504748d52e40c811270bb1523232742cd Mon Sep 17 00:00:00 2001 From: yy <56745951+lingdie@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:21:49 +0800 Subject: [PATCH] add logs for CheckPodConsistency. (#5035) * add log to debug. Signed-off-by: yy * add log to debug. Signed-off-by: yy * add log to debug. Signed-off-by: yy --------- Signed-off-by: yy --- .../devbox/internal/controller/devbox_controller.go | 6 ++++++ .../devbox/internal/controller/helper/devbox.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/controllers/devbox/internal/controller/devbox_controller.go b/controllers/devbox/internal/controller/devbox_controller.go index c588e423de6..c79f2fa7cc6 100644 --- a/controllers/devbox/internal/controller/devbox_controller.go +++ b/controllers/devbox/internal/controller/devbox_controller.go @@ -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]) diff --git a/controllers/devbox/internal/controller/helper/devbox.go b/controllers/devbox/internal/controller/helper/devbox.go index 7f34164135c..bf43eff0a1d 100644 --- a/controllers/devbox/internal/controller/helper/devbox.go +++ b/controllers/devbox/internal/controller/helper/devbox.go @@ -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 } }