Skip to content

Commit 7414006

Browse files
committed
Skip CRD resources when processing multiple YAMLs
This is a bandaid for now. Simply log YAML parsing errors as WARN level instead of Fatal so additional files can be processed.
1 parent 7e02b5c commit 7414006

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

input.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ func readFilesInput() []runtime.Object {
8484
log.Debug().Msgf("reading file: %s", fileName)
8585
content, err := ioutil.ReadFile(fileName)
8686
if err != nil {
87-
log.Fatal().Err(err).Msg("")
87+
log.Fatal().Err(err).Msg("could not read file")
8888
}
8989

9090
r := bytes.NewReader(content)
9191
obj, err := k8sparser.ParseYAML(r)
9292
if err != nil {
93-
log.Fatal().Err(err).Msg("")
93+
log.Warn().Err(err).Msg("could not parse file")
9494
}
9595
objs = append(objs, obj...)
9696
}

pkg/k8sparser/yaml_parser.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func ParseYAML(in io.Reader) ([]runtime.Object, error) {
3535
obj, _, err := d.Decode(doc, nil, nil)
3636
if err != nil {
3737
log.Error().Err(err)
38-
wrapped := fmt.Errorf("could not decode yaml object with main scheme #%d: %s", i, err)
38+
wrapped := fmt.Errorf("could not decode yaml object with main scheme #%d: %v", i, err)
3939

4040
// Fallback on aggregator decoder
4141
d = aggregator_scheme.Codecs.UniversalDeserializer()
@@ -45,7 +45,7 @@ func ParseYAML(in io.Reader) ([]runtime.Object, error) {
4545

4646
// Push both errors
4747
result = multierror.Append(result, wrapped)
48-
wrapped = fmt.Errorf("could not decode yaml object with aggregator scheme #%d: %s", i, err)
48+
wrapped = fmt.Errorf("could not decode yaml object with aggregator scheme #%d: %v", i, err)
4949
result = multierror.Append(result, wrapped)
5050
}
5151
}

test-fixtures/multiple_wCRD/crd.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
# name must match the spec fields below, and be in the form: <plural>.<group>
5+
name: crontabs.stable.example.com
6+
spec:
7+
# group name to use for REST API: /apis/<group>/<version>
8+
group: stable.example.com
9+
# list of versions supported by this CustomResourceDefinition
10+
versions:
11+
- name: v1
12+
# Each version can be enabled/disabled by Served flag.
13+
served: true
14+
# One and only one version must be marked as the storage version.
15+
storage: true
16+
schema:
17+
openAPIV3Schema:
18+
type: object
19+
properties:
20+
spec:
21+
type: object
22+
properties:
23+
cronSpec:
24+
type: string
25+
image:
26+
type: string
27+
replicas:
28+
type: integer
29+
# either Namespaced or Cluster
30+
scope: Namespaced
31+
names:
32+
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
33+
plural: crontabs
34+
# singular name to be used as an alias on the CLI and for display
35+
singular: crontab
36+
# kind is normally the CamelCased singular type. Your resource manifests use this.
37+
kind: CronTab
38+
# shortNames allow shorter string to match your resource on the CLI
39+
shortNames:
40+
- ct

test-fixtures/multiple_wCRD/pod.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
kind: Pod
2+
apiVersion: v1
3+
metadata:
4+
name: poddy
5+
annotations:
6+
foo: fam
7+
labels:
8+
app: nginx
9+
spec:
10+
containers:
11+
- name: nginx
12+
image: nginx
13+
args: ["--debug", "--test"]
14+
ports:
15+
- port: 80
16+
containerPort: 80

0 commit comments

Comments
 (0)