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

sotw: event predicates #915

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
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
128 changes: 108 additions & 20 deletions controllers/state_of_the_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"k8s.io/client-go/dynamic"
"k8s.io/utils/env"
ctrlruntime "sigs.k8s.io/controller-runtime"
ctrlruntimepredicate "sigs.k8s.io/controller-runtime/pkg/predicate"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

kuadrantv1alpha1 "github.com/kuadrant/kuadrant-operator/api/v1alpha1"
Expand All @@ -42,14 +43,53 @@
controller.ManagedBy(manager),
controller.WithLogger(logger),
controller.WithClient(client),
controller.WithRunnable("kuadrant watcher", controller.Watch(&kuadrantv1beta1.Kuadrant{}, kuadrantv1beta1.KuadrantsResource, metav1.NamespaceAll)),
controller.WithRunnable("dnspolicy watcher", controller.Watch(&kuadrantv1alpha1.DNSPolicy{}, kuadrantv1alpha1.DNSPoliciesResource, metav1.NamespaceAll)),
controller.WithRunnable("tlspolicy watcher", controller.Watch(&kuadrantv1alpha1.TLSPolicy{}, kuadrantv1alpha1.TLSPoliciesResource, metav1.NamespaceAll)),
controller.WithRunnable("authpolicy watcher", controller.Watch(&kuadrantv1beta2.AuthPolicy{}, kuadrantv1beta2.AuthPoliciesResource, metav1.NamespaceAll)),
controller.WithRunnable("ratelimitpolicy watcher", controller.Watch(&kuadrantv1beta3.RateLimitPolicy{}, kuadrantv1beta3.RateLimitPoliciesResource, metav1.NamespaceAll)),
controller.WithRunnable("topology configmap watcher", controller.Watch(&corev1.ConfigMap{}, controller.ConfigMapsResource, operatorNamespace, controller.FilterResourcesByLabel[*corev1.ConfigMap](fmt.Sprintf("%s=true", kuadrant.TopologyLabel)))),
controller.WithRunnable("limitador watcher", controller.Watch(&limitadorv1alpha1.Limitador{}, kuadrantv1beta1.LimitadorsResource, metav1.NamespaceAll)),
controller.WithRunnable("authorino watcher", controller.Watch(&authorinov1beta1.Authorino{}, kuadrantv1beta1.AuthorinosResource, metav1.NamespaceAll)),
controller.WithRunnable("kuadrant watcher", controller.Watch(
&kuadrantv1beta1.Kuadrant{},
kuadrantv1beta1.KuadrantsResource,
metav1.NamespaceAll,
controller.WithPredicates(&ctrlruntimepredicate.TypedGenerationChangedPredicate[*kuadrantv1beta1.Kuadrant]{}),
)),
controller.WithRunnable("dnspolicy watcher", controller.Watch(
&kuadrantv1alpha1.DNSPolicy{},
kuadrantv1alpha1.DNSPoliciesResource,
metav1.NamespaceAll,
controller.WithPredicates(&ctrlruntimepredicate.TypedGenerationChangedPredicate[*kuadrantv1alpha1.DNSPolicy]{}),
)),
controller.WithRunnable("tlspolicy watcher", controller.Watch(
&kuadrantv1alpha1.TLSPolicy{},
kuadrantv1alpha1.TLSPoliciesResource,
metav1.NamespaceAll,
controller.WithPredicates(&ctrlruntimepredicate.TypedGenerationChangedPredicate[*kuadrantv1alpha1.TLSPolicy]{}),
)),
controller.WithRunnable("authpolicy watcher", controller.Watch(
&kuadrantv1beta2.AuthPolicy{},
kuadrantv1beta2.AuthPoliciesResource,
metav1.NamespaceAll,
controller.WithPredicates(&ctrlruntimepredicate.TypedGenerationChangedPredicate[*kuadrantv1beta2.AuthPolicy]{}),
)),
controller.WithRunnable("ratelimitpolicy watcher", controller.Watch(
&kuadrantv1beta3.RateLimitPolicy{},
kuadrantv1beta3.RateLimitPoliciesResource,
metav1.NamespaceAll,
controller.WithPredicates(&ctrlruntimepredicate.TypedGenerationChangedPredicate[*kuadrantv1beta3.RateLimitPolicy]{}),
)),
controller.WithRunnable("topology configmap watcher", controller.Watch(
&corev1.ConfigMap{},
controller.ConfigMapsResource,
operatorNamespace,
controller.WithPredicates(&ctrlruntimepredicate.TypedGenerationChangedPredicate[*corev1.ConfigMap]{}),
controller.FilterResourcesByLabel[*corev1.ConfigMap](fmt.Sprintf("%s=true", kuadrant.TopologyLabel)),
)),
controller.WithRunnable("limitador watcher", controller.Watch(
&limitadorv1alpha1.Limitador{},
kuadrantv1beta1.LimitadorsResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("authorino watcher", controller.Watch(
&authorinov1beta1.Authorino{},
kuadrantv1beta1.AuthorinosResource,
metav1.NamespaceAll,
)),
controller.WithPolicyKinds(
kuadrantv1alpha1.DNSPolicyGroupKind,
kuadrantv1alpha1.TLSPolicyGroupKind,
Expand All @@ -74,9 +114,21 @@
logger.Info("gateway api is not installed, skipping watches and reconcilers", "err", err)
} else {
controllerOpts = append(controllerOpts,
controller.WithRunnable("gatewayclass watcher", controller.Watch(&gwapiv1.GatewayClass{}, controller.GatewayClassesResource, metav1.NamespaceAll)),
controller.WithRunnable("gateway watcher", controller.Watch(&gwapiv1.Gateway{}, controller.GatewaysResource, metav1.NamespaceAll)),
controller.WithRunnable("httproute watcher", controller.Watch(&gwapiv1.HTTPRoute{}, controller.HTTPRoutesResource, metav1.NamespaceAll)),
controller.WithRunnable("gatewayclass watcher", controller.Watch(
&gwapiv1.GatewayClass{},
controller.GatewayClassesResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("gateway watcher", controller.Watch(
&gwapiv1.Gateway{},
controller.GatewaysResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("httproute watcher", controller.Watch(
&gwapiv1.HTTPRoute{},
controller.HTTPRoutesResource,
metav1.NamespaceAll,
)),
)
}

Expand All @@ -85,9 +137,21 @@
logger.Info("envoygateway is not installed, skipping related watches and reconcilers", "err", err)
} else {
controllerOpts = append(controllerOpts,
controller.WithRunnable("envoypatchpolicy watcher", controller.Watch(&egv1alpha1.EnvoyPatchPolicy{}, envoygateway.EnvoyPatchPoliciesResource, metav1.NamespaceAll)),
controller.WithRunnable("envoyextensionpolicy watcher", controller.Watch(&egv1alpha1.EnvoyExtensionPolicy{}, envoygateway.EnvoyExtensionPoliciesResource, metav1.NamespaceAll)),
controller.WithRunnable("envoysecuritypolicy watcher", controller.Watch(&egv1alpha1.SecurityPolicy{}, envoygateway.SecurityPoliciesResource, metav1.NamespaceAll)),
controller.WithRunnable("envoypatchpolicy watcher", controller.Watch(
&egv1alpha1.EnvoyPatchPolicy{},
envoygateway.EnvoyPatchPoliciesResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("envoyextensionpolicy watcher", controller.Watch(
&egv1alpha1.EnvoyExtensionPolicy{},
envoygateway.EnvoyExtensionPoliciesResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("envoysecuritypolicy watcher", controller.Watch(
&egv1alpha1.SecurityPolicy{},
envoygateway.SecurityPoliciesResource,
metav1.NamespaceAll,
)),

Check warning on line 154 in controllers/state_of_the_world.go

View check run for this annotation

Codecov / codecov/patch

controllers/state_of_the_world.go#L140-L154

Added lines #L140 - L154 were not covered by tests
controller.WithObjectKinds(
envoygateway.EnvoyPatchPolicyGroupKind,
envoygateway.EnvoyExtensionPolicyGroupKind,
Expand All @@ -103,9 +167,21 @@
logger.Info("istio is not installed, skipping related watches and reconcilers", "err", err)
} else {
controllerOpts = append(controllerOpts,
controller.WithRunnable("envoyfilter watcher", controller.Watch(&istioclientnetworkingv1alpha3.EnvoyFilter{}, istio.EnvoyFiltersResource, metav1.NamespaceAll)),
controller.WithRunnable("wasmplugin watcher", controller.Watch(&istioclientgoextensionv1alpha1.WasmPlugin{}, istio.WasmPluginsResource, metav1.NamespaceAll)),
controller.WithRunnable("authorizationpolicy watcher", controller.Watch(&istioclientgosecurityv1beta1.AuthorizationPolicy{}, istio.AuthorizationPoliciesResource, metav1.NamespaceAll)),
controller.WithRunnable("envoyfilter watcher", controller.Watch(
&istioclientnetworkingv1alpha3.EnvoyFilter{},
istio.EnvoyFiltersResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("wasmplugin watcher", controller.Watch(
&istioclientgoextensionv1alpha1.WasmPlugin{},
istio.WasmPluginsResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("authorizationpolicy watcher", controller.Watch(
&istioclientgosecurityv1beta1.AuthorizationPolicy{},
istio.AuthorizationPoliciesResource,
metav1.NamespaceAll,
)),

Check warning on line 184 in controllers/state_of_the_world.go

View check run for this annotation

Codecov / codecov/patch

controllers/state_of_the_world.go#L170-L184

Added lines #L170 - L184 were not covered by tests
controller.WithObjectKinds(
istio.EnvoyFilterGroupKind,
istio.WasmPluginGroupKind,
Expand All @@ -121,9 +197,21 @@
logger.Info("cert manager is not installed, skipping related watches and reconcilers", "err", err)
} else {
controllerOpts = append(controllerOpts,
controller.WithRunnable("certificate watcher", controller.Watch(&certmanagerv1.Certificate{}, CertManagerCertificatesResource, metav1.NamespaceAll)),
controller.WithRunnable("issuers watcher", controller.Watch(&certmanagerv1.Issuer{}, CertManagerIssuersResource, metav1.NamespaceAll)),
controller.WithRunnable("clusterissuers watcher", controller.Watch(&certmanagerv1.Certificate{}, CertMangerClusterIssuersResource, metav1.NamespaceAll)),
controller.WithRunnable("certificate watcher", controller.Watch(
&certmanagerv1.Certificate{},
CertManagerCertificatesResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("issuers watcher", controller.Watch(
&certmanagerv1.Issuer{},
CertManagerIssuersResource,
metav1.NamespaceAll,
)),
controller.WithRunnable("clusterissuers watcher", controller.Watch(
&certmanagerv1.Certificate{},
CertMangerClusterIssuersResource,
metav1.NamespaceAll,
)),
controller.WithObjectKinds(
CertManagerCertificateKind,
CertManagerIssuerKind,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/kuadrant/authorino-operator v0.11.1
github.com/kuadrant/dns-operator v0.0.0-20241002074817-d0cab9eecbdb
github.com/kuadrant/limitador-operator v0.9.0
github.com/kuadrant/policy-machinery v0.2.0
github.com/kuadrant/policy-machinery v0.5.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't realised main was so much behind. In fact, this explains why I was observing multiple stale update events related to the topology ConfigMap at another branch but not really in main.

Added another commit, shamelessly stolen from @KevFan, to widen the change to all kinds of resources watched by the SOTW reconciler.

github.com/martinlindhe/base36 v1.1.1
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ github.com/kuadrant/limitador-operator v0.9.0 h1:hTQ6CFPayf/sL7cIzwWjCoU8uTn6fzW
github.com/kuadrant/limitador-operator v0.9.0/go.mod h1:DQOlg9qFOcnWPrwO529JRCMLLOEXJQxkmOes952S/Hw=
github.com/kuadrant/policy-machinery v0.2.0 h1:6kACb+bdEwHXz2tvTs6dlLgvxFgFrowvGTZKMI9p0Qo=
github.com/kuadrant/policy-machinery v0.2.0/go.mod h1:ZV4xS0CCxPgu/Xg6gz+YUaS9zqEXKOiAj33bZ67B6Lo=
github.com/kuadrant/policy-machinery v0.5.0 h1:hTllNYswhEOFrS/uj8kY4a4wq2W1xL2hagHeftn9TTY=
github.com/kuadrant/policy-machinery v0.5.0/go.mod h1:ZV4xS0CCxPgu/Xg6gz+YUaS9zqEXKOiAj33bZ67B6Lo=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
Expand Down
Loading