66 "fmt"
77 "strings"
88 "os"
9- // "time"
9+ "time"
1010 "github.com/cloudposse/test-helpers/pkg/atmos"
1111 "github.com/cloudposse/test-helpers/pkg/helm"
1212 awsHelper "github.com/cloudposse/test-helpers/pkg/aws"
@@ -17,13 +17,13 @@ import (
1717 "github.com/stretchr/testify/assert"
1818
1919 // metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20- // corev1 "k8s.io/api/core/v1"
21- // "k8s.io/apimachinery/pkg/runtime/schema"
22- // "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
20+ corev1 "k8s.io/api/core/v1"
21+ "k8s.io/apimachinery/pkg/runtime/schema"
22+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2323
24- // "k8s.io/client-go/dynamic"
25- // "k8s.io/client-go/dynamic/dynamicinformer"
26- // "k8s.io/client-go/tools/cache"
24+ "k8s.io/client-go/dynamic"
25+ "k8s.io/client-go/dynamic/dynamicinformer"
26+ "k8s.io/client-go/tools/cache"
2727)
2828
2929type ComponentSuite struct {
@@ -48,7 +48,7 @@ func (s *ComponentSuite) TestBasic() {
4848
4949 randomID := strings .ToLower (random .UniqueId ())
5050
51- namespace := fmt .Sprintf ("external-secrets -%s" , randomID )
51+ namespace := fmt .Sprintf ("acttions-runners -%s" , randomID )
5252 secretPathPrefix := fmt .Sprintf ("test-%s" , randomID )
5353 secretGithubPATPath := fmt .Sprintf ("/%s/token" , secretPathPrefix )
5454 secretWebhookPath := fmt .Sprintf ("/%s/webhook" , secretPathPrefix )
@@ -140,6 +140,69 @@ func (s *ComponentSuite) TestBasic() {
140140 assert .NotNil (s .T (), runnerMetadata .Values )
141141 assert .Equal (s .T (), runnerMetadata .Version , "0.3.2" )
142142
143+
144+ config , err := awsHelper .NewK8SClientConfig (cluster )
145+ assert .NoError (s .T (), err )
146+ assert .NotNil (s .T (), config )
147+
148+ dynamicClient , err := dynamic .NewForConfig (config )
149+ if err != nil {
150+ panic (fmt .Errorf ("failed to create dynamic client: %v" , err ))
151+ }
152+
153+ // Define the GroupVersionResource for the Runners CRD
154+ runnersGVR := schema.GroupVersionResource {
155+ Group : "actions.summerwind.dev" ,
156+ Version : "v1alpha1" ,
157+ Resource : "runners" ,
158+ }
159+
160+ factory := dynamicinformer .NewFilteredDynamicSharedInformerFactory (dynamicClient , time .Minute , corev1 .NamespaceAll , nil )
161+ informer := factory .ForResource (runnersGVR ).Informer ()
162+
163+ stopChannel := make (chan struct {})
164+
165+ informer .AddEventHandler (cache.ResourceEventHandlerFuncs {
166+ UpdateFunc : func (oldObj , newObj interface {}) {
167+ runner := newObj .(* unstructured.Unstructured )
168+
169+ if ! strings .HasPrefix (runner .GetName (), "infra-runner" ) || runner .GetNamespace () != namespace {
170+ fmt .Printf ("runner name is not 'infra-runner', it is '%s'\n " , runner .GetName ())
171+ return
172+ }
173+
174+ phase , found , err := unstructured .NestedString (runner .Object , "status" , "phase" )
175+
176+ if err != nil || ! found {
177+ fmt .Println ("Error retrieving conditions from status phase" )
178+ return
179+ }
180+
181+ ready , found , err := unstructured .NestedBool (runner .Object , "status" , "ready" )
182+
183+ if err != nil || ! found {
184+ fmt .Println ("Error retrieving conditions from status ready" )
185+ return
186+ }
187+
188+ if phase == "Running" && ready == true {
189+ close (stopChannel ) // Stop the informer if the external secret is ready
190+ }
191+ },
192+ })
193+
194+ go informer .Run (stopChannel )
195+
196+ select {
197+ case <- stopChannel :
198+ msg := "runner is ready"
199+ fmt .Println (msg )
200+ case <- time .After (2 * time .Minute ):
201+ defer close (stopChannel )
202+ msg := "runner is not ready"
203+ assert .Fail (s .T (), msg )
204+ }
205+
143206 client := github .NewClient (nil ).WithAuthToken (token )
144207
145208 runners , _ , err := client .Actions .ListOrganizationRunners (context .Background (), githubOrg , nil )
0 commit comments