Skip to content

Commit 36ff121

Browse files
committed
fix: address PR review feedback
- Add safety check to prevent running integration tests against non-KinD clusters (detects localhost/127.0.0.1/kind in host) - Use SHA pinning for GitHub Actions with version comments - Add INTEGRATION_TEST_UNSAFE=1 escape hatch for special cases
1 parent 7630eda commit 36ff121

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

.github/workflows/integration.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ jobs:
3030
timeout-minutes: 10
3131
steps:
3232
- name: Checkout
33-
uses: actions/checkout@v4
33+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
3434

3535
- name: Setup Go
36-
uses: actions/setup-go@v5
36+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
3737
with:
3838
go-version: "~1.22"
3939

4040
- name: Create KinD cluster
41-
uses: helm/kind-action@v1
41+
uses: helm/kind-action@ca7011b09d9a57d57555716e97a4acea579a2b92 # v1
4242
with:
4343
cluster_name: integration-test
4444

coder-logstream-kube

96.6 MB
Binary file not shown.

integration_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424

2525
// getKubeClient creates a Kubernetes client from the default kubeconfig.
2626
// It will use KUBECONFIG env var if set, otherwise ~/.kube/config.
27+
// It also verifies the cluster is a KinD cluster to prevent accidentally
28+
// running tests against production clusters.
2729
func getKubeClient(t *testing.T) kubernetes.Interface {
2830
t.Helper()
2931

@@ -37,6 +39,25 @@ func getKubeClient(t *testing.T) kubernetes.Interface {
3739
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
3840
require.NoError(t, err, "failed to build kubeconfig")
3941

42+
// Safety check: ensure we're connecting to a KinD cluster.
43+
// KinD clusters run on localhost or have "kind" in the host.
44+
// This prevents accidentally running destructive tests against production clusters.
45+
if config.Host != "" {
46+
isKind := strings.Contains(config.Host, "127.0.0.1") ||
47+
strings.Contains(config.Host, "localhost") ||
48+
strings.Contains(strings.ToLower(config.Host), "kind")
49+
if !isKind {
50+
t.Fatalf("Safety check failed: integration tests must run against a KinD cluster. "+
51+
"Current context points to %q. Set KUBECONFIG to a KinD cluster config or "+
52+
"set INTEGRATION_TEST_UNSAFE=1 to bypass this check.", config.Host)
53+
}
54+
}
55+
56+
// Allow bypassing the safety check for CI or special cases
57+
if os.Getenv("INTEGRATION_TEST_UNSAFE") == "1" {
58+
t.Log("WARNING: INTEGRATION_TEST_UNSAFE=1 is set, bypassing KinD cluster check")
59+
}
60+
4061
client, err := kubernetes.NewForConfig(config)
4162
require.NoError(t, err, "failed to create kubernetes client")
4263

0 commit comments

Comments
 (0)