From 030e8414d96a9dca515ed2be983629b50212d2d1 Mon Sep 17 00:00:00 2001 From: Patrick Seidensal Date: Thu, 31 Oct 2024 14:17:57 +0100 Subject: [PATCH] Deduplicate status messages (#2859) Prevents fleet from crashing due to resources exceeding etcd's configured size limit. Deduplicate messages should only be necessary for edge cases which are not officially supported by fleet but result in ever increasing message sizes. This is due to the messages being copied from one resource to another and back again. Every resource adds its status to the message. This only happens if a cluster group is deployed by a GitRepo, which results in a bundle containing a cluster group. This bundle can only become ready if the cluster group is ready, but if the cluster group points to the cluster of the bundle that deployed the cluster group, this cannot ever happen. The user is expected to fix this situation but deduplicating the messages prevents the message from growing up to the point where etcd's limit is reached and fleet crashes. Deduplicating the messages also has the effect of not changing the status of resources frequently, which results in less controllers being triggered. --- internal/helmdeployer/kustomize/kstatus.go | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/helmdeployer/kustomize/kstatus.go b/internal/helmdeployer/kustomize/kstatus.go index a4f6425ec7..85a7c000af 100644 --- a/internal/helmdeployer/kustomize/kstatus.go +++ b/internal/helmdeployer/kustomize/kstatus.go @@ -1,6 +1,8 @@ package kustomize import ( + "strings" + "github.com/rancher/fleet/internal/cmd/agent/deployer/data" "github.com/rancher/fleet/internal/cmd/agent/deployer/summary" fleetv1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1/summary" @@ -31,7 +33,29 @@ func KStatusSummarizer(obj data.Object, conditions []summary.Condition, summary } if result.Message != "" { - summary.Message = append(summary.Message, result.Message) + // Deduplicate messages here. This should only be necessary for edge + // cases which are not officially supported but result in ever + // increasing message sizes. This is due to the messages being copied + // from one resource to another and back again. Every resource adds its + // status to the message. This only happens if a cluster group is + // deployed by a GitRepo, which results in a bundle containing a cluster + // group. This bundle can only ever become ready if the cluster group is + // ready, but if the cluster group points to the cluster of the bundle, + // this cannot ever happen. This is an edge case and should be fixed by + // the user. Deduplicating the messages prevents the message from + // growing up to the point where etcd's limit is reached and fleet + // crashes. + messages := make(map[string]bool) + var resultMessages []string + for _, message := range strings.Split(result.Message, ";") { + if _, ok := messages[message]; ok { + continue + } + messages[message] = true + resultMessages = append(resultMessages, message) + } + + summary.Message = append(summary.Message, strings.Join(resultMessages, ";")) } return summary