Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add noWait field to yaml for manifests and charts #816

Merged
merged 13 commits into from
Oct 5, 2022
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ build-examples:

@test -s ./build/zarf-package-flux-test-$(ARCH).tar.zst || $(ZARF_BIN) package create examples/flux-test -o build -a $(ARCH) --confirm

@test -s ./build/zarf-package-test-helm-wait-$(ARCH).tar.zst || $(ZARF_BIN) package create examples/helm-no-wait -o build -a $(ARCH) --confirm

## Run e2e tests. Will automatically build any required dependencies that aren't present.
## Requires an existing cluster for the env var APPLIANCE_MODE=true
.PHONY: test-e2e
Expand Down
30 changes: 30 additions & 0 deletions docs/4-user-guide/3-zarf-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,21 @@ Must be one of:
</blockquote>
</details>

<details>
<summary><strong> <a name="components_items_charts_items_noWait"></a>noWait</strong>

</summary>
&nbsp;
<blockquote>

**Description:** Wait for chart resources to be ready before continuing

| Type | `boolean` |
| ---- | --------- |

</blockquote>
</details>

</blockquote>
</details>

Expand Down Expand Up @@ -1078,6 +1093,21 @@ Must be one of:
</blockquote>
</details>

<details>
<summary><strong> <a name="components_items_manifests_items_noWait"></a>noWait</strong>

</summary>
&nbsp;
<blockquote>

**Description:** Wait for manifest resources to be ready before continuing

| Type | `boolean` |
| ---- | --------- |

</blockquote>
</details>

</blockquote>
</details>

Expand Down
17 changes: 17 additions & 0 deletions examples/helm-no-wait/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Helm Alt Release Name
corang marked this conversation as resolved.
Show resolved Hide resolved

This example shows how you can specify for zarf to not wait for resources to report ready within a component's `manifests`. This is also applicable to `charts`.

:::info

To view the example source code, select the `Edit this page` link below the article and select the parent folder.

:::

```
components:
- name: component-name
manifests:
- name: chart-name
noWait: true
```
23 changes: 23 additions & 0 deletions examples/helm-no-wait/never-ready.pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Pod
metadata:
name: never-ready-zarf-wait-test
spec:
containers:
- name: alpine
image: alpine:latest
command:
- "sleep"
- "infinity"
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
readinessProbe:
exec:
command:
- "exit"
- "1"
corang marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions examples/helm-no-wait/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
kind: ZarfPackageConfig
metadata:
name: test-helm-wait
description: "Deploys a pod which never becomes ready"
components:
- name: zarf-helm-no-wait
required: true
manifests:
- name: never-ready
namespace: no-wait
noWait: true
files:
- never-ready.pod.yaml
images:
- alpine:latest

8 changes: 4 additions & 4 deletions src/internal/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type ChartOptions struct {
ChartOverride *chart.Chart
ValueOverride map[string]any
Component types.ZarfComponent
NoWait bool
}

// InstallOrUpgradeChart performs a helm install of the given chart
Expand All @@ -53,7 +52,7 @@ func InstallOrUpgradeChart(options ChartOptions) (types.ConnectStrings, string)
// Do not wait for the chart to be ready if data injections are present
if len(options.Component.DataInjections) > 0 {
spinner.Updatef("Data injections detected, not waiting for chart to be ready")
options.NoWait = true
options.Chart.NoWait = true
}

