(t *testing.T, pod *corev1.Pod)
| 2951 | } |
| 2952 | } |
| 2953 | if !foundEnv { |
| 2954 | t.Fatal("bearer token env var not found or incorrect") |
| 2955 | } |
| 2956 | if !foundSharedWarmWorkerEnv { |
| 2957 | t.Fatal("expected shared worker startup env to be present") |
| 2958 | } |
| 2959 | if !foundTLSCertEnv || !foundTLSKeyEnv { |
| 2960 | t.Fatal("expected worker RPC TLS env vars to be present") |
| 2961 | } |
| 2962 | if !foundMaxSessionsEnv { |
| 2963 | t.Fatal("expected DUCKGRES_DUCKDB_MAX_SESSIONS=1 (one query session per worker)") |
| 2964 | } |
| 2965 | |
| 2966 | // Pre-session memory hygiene: the worker process must know the POD's |
| 2967 | // memory shape from the start. Without these, ConfigureMainDB sizes the |
| 2968 | // base DB off the NODE's /proc/meminfo (sysinfo.AutoMemoryLimit) and all |
| 2969 | // pre-session work (DuckLake ATTACH, activation) runs effectively |
| 2970 | // unbounded, and the Go runtime has no ceiling at all. |
| 2971 | // Default pool shape is 16Gi/8cpu. Headroom is max(25%, min(6GiB, 40%)), |
| 2972 | // so a 16Gi pod keeps 6GiB back and DuckDB gets 10GB, not a flat 75%. |
| 2973 | if got := envByName["DUCKGRES_MEMORY_LIMIT"]; got != "10GB" { |
| 2974 | t.Fatalf("expected DUCKGRES_MEMORY_LIMIT=10GB (16Gi pod less 6GiB headroom), got %q", got) |
| 2975 | } |
| 2976 | if got := envByName["DUCKGRES_THREADS"]; got != "20" { |
| 2977 | t.Fatalf("expected DUCKGRES_THREADS=20 (2.5x the 8 CPU pod request), got %q", got) |
| 2978 | } |
| 2979 | if got := envByName["GOMEMLIMIT"]; got != "2048MiB" { |
| 2980 | t.Fatalf("expected GOMEMLIMIT=2048MiB (1/8 of 16Gi pod), got %q", got) |
| 2981 | } |
| 2982 | |
| 2983 | if len(pod.Spec.Volumes) == 0 { |
| 2984 | t.Fatal("expected configmap volume") |
| 2985 | } |
| 2986 | foundWorkerRPCSecret := false |
| 2987 | for _, volume := range pod.Spec.Volumes { |
| 2988 | if volume.Name == "worker-rpc-tls" && volume.Secret != nil && |
| 2989 | volume.Secret.SecretName == "test-secret-duckgres-worker-test-cp-0" { |
| 2990 | foundWorkerRPCSecret = true |
| 2991 | } |
| 2992 | } |
| 2993 | if !foundWorkerRPCSecret { |
| 2994 | t.Fatal("expected worker RPC volume to reference per-worker secret") |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | func TestK8sPool_RetireWorkerDeletesWorkerRPCSecret(t *testing.T) { |
| 2999 | pool, cs := newTestK8sPool(t, 5) |
| 3000 | worker := &ManagedWorker{ID: 1, podName: "duckgres-worker-test-cp-1", done: make(chan struct{})} |
| 3001 | pool.workers[1] = worker |
| 3002 | |
| 3003 | _, err := cs.CoreV1().Secrets("default").Create(context.Background(), &corev1.Secret{ |
| 3004 | ObjectMeta: metav1.ObjectMeta{Name: "test-secret-duckgres-worker-test-cp-1", Namespace: "default"}, |
| 3005 | Data: map[string][]byte{"bearer-token": []byte("test-token"), "tls.crt": []byte("test-cert"), "tls.key": []byte("test-key")}, |
| 3006 | }, metav1.CreateOptions{}) |
| 3007 | if err != nil { |
| 3008 | t.Fatal(err) |
| 3009 | } |
| 3010 |
no outgoing calls
no test coverage detected