Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logs for CheckPodConsistency. #5035

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading