Skip to content

Commit

Permalink
Stop failing metadata collection from causing a panic
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Aug 12, 2024
1 parent 5994a31 commit 435f1d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions pkg/compare/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ func (rf ReferenceTemplate) Exec(params map[string]any) (*unstructured.Unstructu
content := buf.Bytes()
err = yaml.Unmarshal(bytes.ReplaceAll(content, []byte(noValue), []byte("")), &data)
if err != nil {
return nil, fmt.Errorf("template: %s isn't a yaml file after injection. yaml unmarshal error: %w. The Template After Execution: %s", rf.Name(), err, string(content))
return nil, fmt.Errorf(
"template: %s isn't a yaml file after injection. yaml unmarshal error: %w. The Template After Execution: %s",
rf.Name(), err, string(content),
)
}
return &unstructured.Unstructured{Object: data}, nil
}
Expand Down Expand Up @@ -272,13 +275,13 @@ func parseTemplates(templateReference []*ReferenceTemplate, functionTemplates []
temp.Template = parsedTemp
temp.metadata, err = temp.Exec(map[string]any{}) // Extract Metadata
if err != nil {
errs = append(errs, err)
errs = append(errs, fmt.Errorf("failed to parse template %s with empty data: %w", temp.Path, err))
}
err = temp.ValidateFieldsToOmit(ref.FieldsToOmit)
if err != nil {
errs = append(errs, err)
}
if temp.metadata.GetKind() == "" {
if temp.metadata != nil && temp.metadata.GetKind() == "" {
errs = append(errs, fmt.Errorf("template missing kind: %s", temp.Path))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: failed to constuct template: template: apps.v1.DaemonSet.kube-system.kindnet.yaml:5:61: executing "apps.v1.DaemonSet.kube-system.kindnet.yaml" at <len .spec.annotations>: error calling len: reflect: call of reflect.Value.Type on zero Value
error: failed to parse template apps.v1.DaemonSet.kube-system.kindnet.yaml with empty data: failed to constuct template: template: apps.v1.DaemonSet.kube-system.kindnet.yaml:5:61: executing "apps.v1.DaemonSet.kube-system.kindnet.yaml" at <len .spec.annotations>: error calling len: reflect: call of reflect.Value.Type on zero Value
error code:2
6 changes: 3 additions & 3 deletions pkg/compare/testdata/YAMLOutput/localout.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Diffs:
CorrelatedTemplate: deploymentDashboard.yaml
DiffOutput: "diff -u -N TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard
TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard\n---
TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard\tDATE\n+++ TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard\tDATE\n@@ -14,7 +14,7 @@\n template:\n metadata:\n labels:\n- k8s-app:
kubernetes-dashboard\n+ k8s-app: kubernetes-dashboard-diff\n spec:\n
\ containers:\n - args:\n"
TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard\tDATE\n+++ TEMP/apps-v1_deployment_kubernetes-dashboard_kubernetes-dashboard\tDATE\n@@ -14,7 +14,7 @@\n template:\n metadata:\n labels:\n-
\ k8s-app: kubernetes-dashboard\n+ k8s-app: kubernetes-dashboard-diff\n
\ spec:\n containers:\n - args:\n"
Summary:
NumDiffCRs: 1
NumMissing: 1
Expand Down

0 comments on commit 435f1d9

Please sign in to comment.