Skip to content

Commit

Permalink
Add by pod status for mutators (#1260)
Browse files Browse the repository at this point in the history
* Add by pod status for mutators

Signed-off-by: Max Smythe <smythe@google.com>

* Only enable mutation status if mutation is enabled

Signed-off-by: Max Smythe <smythe@google.com>

* Add tests

Signed-off-by: Max Smythe <smythe@google.com>

* Address PR comments

Signed-off-by: Max Smythe <smythe@google.com>
  • Loading branch information
maxsmythe committed May 6, 2021
1 parent f6d0fc9 commit 20a0e1a
Show file tree
Hide file tree
Showing 44 changed files with 2,057 additions and 441 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ install: manifests
kustomize build config/crd | kubectl apply -f -

deploy-mutation: patch-image
@grep -q -v 'enable-mutation' ./config/overlays/dev_mutation/manager_image_patch.yaml && sed -i '/- --operation=webhook/a \ \ \ \ \ \ \ \ - --enable-mutation=true' ./config/overlays/dev_mutation/manager_image_patch.yaml
@grep -q -v 'enable-mutation' ./config/overlays/dev_mutation/manager_image_patch.yaml && sed -i '/- --operation=webhook/a \ \ \ \ \ \ \ \ - --enable-mutation=true' ./config/overlays/dev_mutation/manager_image_patch.yaml && sed -i '/- --operation=status/a \ \ \ \ \ \ \ \ - --operation=mutation-status' ./config/overlays/dev_mutation/manager_image_patch.yaml
kustomize build config/overlays/dev_mutation | kubectl apply -f -
kustomize build --load_restrictor LoadRestrictionsNone config/overlays/mutation | kubectl apply -f -

Expand Down
21 changes: 9 additions & 12 deletions apis/mutations/v1alpha1/assign_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package v1alpha1
import (
"encoding/json"

"github.com/open-policy-agent/gatekeeper/apis/status/v1beta1"
"github.com/open-policy-agent/gatekeeper/pkg/mutation/match"
"github.com/open-policy-agent/gatekeeper/pkg/mutation/path/tester"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -30,18 +32,10 @@ import (
type AssignSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
ApplyTo []ApplyTo `json:"applyTo,omitempty"`
Match Match `json:"match,omitempty"`
Location string `json:"location,omitempty"`
Parameters Parameters `json:"parameters,omitempty"`
}

// ApplyTo determines what GVKs items the mutation should apply to.
// Globs are not allowed.
type ApplyTo struct {
Groups []string `json:"groups,omitempty"`
Kinds []string `json:"kinds,omitempty"`
Versions []string `json:"versions,omitempty"`
ApplyTo []match.ApplyTo `json:"applyTo,omitempty"`
Match match.Match `json:"match,omitempty"`
Location string `json:"location,omitempty"`
Parameters Parameters `json:"parameters,omitempty"`
}

type Parameters struct {
Expand Down Expand Up @@ -75,11 +69,14 @@ type PathTest struct {
type AssignStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

ByPod []v1beta1.MutatorPodStatusStatus `json:"byPod,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:path="assign"
// +kubebuilder:resource:scope="Cluster"
// +kubebuilder:subresource:status

// Assign is the Schema for the assign API
type Assign struct {
Expand Down
6 changes: 5 additions & 1 deletion apis/mutations/v1alpha1/assignmetadata_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.
package v1alpha1

import (
"github.com/open-policy-agent/gatekeeper/apis/status/v1beta1"
"github.com/open-policy-agent/gatekeeper/pkg/mutation/match"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
Expand All @@ -25,7 +27,7 @@ import (

// AssignMetadataSpec defines the desired state of AssignMetadata
type AssignMetadataSpec struct {
Match Match `json:"match,omitempty"`
Match match.Match `json:"match,omitempty"`
Location string `json:"location,omitempty"`
Parameters MetadataParameters `json:"parameters,omitempty"`
}
Expand All @@ -40,10 +42,12 @@ type MetadataParameters struct {
type AssignMetadataStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
ByPod []v1beta1.MutatorPodStatusStatus `json:"byPod,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope="Cluster"
// +kubebuilder:subresource:status

// AssignMetadata is the Schema for the assignmetadata API
type AssignMetadata struct {
Expand Down
42 changes: 0 additions & 42 deletions apis/mutations/v1alpha1/match.go

This file was deleted.

118 changes: 18 additions & 100 deletions apis/mutations/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions apis/status/v1beta1/constraintpodstatus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import (
)

const (
ConstraintNameLabel = "internal.gatekeeper.sh/constraint-name"
ConstraintKindLabel = "internal.gatekeeper.sh/constraint-kind"
PodLabel = "internal.gatekeeper.sh/pod"
ConstraintsGroup = "constraints.gatekeeper.sh"
ConstraintsGroup = "constraints.gatekeeper.sh"
)

// ConstraintPodStatusStatus defines the observed state of ConstraintPodStatus
Expand Down
4 changes: 0 additions & 4 deletions apis/status/v1beta1/constrainttemplatepodstatus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

const (
ConstraintTemplateNameLabel = "internal.gatekeeper.sh/constrainttemplate-name"
)

// ConstraintTemplatePodStatusStatus defines the observed state of ConstraintTemplatePodStatus
type ConstraintTemplatePodStatusStatus struct {
// Important: Run "make" to regenerate code after modifying this file
Expand Down
10 changes: 10 additions & 0 deletions apis/status/v1beta1/labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package v1beta1

const (
ConstraintNameLabel = "internal.gatekeeper.sh/constraint-name"
ConstraintKindLabel = "internal.gatekeeper.sh/constraint-kind"
ConstraintTemplateNameLabel = "internal.gatekeeper.sh/constrainttemplate-name"
MutatorNameLabel = "internal.gatekeeper.sh/mutator-name"
MutatorKindLabel = "internal.gatekeeper.sh/mutator-kind"
PodLabel = "internal.gatekeeper.sh/pod"
)

0 comments on commit 20a0e1a

Please sign in to comment.