Skip to content
Open
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
52 changes: 52 additions & 0 deletions e2e/testcases/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Comment on lines +1305 to +1321

Choose a reason for hiding this comment

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

medium

This cleanup logic is duplicated in TestNomosMigrateMonoRepo (lines 1490-1506) and TestACMUninstallScript (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:

func deleteLegacyDeployments(nt *nomostest.NT) {
	nt.T.Helper()
	// 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)
	}
}

Then, you can replace the duplicated blocks in each T.Cleanup with a single call to deleteLegacyDeployments(nt).

if err := nomostest.InstallConfigSync(nt); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down