Skip to content

Commit

Permalink
add logs for CheckPodConsistency. (labring#5035)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
lingdie authored Sep 4, 2024
1 parent 980e796 commit 7d882d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions controllers/devbox/internal/controller/devbox_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
10 changes: 10 additions & 0 deletions controllers/devbox/internal/controller/helper/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package helper

import (
"fmt"
"log/slog"

"crypto/ed25519"
"crypto/rand"
Expand Down Expand Up @@ -106,16 +107,19 @@ 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]
expectContainer := expectPod.Spec.Containers[0]

// 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
}

Expand All @@ -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
}
}
Expand All @@ -149,6 +158,7 @@ func CheckPodConsistency(expectPod *corev1.Pod, pod *corev1.Pod) bool {
}
}
if !found {
slog.Info("Ports are not equal")
return false
}
}
Expand Down

0 comments on commit 7d882d0

Please sign in to comment.