-
Notifications
You must be signed in to change notification settings - Fork 190
feat: recording deployed component status in package deploy #3556
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
Merged
brandtkeller
merged 9 commits into
zarf-dev:main
from
sgettys:feat/deployed-component-status
Mar 10, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f935c16
feat: recording deployed component status in package deploy
sgettys b3f53e6
test: added e2e test for component status
sgettys fc67de0
test: added test timeout
sgettys 9d2aeef
test: increased timeout
sgettys b8a4ae7
Merge branch 'main' into feat/deployed-component-status
sgettys b03376a
fix: only attempt to record package deployment if connected to cluster
sgettys 61d54aa
chore: test lint fix
sgettys d8c928f
fix: added package generation to RecordPackageDeployment
sgettys f38c93b
Merge branch 'main' into feat/deployed-component-status
sgettys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
// Package test provides e2e tests for Zarf. | ||
package test | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"path/filepath" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/zarf-dev/zarf/src/types" | ||
) | ||
|
||
func TestComponentStatus(t *testing.T) { | ||
t.Log("E2E: Component Status") | ||
tmpDir := t.TempDir() | ||
_, _, err := e2e.Zarf(t, "package", "create", "src/test/packages/37-component-status", "-o", tmpDir, "--confirm") | ||
require.NoError(t, err) | ||
packageName := fmt.Sprintf("zarf-package-component-status-%s.tar.zst", e2e.Arch) | ||
path := filepath.Join(tmpDir, packageName) | ||
// Stop channel getting the zarf state | ||
stop := make(chan bool) | ||
// Error channel to return any errors from the goroutine. Testify doesn't like require in a goroutine | ||
errCh := make(chan error, 1) | ||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
// Goroutine to wait for the package to show "deploying" status | ||
go func() { | ||
defer wg.Done() | ||
// Give extra time to build and push the package | ||
ticker := time.NewTicker(30 * time.Second) | ||
for { | ||
select { | ||
case <-ticker.C: | ||
t.Log("Timed out waiting for package to deploy") | ||
errCh <- fmt.Errorf("timed out waiting for package to deploy") | ||
return | ||
case <-stop: | ||
sgettys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
default: | ||
stdOut, _, err := e2e.Kubectl(t, "get", "secret", "zarf-package-component-status", "-n", "zarf", "-o", "jsonpath={.data.data}") | ||
if err != nil { | ||
// Wait for the secret to be created and try again | ||
time.Sleep(2 * time.Second) | ||
continue | ||
} | ||
deployedPackage, err := getDeployedPackage(stdOut) | ||
if err != nil { | ||
errCh <- err | ||
return | ||
} | ||
if len(deployedPackage.DeployedComponents) != 1 { | ||
errCh <- fmt.Errorf("expected 1 component got %d", len(deployedPackage.DeployedComponents)) | ||
return | ||
} | ||
status := deployedPackage.DeployedComponents[0].Status | ||
if status != types.ComponentStatusDeploying { | ||
errCh <- fmt.Errorf("expected %s got %s", types.ComponentStatusDeploying, status) | ||
return | ||
} | ||
time.Sleep(2 * time.Second) | ||
return | ||
} | ||
} | ||
}() | ||
stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--confirm") | ||
require.NoError(t, err, stdOut, stdErr) | ||
close(stop) | ||
wg.Wait() | ||
select { | ||
case err := <-errCh: | ||
require.NoError(t, err) | ||
default: | ||
} | ||
// Verify that the component status is "succeeded" | ||
stdOut, stdErr, err = e2e.Kubectl(t, "get", "secret", "zarf-package-component-status", "-n", "zarf", "-o", "jsonpath={.data.data}") | ||
require.NoError(t, err, stdOut, stdErr) | ||
deployedPackage, err := getDeployedPackage(stdOut) | ||
require.NoError(t, err) | ||
require.Len(t, deployedPackage.DeployedComponents, 1) | ||
require.Equal(t, types.ComponentStatusSucceeded, deployedPackage.DeployedComponents[0].Status) | ||
// Remove the package | ||
t.Cleanup(func() { | ||
stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "component-status", "--confirm") | ||
require.NoError(t, err, stdOut, stdErr) | ||
}) | ||
} | ||
|
||
func getDeployedPackage(secret string) (*types.DeployedPackage, error) { | ||
deployedPackage := &types.DeployedPackage{} | ||
decoded, err := base64.StdEncoding.DecodeString(secret) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = json.Unmarshal(decoded, &deployedPackage) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return deployedPackage, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/test/packages/37-component-status/component-status.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: component-status | ||
spec: | ||
# Extra security to ensure the pod isn't ready before the health checks run | ||
initContainers: | ||
- name: init-wait | ||
image: ghcr.io/stefanprodan/podinfo:6.4.0 | ||
command: ["sh", "-c", "sleep 10"] | ||
containers: | ||
- name: component-status | ||
image: ghcr.io/stefanprodan/podinfo:6.4.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
kind: ZarfPackageConfig | ||
metadata: | ||
name: component-status | ||
description: Test the status of components | ||
|
||
components: | ||
- name: component-status | ||
required: true | ||
manifests: | ||
- name: first-component | ||
namespace: first-component | ||
files: | ||
- component-status.yaml | ||
images: | ||
- ghcr.io/stefanprodan/podinfo:6.4.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.