Skip to content

Commit d94849b

Browse files
committed
feat(understackctl): deploy check uses kustomize build to validate
Validate the manifests by running 'kustomize build' against each enabled component.
1 parent 89521fe commit d94849b

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

go/understackctl/cmd/deploy/check.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@ package deploy
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"path/filepath"
8+
"strings"
79

810
"github.com/charmbracelet/log"
911
"github.com/spf13/cobra"
1012
)
1113

14+
// kustomizeBuildArgs mirrors the kustomize.buildOptions configured in
15+
// components/argocd/values.yaml so local validation matches ArgoCD's behaviour.
16+
var kustomizeBuildArgs = []string{
17+
"--enable-alpha-plugins",
18+
"--enable-exec",
19+
"--enable-helm",
20+
"--load-restrictor", "LoadRestrictionsNone",
21+
}
22+
1223
func newCmdDeployCheck() *cobra.Command {
1324
cmd := &cobra.Command{
1425
Use: "check <cluster-name>",
@@ -36,7 +47,14 @@ func runDeployCheck(clusterName string) error {
3647
return nil
3748
}
3849

50+
kustomizePath, err := exec.LookPath("kustomize")
51+
if err != nil {
52+
log.Warn("kustomize not found in PATH, skipping kustomization.yaml validation")
53+
kustomizePath = ""
54+
}
55+
3956
missing := []string{}
57+
var kustomizeErrors []string
4058

4159
for _, comp := range components {
4260
compDir := filepath.Join(clusterName, comp.Name)
@@ -52,6 +70,16 @@ func runDeployCheck(clusterName string) error {
5270
kustomPath := filepath.Join(compDir, "kustomization.yaml")
5371
if _, err := os.Stat(kustomPath); os.IsNotExist(err) {
5472
missing = append(missing, kustomPath)
73+
continue
74+
}
75+
76+
if kustomizePath != "" {
77+
args := append(append([]string{"build"}, kustomizeBuildArgs...), compDir)
78+
out, err := exec.Command(kustomizePath, args...).CombinedOutput()
79+
if err != nil {
80+
kustomizeErrors = append(kustomizeErrors,
81+
fmt.Sprintf("%s: %s", kustomPath, strings.TrimSpace(string(out))))
82+
}
5583
}
5684
}
5785
}
@@ -61,7 +89,17 @@ func runDeployCheck(clusterName string) error {
6189
for _, path := range missing {
6290
log.Errorf(" - %s", path)
6391
}
64-
return fmt.Errorf("validation failed: %d missing files", len(missing))
92+
}
93+
94+
if len(kustomizeErrors) > 0 {
95+
log.Error("kustomize build failures:")
96+
for _, msg := range kustomizeErrors {
97+
log.Errorf(" - %s", msg)
98+
}
99+
}
100+
101+
if total := len(missing) + len(kustomizeErrors); total > 0 {
102+
return fmt.Errorf("validation failed: %d error(s)", total)
65103
}
66104

67105
log.Infof("All %d components validated successfully", len(components))

go/understackctl/cmd/deploy/deploy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func TestDeployCheck(t *testing.T) {
284284
kustomPath := filepath.Join(keystoneDir, "kustomization.yaml")
285285
valuesPath := filepath.Join(keystoneDir, "values.yaml")
286286

287-
if err := os.WriteFile(kustomPath, []byte("test"), 0644); err != nil {
287+
if err := os.WriteFile(kustomPath, []byte(kustomizationContent), 0644); err != nil {
288288
t.Fatalf("failed to write kustomization.yaml: %v", err)
289289
}
290290

0 commit comments

Comments
 (0)