Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
38 changes: 34 additions & 4 deletions e2e/nomostest/config_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

A DeepCopy should not be necessary here for every object, can this be switched to populating an empty object (e.g. Unstructured)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

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
Expand Down
2 changes: 1 addition & 1 deletion e2e/nomostest/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 13 additions & 11 deletions e2e/testcases/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down