63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
|
|
package cluster
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
// TestStuckVaultInitReasonDetectsHungInit runs one orchestration or CLI step.
|
||
|
|
// Signature: TestStuckVaultInitReasonDetectsHungInit(t *testing.T).
|
||
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
||
|
|
func TestStuckVaultInitReasonDetectsHungInit(t *testing.T) {
|
||
|
|
var pod podResource
|
||
|
|
pod.Status.Phase = "Pending"
|
||
|
|
pod.Metadata.Annotations = map[string]string{
|
||
|
|
"vault.hashicorp.com/agent-inject": "true",
|
||
|
|
}
|
||
|
|
pod.Status.InitContainerStatuses = []podContainerStatus{
|
||
|
|
{
|
||
|
|
Name: "vault-agent-init",
|
||
|
|
State: podContainerState{
|
||
|
|
Running: &podContainerRunningState{
|
||
|
|
StartedAt: time.Now().Add(-10 * time.Minute),
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
reason := stuckVaultInitReason(pod, 3*time.Minute)
|
||
|
|
if reason != "VaultInitStuck" {
|
||
|
|
t.Fatalf("expected VaultInitStuck reason, got %q", reason)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestStuckVaultInitReasonIgnoresFreshOrNonVaultPods runs one orchestration or CLI step.
|
||
|
|
// Signature: TestStuckVaultInitReasonIgnoresFreshOrNonVaultPods(t *testing.T).
|
||
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
||
|
|
func TestStuckVaultInitReasonIgnoresFreshOrNonVaultPods(t *testing.T) {
|
||
|
|
var pod podResource
|
||
|
|
pod.Status.Phase = "Pending"
|
||
|
|
pod.Metadata.Annotations = map[string]string{
|
||
|
|
"vault.hashicorp.com/agent-inject": "true",
|
||
|
|
}
|
||
|
|
pod.Status.InitContainerStatuses = []podContainerStatus{
|
||
|
|
{
|
||
|
|
Name: "vault-agent-init",
|
||
|
|
State: podContainerState{
|
||
|
|
Running: &podContainerRunningState{
|
||
|
|
StartedAt: time.Now().Add(-30 * time.Second),
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
if reason := stuckVaultInitReason(pod, 3*time.Minute); reason != "" {
|
||
|
|
t.Fatalf("expected no reason for fresh init, got %q", reason)
|
||
|
|
}
|
||
|
|
|
||
|
|
pod.Metadata.Annotations["vault.hashicorp.com/agent-inject"] = "false"
|
||
|
|
pod.Status.InitContainerStatuses[0].State.Running.StartedAt = time.Now().Add(-10 * time.Minute)
|
||
|
|
if reason := stuckVaultInitReason(pod, 3*time.Minute); reason != "" {
|
||
|
|
t.Fatalf("expected no reason for non-vault pod, got %q", reason)
|
||
|
|
}
|
||
|
|
}
|