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

Add enforcementAction to status #180

Merged
merged 2 commits into from
Jul 11, 2019
Merged
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
52 changes: 28 additions & 24 deletions pkg/audit/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,24 @@ type AuditManager struct {
}

type auditResult struct {
cname string
cnamespace string
cgvk schema.GroupVersionKind
capiversion string
rkind string
rname string
rnamespace string
message string
cname string
cnamespace string
cgvk schema.GroupVersionKind
capiversion string
rkind string
rname string
rnamespace string
message string
enforcementaction string
}

// StatusViolation represents each violation under status
type StatusViolation struct {
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
Message string `json:"message"`
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
Message string `json:"message"`
EnforcementAction string `json:"enforcementAction"`
}

// New creates a new manager for audit
Expand Down Expand Up @@ -182,14 +184,15 @@ func getUpdateListsFromAuditResponses(resp *constraintTypes.Responses) (map[stri
rkind := resource.GetKind()
rnamespace := resource.GetNamespace()
updateLists[selfLink] = append(updateLists[selfLink], auditResult{
cgvk: gvk,
capiversion: apiVersion,
cname: name,
cnamespace: namespace,
rkind: rkind,
rname: rname,
rnamespace: rnamespace,
message: message,
cgvk: gvk,
capiversion: apiVersion,
cname: name,
cnamespace: namespace,
rkind: rkind,
rname: rname,
rnamespace: rnamespace,
message: message,
enforcementaction: "deny", // default value to "deny" until we have more actions to support
})
}
return updateLists, nil
Expand Down Expand Up @@ -251,10 +254,11 @@ func (ucloop *updateConstraintLoop) updateConstraintStatus(ctx context.Context,
var statusViolations []interface{}
for _, ar := range auditResults {
statusViolations = append(statusViolations, StatusViolation{
Kind: ar.rkind,
Name: ar.rname,
Namespace: ar.rnamespace,
Message: ar.message,
Kind: ar.rkind,
Name: ar.rname,
Namespace: ar.rnamespace,
Message: ar.message,
EnforcementAction: ar.enforcementaction,
})
}
raw, err := json.Marshal(statusViolations)
Expand Down