Skip to content

Commit 851c901

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 851c901

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,11 @@ func TestNomosMigrate(t *testing.T) {
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+
// Check that reconciler-manager is properly recreated after Config Sync installation
1308+
nt.Must(nt.WatchForAllSyncs())
13071309
})
13081310
nt.T.Cleanup(func() {
13091311
cmObj := &unstructured.Unstructured{
@@ -1468,10 +1470,11 @@ func TestNomosMigrateMonoRepo(t *testing.T) {
14681470

14691471
nt.T.Cleanup(func() {
14701472
// 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 {
1473+
if err := nomostest.InstallConfigSyncFromManifest(nt); err != nil {
14731474
nt.T.Fatal(err)
14741475
}
1476+
// Check that Reconciler-manager is properly recreated after Config Sync installation
1477+
nt.Must(nt.WatchForAllSyncs())
14751478
})
14761479
nt.T.Cleanup(func() {
14771480
crds := []string{
@@ -1711,9 +1714,11 @@ func TestACMUninstallScript(t *testing.T) {
17111714

17121715
nt.T.Cleanup(func() {
17131716
// Restore state of Config Sync installation after test
1714-
if err := nomostest.InstallConfigSync(nt); err != nil {
1717+
if err := nomostest.InstallConfigSyncFromManifest(nt); err != nil {
17151718
nt.T.Fatal(err)
17161719
}
1720+
// Check that reconciler-manager is properly recreated after Config Sync installation
1721+
nt.Must(nt.WatchForAllSyncs())
17171722
})
17181723
nt.T.Cleanup(func() {
17191724
cmObj := &unstructured.Unstructured{

0 commit comments

Comments
 (0)