From 165aa72a283299e634d3aac75ab267303efe89ee Mon Sep 17 00:00:00 2001 From: Ilya Drey Date: Wed, 5 Aug 2026 11:29:59 +0300 Subject: [PATCH] fix: optimize validation args Signed-off-by: Ilya Drey --- cmd/nelm/common_flags.go | 7 ------- docs/reference.md | 16 ---------------- pkg/common/options.go | 2 -- pkg/resource/kubeconform.go | 6 +----- pkg/resource/validate.go | 2 +- 5 files changed, 2 insertions(+), 31 deletions(-) diff --git a/cmd/nelm/common_flags.go b/cmd/nelm/common_flags.go index d4020616..464ce924 100644 --- a/cmd/nelm/common_flags.go +++ b/cmd/nelm/common_flags.go @@ -351,13 +351,6 @@ func AddResourceValidationFlags(cmd *cobra.Command, cfg *common.ResourceValidati return fmt.Errorf("add flag: %w", err) } - if err := cli.AddFlag(cmd, &cfg.LocalResourceValidation, "local-resource-validation", false, "Do not use external json schema sources, validate against the json schemas embedded into the binary instead", cli.AddFlagOptions{ - GetEnvVarRegexesFunc: cli.GetFlagGlobalAndLocalEnvVarRegexes, - Group: resourceValidationGroup, - }); err != nil { - return fmt.Errorf("add flag: %w", err) - } - if err := cli.AddFlag(cmd, &cfg.ValidationSkip, "resource-validation-skip", []string{}, "Skip resource validation for resources with specified attributes. Format: key1=value1,key2=value2. Supported keys: group, version, kind, name, namespace. Example: kind=Deployment,name=my-app", cli.AddFlagOptions{ GetEnvVarRegexesFunc: cli.GetFlagGlobalAndLocalEnvVarRegexes, Group: resourceValidationGroup, diff --git a/docs/reference.md b/docs/reference.md index e871b25c..e6debf80 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -264,10 +264,6 @@ nelm release install [options...] -n namespace -r release [chart-dir|chart-repo- **Resource validation options:** -- `--local-resource-validation` (default: `false`) - - Do not use external json schema sources, validate against the json schemas embedded into the binary instead\. Vars: \$NELM\_LOCAL\_RESOURCE\_VALIDATION, \$NELM\_RELEASE\_INSTALL\_LOCAL\_RESOURCE\_VALIDATION - - `--no-resource-validation` (default: `false`) Disable resource validation\. Vars: \$NELM\_NO\_RESOURCE\_VALIDATION, \$NELM\_RELEASE\_INSTALL\_NO\_RESOURCE\_VALIDATION @@ -621,10 +617,6 @@ nelm release rollback [options...] -n namespace -r release [revision] **Resource validation options:** -- `--local-resource-validation` (default: `false`) - - Do not use external json schema sources, validate against the json schemas embedded into the binary instead\. Vars: \$NELM\_LOCAL\_RESOURCE\_VALIDATION, \$NELM\_RELEASE\_ROLLBACK\_LOCAL\_RESOURCE\_VALIDATION - - `--no-resource-validation` (default: `false`) Disable resource validation\. Vars: \$NELM\_NO\_RESOURCE\_VALIDATION, \$NELM\_RELEASE\_ROLLBACK\_NO\_RESOURCE\_VALIDATION @@ -990,10 +982,6 @@ nelm release plan install [options...] -n namespace -r release [chart-dir|chart- **Resource validation options:** -- `--local-resource-validation` (default: `false`) - - Do not use external json schema sources, validate against the json schemas embedded into the binary instead\. Vars: \$NELM\_LOCAL\_RESOURCE\_VALIDATION, \$NELM\_RELEASE\_PLAN\_INSTALL\_LOCAL\_RESOURCE\_VALIDATION - - `--no-resource-validation` (default: `false`) Disable resource validation\. Vars: \$NELM\_NO\_RESOURCE\_VALIDATION, \$NELM\_RELEASE\_PLAN\_INSTALL\_NO\_RESOURCE\_VALIDATION @@ -2159,10 +2147,6 @@ nelm chart lint [options...] [chart-dir|chart-repo-name/chart-name|chart-archive **Resource validation options:** -- `--local-resource-validation` (default: `false`) - - Do not use external json schema sources, validate against the json schemas embedded into the binary instead\. Vars: \$NELM\_LOCAL\_RESOURCE\_VALIDATION, \$NELM\_CHART\_LINT\_LOCAL\_RESOURCE\_VALIDATION - - `--no-resource-validation` (default: `false`) Disable resource validation\. Vars: \$NELM\_NO\_RESOURCE\_VALIDATION, \$NELM\_CHART\_LINT\_NO\_RESOURCE\_VALIDATION diff --git a/pkg/common/options.go b/pkg/common/options.go index 964115a0..cc018a0f 100644 --- a/pkg/common/options.go +++ b/pkg/common/options.go @@ -222,8 +222,6 @@ type ResourceValidationOptions struct { NoResourceValidation bool `json:"noResourceValidation"` // NoValuesSchemaValidation disables values validation against json schema. NoValuesSchemaValidation bool `json:"noValuesSchemaValidation"` - // LocalResourceValidation validates by using kubeconform embedded schemas and client-go codec only. - LocalResourceValidation bool `json:"localResourceValidation"` // ValidationSkip Do not validate resources with specific attributes. ValidationSkip []string `json:"validationSkip"` // ValidationSchemaCacheLifetime how long the schema cache should be valid. diff --git a/pkg/resource/kubeconform.go b/pkg/resource/kubeconform.go index 33e69f77..712ab96a 100644 --- a/pkg/resource/kubeconform.go +++ b/pkg/resource/kubeconform.go @@ -44,7 +44,7 @@ type kubeConformValidator struct { validators []*kubeConformInstance } -func newKubeConformValidator(schemaCacheLifetime time.Duration, schemaSources []string, embeddedSchemasOnly bool) (*kubeConformValidator, error) { +func newKubeConformValidator(schemaCacheLifetime time.Duration, schemaSources []string) (*kubeConformValidator, error) { kubernetesSource, err := schemas.KubernetesSource() if err != nil { return nil, fmt.Errorf("get embedded Kubernetes schemas: %w", err) @@ -55,10 +55,6 @@ func newKubeConformValidator(schemaCacheLifetime time.Duration, schemaSources [] return nil, fmt.Errorf("get embedded CRD schemas: %w", err) } - if embeddedSchemasOnly { - schemaSources = nil - } - cacheSubDirName := getHash(strings.Join(schemaSources, "-")) sources := slices.Clone(schemaSources) diff --git a/pkg/resource/validate.go b/pkg/resource/validate.go index 700d127e..1c826fec 100644 --- a/pkg/resource/validate.go +++ b/pkg/resource/validate.go @@ -45,7 +45,7 @@ func validateResourceSchemas(ctx context.Context, releaseNamespace string, resou kubeConformValidator, err := newKubeConformValidator( opts.ValidationSchemaCacheLifetime, opts.ValidationExtraSchemas, - opts.LocalResourceValidation) + ) if err != nil { return fmt.Errorf("get schema validator: %w", err) }