actionConfig, err := createActionConfig(options.Chart.Namespace, spinner)
Expand Down Expand Up @@ -207,6 +206,7 @@ func GenerateChart(basePath string, manifest types.ZarfManifest, component types
ReleaseName: sha1ReleaseName,
Version: tmpChart.Metadata.Version,
Namespace: manifest.Namespace,
NoWait: manifest.NoWait,
},
ChartOverride: tmpChart,
// We don't have any values because we do not expose them in the zarf.yaml currently
Expand All @@ -229,7 +229,7 @@ func installChart(actionConfig *action.Configuration, options ChartOptions, post
client.Timeout = 15 * time.Minute

// Default helm behavior for Zarf is to wait for the resources to deploy, NoWait overrides that for special cases (such as data-injection)
client.Wait = !options.NoWait
client.Wait = !options.Chart.NoWait

// We need to include CRDs or operator installations will fail spectacularly
client.SkipCRDs = false
Expand Down Expand Up @@ -260,7 +260,7 @@ func upgradeChart(actionConfig *action.Configuration, options ChartOptions, post
client.Timeout = 15 * time.Minute

// Default helm behavior for Zarf is to wait for the resources to deploy, NoWait overrides that for special cases (such as data-injection)k3
client.Wait = !options.NoWait
client.Wait = !options.Chart.NoWait

client.SkipCRDs = true

Expand Down
69 changes: 69 additions & 0 deletions src/test/e2e/28_wait_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package test

import (
// "context"
"fmt"
"os/exec"
"time"

// "os/exec"
"testing"

// "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type zarfCommandResult struct {
stdOut string
stdErr string
err error
}

func zarfCommandWStruct(e2e ZarfE2ETest, path string) (result zarfCommandResult) {
result.stdOut, result.stdErr, result.err = e2e.execZarfCommand("package", "deploy", path, "--confirm")
return result
}

func TestWait(t *testing.T) {
t.Log("E2E: Helm Wait")
e2e.setup(t)
defer e2e.teardown(t)

path := fmt.Sprintf("build/zarf-package-test-helm-wait-%s.tar.zst", e2e.arch)

zarfChannel := make(chan zarfCommandResult, 1)
corang marked this conversation as resolved.
Show resolved Hide resolved
go func() {
zarfChannel <- zarfCommandWStruct(e2e, path)
}()

var stdOut string
var stdErr string
var err error

select{
case res := <-zarfChannel:
stdOut = res.stdOut
stdErr = res.stdErr
err = res.err
case <-time.After(10 * time.Second):
t.Error("Timeout waiting for zarf deploy (it tried to wait)")
t.Log("Removing hanging namespace...")
kubectlOut, err := exec.Command("kubectl", "delete", "namespace", "no-wait", "--force=true", "--wait=false", "--grace-period=0").Output()
if err != nil {
t.Log(kubectlOut)
} else {
panic(err)
}
}

// Deploy the charts
// stdOut, stdErr, err := e2e.execZarfCommand("package", "deploy", path, "--confirm")
require.NoError(t, err, stdOut, stdErr)

// // Verify multiple helm installs of different release names were deployed
// kubectlOut, _ := exec.Command("kubectl", "get", "pods", "-n=helm-releasename", "--no-headers").Output()
corang marked this conversation as resolved.
Show resolved Hide resolved
// assert.Contains(t, string(kubectlOut), "zarf-cool-name-podinfo")

stdOut, stdErr, err = e2e.execZarfCommand("package", "remove", "test-helm-wait", "--confirm")
require.NoError(t, err, stdOut, stdErr)
}
corang marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/types/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ZarfChart struct {
Namespace string `json:"namespace" jsonschema:"description=The namespace to deploy the chart to"`
ValuesFiles []string `json:"valuesFiles,omitempty" jsonschema:"description=List of values files to include in the package, these will be merged together"`
GitPath string `json:"gitPath,omitempty" jsonschema:"description=If using a git repo, the path to the chart in the repo"`
NoWait bool `json:"noWait,omitempty" jsonschema:"description=Wait for chart resources to be ready before continuing"`
}

// ZarfManifest defines raw manifests Zarf will deploy as a helm chart
Expand All @@ -87,6 +88,7 @@ type ZarfManifest struct {
Files []string `json:"files,omitempty" jsonschema:"description=List of individual K8s YAML files to deploy (in order)"`
KustomizeAllowAnyDirectory bool `json:"kustomizeAllowAnyDirectory,omitempty" jsonschema:"description=Allow traversing directory above the current directory if needed for kustomization"`
Kustomizations []string `json:"kustomizations,omitempty" jsonschema:"description=List of kustomization paths to include in the package"`
NoWait bool `json:"noWait,omitempty" jsonschema:"description=Wait for manifest resources to be ready before continuing"`
}

// ZarfComponentScripts are scripts that run before or after a component is deployed
Expand Down
10 changes: 10 additions & 0 deletions src/ui/lib/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export interface ZarfChart {
* The namespace to deploy the chart to
*/
namespace: string;
/**
* Wait for chart resources to be ready before continuing
*/
noWait?: boolean;
/**
* The name of the release to create
*/
Expand Down Expand Up @@ -248,6 +252,10 @@ export interface ZarfManifest {
* The namespace to deploy the manifests to
*/
namespace?: string;
/**
* Wait for manifest resources to be ready before continuing
*/
noWait?: boolean;
}

/**
Expand Down Expand Up @@ -789,6 +797,7 @@ const typeMap: any = {
{ json: "gitPath", js: "gitPath", typ: u(undefined, "") },
{ json: "name", js: "name", typ: "" },
{ json: "namespace", js: "namespace", typ: "" },
{ json: "noWait", js: "noWait", typ: u(undefined, true) },
{ json: "releaseName", js: "releaseName", typ: u(undefined, "") },
{ json: "url", js: "url", typ: "" },
{ json: "valuesFiles", js: "valuesFiles", typ: u(undefined, a("")) },
Expand Down Expand Up @@ -822,6 +831,7 @@ const typeMap: any = {
{ json: "kustomizeAllowAnyDirectory", js: "kustomizeAllowAnyDirectory", typ: u(undefined, true) },
{ json: "name", js: "name", typ: "" },
{ json: "namespace", js: "namespace", typ: u(undefined, "") },
{ json: "noWait", js: "noWait", typ: u(undefined, true) },
], false),
"ZarfComponentOnlyTarget": o([
{ json: "cluster", js: "cluster", typ: u(undefined, r("ZarfComponentOnlyCluster")) },
Expand Down
8 changes: 8 additions & 0 deletions zarf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
"gitPath": {
"type": "string",
"description": "If using a git repo"
},
"noWait": {
"type": "boolean",
"description": "Wait for chart resources to be ready before continuing"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -377,6 +381,10 @@
},
"type": "array",
"description": "List of kustomization paths to include in the package"
},
"noWait": {
"type": "boolean",
"description": "Wait for manifest resources to be ready before continuing"
}
},
"additionalProperties": false,
Expand Down