Skip to content

Commit

Permalink
fix(ci): wait for longhorn node resource
Browse files Browse the repository at this point in the history
Wait for longhorn node resource before checking resource status.

Signed-off-by: Noel Georgi <git@frezbo.dev>
  • Loading branch information
frezbo committed Jan 24, 2025
1 parent 601cdcc commit f407c88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/integration/base/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,18 @@ func (k8sSuite *K8sSuite) WaitForResource(ctx context.Context, namespace, group,
return nil
}

// WaitForResourceToBeAvailable waits for the resource with the given namespace, group, kind, version and name to be available.
func (k8sSuite *K8sSuite) WaitForResourceToBeAvailable(ctx context.Context, duration time.Duration, namespace, group, kind, version, resourceName string) error {
return retry.Constant(duration).Retry(func() error {
_, err := k8sSuite.GetUnstructuredResource(ctx, namespace, group, kind, version, resourceName)
if errors.IsNotFound(err) {
return retry.ExpectedError(err)
}

return err
})
}

// GetUnstructuredResource gets the unstructured resource with the given namespace, group, kind, version and name.
func (k8sSuite *K8sSuite) GetUnstructuredResource(ctx context.Context, namespace, group, kind, version, resourceName string) (*unstructured.Unstructured, error) {
mapping, err := k8sSuite.Mapper.RESTMapping(schema.GroupKind{
Expand Down
2 changes: 2 additions & 0 deletions internal/integration/k8s/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (suite *LongHornSuite) TestDeploy() {
k8sNode, err := suite.GetK8sNodeByInternalIP(ctx, node)
suite.Require().NoError(err)

suite.Require().NoError(suite.WaitForResourceToBeAvailable(ctx, 2*time.Minute, "longhorn-system", "longhorn.io", "Node", "v1beta2", k8sNode.Name))

suite.Require().NoError(suite.WaitForResource(ctx, "longhorn-system", "longhorn.io", "Node", "v1beta2", k8sNode.Name, "{.status.diskStatus.*.conditions[?(@.type==\"Ready\")].status}", "True"))
suite.Require().NoError(suite.WaitForResource(ctx, "longhorn-system", "longhorn.io", "Node", "v1beta2", k8sNode.Name, "{.status.diskStatus.*.conditions[?(@.type==\"Schedulable\")].status}", "True"))

Expand Down

0 comments on commit f407c88

Please sign in to comment.