Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Sync from open-cluster-management-io/config-policy-controller: #134 #503

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"os"
"reflect"
"sort"
"strconv"
Expand Down Expand Up @@ -1106,6 +1105,14 @@ func (r *ConfigurationPolicyReconciler) handleObjectTemplates(plc policyv1.Confi
numCompliant := 0
numNonCompliant := 0
handled := false
// map raw object to a resource, generate a violation if resource cannot be found
mapping, statusUpdateNeeded := r.getMapping(objectT.ObjectDefinition, &plc, indx)

unstruct, err := unmarshalFromJSON(objectT.ObjectDefinition.Raw)
if err != nil {
panic(err)
}

// iterate through all namespaces the configurationpolicy is set on
for _, ns := range relevantNamespaces {
log.Info(
Expand All @@ -1114,10 +1121,16 @@ func (r *ConfigurationPolicyReconciler) handleObjectTemplates(plc policyv1.Confi
"desiredName", templateObjs[indx].name,
"index", indx,
)

names, compliant, reason, objKind, related, statusUpdateNeeded := r.handleObjects(
objectT, ns, templateObjs[indx], indx, &plc,
)
var names []string
var compliant bool
var reason, objKind string
var related []policyv1.RelatedObject

if mapping != nil {
names, compliant, reason, objKind, related, statusUpdateNeeded = r.handleObjects(
objectT, ns, templateObjs[indx], indx, &plc, mapping, unstruct,
)
}

if statusUpdateNeeded {
parentStatusUpdateNeeded = true
Expand Down Expand Up @@ -1429,6 +1442,8 @@ func (r *ConfigurationPolicyReconciler) handleObjects(
objDetails objectTemplateDetails,
index int,
policy *policyv1.ConfigurationPolicy,
mapping *meta.RESTMapping,
unstruct unstructured.Unstructured,
) (
objNameList []string,
compliant bool,
Expand All @@ -1445,19 +1460,6 @@ func (r *ConfigurationPolicyReconciler) handleObjects(
log.V(2).Info("Handling object template, no namespace specified")
}

ext := objectT.ObjectDefinition

// map raw object to a resource, generate a violation if resource cannot be found
mapping, statusUpdateNeeded := r.getMapping(ext, policy, index)
if mapping == nil {
return nil, false, "", "", nil, statusUpdateNeeded
}

unstruct, err := unmarshalFromJSON(ext.Raw)
if err != nil {
os.Exit(1)
}

exists := true
objNames := []string{}
remediation := policy.Spec.RemediationAction
Expand Down