Skip to content

feat(understackctl): deploy check uses kustomize build to validate#1923

Open
cardoe wants to merge 1 commit intomainfrom
understackctl-check
Open

feat(understackctl): deploy check uses kustomize build to validate#1923
cardoe wants to merge 1 commit intomainfrom
understackctl-check

Conversation

@cardoe
Copy link
Copy Markdown
Contributor

@cardoe cardoe commented Apr 8, 2026

Validate the manifests by running 'kustomize build' against each enabled
component.

Validate the manifests by running 'kustomize build' against each enabled
component.
@cardoe cardoe force-pushed the understackctl-check branch from 38ce2e2 to d94849b Compare April 8, 2026 20:31
@cardoe cardoe requested a review from a team April 8, 2026 21:40
Copy link
Copy Markdown
Collaborator

@skrobul skrobul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but I was wondering what do you think about not relying on the kustomize binary to be present on the system and running kustomize natively instead?

import (
	"fmt"
	"path/filepath"
	"sigs.k8s.io/kustomize/api/krusty"
	kusttypes "sigs.k8s.io/kustomize/api/types"
	"sigs.k8s.io/kustomize/kyaml/filesys"
)
// validateKustomizationNative runs the equivalent of:
// kustomize build --enable-alpha-plugins --enable-exec --enable-helm --load-restrictor LoadRestrictionsNone <compDir>
func validateKustomizationNative(compDir string) error {
	opts := krusty.MakeDefaultOptions()
	// --load-restrictor LoadRestrictionsNone
	opts.LoadRestrictions = kusttypes.LoadRestrictionsNone
	// --enable-alpha-plugins + --enable-helm
	opts.PluginConfig = kusttypes.EnabledPluginConfig(kusttypes.BploLoadFromFileSys)
	opts.PluginConfig.HelmConfig.Command = "helm"
	// --enable-exec (for function plugins)
	opts.PluginConfig.FnpLoadingOptions.EnableExec = true
	k := krusty.MakeKustomizer(opts)
	if _, err := k.Run(filesys.MakeFsOnDisk(), compDir); err != nil {
		return fmt.Errorf("%s: %w", filepath.Join(compDir, "kustomization.yaml"), err)
	}
	return nil
}

And in runDeployCheck, replace the `exec.Command(...) with:

if err := validateKustomizationNative(compDir); err != nil {
	kustomizeErrors = append(kustomizeErrors, err.Error())
}

the import block will need:

	"sigs.k8s.io/kustomize/api/krusty"
	kusttypes "sigs.k8s.io/kustomize/api/types"
	"sigs.k8s.io/kustomize/kyaml/filesys"

the docs:
https://pkg.go.dev/sigs.k8s.io/kustomize/api/krusty
https://pkg.go.dev/sigs.k8s.io/kustomize/api/types

@cardoe
Copy link
Copy Markdown
Contributor Author

cardoe commented Apr 9, 2026

That's probably better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants