Skip to content

Commit 0c6b0b4

Browse files
committed
Replace informers with sleep timeout
1 parent e13e1e5 commit 0c6b0b4

File tree

1 file changed

+64
-63
lines changed

1 file changed

+64
-63
lines changed

test/component_test.go

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2121

2222
"k8s.io/client-go/dynamic"
23-
"k8s.io/client-go/dynamic/dynamicinformer"
24-
"k8s.io/client-go/tools/cache"
23+
// "k8s.io/client-go/dynamic/dynamicinformer"
24+
// "k8s.io/client-go/tools/cache"
2525
)
2626

2727
type ComponentSuite struct {
@@ -127,67 +127,68 @@ func (s *ComponentSuite) TestBasic() {
127127
}
128128
}()
129129

130-
131-
// // Wait for the DnsEndpoint to be updated with the LoadBalancer metadata
132-
factory := dynamicinformer.NewDynamicSharedInformerFactory(dynamicClient, 0)
133-
// Create an informer for the DNSEndpoint resource
134-
informer := factory.ForResource(dnsEndpointGVR).Informer()
135-
136-
137-
stopChannel := make(chan struct{})
138-
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
139-
UpdateFunc: func(oldObj, newObj interface{}) {
140-
_, ok := oldObj.(*unstructured.Unstructured)
141-
if !ok {
142-
return
143-
}
144-
newDNS, ok := newObj.(*unstructured.Unstructured)
145-
if !ok {
146-
return
147-
}
148-
149-
name, found, err := unstructured.NestedString(newDNS.Object, "metadata", "name")
150-
if err != nil {
151-
fmt.Printf("Error getting name: %v\n", err)
152-
return
153-
}
154-
if !found {
155-
fmt.Printf("Name not found\n")
156-
return
157-
}
158-
if name != dnsEndpointName {
159-
fmt.Printf("DNS record is not %s\n", dnsEndpointName)
160-
return
161-
}
162-
163-
observedGeneration, found, err := unstructured.NestedInt64(newDNS.Object, "status", "observedGeneration")
164-
if err != nil {
165-
fmt.Printf("Error getting status: %v\n", err)
166-
return
167-
}
168-
if !found {
169-
fmt.Printf("Status not found\n")
170-
return
171-
}
172-
173-
if observedGeneration > 0 {
174-
fmt.Printf("Dns Record %s is ready\n", name)
175-
close(stopChannel)
176-
} else {
177-
fmt.Printf("Dns Record %s is not ready yet\n", name)
178-
}
179-
},
180-
})
181-
go informer.Run(stopChannel)
182-
183-
select {
184-
case <-stopChannel:
185-
msg := "Dns endpoint created"
186-
fmt.Println(msg)
187-
case <-time.After(1 * time.Minute):
188-
msg := "Dns endpoint creation timed out"
189-
assert.Fail(s.T(), msg)
190-
}
130+
time.Sleep(2 * time.Minute)
131+
132+
// // // Wait for the DnsEndpoint to be updated with the LoadBalancer metadata
133+
// factory := dynamicinformer.NewDynamicSharedInformerFactory(dynamicClient, 0)
134+
// // Create an informer for the DNSEndpoint resource
135+
// informer := factory.ForResource(dnsEndpointGVR).Informer()
136+
137+
138+
// stopChannel := make(chan struct{})
139+
// informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
140+
// UpdateFunc: func(oldObj, newObj interface{}) {
141+
// _, ok := oldObj.(*unstructured.Unstructured)
142+
// if !ok {
143+
// return
144+
// }
145+
// newDNS, ok := newObj.(*unstructured.Unstructured)
146+
// if !ok {
147+
// return
148+
// }
149+
150+
// name, found, err := unstructured.NestedString(newDNS.Object, "metadata", "name")
151+
// if err != nil {
152+
// fmt.Printf("Error getting name: %v\n", err)
153+
// return
154+
// }
155+
// if !found {
156+
// fmt.Printf("Name not found\n")
157+
// return
158+
// }
159+
// if name != dnsEndpointName {
160+
// fmt.Printf("DNS record is not %s\n", dnsEndpointName)
161+
// return
162+
// }
163+
164+
// observedGeneration, found, err := unstructured.NestedInt64(newDNS.Object, "status", "observedGeneration")
165+
// if err != nil {
166+
// fmt.Printf("Error getting status: %v\n", err)
167+
// return
168+
// }
169+
// if !found {
170+
// fmt.Printf("Status not found\n")
171+
// return
172+
// }
173+
174+
// if observedGeneration > 0 {
175+
// fmt.Printf("Dns Record %s is ready\n", name)
176+
// close(stopChannel)
177+
// } else {
178+
// fmt.Printf("Dns Record %s is not ready yet\n", name)
179+
// }
180+
// },
181+
// })
182+
// go informer.Run(stopChannel)
183+
184+
// select {
185+
// case <-stopChannel:
186+
// msg := "Dns endpoint created"
187+
// fmt.Println(msg)
188+
// case <-time.After(1 * time.Minute):
189+
// msg := "Dns endpoint creation timed out"
190+
// assert.Fail(s.T(), msg)
191+
// }
191192

192193
delegatedNSRecord := awsTerratest.GetRoute53Record(s.T(), defaultDNSZoneId, dnsRecordHostName, "A", awsRegion)
193194
assert.Equal(s.T(), fmt.Sprintf("%s.", dnsRecordHostName), *delegatedNSRecord.Name)

0 commit comments

Comments
 (0)