diff --git a/e2e/nomostest/config_sync.go b/e2e/nomostest/config_sync.go index 58918a7803..cdd4200af6 100644 --- a/e2e/nomostest/config_sync.go +++ b/e2e/nomostest/config_sync.go @@ -78,6 +78,16 @@ const ( shortSyncPollingPeriod = 5 * time.Second ) +// InstallMethod defines how Config Sync should be installed +type InstallMethod string + +const ( + // InstallMethodApply uses server-side apply (default) + InstallMethodApply InstallMethod = "apply" + // InstallMethodUpdate uses client-side update + InstallMethodUpdate InstallMethod = "update" +) + var ( // baseDir is the path to the Nomos repository root from test case files. // @@ -230,16 +240,36 @@ func parseConfigSyncManifests(nt *NT) ([]client.Object, error) { } // InstallConfigSync installs ConfigSync on the test cluster -func InstallConfigSync(nt *NT) error { - nt.T.Log("[SETUP] Installing Config Sync") +func InstallConfigSync(nt *NT, method InstallMethod) error { + nt.T.Log("[SETUP] Installing Config Sync using method: ", method) objs, err := parseConfigSyncManifests(nt) if err != nil { return err } for _, o := range objs { nt.T.Logf("installConfigSync obj: %v", core.GKNN(o)) - if err := nt.KubeClient.Apply(o); err != nil { - return err + switch method { + case InstallMethodApply: + if err := nt.KubeClient.Apply(o); err != nil { + return err + } + case InstallMethodUpdate: + currentObj := o.DeepCopyObject().(client.Object) + if err := nt.KubeClient.Get(currentObj.GetName(), currentObj.GetNamespace(), currentObj); err != nil { + if apierrors.IsNotFound(err) { + if err := nt.KubeClient.Create(o); err != nil { + return err + } + } else { + return err + } + } else { + // Attach existing resourceVersion to the object + o.SetResourceVersion(currentObj.GetResourceVersion()) + if err := nt.KubeClient.Update(o); err != nil { + return err + } + } } } return nil diff --git a/e2e/nomostest/new.go b/e2e/nomostest/new.go index 316f06b0ca..47d67da80f 100644 --- a/e2e/nomostest/new.go +++ b/e2e/nomostest/new.go @@ -385,7 +385,7 @@ func FreshTestEnv(t nomostesting.NTB, opts *ntopts.New) *NT { return setupRegistry(nt) }) tg.Go(func() error { - return InstallConfigSync(nt) + return InstallConfigSync(nt, InstallMethodApply) }) tg.Go(func() error { return installPrometheus(nt) diff --git a/e2e/testcases/cli_test.go b/e2e/testcases/cli_test.go index 854051e3e5..e19b700825 100644 --- a/e2e/testcases/cli_test.go +++ b/e2e/testcases/cli_test.go @@ -1297,13 +1297,14 @@ func TestApiResourceFormatting(t *testing.T) { } func TestNomosMigrate(t *testing.T) { - nt := nomostest.New(t, nomostesting.NomosCLI, ntopts.SkipConfigSyncInstall) + nt := nomostest.New(t, nomostesting.NomosCLI) nt.T.Cleanup(func() { // Restore state of Config Sync installation after test - if err := nomostest.InstallConfigSync(nt); err != nil { + if err := nomostest.InstallConfigSync(nt, nomostest.InstallMethodUpdate); err != nil { nt.T.Fatal(err) } + nt.Must(nt.WatchForAllSyncs()) }) nt.T.Cleanup(func() { cmObj := &unstructured.Unstructured{ @@ -1451,11 +1452,11 @@ func TestNomosMigrate(t *testing.T) { configmanagement.RGControllerName, configmanagement.RGControllerNamespace) }) tg.Go(func() error { - return nt.Watcher.WatchForNotFound(kinds.Deployment(), + return nt.Watcher.WatchForCurrentStatus(kinds.Deployment(), core.RootReconcilerName(configsync.RootSyncName), configsync.ControllerNamespace) }) tg.Go(func() error { - return nt.Watcher.WatchForNotFound(kinds.RootSyncV1Beta1(), + return nt.Watcher.WatchForCurrentStatus(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace) }) if err := tg.Wait(); err != nil { @@ -1464,14 +1465,14 @@ func TestNomosMigrate(t *testing.T) { } func TestNomosMigrateMonoRepo(t *testing.T) { - nt := nomostest.New(t, nomostesting.NomosCLI, ntopts.SkipConfigSyncInstall) + nt := nomostest.New(t, nomostesting.NomosCLI) nt.T.Cleanup(func() { // Restore state of Config Sync installation after test. - // This also emulates upgrading to the current version after migrating - if err := nomostest.InstallConfigSync(nt); err != nil { + if err := nomostest.InstallConfigSync(nt, nomostest.InstallMethodUpdate); err != nil { nt.T.Fatal(err) } + nt.Must(nt.WatchForAllSyncs()) }) nt.T.Cleanup(func() { crds := []string{ @@ -1707,13 +1708,14 @@ func TestNomosMigrateMonoRepo(t *testing.T) { // This test case validates the behavior of the uninstall script defined // at installation/uninstall_configmanagement.sh func TestACMUninstallScript(t *testing.T) { - nt := nomostest.New(t, nomostesting.NomosCLI, ntopts.SkipConfigSyncInstall) + nt := nomostest.New(t, nomostesting.NomosCLI) nt.T.Cleanup(func() { // Restore state of Config Sync installation after test - if err := nomostest.InstallConfigSync(nt); err != nil { + if err := nomostest.InstallConfigSync(nt, nomostest.InstallMethodUpdate); err != nil { nt.T.Fatal(err) } + nt.Must(nt.WatchForAllSyncs()) }) nt.T.Cleanup(func() { cmObj := &unstructured.Unstructured{ @@ -1861,11 +1863,11 @@ func TestACMUninstallScript(t *testing.T) { configmanagement.RGControllerName, configmanagement.RGControllerNamespace) }) tg.Go(func() error { - return nt.Watcher.WatchForNotFound(kinds.Deployment(), + return nt.Watcher.WatchForCurrentStatus(kinds.Deployment(), core.RootReconcilerName(configsync.RootSyncName), configsync.ControllerNamespace) }) tg.Go(func() error { - return nt.Watcher.WatchForNotFound(kinds.RootSyncV1Beta1(), + return nt.Watcher.WatchForCurrentStatus(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace) }) if err := tg.Wait(); err != nil {