-
Notifications
You must be signed in to change notification settings - Fork 271
Detect offline clusters #2933
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
Open
weyfonk
wants to merge
28
commits into
rancher:main
Choose a base branch
from
weyfonk:594-detect-offline-cluster
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Detect offline clusters #2933
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7a0a92b
Add cluster status monitor to controller
weyfonk 9e364db
Reflect offline cluster state in more bundle deployment status fields
weyfonk 3599997
Move cluster status monitor to separate package
weyfonk a6938fe
Set sensible configuration for cluster status monitor
weyfonk 38ee90a
Eliminate linting errors
weyfonk 02937c1
Check for condition status and reason
weyfonk e1f3998
Prevent agent check-in interval from being 0
weyfonk 1224333
Prevent check-in interval from being 0 when importing cluster
weyfonk 9bc99d8
Make cluster monitor interval and threshold configurable
weyfonk 1ad8b3b
Skip bundle deployment updates for already offline clusters
weyfonk 0e53496
Set Ready condition to Unknown for offline clusters
weyfonk 6fbe68e
Fix json attribute for cluster monitor interval
weyfonk 6c83845
Run cluster status monitor on unsharded controller only
weyfonk c22a760
Add agent check-in interval to agent install tests
weyfonk 5a2c6a3
Fix linting errors
weyfonk 3784896
Use feature flag for enabling cluster monitor
weyfonk 5299b88
Add threshold to cluster status check log message
weyfonk 4d523c2
Mark Cluster as Offline when its bundle deployments are offline
weyfonk ba25110
Prevent cluster updates triggered by cluster status updates
weyfonk 56a21af
Use patch operations in cluster monitor
weyfonk 772791c
Validate offline cluster status changes in both directions
weyfonk de3ad8e
Detect online clusters from online bundle deployments
weyfonk 94a188f
Make linters happy
weyfonk da57fd6
Disconnect cluster instead of scaling Fleet agent deployment
weyfonk 57ca339
Address Copilot's comments
weyfonk c419d10
Make linters happy
weyfonk 63a964a
Skip single bundle deployment if already offline instead of whole set
weyfonk 4a32093
Simplify setting cluster offline and back online from BDs
weyfonk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| package multicluster_test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os/exec" | ||
| "time" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
|
|
||
| "github.com/rancher/fleet/e2e/testenv" | ||
| "github.com/rancher/fleet/e2e/testenv/kubectl" | ||
| "github.com/rancher/wrangler/v3/pkg/genericcondition" | ||
| ) | ||
|
|
||
| // This test uses two clusters to demonstrate offline cluster handling. | ||
| var _ = Describe("Offline cluster detection", func() { | ||
| var ( | ||
| k kubectl.Command | ||
| asset string | ||
| name string | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| k = env.Kubectl.Context(env.Upstream) | ||
| }) | ||
|
|
||
| Context("cluster with deployed workload becomes offline", func() { | ||
| BeforeEach(func() { | ||
| asset = "multi-cluster/helmop.yaml" | ||
| name = "test-offline-cluster" | ||
|
|
||
| err := testenv.ApplyTemplate(k.Namespace(env.ClusterRegistrationNamespace), testenv.AssetPath(asset), struct { | ||
| Name string | ||
| Namespace string | ||
| Repo string | ||
| Chart string | ||
| Version string | ||
| PollingInterval time.Duration | ||
| HelmSecretName string | ||
| InsecureSkipTLSVerify bool | ||
| }{ | ||
| name, | ||
| env.ClusterRegistrationNamespace, | ||
| "", | ||
| "https://github.com/rancher/fleet/raw/refs/heads/main/integrationtests/cli/assets/helmrepository/config-chart-0.1.0.tgz", | ||
| "", | ||
| 0, | ||
| "", | ||
| false, | ||
| }) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| DeferCleanup(func() { | ||
| connectCmd := exec.Command("docker", "network", "connect", "fleet", "k3d-"+k3dDownstreamCluster+"-server-0") | ||
| _, _ = connectCmd.CombinedOutput() // will fail if the node is already connected. | ||
|
|
||
| _, _ = k.Namespace(env.ClusterRegistrationNamespace).Delete("helmop", name) | ||
| }) | ||
| }) | ||
| It("marks any offline cluster as such, along with its bundle deployments", func() { | ||
| By("checking the initial online state of the cluster") | ||
| // Cluster should be ready | ||
| Eventually(func(g Gomega) { | ||
| out, err := k.Get( | ||
| "cluster", "-n", env.ClusterRegistrationNamespace, | ||
| "-o", `jsonpath={.items[0].status.conditions}`, | ||
| ) | ||
| g.Expect(err).ToNot(HaveOccurred(), out) | ||
|
|
||
| checkReadyCondition(g, out, "", "True") | ||
| }).To(Succeed()) | ||
|
|
||
| // Bundle deployment should be ready | ||
| Eventually(func(g Gomega) { | ||
| out, err := k.Get( | ||
| "bundledeployments", "-A", | ||
| "-l", "fleet.cattle.io/bundle-name="+name, | ||
| "-l", "fleet.cattle.io/bundle-namespace="+env.ClusterRegistrationNamespace, | ||
| "-o", `jsonpath={.items[0].status.conditions}`, | ||
| ) | ||
| g.Expect(err).ToNot(HaveOccurred(), out) | ||
|
|
||
| checkReadyCondition(g, out, "", "True") | ||
| }).To(Succeed()) | ||
|
|
||
| By("taking the cluster offline") | ||
| disconnectCmd := exec.Command("docker", "network", "disconnect", "fleet", "k3d-"+k3dDownstreamCluster+"-server-0") | ||
| out, err := disconnectCmd.CombinedOutput() | ||
| Expect(err).ToNot(HaveOccurred(), string(out)) | ||
|
|
||
| By("checking that the bundle deployment and the cluster appear offline") | ||
| // Cluster should be offline | ||
| Eventually(func(g Gomega) { | ||
| out, err := k.Get( | ||
| "cluster", "-n", env.ClusterRegistrationNamespace, | ||
| "-o", `jsonpath={.items[0].status.conditions}`, | ||
| ) | ||
| g.Expect(err).ToNot(HaveOccurred(), out) | ||
|
|
||
| checkReadyCondition(g, out, "cluster is offline", "Unknown") | ||
| }).To(Succeed()) | ||
|
|
||
| // Bundle deployment should be offline | ||
| Eventually(func(g Gomega) { | ||
| out, err := k.Get( | ||
| "bundledeployments", "-A", | ||
| "-l", "fleet.cattle.io/bundle-name="+name, | ||
| "-l", "fleet.cattle.io/bundle-namespace="+env.ClusterRegistrationNamespace, | ||
| "-o", `jsonpath={.items[0].status.conditions}`, | ||
| ) | ||
| g.Expect(err).ToNot(HaveOccurred(), out) | ||
|
|
||
| checkReadyCondition(g, out, "cluster is offline", "Unknown") | ||
| }).To(Succeed()) | ||
|
|
||
| By("taking the cluster back online") | ||
| connectCmd := exec.Command("docker", "network", "connect", "fleet", "k3d-"+k3dDownstreamCluster+"-server-0") | ||
| out, err = connectCmd.CombinedOutput() | ||
| Expect(err).ToNot(HaveOccurred(), string(out)) | ||
|
|
||
| By("checking the new online state of the cluster") | ||
| // Cluster should be ready again | ||
| Eventually(func(g Gomega) { | ||
| out, err := k.Get( | ||
| "cluster", "-n", env.ClusterRegistrationNamespace, | ||
| "-o", `jsonpath={.items[0].status.conditions}`, | ||
| ) | ||
| g.Expect(err).ToNot(HaveOccurred(), out) | ||
|
|
||
| checkReadyCondition(g, out, "", "True") | ||
| }).To(Succeed()) | ||
|
|
||
| // Bundle deployment should be ready again | ||
| Eventually(func(g Gomega) { | ||
| out, err := k.Get( | ||
| "bundledeployments", "-A", | ||
| "-l", "fleet.cattle.io/bundle-name="+name, | ||
| "-l", "fleet.cattle.io/bundle-namespace="+env.ClusterRegistrationNamespace, | ||
| "-o", `jsonpath={.items[0].status.conditions}`, | ||
| ) | ||
| g.Expect(err).ToNot(HaveOccurred(), out) | ||
|
|
||
| checkReadyCondition(g, out, "", "True") | ||
| }).To(Succeed()) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| func checkReadyCondition(g Gomega, out, msg, status string) { | ||
| conds := []genericcondition.GenericCondition{} | ||
| err := json.Unmarshal([]byte(out), &conds) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| var readyCond *genericcondition.GenericCondition | ||
| for i, c := range conds { | ||
| if c.Type == "Ready" { | ||
| readyCond = &conds[i] | ||
| } | ||
| } | ||
|
|
||
| g.Expect(readyCond).NotTo(BeNil()) | ||
| g.Expect(readyCond.Message).To(ContainSubstring(msg)) | ||
| g.Expect(readyCond.Status).To(Equal(corev1.ConditionStatus(status))) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.