Skip to content

Commit f407c88

Browse files
committed
fix(ci): wait for longhorn node resource
Wait for longhorn node resource before checking resource status. Signed-off-by: Noel Georgi <[email protected]>
1 parent 601cdcc commit f407c88

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

internal/integration/base/k8s.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,18 @@ func (k8sSuite *K8sSuite) WaitForResource(ctx context.Context, namespace, group,
637637
return nil
638638
}
639639

640+
// WaitForResourceToBeAvailable waits for the resource with the given namespace, group, kind, version and name to be available.
641+
func (k8sSuite *K8sSuite) WaitForResourceToBeAvailable(ctx context.Context, duration time.Duration, namespace, group, kind, version, resourceName string) error {
642+
return retry.Constant(duration).Retry(func() error {
643+
_, err := k8sSuite.GetUnstructuredResource(ctx, namespace, group, kind, version, resourceName)
644+
if errors.IsNotFound(err) {
645+
return retry.ExpectedError(err)
646+
}
647+
648+
return err
649+
})
650+
}
651+
640652
// GetUnstructuredResource gets the unstructured resource with the given namespace, group, kind, version and name.
641653
func (k8sSuite *K8sSuite) GetUnstructuredResource(ctx context.Context, namespace, group, kind, version, resourceName string) (*unstructured.Unstructured, error) {
642654
mapping, err := k8sSuite.Mapper.RESTMapping(schema.GroupKind{

internal/integration/k8s/longhorn.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ func (suite *LongHornSuite) TestDeploy() {
9797
k8sNode, err := suite.GetK8sNodeByInternalIP(ctx, node)
9898
suite.Require().NoError(err)
9999

100+
suite.Require().NoError(suite.WaitForResourceToBeAvailable(ctx, 2*time.Minute, "longhorn-system", "longhorn.io", "Node", "v1beta2", k8sNode.Name))
101+
100102
suite.Require().NoError(suite.WaitForResource(ctx, "longhorn-system", "longhorn.io", "Node", "v1beta2", k8sNode.Name, "{.status.diskStatus.*.conditions[?(@.type==\"Ready\")].status}", "True"))
101103
suite.Require().NoError(suite.WaitForResource(ctx, "longhorn-system", "longhorn.io", "Node", "v1beta2", k8sNode.Name, "{.status.diskStatus.*.conditions[?(@.type==\"Schedulable\")].status}", "True"))
102104

0 commit comments

Comments
 (0)