Skip to content

Commit

Permalink
Proper way for detect what parts of porch are in-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
kispaljr committed Jun 4, 2024
1 parent e6efac3 commit 2dc1e6b
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions test/e2e/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (t *TestSuite) Initialize(ctx context.Context) {
t.clientset = cs
}

_, t.local = t.IsUsingDevPorch()
t.local = !t.IsTestRunnerInCluster()

namespace := fmt.Sprintf("porch-test-%d", time.Now().UnixMicro())
t.CreateF(ctx, &coreapi.Namespace{
Expand All @@ -154,7 +154,7 @@ func (t *TestSuite) Initialize(ctx context.Context) {
})
}

func (t *TestSuite) IsUsingDevPorch() (bool, bool) {
func (t *TestSuite) IsPorchServerInCluster() bool {
porch := aggregatorv1.APIService{}
ctx := context.TODO()
t.GetF(ctx, client.ObjectKey{
Expand All @@ -166,19 +166,33 @@ func (t *TestSuite) IsUsingDevPorch() (bool, bool) {
Name: porch.Spec.Service.Name,
}, &service)

isPorchLocal := len(service.Spec.Selector) == 0
areAllLocal := service.Spec.Type == coreapi.ServiceTypeExternalName
return isPorchLocal, areAllLocal
return len(service.Spec.Selector) > 0
}

func (t *TestSuite) IsTestRunnerInCluster() bool {
porch := aggregatorv1.APIService{}
ctx := context.TODO()
t.GetF(ctx, client.ObjectKey{
Name: "v1alpha1.porch.kpt.dev",
}, &porch)
service := coreapi.Service{}
err := t.client.Get(ctx, client.ObjectKey{
Namespace: porch.Spec.Service.Namespace,
Name: "function-runner",
}, &service)
if err != nil {
return false
}
return len(service.Spec.Selector) > 0
}

func (t *TestSuite) CreateGitRepo() GitConfig {
// Deploy Git server via k8s client.
t.Logf("creating git server in cluster")
isPorchLocal, areAllLocal := t.IsUsingDevPorch()
if areAllLocal {
return createLocalGitServer(t.T)
if t.IsTestRunnerInCluster() {
return t.createInClusterGitServer(context.TODO(), !t.IsPorchServerInCluster())
} else {
return t.createInClusterGitServer(context.TODO(), isPorchLocal)
return createLocalGitServer(t.T)
}
}

Expand Down

0 comments on commit 2dc1e6b

Please sign in to comment.