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

fix: add --operation=mutation-controller flag #2542

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 7 additions & 7 deletions pkg/controller/mutators/core/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func TestReconciler_Reconcile(t *testing.T) {
},
Status: statusv1beta1.MutatorPodStatusStatus{
ID: "no-pod",
Operations: []string{"audit", "mutation-status", "mutation-webhook", "status", "webhook"},
Operations: []string{"audit", "mutation-controller", "mutation-status", "mutation-webhook", "status", "webhook"},
davis-haba marked this conversation as resolved.
Show resolved Hide resolved
Enforced: true,
Errors: nil,
},
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestReconciler_Reconcile(t *testing.T) {
},
Status: statusv1beta1.MutatorPodStatusStatus{
ID: "no-pod",
Operations: []string{"audit", "mutation-status", "mutation-webhook", "status", "webhook"},
Operations: []string{"audit", "mutation-controller", "mutation-status", "mutation-webhook", "status", "webhook"},
Enforced: true,
Errors: nil,
},
Expand Down Expand Up @@ -494,7 +494,7 @@ func TestReconciler_Reconcile(t *testing.T) {
},
Status: statusv1beta1.MutatorPodStatusStatus{
ID: "no-pod",
Operations: []string{"audit", "mutation-status", "mutation-webhook", "status", "webhook"},
Operations: []string{"audit", "mutation-controller", "mutation-status", "mutation-webhook", "status", "webhook"},
Enforced: false,
Errors: []statusv1beta1.MutatorError{{Message: newErrSome(1).Error()}},
},
Expand Down Expand Up @@ -535,7 +535,7 @@ func TestReconciler_Reconcile(t *testing.T) {
},
Status: statusv1beta1.MutatorPodStatusStatus{
ID: "no-pod",
Operations: []string{"audit", "mutation-status", "mutation-webhook", "status", "webhook"},
Operations: []string{"audit", "mutation-controller", "mutation-status", "mutation-webhook", "status", "webhook"},
Enforced: false,
Errors: []statusv1beta1.MutatorError{
{
Expand Down Expand Up @@ -634,7 +634,7 @@ func TestReconciler_Reconcile(t *testing.T) {
},
Status: statusv1beta1.MutatorPodStatusStatus{
ID: "no-pod",
Operations: []string{"audit", "mutation-status", "mutation-webhook", "status", "webhook"},
Operations: []string{"audit", "mutation-controller", "mutation-status", "mutation-webhook", "status", "webhook"},
Enforced: false,
Errors: []statusv1beta1.MutatorError{
{
Expand Down Expand Up @@ -685,7 +685,7 @@ func TestReconciler_Reconcile(t *testing.T) {
},
Status: statusv1beta1.MutatorPodStatusStatus{
ID: "no-pod",
Operations: []string{"audit", "mutation-status", "mutation-webhook", "status", "webhook"},
Operations: []string{"audit", "mutation-controller", "mutation-status", "mutation-webhook", "status", "webhook"},
Enforced: true,
Errors: nil,
},
Expand Down Expand Up @@ -940,7 +940,7 @@ func TestReconciler_Reconcile_DeletePodStatus(t *testing.T) {
},
Status: statusv1beta1.MutatorPodStatusStatus{
ID: "no-pod",
Operations: []string{"audit", "mutation-status", "mutation-webhook", "status", "webhook"},
Operations: []string{"audit", "mutation-controller", "mutation-status", "mutation-webhook", "status", "webhook"},
Enforced: true,
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mutation/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func init() {

// Enabled indicates if the mutation feature is enabled.
func Enabled() bool {
return operations.IsAssigned(operations.MutationStatus) || operations.IsAssigned(operations.MutationWebhook)
return operations.IsAssigned(operations.MutationStatus) || operations.IsAssigned(operations.MutationWebhook) || operations.IsAssigned(operations.MutationController)
}
29 changes: 9 additions & 20 deletions pkg/operations/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ type Operation string

// All defined Operations.
const (
Audit = Operation("audit")
Status = Operation("status")
MutationStatus = Operation("mutation-status")
MutationWebhook = Operation("mutation-webhook")
Webhook = Operation("webhook")
Audit = Operation("audit")
MutationController = Operation("mutation-controller")
MutationStatus = Operation("mutation-status")
MutationWebhook = Operation("mutation-webhook")
Status = Operation("status")
Webhook = Operation("webhook")
)

var (
// allOperations is a list of all possible Operations that can be assigned to
// a pod. It is NOT intended to be mutated. It should be kept in alphabetical
// order so that it can be readily compared to the results from AssignedOperations.
// a pod. It is NOT intended to be mutated.
allOperations = []Operation{
Audit,
Status,
MutationController,
MutationStatus,
MutationWebhook,
Status,
Webhook,
}

Expand Down Expand Up @@ -85,18 +86,6 @@ func init() {
flag.Var(operations, "operation", "The operation to be performed by this instance. e.g. audit, webhook. This flag can be declared more than once. Omitting will default to supporting all operations.")
}

// AssignedOperations returns a map of operations assigned to the pod.
davis-haba marked this conversation as resolved.
Show resolved Hide resolved
func AssignedOperations() map[Operation]bool {
ret := make(map[Operation]bool)
operationsMtx.RLock()
defer operationsMtx.RUnlock()

for k, v := range operations.assignedOperations {
ret[k] = v
}
return ret
}

// IsAssigned returns true when the provided operation is assigned to the pod.
func IsAssigned(op Operation) bool {
operationsMtx.RLock()
Expand Down
2 changes: 1 addition & 1 deletion pkg/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Test_Flags(t *testing.T) {
}{
"default": {
input: []string{},
expected: map[Operation]bool{Audit: true, Webhook: true, Status: true, MutationStatus: true, MutationWebhook: true},
expected: map[Operation]bool{Audit: true, Webhook: true, Status: true, MutationStatus: true, MutationWebhook: true, MutationController: true},
},
"multiple": {
input: []string{"-operation", "audit", "-operation", "webhook"},
Expand Down
23 changes: 23 additions & 0 deletions website/docs/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,29 @@ At a high level, this requires:
* The ability to write to all objects in the group `mutations.gatekeeper.sh` (mutators)
* The ability to read `MutatorPodStatus` objects in Gatekeeper's namespace

## Mutation Controller

__--operation key:__ `mutation-controller`

This operation runs the process responsible for ingesting and registering
davis-haba marked this conversation as resolved.
Show resolved Hide resolved
mutators. `mutation-controller` is run implicitly with the `mutation-webhook`
and `mutation-status` operations, and is redundant if any of the 2
aforementioned operations are already specified.

If the `webhook` operation is used in isolation without the `mutation-webhook`
davis-haba marked this conversation as resolved.
Show resolved Hide resolved
or `mutation-status` operations, then the `mutation-controller` operation is
required for mutation to work with [workload expansion](workload-resources.md).

### Required Behaviors:

At a high level, this requires:

* Ingesting Mutator objects

### Permissions Required

* The ability to read all objects in the group `mutations.gatekeeper.sh` (mutators)

# A Note on Permissions

"Create" implies the `create` and `delete` permissions in addition to the permissions implied by "Read" and "Write".
Expand Down