Skip to content

Commit 9794bfa

Browse files
committed
Wait for the project's spec.{clusterName,displayName} to be set
There seems to be a bit of a delay between when a project is created and when these values exist. This is more likely to show up in CI than locally, sure sounds like a timing issue.
1 parent 6ee3130 commit 9794bfa

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pkg/sqlcache/integration_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,43 @@ func waitForObjectsBySchema(ctx context.Context, proxyStore *sqlproxy.Store, sch
540540
})
541541
}
542542

543+
// Do not call this if there are no projects -- the function will run until it times out.
544+
func waitForProjectsDisplayName(ctx context.Context, proxyStore *sqlproxy.Store, schema *types.APISchema) error {
545+
return wait.PollUntilContextCancel(ctx, time.Second*10, true, func(ctx context.Context) (done bool, err error) {
546+
req, err := http.NewRequest("GET", "http://localhost:8080", nil)
547+
if err != nil {
548+
return false, err
549+
}
550+
apiOp := &types.APIRequest{
551+
Request: req,
552+
}
553+
partitions := []partition.Partition{defaultPartition}
554+
list, total, _, err := proxyStore.ListByPartitions(apiOp, schema, partitions)
555+
if err != nil || total == 0 {
556+
// note that we don't return the error since that would stop the polling
557+
return false, nil
558+
}
559+
// Moving on, if there are errors return them
560+
for _, item := range list.Items {
561+
displayName, ok, err := unstructured.NestedFieldNoCopy(item.Object, "spec", "displayName")
562+
if !ok || displayName == "" || err != nil {
563+
if err == nil && ok {
564+
fmt.Printf("No displayName yet for mcio.project %q\n", item.GetName())
565+
}
566+
return false, err
567+
}
568+
clusterName, ok, err := unstructured.NestedFieldNoCopy(item.Object, "spec", "clusterName")
569+
if !ok || clusterName == "" || err != nil {
570+
if err == nil {
571+
fmt.Printf("No clusterName yet for mcio.project %q\n", item.GetName())
572+
}
573+
return false, err
574+
}
575+
}
576+
return true, nil
577+
})
578+
}
579+
543580
type ResetFunc func(k8sschema.GroupVersionKind) error
544581

545582
func (f ResetFunc) Reset(gvk k8sschema.GroupVersionKind) error {
@@ -1131,6 +1168,8 @@ func (i *IntegrationSuite) TestNamespaceProjectDependencies() {
11311168
requireT.NoError(err)
11321169
err = waitForObjectsBySchema(ctx, proxyStore, nsSchema, labelTest, len(namespaceInfo))
11331170
requireT.NoError(err)
1171+
err = waitForProjectsDisplayName(ctx, proxyStore, mcioSchema)
1172+
requireT.NoError(err)
11341173

11351174
partitions := []partition.Partition{defaultPartition}
11361175
for _, test := range tests {
@@ -1211,12 +1250,14 @@ func (i *IntegrationSuite) TestSecretProjectDependencies() {
12111250
err = ctrl.Start(ctx)
12121251
requireT.NoError(err)
12131252
secretInfo := [][2]string{
1253+
// metadata.name, metadata.projects[management.cattle.io/project-scoped-secret]
12141254
{"morocco", "rabat"},
12151255
{"eritrea", "asmara"},
12161256
{"kenya", "nairobi"},
12171257
{"benin", "portonovo"},
12181258
}
12191259
projectInfo := [][3]string{
1260+
// metadata.name, spec.clusterName, spec.displayName
12201261
{"rabat", "arabic", "casablanca"},
12211262
{"asmara", "tigrinya", "keren"},
12221263
{"nairobi", "english", "mombasa"},
@@ -1308,6 +1349,8 @@ func (i *IntegrationSuite) TestSecretProjectDependencies() {
13081349
requireT.NoError(err)
13091350
err = waitForObjectsBySchema(ctx, proxyStore, secretSchema, labelTest, len(secretInfo))
13101351
requireT.NoError(err)
1352+
err = waitForProjectsDisplayName(ctx, proxyStore, mcioSchema)
1353+
requireT.NoError(err)
13111354

13121355
partitions := []partition.Partition{defaultPartition}
13131356
for _, test := range tests {

0 commit comments

Comments
 (0)