Skip to content

Commit d804814

Browse files
committed
fix
Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
1 parent 6fd433c commit d804814

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
apiVersion: v1
2-
kind: Pod
2+
kind: InvalidKind
33
metadata:
4-
creationTimestamp: null
54
name: foo-pod
65
namespace: foo
76
spec:
8-
containers:
9-
- image: busybox
10-
name: invalid
11-
command:
12-
- "sleep"
13-
args:
14-
- "infinity"
15-
resources:
16-
limits:
17-
cpu: 25m
18-
memory: 1GB
19-
requests:
20-
cpu: 25m
21-
memory: 1GB
22-
dnsPolicy: ClusterFirst
23-
restartPolicy: Always
24-
status: {}
7+
invalidField: [this is invalid YAML that should fail to parse
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
1-
apiVersion: v1
2-
kind: PersistentVolumeClaim
3-
metadata:
4-
name: foo-pvc
5-
namespace: foo
6-
spec:
7-
accessModes:
8-
- ReadWriteOnce
9-
resources:
10-
requests:
11-
storage: 250GB
12-
storageClassName: thin-disk
1+
this is malformed YAML that should fail to parse: {
2+
invalid: unclosed bracket

pkg/templates/kubeconform/template.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kubeconform
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/yannh/kubeconform/pkg/resource"
78
"github.com/yannh/kubeconform/pkg/validator"
@@ -33,6 +34,13 @@ func init() {
3334
}
3435

3536
func validate(p params.Params) (check.Func, error) {
37+
// Create cache directory if it doesn't exist
38+
if p.Cache != "" {
39+
if err := os.MkdirAll(p.Cache, 0755); err != nil {
40+
return nil, fmt.Errorf("creating cache directory %s: %w", p.Cache, err)
41+
}
42+
}
43+
3644
v, err := validator.New(p.SchemaLocations, validator.Opts{
3745
Cache: p.Cache,
3846
SkipKinds: sliceToMap(p.SkipKinds),

0 commit comments

Comments
 (0)