Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 70 additions & 8 deletions test/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"strings"
"os"
// "time"
"time"
"github.com/cloudposse/test-helpers/pkg/atmos"
"github.com/cloudposse/test-helpers/pkg/helm"
awsHelper "github.com/cloudposse/test-helpers/pkg/aws"
Expand All @@ -17,13 +17,13 @@ import (
"github.com/stretchr/testify/assert"

// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// corev1 "k8s.io/api/core/v1"
// "k8s.io/apimachinery/pkg/runtime/schema"
// "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

// "k8s.io/client-go/dynamic"
// "k8s.io/client-go/dynamic/dynamicinformer"
// "k8s.io/client-go/tools/cache"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic/dynamicinformer"
"k8s.io/client-go/tools/cache"
)

type ComponentSuite struct {
Expand All @@ -48,7 +48,7 @@ func (s *ComponentSuite) TestBasic() {

randomID := strings.ToLower(random.UniqueId())

namespace := fmt.Sprintf("external-secrets-%s", randomID)
namespace := fmt.Sprintf("acttions-runners-%s", randomID)
secretPathPrefix := fmt.Sprintf("test-%s", randomID)
secretGithubPATPath := fmt.Sprintf("/%s/token", secretPathPrefix)
secretWebhookPath := fmt.Sprintf("/%s/webhook", secretPathPrefix)
Expand Down Expand Up @@ -141,6 +141,68 @@ func (s *ComponentSuite) TestBasic() {
assert.Equal(s.T(), runnerMetadata.Version, "0.3.2")


config, err := awsHelper.NewK8SClientConfig(cluster)
assert.NoError(s.T(), err)
assert.NotNil(s.T(), config)

dynamicClient, err := dynamic.NewForConfig(config)
if err != nil {
panic(fmt.Errorf("failed to create dynamic client: %v", err))
}

// Define the GroupVersionResource for the Runners CRD
runnersGVR := schema.GroupVersionResource{
Group: "actions.summerwind.dev",
Version: "v1alpha1",
Resource: "runners",
}

factory := dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynamicClient, time.Minute, corev1.NamespaceAll, nil)
informer := factory.ForResource(runnersGVR).Informer()

stopChannel := make(chan struct{})

informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(oldObj, newObj interface{}) {
runner := newObj.(*unstructured.Unstructured)

if !strings.HasPrefix(runner.GetName(), "infra-runner") || runner.GetNamespace() != namespace {
fmt.Printf("runner name is not 'infra-runner', it is '%s'\n", runner.GetName())
return
}

phase, found, err := unstructured.NestedString(runner.Object, "status", "phase")

if err != nil || !found {
fmt.Println("Error retrieving conditions from status phase")
return
}

ready, found, err := unstructured.NestedBool(runner.Object, "status", "ready")

if err != nil || !found {
fmt.Println("Error retrieving conditions from status ready")
return
}

if phase == "Running" && ready == true {
close(stopChannel) // Stop the informer if the external secret is ready
}
},
})

go informer.Run(stopChannel)

select {
case <-stopChannel:
msg := "runner is ready"
fmt.Println(msg)
case <-time.After(2 * time.Minute):
defer close(stopChannel)
msg := "runner is not ready"
assert.Fail(s.T(), msg)
}

client := github.NewClient(nil).WithAuthToken(token)

runners, _, err := client.Actions.ListOrganizationRunners(context.Background(), githubOrg, nil)
Expand Down