@@ -38,6 +38,21 @@ func InstallCSIHostpath(kubeContext string) func(ctx context.Context) error {
3838 return fmt .Errorf ("install snapshot CRDs: %w" , err )
3939 }
4040
41+ // Wait for the snapshot CRDs to be Established before continuing. deploy.sh
42+ // applies a VolumeSnapshotClass, which fails with "no matches for kind
43+ // VolumeSnapshotClass" if the apiserver has not finished registering the
44+ // CRD yet. Waiting here makes the CRDs discoverable for every caller,
45+ // including parallel SnapshotPreSetup runs in other Ginkgo processes.
46+ establishCmd := exec .CommandContext (ctx , "kubectl" , "wait" , "--for=condition=established" ,
47+ "--timeout=60s" , "--context" , kubeContext , "crd" ,
48+ "volumesnapshotclasses.snapshot.storage.k8s.io" ,
49+ "volumesnapshotcontents.snapshot.storage.k8s.io" ,
50+ "volumesnapshots.snapshot.storage.k8s.io" ,
51+ )
52+ if out , err := establishCmd .CombinedOutput (); err != nil {
53+ return fmt .Errorf ("wait for snapshot CRDs to be established: %s: %w" , string (out ), err )
54+ }
55+
4156 // Install snapshot-controller
4257 if err := kubectlApplyKustomize (ctx , kubeContext ,
4358 "https://github.com/kubernetes-csi/external-snapshotter/deploy/kubernetes/snapshot-controller?ref=" + externalSnapshotterVersion ); err != nil {
@@ -61,15 +76,24 @@ func InstallCSIHostpath(kubeContext string) func(ctx context.Context) error {
6176 // csi-sanity/csc testing and its StatefulSet is flaky on Kind.
6277 _ = os .Remove (filepath .Join (tmpDir , "deploy" , "kubernetes-latest" , "hostpath" , "csi-hostpath-testing.yaml" ))
6378
64- // Set the kubectl context before running deploy.sh so the CSI driver
65- // is installed into the correct cluster even when multiple contexts exist.
66- setCtxCmd := exec .CommandContext (ctx , "kubectl" , "config" , "use-context" , kubeContext )
67- if out , err := setCtxCmd .CombinedOutput (); err != nil {
68- return fmt .Errorf ("set kubectl context to %s: %s: %w" , kubeContext , string (out ), err )
79+ // deploy.sh operates on the current kubeconfig context. Rather than mutate
80+ // the shared ~/.kube/config with `kubectl config use-context` (which races
81+ // when multiple installs run in parallel Ginkgo processes), write an
82+ // isolated kubeconfig minified to the target context and point deploy.sh at
83+ // it via KUBECONFIG. The temp dir is removed by the deferred cleanup above.
84+ kubeconfigPath := filepath .Join (tmpDir , "kubeconfig" )
85+ viewCmd := exec .CommandContext (ctx , "kubectl" , "config" , "view" , "--raw" , "--minify" , "--context" , kubeContext )
86+ kubeconfigData , err := viewCmd .Output ()
87+ if err != nil {
88+ return fmt .Errorf ("export kubeconfig for context %s: %w" , kubeContext , err )
89+ }
90+ if err := os .WriteFile (kubeconfigPath , kubeconfigData , 0o600 ); err != nil {
91+ return fmt .Errorf ("write isolated kubeconfig: %w" , err )
6992 }
7093
7194 deployScript := tmpDir + "/deploy/kubernetes-latest/deploy.sh"
7295 deployCmd := exec .CommandContext (ctx , "bash" , deployScript )
96+ deployCmd .Env = append (os .Environ (), "KUBECONFIG=" + kubeconfigPath )
7397 if out , err := deployCmd .CombinedOutput (); err != nil {
7498 return fmt .Errorf ("deploy CSI hostpath driver: %s: %w" , string (out ), err )
7599 }
0 commit comments