Skip to content

Commit ade37d0

Browse files
fix(wait): ensure cluster is connectable in loop (#4616)
Signed-off-by: Austin Abro <austinabro321@gmail.com> Signed-off-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Co-authored-by: Brandt Keller <43887158+brandtkeller@users.noreply.github.com>
1 parent a97a755 commit ade37d0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/pkg/packager/layout/package_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/stretchr/testify/require"
1616

1717
"github.com/zarf-dev/zarf/src/api/v1alpha1"
18-
"github.com/zarf-dev/zarf/src/config"
1918
"github.com/zarf-dev/zarf/src/pkg/feature"
2019
"github.com/zarf-dev/zarf/src/pkg/utils"
2120
"github.com/zarf-dev/zarf/src/test/testutil"
@@ -76,7 +75,6 @@ func TestPackageLayout(t *testing.T) {
7675

7776
func TestPackageFileName(t *testing.T) {
7877
t.Parallel()
79-
config.CLIArch = "amd64"
8078
tests := []struct {
8179
name string
8280
pkg v1alpha1.ZarfPackage

src/pkg/wait/wait.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func ForResource(ctx context.Context, kind, identifier, condition, namespace str
5050
// Wait for the cluster to become available by polling for a successful REST config.
5151
var restConfig *rest.Config
5252
var clientCfg clientcmd.ClientConfig
53+
var discoveryClient *discovery.DiscoveryClient
5354
err := wait.PollUntilContextTimeout(ctx, waitInterval, timeout, true, func(_ context.Context) (bool, error) {
5455
var err error
5556
loader := clientcmd.NewDefaultClientConfigLoadingRules()
@@ -59,24 +60,28 @@ func ForResource(ctx context.Context, kind, identifier, condition, namespace str
5960
l.Debug("failed to get REST config, retrying", "error", err)
6061
return false, nil
6162
}
63+
discoveryClient, err = discovery.NewDiscoveryClientForConfig(restConfig)
64+
if err != nil {
65+
l.Debug("failed to get discovery client, retrying", "error", err)
66+
return false, nil
67+
}
68+
_, err = discoveryClient.ServerVersion()
69+
if err != nil {
70+
l.Debug("cluster not reachable, retrying", "error", err)
71+
return false, nil
72+
}
6273
return true, nil
6374
})
6475
if err != nil {
6576
return fmt.Errorf("timed out waiting for REST config: %w", err)
6677
}
6778

68-
discoveryClient, err := discovery.NewDiscoveryClientForConfig(restConfig)
69-
if err != nil {
70-
return fmt.Errorf("failed to create discovery client: %w", err)
71-
}
72-
7379
// Wait for the resource kind to be resolvable (e.g. CRDs may not be registered yet).
7480
var mapping *meta.RESTMapping
7581
err = wait.PollUntilContextTimeout(ctx, waitInterval, time.Until(deadline), true, func(_ context.Context) (bool, error) {
7682
groupResources, err := restmapper.GetAPIGroupResources(discoveryClient)
7783
if err != nil {
78-
l.Debug("failed to get API group resources, retrying", "error", err)
79-
return false, nil
84+
return true, fmt.Errorf("failed to get API group resources: %w", err)
8085
}
8186
restMapper := restmapper.NewShortcutExpander(restmapper.NewDiscoveryRESTMapper(groupResources), discoveryClient, nil)
8287
mapping, err = resolveResourceKind(restMapper, kind)

0 commit comments

Comments
 (0)