@@ -9,9 +9,12 @@ import (
99 "io/fs"
1010 "os"
1111 "path/filepath"
12- "runtime"
1312 "testing"
1413
14+ corev1 "k8s.io/api/core/v1"
15+ "k8s.io/apimachinery/pkg/labels"
16+ "sigs.k8s.io/controller-runtime/pkg/client"
17+
1518 "github.com/kgateway-dev/kgateway/v2/pkg/utils/helmutils"
1619 "github.com/kgateway-dev/kgateway/v2/test/e2e/testutils/actions"
1720 "github.com/kgateway-dev/kgateway/v2/test/e2e/testutils/assertions"
@@ -78,7 +81,9 @@ func CreateTestInstallationForCluster(
7881 // between TestInstallation outputs per CI run
7982 GeneratedFiles : MustGeneratedFiles (installContext .InstallNamespace , clusterContext .Name ),
8083 }
81- runtime .SetFinalizer (installation , func (i * TestInstallation ) { i .finalize () })
84+ testutils .Cleanup (t , func () {
85+ installation .finalize ()
86+ })
8287 return installation
8388}
8489
@@ -159,7 +164,7 @@ func (i *TestInstallation) InstallKgatewayCRDsFromLocalChart(ctx context.Context
159164
160165 // Check if we should skip installation if the release already exists (PERSIST_INSTALL or FAIL_FAST_AND_PERSIST mode)
161166 if testutils .ShouldPersistInstall () || testutils .ShouldFailFastAndPersist () {
162- if i .Actions . Helm (). ReleaseExists (ctx , helmutils .CRDChartName , i .Metadata .InstallNamespace ) {
167+ if i .releaseExists (ctx , helmutils .CRDChartName , i .Metadata .InstallNamespace ) {
163168 return
164169 }
165170 }
@@ -185,7 +190,7 @@ func (i *TestInstallation) InstallKgatewayCoreFromLocalChart(ctx context.Context
185190
186191 // Check if we should skip installation if the release already exists (PERSIST_INSTALL or FAIL_FAST_AND_PERSIST mode)
187192 if testutils .ShouldPersistInstall () || testutils .ShouldFailFastAndPersist () {
188- if i .Actions . Helm (). ReleaseExists (ctx , helmutils .ChartName , i .Metadata .InstallNamespace ) {
193+ if i .releaseExists (ctx , helmutils .ChartName , i .Metadata .InstallNamespace ) {
189194 return
190195 }
191196 }
@@ -309,3 +314,16 @@ func MustGeneratedFiles(tmpDirId, clusterId string) GeneratedFiles {
309314 FailureDir : failureDir ,
310315 }
311316}
317+ func (i * TestInstallation ) releaseExists (ctx context.Context , releaseName , namespace string ) bool {
318+ l := & corev1.SecretList {}
319+ if err := i .ClusterContext .Client .List (ctx , l , & client.ListOptions {
320+ Namespace : namespace ,
321+ LabelSelector : labels .SelectorFromSet (map [string ]string {
322+ "owner" : "helm" ,
323+ "name" : releaseName ,
324+ }),
325+ }); err != nil {
326+ return false
327+ }
328+ return len (l .Items ) > 0
329+ }
0 commit comments