-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: Harden informer cache with label selectors and memory optimizations #6242
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,18 @@ import ( | |
| // to ensure that exec-entrypoint and run can make use of them. | ||
| _ "k8s.io/client-go/plugin/pkg/client/auth" | ||
|
|
||
| appsv1 "k8s.io/api/apps/v1" | ||
| autoscalingv2 "k8s.io/api/autoscaling/v2" | ||
| batchv1 "k8s.io/api/batch/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| policyv1 "k8s.io/api/policy/v1" | ||
| rbacv1 "k8s.io/api/rbac/v1" | ||
| "k8s.io/apimachinery/pkg/labels" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/cache" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/healthz" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
|
@@ -59,6 +66,29 @@ func init() { | |
| // +kubebuilder:scaffold:scheme | ||
| } | ||
|
|
||
| func newCacheOptions() cache.Options { | ||
| managedBySelector := labels.SelectorFromSet(labels.Set{ | ||
| services.ManagedByLabelKey: services.ManagedByLabelValue, | ||
| }) | ||
| managedByFilter := cache.ByObject{Label: managedBySelector} | ||
|
|
||
| return cache.Options{ | ||
| DefaultTransform: cache.TransformStripManagedFields(), | ||
| ByObject: map[client.Object]cache.ByObject{ | ||
| &corev1.ConfigMap{}: managedByFilter, | ||
| &appsv1.Deployment{}: managedByFilter, | ||
| &corev1.Service{}: managedByFilter, | ||
| &corev1.ServiceAccount{}: managedByFilter, | ||
| &corev1.PersistentVolumeClaim{}: managedByFilter, | ||
| &rbacv1.RoleBinding{}: managedByFilter, | ||
| &rbacv1.Role{}: managedByFilter, | ||
devin-ai-integration[bot] marked this conversation as resolved.
Show resolved
Hide resolved
devin-ai-integration[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| &batchv1.CronJob{}: managedByFilter, | ||
| &autoscalingv2.HorizontalPodAutoscaler{}: managedByFilter, | ||
| &policyv1.PodDisruptionBudget{}: managedByFilter, | ||
| }, | ||
| } | ||
|
Comment on lines
+77
to
+89
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Cache label filter breaks operator for pre-existing resources on upgrade The new cache On upgrade from a prior version, existing operator-managed resources won't have the
This is a permanent deadlock: the operator can never update the resource to add the label because it can't find it through the cache. This affects all existing FeatureStore instances after an operator upgrade. Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
|
|
||
| func main() { | ||
| var metricsAddr string | ||
| var enableLeaderElection bool | ||
|
|
@@ -145,6 +175,7 @@ func main() { | |
| // if you are doing or is intended to do any operation such as perform cleanups | ||
| // after the manager stops then its usage might be unsafe. | ||
| // LeaderElectionReleaseOnCancel: true, | ||
| Cache: newCacheOptions(), | ||
| Client: client.Options{ | ||
| Cache: &client.CacheOptions{ | ||
| DisableFor: []client.Object{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,16 @@ | ||
| - op: test | ||
| path: "/spec/template/spec/containers/0/env/1/name" | ||
| value: RELATED_IMAGE_FEATURE_SERVER | ||
| - op: replace | ||
| path: "/spec/template/spec/containers/0/env/0" | ||
| path: "/spec/template/spec/containers/0/env/1" | ||
| value: | ||
| name: RELATED_IMAGE_FEATURE_SERVER | ||
| value: ${FS_IMG} | ||
| - op: test | ||
| path: "/spec/template/spec/containers/0/env/2/name" | ||
| value: RELATED_IMAGE_CRON_JOB | ||
| - op: replace | ||
| path: "/spec/template/spec/containers/0/env/1" | ||
| path: "/spec/template/spec/containers/0/env/2" | ||
| value: | ||
| name: RELATED_IMAGE_CRON_JOB | ||
| value: ${CJ_IMG} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,16 @@ | ||
| - op: test | ||
| path: "/spec/template/spec/containers/0/env/1/name" | ||
| value: RELATED_IMAGE_FEATURE_SERVER | ||
| - op: replace | ||
| path: "/spec/template/spec/containers/0/env/0" | ||
| path: "/spec/template/spec/containers/0/env/1" | ||
| value: | ||
| name: RELATED_IMAGE_FEATURE_SERVER | ||
| value: quay.io/feastdev/feature-server:0.62.0 | ||
| - op: test | ||
| path: "/spec/template/spec/containers/0/env/2/name" | ||
| value: RELATED_IMAGE_CRON_JOB | ||
| - op: replace | ||
| path: "/spec/template/spec/containers/0/env/1" | ||
| path: "/spec/template/spec/containers/0/env/2" | ||
| value: | ||
| name: RELATED_IMAGE_CRON_JOB | ||
| value: quay.io/openshift/origin-cli:4.17 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,7 @@ func (feast *FeastServices) setNamespaceRegistryRoleBinding(rb *rbacv1.RoleBindi | |
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: roleName, | ||
| Namespace: rb.Namespace, | ||
| Labels: feast.getLabels(), | ||
| }, | ||
| } | ||
| role.Rules = desiredRules | ||
|
|
@@ -205,6 +206,7 @@ func (feast *FeastServices) setNamespaceRegistryRoleBinding(rb *rbacv1.RoleBindi | |
| } | ||
| } | ||
|
Comment on lines
206
to
207
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Namespace registry Role Get from filtered cache fails after tolerated AlreadyExists on Create In (Refers to lines 182-207) Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| rb.Labels = feast.getLabels() | ||
| rb.RoleRef = rbacv1.RoleRef{ | ||
| APIGroup: "rbac.authorization.k8s.io", | ||
| Kind: "Role", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.