Skip to content

Commit

Permalink
Add an error when apiVersion is missing
Browse files Browse the repository at this point in the history
The apiVersion field is generally required by kubernetes objects... it's
surprising that this situation wasn't already caught by an error when
decoding or getting a mapping.

Refs:
 - https://issues.redhat.com/browse/ACM-7127

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
  • Loading branch information
JustinKuli committed Sep 19, 2023
1 parent de86a78 commit 87bf0c8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,20 @@ func (r *ConfigurationPolicyReconciler) getMapping(
return nil, result
}

if gvk.Group == "" && gvk.Version == "" {
err := fmt.Errorf("object template at index [%v] in policy `%v` missing apiVersion", index, policy.Name)

log.Error(err, "Can not get mapping for object")

result = &objectTmplEvalResult{
events: []objectTmplEvalEvent{
{compliant: false, reason: "K8s object definition error", message: err.Error()},
},
}

return nil, result
}

// initializes a mapping between Kind and APIVersion to a resource name
r.lock.RLock()
mapper := restmapper.NewDiscoveryRESTMapper(r.apiGroups)
Expand Down

0 comments on commit 87bf0c8

Please sign in to comment.