From c4b138d498107d5803efe2b59d05b08a6cce5de0 Mon Sep 17 00:00:00 2001 From: Kit Patella Date: Tue, 10 Sep 2024 10:42:09 -0700 Subject: [PATCH] fix(pkg/cluster): partially revert 9c8e3e18eccc3a925509f4a6e335055ca32b5347 to remove changes to PackageSecretNeedsWait Signed-off-by: Kit Patella --- src/pkg/cluster/zarf.go | 21 ++++++++++----------- src/pkg/cluster/zarf_test.go | 12 +++++++++++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/pkg/cluster/zarf.go b/src/pkg/cluster/zarf.go index a9851a29f3..eebbd6d295 100644 --- a/src/pkg/cluster/zarf.go +++ b/src/pkg/cluster/zarf.go @@ -109,29 +109,28 @@ func (c *Cluster) StripZarfLabelsAndSecretsFromNamespaces(ctx context.Context) { spinner.Success() } -// PackageSecretNeedsWait checks if a package component has a running webhook that needs to be waited on. Returns the -// number of seconds remaining to wait and the name of the webhook. If seconds is zero there's no need to wait. -func (c *Cluster) PackageSecretNeedsWait(deployedPackage *types.DeployedPackage, component v1alpha1.ZarfComponent, skipWebhooks bool) (int, string) { +// PackageSecretNeedsWait checks if a package component has a running webhook that needs to be waited on. +func (c *Cluster) PackageSecretNeedsWait(deployedPackage *types.DeployedPackage, component v1alpha1.ZarfComponent, skipWebhooks bool) (needsWait bool, waitSeconds int, hookName string) { // Skip checking webhook status when '--skip-webhooks' flag is provided and for YOLO packages if skipWebhooks || deployedPackage == nil || deployedPackage.Data.Metadata.YOLO { - return 0, "" + return false, 0, "" } // Look for the specified component hookMap, componentExists := deployedPackage.ComponentWebhooks[component.Name] if !componentExists { - return 0, "" // Component not found, no need to wait + return false, 0, "" // Component not found, no need to wait } // Check if there are any "Running" webhooks for the component that we need to wait for for hookName, webhook := range hookMap { if webhook.Status == types.WebhookStatusRunning { - return webhook.WaitDurationSeconds, hookName + return true, webhook.WaitDurationSeconds, hookName } } // If we get here, the component doesn't need to wait for a webhook to run - return 0, "" + return false, 0, "" } // RecordPackageDeploymentAndWait records the deployment of a package to the cluster and waits for any webhooks to complete. @@ -141,9 +140,9 @@ func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg v1alph return nil, err } - waitSeconds, hookName := c.PackageSecretNeedsWait(deployedPackage, component, skipWebhooks) + packageNeedsWait, waitSeconds, hookName := c.PackageSecretNeedsWait(deployedPackage, component, skipWebhooks) // If no webhooks need to complete, we can return immediately. - if waitSeconds == 0 { + if !packageNeedsWait { return deployedPackage, nil } @@ -161,8 +160,8 @@ func (c *Cluster) RecordPackageDeploymentAndWait(ctx context.Context, pkg v1alph if err != nil { return nil, err } - waitSeconds, _ = c.PackageSecretNeedsWait(deployedPackage, component, skipWebhooks) - if waitSeconds == 0 { + packageNeedsWait, _, _ = c.PackageSecretNeedsWait(deployedPackage, component, skipWebhooks) + if !packageNeedsWait { return deployedPackage, nil } return deployedPackage, nil diff --git a/src/pkg/cluster/zarf_test.go b/src/pkg/cluster/zarf_test.go index 89b9c26e1a..d2f3aefcde 100644 --- a/src/pkg/cluster/zarf_test.go +++ b/src/pkg/cluster/zarf_test.go @@ -30,6 +30,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { deployedPackage *types.DeployedPackage component v1alpha1.ZarfComponent skipWebhooks bool + needsWait bool waitSeconds int hookName string } @@ -48,6 +49,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { Name: packageName, ComponentWebhooks: map[string]map[string]types.Webhook{}, }, + needsWait: false, waitSeconds: 0, hookName: "", }, @@ -65,6 +67,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, }, }, + needsWait: true, waitSeconds: 10, hookName: webhookName, }, @@ -83,6 +86,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, }, }, + needsWait: false, waitSeconds: 0, hookName: "", }, @@ -99,6 +103,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, }, }, + needsWait: false, waitSeconds: 0, hookName: "", }, @@ -115,6 +120,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, }, }, + needsWait: false, waitSeconds: 0, hookName: "", }, @@ -131,6 +137,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, }, }, + needsWait: false, waitSeconds: 0, hookName: "", }, @@ -153,6 +160,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, }, }, + needsWait: false, waitSeconds: 0, hookName: "", }, @@ -171,6 +179,7 @@ func TestPackageSecretNeedsWait(t *testing.T) { }, }, }, + needsWait: false, waitSeconds: 0, hookName: "", }, @@ -184,8 +193,9 @@ func TestPackageSecretNeedsWait(t *testing.T) { c := &Cluster{} - waitSeconds, hookName := c.PackageSecretNeedsWait(testCase.deployedPackage, testCase.component, testCase.skipWebhooks) + needsWait, waitSeconds, hookName := c.PackageSecretNeedsWait(testCase.deployedPackage, testCase.component, testCase.skipWebhooks) + require.Equal(t, testCase.needsWait, needsWait) require.Equal(t, testCase.waitSeconds, waitSeconds) require.Equal(t, testCase.hookName, hookName) })