Skip to content

Commit

Permalink
chore: remove useless config validation (#1642)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly authored Jul 16, 2024
1 parent 9a9d0ec commit bcaa04c
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 164 deletions.
15 changes: 2 additions & 13 deletions pkg/loaders/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/openapi"
"sigs.k8s.io/kubectl-validate/pkg/openapiclient"
)
Expand All @@ -29,7 +28,6 @@ type (
splitter = func([]byte) ([][]byte, error)
loaderFactory = func(openapi.Client) (loader.Loader, error)
converter = func(schema.GroupVersionKind, unstructured.Unstructured) (*v1alpha2.Configuration, error)
validator = func(obj *v1alpha2.Configuration) field.ErrorList
)

var (
Expand Down Expand Up @@ -64,10 +62,10 @@ func LoadBytes(content []byte) (*v1alpha2.Configuration, error) {
}

func Parse(content []byte) ([]*v1alpha2.Configuration, error) {
return parse(content, nil, nil, nil, nil)
return parse(content, nil, nil, nil)
}

func parse(content []byte, splitter splitter, loaderFactory loaderFactory, converter converter, validator validator) ([]*v1alpha2.Configuration, error) {
func parse(content []byte, splitter splitter, loaderFactory loaderFactory, converter converter) ([]*v1alpha2.Configuration, error) {
if splitter == nil {
splitter = yaml.SplitDocuments
}
Expand All @@ -77,12 +75,6 @@ func parse(content []byte, splitter splitter, loaderFactory loaderFactory, conve
if converter == nil {
converter = defaultConverter
}
if validator == nil {
// TODO: replace with schema validation
validator = func(obj *v1alpha2.Configuration) field.ErrorList {
return nil
}
}
documents, err := splitter(content)
if err != nil {
return nil, err
Expand All @@ -106,9 +98,6 @@ func parse(content []byte, splitter splitter, loaderFactory loaderFactory, conve
if err != nil {
return nil, err
}
if err := validator(config).ToAggregate(); err != nil {
return nil, err
}
configs = append(configs, config)
}
return configs, nil
Expand Down
15 changes: 1 addition & 14 deletions pkg/loaders/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/openapi"
"k8s.io/utils/ptr"
)
Expand Down Expand Up @@ -141,7 +140,6 @@ func Test_parse(t *testing.T) {
splitter splitter
loaderFactory loaderFactory
converter converter
validator validator
wantErr bool
}{{
name: "default",
Expand Down Expand Up @@ -185,21 +183,10 @@ func Test_parse(t *testing.T) {
return nil, errors.New("converter")
},
wantErr: true,
}, {
name: "validator error",
splitter: nil,
loaderFactory: nil,
converter: nil,
validator: func(obj *v1alpha2.Configuration) field.ErrorList {
return field.ErrorList{
field.Invalid(nil, nil, ""),
}
},
wantErr: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := parse(content, tt.splitter, tt.loaderFactory, tt.converter, tt.validator)
_, err := parse(content, tt.splitter, tt.loaderFactory, tt.converter)
if tt.wantErr {
assert.Error(t, err)
} else {
Expand Down
14 changes: 0 additions & 14 deletions pkg/validation/config/cluster.go

This file was deleted.

41 changes: 0 additions & 41 deletions pkg/validation/config/cluster_test.go

This file was deleted.

15 changes: 0 additions & 15 deletions pkg/validation/config/configuration.go

This file was deleted.

19 changes: 0 additions & 19 deletions pkg/validation/config/configuration_spec.go

This file was deleted.

48 changes: 0 additions & 48 deletions pkg/validation/config/configuration_test.go

This file was deleted.

0 comments on commit bcaa04c

Please sign in to comment.