Repository navigation
test(e2e): cover trusted and untrusted PKI chains - #220
tzprograms wants to merge 1 commit into
Conversation
PKI verification lacked Kind regression coverage. Exercise a trusted certificate chain and an unrelated trust anchor through the real agent, using committed public fixtures and the existing E2E templates. Signed-off-by: Tejas Soham <tejassoham05@gmail.com>
| g.Expect(utils.KubectlGetJSON("pod", podName, webhookTestNamespace, &pod)).To(Succeed()) | ||
| g.Expect(pod.Status.Phase).To(Equal(corev1.PodRunning)) | ||
| g.Expect(pod.Status.InitContainerStatuses).ToNot(BeEmpty()) | ||
| initStatus := pod.Status.InitContainerStatuses[0] |
There was a problem hiding this comment.
The InitContainerStatuses[0] index assumes the validation container is first, but the webhook appends it to the end of InitContainers (internal/webhooks/pod_webhook.go:166) — so this only holds while the pod template has zero other init containers. If someone adds one, the trusted test would read the wrong container's exit code 0 and pass vacuously. Could we select the status by name, like the injection check a few lines up already does? (There may be enough shared shape here for a small expectValidationResult(podName, wantExitZero, logSubstring) helper covering both specs — it would also dedupe the copy in validation_test.go.)
| mkdir -p /host-data /host-keys /host-fixtures | ||
| cp -r /data/* /host-data/ | ||
| cp -r /keys/* /host-keys/ | ||
| cp -r /fixtures/* /host-fixtures/ |
There was a problem hiding this comment.
The cp -r /fixtures/* /host-fixtures/ runs without set -e, so if the node has a stale model-validation-test-model:latest loaded (with imagePullPolicy: Never it is never re-pulled), the cp fails silently, the DaemonSet still reports ready, and the failure surfaces as a 90s timeout in the PKI tests with no hint of the real cause. Adding set -e (or a [ -d /fixtures ] || exit 1 guard) would crashloop the DaemonSet and fail setup immediately with the actual error.
| crData := utils.CRTemplateData{ModelName: modelName, Namespace: webhookTestNamespace, KeyPath: caPath} | ||
| podData := pkiPodData(podName, modelName) | ||
| // Delete the pod before its ModelValidation so the webhook can still resolve it. | ||
| DeferCleanup(func() { |
There was a problem hiding this comment.
The two Expects are chained in one cleanup func, so if the pod delete fails or times out (it carries the ModelValidation finalizer, so it depends on a live controller), the CR delete never runs and the pki ModelValidation leaks into the specs that run after this file. Registering them as two separate DeferCleanup calls — or tolerating/logging the pod error before deleting the CR — keeps teardown isolated.
|
|
||
| By("verifying the init container logs show the CA was not trusted") | ||
| Eventually(func(g Gomega) { | ||
| output, err := utils.Run(exec.Command("kubectl", "logs", podName, "-n", webhookTestNamespace, |
There was a problem hiding this comment.
This ~15-line block (fetch pod JSON → check phase → init container exit code → kubectl logs substring) is now in three places: here twice and in validation_test.go:84-91. Any change to log retrieval or status checking has to be made three times. One expectValidationResult(podName, wantExitZero, logSubstring) helper would collapse all of them — and fix the by-index lookup at the same time.
Note: AI Assisted Review Comment
Summary
Add Kind E2E coverage for PKI certificate-chain validation through the real validation agent.
unknown authorityerror.Testing:
go vet ./test/...passed.AfterSuite; the specs passed.Release Note
NONE
Documentation
No documentation update is required; this test-only change adds no user-facing behavior.