1
0
mirror of synced 2026-04-14 10:46:56 +00:00

feat: add --ignore-not-found flag to 'flux diff ks' command

Signed-off-by: rycli <cyril@ryc.li>
Assisted-by: claude-code/claude-opus-4-6
This commit is contained in:
rycli
2026-04-12 09:19:33 +02:00
parent ac7f72b62b
commit d349ffe37d
11 changed files with 200 additions and 5 deletions

View File

@@ -146,8 +146,9 @@ type Builder struct {
strictSubst bool
recursive bool
localSources map[string]string
// diff needs to handle kustomizations one by one
// diff needs to handle kustomizations one by one, and opt-in to ignore kustomizations missing on cluster
singleKustomization bool
ignoreNotFound bool
fsBackend fsBackend
}
@@ -235,6 +236,15 @@ func WithStrictSubstitute(strictSubstitute bool) BuilderOptionFunc {
}
}
// WithIgnoreNotFound ignores NotFound errors from the cluster kustomization
// lookup as long as a local kustomization file is provided
func WithIgnoreNotFound(ignore bool) BuilderOptionFunc {
return func(b *Builder) error {
b.ignoreNotFound = ignore
return nil
}
}
// WithIgnore sets ignore field
func WithIgnore(ignore []string) BuilderOptionFunc {
return func(b *Builder) error {
@@ -345,6 +355,10 @@ func NewBuilder(name, resources string, opts ...BuilderOptionFunc) (*Builder, er
return nil, fmt.Errorf("kustomization file is required for dry-run")
}
if b.ignoreNotFound && b.kustomizationFile == "" {
return nil, fmt.Errorf("kustomization file is required when assuming new kustomizations")
}
if !b.dryRun && b.client == nil {
return nil, fmt.Errorf("client is required for live run")
}
@@ -443,10 +457,11 @@ func (b *Builder) build() (m resmap.ResMap, err error) {
} else {
liveKus, err = b.getKustomization(ctx)
if err != nil {
if !apierrors.IsNotFound(err) || b.kustomization == nil {
unknownError := !apierrors.IsNotFound(err)
hasLocalFallback := b.kustomization != nil || b.ignoreNotFound
if unknownError || !hasLocalFallback {
return nil, fmt.Errorf("failed to get kustomization object: %w", err)
}
// use provided Kustomization
liveKus = b.kustomization
}
}