Skip to content

Commit c6f8085

Browse files
authored
Merge branch 'master' into add-support-for-duration
2 parents 8e1fad3 + a23275d commit c6f8085

9 files changed

+22151
-9578
lines changed

acceptance-nonetwork.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@
1919
run bin/kubeconform -schema-location 'fixtures/{{ .ResourceKind }}.json' -schema-location './fixtures/registry/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/test_crd.yaml
2020
[ "$status" -eq 0 ]
2121
}
22+
23+
@test "Pass when using a cached schema with external references" {
24+
run bin/kubeconform -cache fixtures/cache -summary -schema-location 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{ .NormalizedKubernetesVersion }}{{ .StrictSuffix }}/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/valid.yaml
25+
[ "$status" -eq 0 ]
26+
}

acceptance.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ resetCacheFolder() {
276276
[ "$output" = "failed opening cache folder cache_does_not_exist: stat cache_does_not_exist: no such file or directory" ]
277277
}
278278

279+
@test "HTTP references should be cached" {
280+
resetCacheFolder
281+
run bin/kubeconform -cache cache -summary -schema-location 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{ .NormalizedKubernetesVersion }}{{ .StrictSuffix }}/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/valid.yaml
282+
[ "$status" -eq 0 ]
283+
[ "`ls cache/ | wc -l`" -eq 2 ]
284+
}
285+
279286
@test "Produces correct TAP output" {
280287
run bin/kubeconform -output tap fixtures/valid.yaml
281288
[ "$status" -eq 0 ]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"description": "ReplicationController represents the configuration of a replication controller.",
3+
"properties": {
4+
"apiVersion": {
5+
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
6+
"type": [
7+
"string",
8+
"null"
9+
],
10+
"enum": [
11+
"v1"
12+
]
13+
},
14+
"kind": {
15+
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
16+
"type": [
17+
"string",
18+
"null"
19+
],
20+
"enum": [
21+
"ReplicationController"
22+
]
23+
},
24+
"metadata": {
25+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master/_definitions.json#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta",
26+
"description": "If the Labels of a ReplicationController are empty, they are defaulted to be the same as the Pod(s) that the replication controller manages. Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata"
27+
},
28+
"spec": {
29+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master/_definitions.json#/definitions/io.k8s.api.core.v1.ReplicationControllerSpec",
30+
"description": "Spec defines the specification of the desired behavior of the replication controller. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status"
31+
},
32+
"status": {
33+
"$ref": "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master/_definitions.json#/definitions/io.k8s.api.core.v1.ReplicationControllerStatus",
34+
"description": "Status is the most recently observed status of the replication controller. This data may be out of date by some window of time. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status"
35+
}
36+
},
37+
"type": "object",
38+
"x-kubernetes-group-version-kind": [
39+
{
40+
"group": "",
41+
"kind": "ReplicationController",
42+
"version": "v1"
43+
}
44+
],
45+
"$schema": "http://json-schema.org/schema#"
46+
}

fixtures/cache/6dc6142c64b944d783a3e783526114da8e747a14a11d8b32dd1f12e2d89a8330

Lines changed: 22067 additions & 0 deletions
Large diffs are not rendered by default.

fixtures/cache/f07bea3f9d3a1cb6c76a58db9823ac1a603074e8997c5dc20a483b60f8c1b14b

Lines changed: 0 additions & 9575 deletions
This file was deleted.

pkg/loader/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (l *HTTPURLLoader) Load(url string) (any, error) {
5656

5757
s, err := jsonschema.UnmarshalJSON(bytes.NewReader(body))
5858
if err != nil {
59-
return nil, err
59+
return nil, NewNonJSONResponseError(err)
6060
}
6161

6262
return s, nil

pkg/loader/loaders.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ func NewNotFoundError(err error) *NotFoundError {
1010
}
1111
func (e *NotFoundError) Error() string { return e.err.Error() }
1212
func (e *NotFoundError) Retryable() bool { return false }
13+
14+
type NonJSONResponseError struct {
15+
err error
16+
}
17+
18+
func NewNonJSONResponseError(err error) *NotFoundError {
19+
return &NotFoundError{err}
20+
}
21+
func (e *NonJSONResponseError) Error() string { return e.err.Error() }
22+
func (e *NonJSONResponseError) Retryable() bool { return false }

pkg/validator/validator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ func downloadSchema(registries []registry.Registry, l jsonschema.SchemeURLLoader
390390
if _, notfound := err.(*loader.NotFoundError); notfound {
391391
continue
392392
}
393+
if _, nonJSONError := err.(*loader.NonJSONResponseError); nonJSONError {
394+
continue
395+
}
396+
393397
return nil, err
394398
}
395399

pkg/validator/validator_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ lastName: bar
316316
}`),
317317
false,
318318
false,
319-
Error,
319+
Valid,
320320
[]ValidationError{},
321321
},
322322
{
@@ -361,7 +361,7 @@ lastName: bar
361361
[]byte(`<html>error page</html>`),
362362
true,
363363
false,
364-
Error,
364+
Skipped,
365365
[]ValidationError{},
366366
},
367367
{
@@ -475,13 +475,19 @@ interval: test
475475
return "", nil, loader.NewNotFoundError(nil)
476476
}
477477
s, err := jsonschema.UnmarshalJSON(bytes.NewReader(testCase.schemaRegistry1))
478+
if err != nil {
479+
return "", s, loader.NewNonJSONResponseError(err)
480+
}
478481
return "", s, err
479482
}),
480483
newMockRegistry(func() (string, any, error) {
481484
if testCase.schemaRegistry2 == nil {
482485
return "", nil, loader.NewNotFoundError(nil)
483486
}
484487
s, err := jsonschema.UnmarshalJSON(bytes.NewReader(testCase.schemaRegistry2))
488+
if err != nil {
489+
return "", s, loader.NewNonJSONResponseError(err)
490+
}
485491
return "", s, err
486492
}),
487493
},
@@ -550,6 +556,9 @@ age: not a number
550556
regs: []registry.Registry{
551557
newMockRegistry(func() (string, any, error) {
552558
s, err := jsonschema.UnmarshalJSON(bytes.NewReader(schema))
559+
if err != nil {
560+
return "", s, loader.NewNonJSONResponseError(err)
561+
}
553562
return "", s, err
554563
}),
555564
},

0 commit comments

Comments
 (0)