Skip to content

Commit 313a440

Browse files
committed
test: Add client side install method for restoring Config Sync
To guarantee the e2e client claims ownership of all fields for objects that might have drifted, use client-side apply when reinstalling Config Sync and Webhook fter ConfigManagement was previously installed and removed.
1 parent c8fb6cf commit 313a440

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

e2e/nomostest/config_sync.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ var (
8383
//
8484
// All paths must be relative to the test file that is running. There is probably
8585
// a more elegant way to do this.
86-
baseDir = filepath.FromSlash("../..")
87-
outputManifestsDir = filepath.Join(baseDir, ".output", "staging", "oss")
88-
configSyncManifest = filepath.Join(outputManifestsDir, "config-sync-manifest.yaml")
89-
multiConfigMaps = filepath.Join(baseDir, "e2e", "raw-nomos", configSyncManifests, multiConfigMapsName)
86+
baseDir = filepath.FromSlash("../..")
87+
outputManifestsDir = filepath.Join(baseDir, ".output", "staging", "oss")
88+
configSyncManifest = filepath.Join(outputManifestsDir, "config-sync-manifest.yaml")
89+
admissionWebhookManifest = filepath.Join(outputManifestsDir, "admission-webhook.yaml")
90+
multiConfigMaps = filepath.Join(baseDir, "e2e", "raw-nomos", configSyncManifests, multiConfigMapsName)
9091
)
9192

