Skip to content

Commit

Permalink
Merge pull request #533 from jvanz/controller-runtime-update
Browse files Browse the repository at this point in the history
chore: bump controller-runtime
  • Loading branch information
jvanz committed Sep 26, 2023
2 parents 646b269 + 04b6009 commit 94c8d9b
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 857 deletions.
36 changes: 16 additions & 20 deletions config/crd/bases/policies.kubewarden.io_policyservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ spec:
in a file on the node should be used. The profile must
be preconfigured on the node to work. Must be a descending
path, relative to the kubelet's configured seccomp profile
location. Must only be set if type is "Localhost".
location. Must be set if type is "Localhost". Must NOT
be set for any other type.
type: string
type:
description: "type indicates which kind of seccomp profile
Expand Down Expand Up @@ -328,15 +329,12 @@ spec:
type: string
hostProcess:
description: HostProcess determines if a container should
be run as a 'Host Process' container. This field is
alpha-level and will only be honored by components that
enable the WindowsHostProcessContainers feature flag.
Setting this field without the feature flag will result
in errors when validating the Pod. All of a Pod's containers
must have the same effective HostProcess value (it is
not allowed to have a mix of HostProcess containers
and non-HostProcess containers). In addition, if HostProcess
is true then HostNetwork must also be set to true.
be run as a 'Host Process' container. All of a Pod's
containers must have the same effective HostProcess
value (it is not allowed to have a mix of HostProcess
containers and non-HostProcess containers). In addition,
if HostProcess is true then HostNetwork must also be
set to true.
type: boolean
runAsUserName:
description: The UserName in Windows to run the entrypoint
Expand Down Expand Up @@ -438,7 +436,8 @@ spec:
in a file on the node should be used. The profile must
be preconfigured on the node to work. Must be a descending
path, relative to the kubelet's configured seccomp profile
location. Must only be set if type is "Localhost".
location. Must be set if type is "Localhost". Must NOT
be set for any other type.
type: string
type:
description: "type indicates which kind of seccomp profile
Expand Down Expand Up @@ -503,15 +502,12 @@ spec:
type: string
hostProcess:
description: HostProcess determines if a container should
be run as a 'Host Process' container. This field is
alpha-level and will only be honored by components that
enable the WindowsHostProcessContainers feature flag.
Setting this field without the feature flag will result
in errors when validating the Pod. All of a Pod's containers
must have the same effective HostProcess value (it is
not allowed to have a mix of HostProcess containers
and non-HostProcess containers). In addition, if HostProcess
is true then HostNetwork must also be set to true.
be run as a 'Host Process' container. All of a Pod's
containers must have the same effective HostProcess
value (it is not allowed to have a mix of HostProcess
containers and non-HostProcess containers). In addition,
if HostProcess is true then HostNetwork must also be
set to true.
type: boolean
runAsUserName:
description: The UserName in Windows to run the entrypoint
Expand Down
13 changes: 6 additions & 7 deletions controllers/admissionpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// Warning: this controller is deployed by a helm chart which has its own
Expand Down Expand Up @@ -78,15 +77,15 @@ func (r *AdmissionPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
err := ctrl.NewControllerManagedBy(mgr).
For(&policiesv1.AdmissionPolicy{}).
Watches(
&source.Kind{Type: &corev1.Pod{}},
&corev1.Pod{},
handler.EnqueueRequestsFromMapFunc(r.findAdmissionPoliciesForPod),
).
// Despite this policy server watch is not strictly necessary, we
// include it for the integration tests, so that we identify
// policy server creations even when the controller-manager is not
// present (so no pods end up being created)
Watches(
&source.Kind{Type: &policiesv1.PolicyServer{}},
&policiesv1.PolicyServer{},
handler.EnqueueRequestsFromMapFunc(r.findAdmissionPoliciesForPolicyServer),
).
Complete(r)
Expand All @@ -112,7 +111,7 @@ func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForConfigMap(object cli
return policyMap.ToAdmissionPolicyReconcileRequests()
}

func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForPod(object client.Object) []reconcile.Request {
func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForPod(ctx context.Context, object client.Object) []reconcile.Request {
pod, ok := object.(*corev1.Pod)
if !ok {
return []reconcile.Request{}
Expand All @@ -123,7 +122,7 @@ func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForPod(object client.Ob
}
policyServerDeploymentName := naming.PolicyServerDeploymentNameForPolicyServerName(policyServerName)
configMap := corev1.ConfigMap{}
err := r.Reconciler.APIReader.Get(context.TODO(), client.ObjectKey{
err := r.Reconciler.APIReader.Get(ctx, client.ObjectKey{
Namespace: pod.ObjectMeta.Namespace,
Name: policyServerDeploymentName, // As the deployment name matches the name of the ConfigMap
}, &configMap)
Expand All @@ -133,14 +132,14 @@ func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForPod(object client.Ob
return r.findAdmissionPoliciesForConfigMap(&configMap)
}

func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForPolicyServer(object client.Object) []reconcile.Request {
func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForPolicyServer(ctx context.Context, object client.Object) []reconcile.Request {
policyServer, ok := object.(*policiesv1.PolicyServer)
if !ok {
return []reconcile.Request{}
}
policyServerDeploymentName := naming.PolicyServerDeploymentNameForPolicyServerName(policyServer.Name)
configMap := corev1.ConfigMap{}
err := r.Reconciler.APIReader.Get(context.TODO(), client.ObjectKey{
err := r.Reconciler.APIReader.Get(ctx, client.ObjectKey{
Namespace: r.Reconciler.DeploymentsNamespace,
Name: policyServerDeploymentName, // As the deployment name matches the name of the ConfigMap
}, &configMap)
Expand Down
13 changes: 6 additions & 7 deletions controllers/clusteradmissionpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// Warning: this controller is deployed by a helm chart which has its own
Expand Down Expand Up @@ -78,15 +77,15 @@ func (r *ClusterAdmissionPolicyReconciler) SetupWithManager(mgr ctrl.Manager) er
err := ctrl.NewControllerManagedBy(mgr).
For(&policiesv1.ClusterAdmissionPolicy{}).
Watches(
&source.Kind{Type: &corev1.Pod{}},
&corev1.Pod{},
handler.EnqueueRequestsFromMapFunc(r.findClusterAdmissionPoliciesForPod),
).
// Despite this policy server watch is not strictly necessary, we
// include it for the integration tests, so that we identify
// policy server creations even when the controller-manager is not
// present (so no pods end up being created)
Watches(
&source.Kind{Type: &policiesv1.PolicyServer{}},
&policiesv1.PolicyServer{},
handler.EnqueueRequestsFromMapFunc(r.findClusterAdmissionPoliciesForPolicyServer),
).
Complete(r)
Expand All @@ -109,7 +108,7 @@ func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForConfig
return policyMap.ToClusterAdmissionPolicyReconcileRequests()
}

func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForPod(object client.Object) []reconcile.Request {
func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForPod(ctx context.Context, object client.Object) []reconcile.Request {
pod, ok := object.(*corev1.Pod)
if !ok {
return []reconcile.Request{}
Expand All @@ -120,7 +119,7 @@ func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForPod(ob
}
policyServerDeploymentName := naming.PolicyServerDeploymentNameForPolicyServerName(policyServerName)
configMap := corev1.ConfigMap{}
err := r.Reconciler.APIReader.Get(context.TODO(), client.ObjectKey{
err := r.Reconciler.APIReader.Get(ctx, client.ObjectKey{
Namespace: pod.ObjectMeta.Namespace,
Name: policyServerDeploymentName, // As the deployment name matches the name of the ConfigMap
}, &configMap)
Expand All @@ -130,14 +129,14 @@ func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForPod(ob
return r.findClusterAdmissionPoliciesForConfigMap(&configMap)
}

func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForPolicyServer(object client.Object) []reconcile.Request {
func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForPolicyServer(ctx context.Context, object client.Object) []reconcile.Request {
policyServer, ok := object.(*policiesv1.PolicyServer)
if !ok {
return []reconcile.Request{}
}
policyServerDeploymentName := naming.PolicyServerDeploymentNameForPolicyServerName(policyServer.Name)
configMap := corev1.ConfigMap{}
err := r.Reconciler.APIReader.Get(context.TODO(), client.ObjectKey{
err := r.Reconciler.APIReader.Get(ctx, client.ObjectKey{
Namespace: r.Reconciler.DeploymentsNamespace,
Name: policyServerDeploymentName, // As the deployment name matches the name of the ConfigMap
}, &configMap)
Expand Down
5 changes: 2 additions & 3 deletions controllers/policyserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// PolicyServerReconciler reconciles a PolicyServer object
Expand Down Expand Up @@ -153,7 +152,7 @@ func (r *PolicyServerReconciler) SetupWithManager(mgr ctrl.Manager) error {
}
err = ctrl.NewControllerManagedBy(mgr).
For(&policiesv1.PolicyServer{}).
Watches(&source.Kind{Type: &policiesv1.AdmissionPolicy{}}, handler.EnqueueRequestsFromMapFunc(func(object client.Object) []reconcile.Request {
Watches(&policiesv1.AdmissionPolicy{}, handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, object client.Object) []reconcile.Request {
// The watch will trigger twice per object change; once with the old
// object, and once the new object. We need to be mindful when doing
// Updates since they will invalidate the newever versions of the
Expand All @@ -172,7 +171,7 @@ func (r *PolicyServerReconciler) SetupWithManager(mgr ctrl.Manager) error {
},
}
})).
Watches(&source.Kind{Type: &policiesv1.ClusterAdmissionPolicy{}}, handler.EnqueueRequestsFromMapFunc(func(object client.Object) []reconcile.Request {
Watches(&policiesv1.ClusterAdmissionPolicy{}, handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, object client.Object) []reconcile.Request {
// The watch will trigger twice per object change; once with the old
// object, and once the new object. We need to be mindful when doing
// Updates since they will invalidate the newever versions of the
Expand Down
48 changes: 24 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module github.com/kubewarden/kubewarden-controller
go 1.21

require (
github.com/ereslibre/kube-webhook-wrapper v0.0.2
github.com/go-logr/logr v1.2.4
github.com/google/go-cmp v0.5.9
github.com/kubewarden/kube-webhook-wrapper v0.0.3
github.com/onsi/ginkgo/v2 v2.12.0
github.com/onsi/gomega v1.27.10
go.opentelemetry.io/otel v1.18.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.41.0
go.opentelemetry.io/otel/metric v1.18.0
go.opentelemetry.io/otel/sdk/metric v0.41.0
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
sigs.k8s.io/controller-runtime v0.14.6
k8s.io/api v0.28.1
k8s.io/apimachinery v0.28.1
k8s.io/client-go v0.28.1
sigs.k8s.io/controller-runtime v0.16.2
)

require (
Expand All @@ -28,17 +28,17 @@ require (
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
Expand All @@ -50,26 +50,26 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.41.0 // indirect
go.opentelemetry.io/otel/sdk v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
Expand All @@ -78,12 +78,12 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.1 // indirect
k8s.io/component-base v0.26.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/apiextensions-apiserver v0.28.0 // indirect
k8s.io/component-base v0.28.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 94c8d9b

Please sign in to comment.