-
Notifications
You must be signed in to change notification settings - Fork 50
Cleanup legacy controller deployments in test teardown #1834
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: main
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 |
---|---|---|
|
@@ -43,6 +43,7 @@ import ( | |
"kpt.dev/configsync/e2e/nomostest/ntopts" | ||
"kpt.dev/configsync/e2e/nomostest/policy" | ||
"kpt.dev/configsync/e2e/nomostest/syncsource" | ||
|
||
"kpt.dev/configsync/e2e/nomostest/taskgroup" | ||
nomostesting "kpt.dev/configsync/e2e/nomostest/testing" | ||
"kpt.dev/configsync/e2e/nomostest/testpredicates" | ||
|
@@ -1301,6 +1302,23 @@ func TestNomosMigrate(t *testing.T) { | |
|
||
nt.T.Cleanup(func() { | ||
// Restore state of Config Sync installation after test | ||
// Legacy ConfigManagement sets readiness on reconciler-manager and resource-group-controller, | ||
// which isn't reliably cleaned up after tests. Delete both to ensure a fresh | ||
// install instead of patching. | ||
rmDeployment := k8sobjects.DeploymentObject( | ||
core.Name(reconcilermanager.ManagerName), | ||
core.Namespace(configsync.ControllerNamespace), | ||
) | ||
rgDeployment := k8sobjects.DeploymentObject( | ||
core.Name(configmanagement.RGControllerName), | ||
core.Namespace(configmanagement.RGControllerNamespace), | ||
) | ||
if err := nt.KubeClient.Delete(rmDeployment); err != nil && !apierrors.IsNotFound(err) { | ||
nt.T.Error(err) | ||
} | ||
if err := nt.KubeClient.Delete(rgDeployment); err != nil && !apierrors.IsNotFound(err) { | ||
nt.T.Error(err) | ||
} | ||
if err := nomostest.InstallConfigSync(nt); err != nil { | ||
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. Deleting and recreating specific subcomponents is going to be error prone, as it doesn't guarantee the e2e client claims ownership of all fields for all objects which could have drifted. Perhaps using client side apply here when reinstalling would be a more thorough option 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. Mmm without the other PR it's hard to know whether further changes are effective or just false positive, some natural result from the standalone branching. I might need to add some check for the readiness field as well to verify it's actually removed. 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. I'd suggest rebasing that PR on top of this one, then you can validate it works from the tests in the other PR |
||
nt.T.Fatal(err) | ||
} | ||
|
@@ -1469,6 +1487,23 @@ func TestNomosMigrateMonoRepo(t *testing.T) { | |
nt.T.Cleanup(func() { | ||
// Restore state of Config Sync installation after test. | ||
// This also emulates upgrading to the current version after migrating | ||
// Legacy ConfigManagement sets readiness on reconciler-manager and resource-group-controller, | ||
// which isn’t reliably cleaned up after tests. Delete both to ensure a fresh | ||
// install instead of patching. | ||
rmDeployment := k8sobjects.DeploymentObject( | ||
core.Name(reconcilermanager.ManagerName), | ||
core.Namespace(configsync.ControllerNamespace), | ||
) | ||
rgDeployment := k8sobjects.DeploymentObject( | ||
core.Name(configmanagement.RGControllerName), | ||
core.Namespace(configmanagement.RGControllerNamespace), | ||
) | ||
if err := nt.KubeClient.Delete(rmDeployment); err != nil && !apierrors.IsNotFound(err) { | ||
nt.T.Error(err) | ||
} | ||
if err := nt.KubeClient.Delete(rgDeployment); err != nil && !apierrors.IsNotFound(err) { | ||
nt.T.Error(err) | ||
} | ||
if err := nomostest.InstallConfigSync(nt); err != nil { | ||
nt.T.Fatal(err) | ||
} | ||
|
@@ -1711,6 +1746,23 @@ func TestACMUninstallScript(t *testing.T) { | |
|
||
nt.T.Cleanup(func() { | ||
// Restore state of Config Sync installation after test | ||
// Legacy ConfigManagement sets readiness on reconciler-manager and resource-group-controller, | ||
// which isn’t reliably cleaned up after tests. Delete both to ensure a fresh | ||
// install instead of patching. | ||
rmDeployment := k8sobjects.DeploymentObject( | ||
core.Name(reconcilermanager.ManagerName), | ||
core.Namespace(configsync.ControllerNamespace), | ||
) | ||
rgDeployment := k8sobjects.DeploymentObject( | ||
core.Name(configmanagement.RGControllerName), | ||
core.Namespace(configmanagement.RGControllerNamespace), | ||
) | ||
if err := nt.KubeClient.Delete(rmDeployment); err != nil && !apierrors.IsNotFound(err) { | ||
nt.T.Error(err) | ||
} | ||
if err := nt.KubeClient.Delete(rgDeployment); err != nil && !apierrors.IsNotFound(err) { | ||
nt.T.Error(err) | ||
} | ||
if err := nomostest.InstallConfigSync(nt); err != nil { | ||
nt.T.Fatal(err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cleanup logic is duplicated in
TestNomosMigrateMonoRepo
(lines 1490-1506) andTestACMUninstallScript
(lines 1749-1765). To improve maintainability and reduce code duplication, consider extracting this logic into a local helper function within this file.For example, you could create a function like this:
Then, you can replace the duplicated blocks in each
T.Cleanup
with a single call todeleteLegacyDeployments(nt)
.