9293
var (
@@ -245,6 +246,34 @@ func InstallConfigSync(nt *NT) error {
245246
return nil
246247
}
247248

249+
// InstallConfigSyncFromManifest installs ConfigSync on the test cluster by directly
250+
// applying the manifest file using kubectl client-side apply
251+
func InstallConfigSyncFromManifest(nt *NT) error {
252+
nt.T.Log("[SETUP] Installing Config Sync directly from manifest file")
253+
254+
nt.T.Logf("Applying Config Sync manifest directly from %s", configSyncManifest)
255+
256+
out, err := nt.Shell.Kubectl("apply", "-f", configSyncManifest)
257+
if err != nil {
258+
return fmt.Errorf("failed to apply Config Sync manifest: %v\n%s", err, out)
259+
}
260+
261+
nt.T.Logf("Applying multi-repo configmaps from %s", multiConfigMaps)
262+
out, err = nt.Shell.Kubectl("apply", "-f", multiConfigMaps)
263+
if err != nil {
264+
return fmt.Errorf("failed to apply multi-repo configmaps: %v\n%s", err, out)
265+
}
266+
267+
// Apply the admission webhook manifest
268+
nt.T.Logf("Applying admission webhook manifest from %s", admissionWebhookManifest)
269+
out, err = nt.Shell.Kubectl("apply", "-f", admissionWebhookManifest)
270+
if err != nil {
271+
return fmt.Errorf("failed to apply admission webhook manifest: %v\n%s", err, out)
272+
}
273+
274+
return nil
275+
}
276+
248277
// uninstallConfigSync uninstalls ConfigSync on the test cluster
249278
func uninstallConfigSync(nt *NT) error {
250279
nt.T.Log("[CLEANUP] Uninstalling Config Sync")

e2e/testcases/cli_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,13 +1297,14 @@ func TestApiResourceFormatting(t *testing.T) {
12971297
}
12981298

12991299
func TestNomosMigrate(t *testing.T) {
1300-
nt := nomostest.New(t, nomostesting.NomosCLI, ntopts.SkipConfigSyncInstall)
1300+
nt := nomostest.New(t, nomostesting.NomosCLI)
13011301

13021302
nt.T.Cleanup(func() {
13031303
// Restore state of Config Sync installation after test
1304-
if err := nomostest.InstallConfigSync(nt); err != nil {
1304+
if err := nomostest.InstallConfigSyncFromManifest(nt); err != nil {
13051305
nt.T.Fatal(err)
13061306
}
1307+
nt.Must(nt.WatchForAllSyncs())
13071308
})
13081309
nt.T.Cleanup(func() {
13091310
cmObj := &unstructured.Unstructured{
@@ -1451,11 +1452,11 @@ func TestNomosMigrate(t *testing.T) {
14511452
configmanagement.RGControllerName, configmanagement.RGControllerNamespace)
14521453
})
14531454
tg.Go(func() error {
1454-
return nt.Watcher.WatchForNotFound(kinds.Deployment(),
1455+
return nt.Watcher.WatchForCurrentStatus(kinds.Deployment(),
14551456
core.RootReconcilerName(configsync.RootSyncName), configsync.ControllerNamespace)
14561457
})
14571458
tg.Go(func() error {
1458-
return nt.Watcher.WatchForNotFound(kinds.RootSyncV1Beta1(),
1459+
return nt.Watcher.WatchForCurrentStatus(kinds.RootSyncV1Beta1(),
14591460
configsync.RootSyncName, configsync.ControllerNamespace)
14601461
})
14611462
if err := tg.Wait(); err != nil {
@@ -1464,14 +1465,14 @@ func TestNomosMigrate(t *testing.T) {
14641465
}
14651466

14661467
func TestNomosMigrateMonoRepo(t *testing.T) {
1467-
nt := nomostest.New(t, nomostesting.NomosCLI, ntopts.SkipConfigSyncInstall)
1468+
nt := nomostest.New(t, nomostesting.NomosCLI)
14681469

14691470
nt.T.Cleanup(func() {
14701471
// Restore state of Config Sync installation after test.
1471-
// This also emulates upgrading to the current version after migrating
1472-
if err := nomostest.InstallConfigSync(nt); err != nil {
1472+
if err := nomostest.InstallConfigSyncFromManifest(nt); err != nil {
14731473
nt.T.Fatal(err)
14741474
}
1475+
nt.Must(nt.WatchForAllSyncs())
14751476
})
14761477
nt.T.Cleanup(func() {
14771478
crds := []string{
@@ -1707,13 +1708,14 @@ func TestNomosMigrateMonoRepo(t *testing.T) {
17071708
// This test case validates the behavior of the uninstall script defined
17081709
// at installation/uninstall_configmanagement.sh
17091710
func TestACMUninstallScript(t *testing.T) {
1710-
nt := nomostest.New(t, nomostesting.NomosCLI, ntopts.SkipConfigSyncInstall)
1711+
nt := nomostest.New(t, nomostesting.NomosCLI)
17111712

17121713
nt.T.Cleanup(func() {
17131714
// Restore state of Config Sync installation after test
1714-
if err := nomostest.InstallConfigSync(nt); err != nil {
1715+
if err := nomostest.InstallConfigSyncFromManifest(nt); err != nil {
17151716
nt.T.Fatal(err)
17161717
}
1718+
nt.Must(nt.WatchForAllSyncs())
17171719
})
17181720
nt.T.Cleanup(func() {
17191721
cmObj := &unstructured.Unstructured{
@@ -1861,11 +1863,11 @@ func TestACMUninstallScript(t *testing.T) {
18611863
configmanagement.RGControllerName, configmanagement.RGControllerNamespace)
18621864
})
18631865
tg.Go(func() error {
1864-
return nt.Watcher.WatchForNotFound(kinds.Deployment(),
1866+
return nt.Watcher.WatchForCurrentStatus(kinds.Deployment(),
18651867
core.RootReconcilerName(configsync.RootSyncName), configsync.ControllerNamespace)
18661868
})
18671869
tg.Go(func() error {
1868-
return nt.Watcher.WatchForNotFound(kinds.RootSyncV1Beta1(),
1870+
return nt.Watcher.WatchForCurrentStatus(kinds.RootSyncV1Beta1(),
18691871
configsync.RootSyncName, configsync.ControllerNamespace)
18701872
})
18711873
if err := tg.Wait(); err != nil {

0 commit comments

Comments
 (0)