From 74898a60490da9eb48774c7198583e34a8a125ec Mon Sep 17 00:00:00 2001 From: Karl Isenberg Date: Tue, 20 Aug 2024 17:28:56 -0700 Subject: [PATCH] e2e: Simplify tracking of RSync sources (#1395) --- e2e/nomostest/config_sync.go | 344 +++++++++----- e2e/nomostest/new.go | 31 +- e2e/nomostest/nt.go | 164 +++---- e2e/nomostest/prometheus_metrics.go | 35 +- e2e/nomostest/registryproviders/helm_chart.go | 5 + e2e/nomostest/reset.go | 9 +- e2e/nomostest/syncsource/set.go | 83 ++++ e2e/nomostest/syncsource/syncsource.go | 82 ++++ e2e/nomostest/wait_for_sync.go | 67 +-- e2e/testcases/acme_test.go | 32 +- e2e/testcases/admission_test.go | 20 +- .../adopt_client_side_applied_test.go | 11 +- e2e/testcases/apiservice_test.go | 27 +- e2e/testcases/basic_test.go | 63 +-- e2e/testcases/cli_test.go | 6 +- e2e/testcases/cluster_resources_test.go | 18 +- e2e/testcases/cluster_selectors_test.go | 201 ++++---- e2e/testcases/composition_test.go | 14 +- ...custom_resource_definitions_schema_test.go | 16 +- .../custom_resource_definitions_test.go | 110 ++--- e2e/testcases/custom_resources_test.go | 30 +- e2e/testcases/declared_fields_test.go | 14 +- e2e/testcases/gatekeeper_test.go | 19 +- e2e/testcases/gcenode_test.go | 17 +- e2e/testcases/git_sync_test.go | 11 +- e2e/testcases/helm_sync_test.go | 58 ++- e2e/testcases/hydration_test.go | 98 ++-- e2e/testcases/invalid_auth_test.go | 4 +- e2e/testcases/invalid_git_branch_test.go | 43 +- e2e/testcases/kptfile_test.go | 11 +- e2e/testcases/lifecycle_directives_test.go | 58 +-- e2e/testcases/local_config_test.go | 35 +- e2e/testcases/managed_resources_test.go | 67 +-- e2e/testcases/multi_sync_test.go | 435 ++++++++++-------- e2e/testcases/multiversion_test.go | 34 +- e2e/testcases/namespace_repo_test.go | 98 ++-- e2e/testcases/namespace_selectors_test.go | 48 +- e2e/testcases/namespace_strategy_test.go | 58 ++- e2e/testcases/namespaces_test.go | 122 ++--- e2e/testcases/no_ssl_verify_test.go | 20 +- e2e/testcases/oci_sync_test.go | 38 +- e2e/testcases/otel_collector_test.go | 23 +- e2e/testcases/override_git_sync_depth_test.go | 28 +- e2e/testcases/override_log_level_test.go | 36 +- .../override_reconcile_timeout_test.go | 15 +- .../override_resource_limits_test.go | 30 +- e2e/testcases/override_role_refs_test.go | 19 +- e2e/testcases/policy_dir_test.go | 9 +- e2e/testcases/preserve_fields_test.go | 67 +-- e2e/testcases/private_cert_secret_test.go | 177 +++---- e2e/testcases/profiling_test.go | 66 +-- e2e/testcases/reconciler_finalizer_test.go | 168 +++---- e2e/testcases/reconciler_manager_test.go | 32 +- e2e/testcases/remediator_test.go | 9 +- .../resource_group_controller_test.go | 7 +- e2e/testcases/root_sync_test.go | 46 +- e2e/testcases/ssh_known_hosts_test.go | 26 +- e2e/testcases/status_enablement_test.go | 7 +- e2e/testcases/stress_test.go | 70 +-- e2e/testcases/sync_ordering_test.go | 159 +++---- e2e/testcases/workload_identity_test.go | 6 +- 61 files changed, 2091 insertions(+), 1565 deletions(-) create mode 100644 e2e/nomostest/syncsource/set.go create mode 100644 e2e/nomostest/syncsource/syncsource.go diff --git a/e2e/nomostest/config_sync.go b/e2e/nomostest/config_sync.go index 483179d5bb..3b03664019 100644 --- a/e2e/nomostest/config_sync.go +++ b/e2e/nomostest/config_sync.go @@ -31,12 +31,14 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "kpt.dev/configsync/e2e" "kpt.dev/configsync/e2e/nomostest/gitproviders" "kpt.dev/configsync/e2e/nomostest/metrics" "kpt.dev/configsync/e2e/nomostest/ntopts" "kpt.dev/configsync/e2e/nomostest/registryproviders" + "kpt.dev/configsync/e2e/nomostest/syncsource" "kpt.dev/configsync/e2e/nomostest/taskgroup" "kpt.dev/configsync/e2e/nomostest/testpredicates" "kpt.dev/configsync/e2e/nomostest/testwatcher" @@ -87,8 +89,59 @@ var ( reconcilerPollingPeriod time.Duration // hydrationPollingPeriod specifies hydration-controller polling period as time.Duration hydrationPollingPeriod time.Duration + + // DefaultRootReconcilerName is the root-reconciler name of the default RootSync object: "root-sync". + DefaultRootReconcilerName = core.RootReconcilerName(configsync.RootSyncName) + // DefaultRootRepoNamespacedName is the NamespacedName of the default RootSync object. + DefaultRootRepoNamespacedName = RootSyncNN(configsync.RootSyncName) + // DefaultRootSyncID is the ID of the default RootSync object. + DefaultRootSyncID = RootSyncID(configsync.RootSyncName) ) +// RootSyncNN returns the NamespacedName of the RootSync object. +func RootSyncNN(name string) types.NamespacedName { + return types.NamespacedName{ + Namespace: configsync.ControllerNamespace, + Name: name, + } +} + +// RepoSyncNN returns the NamespacedName of the RepoSync object. +func RepoSyncNN(ns, name string) types.NamespacedName { + return types.NamespacedName{ + Namespace: ns, + Name: name, + } +} + +// RootSyncID returns an ID for the specified RootSync object. +func RootSyncID(name string) core.ID { + return core.ID{ + GroupKind: schema.GroupKind{ + Group: v1beta1.SchemeGroupVersion.Group, + Kind: configsync.RootSyncKind, + }, + ObjectKey: client.ObjectKey{ + Name: name, + Namespace: configsync.ControllerNamespace, + }, + } +} + +// RepoSyncID returns an ID for the specified RepoSync object. +func RepoSyncID(name, namespace string) core.ID { + return core.ID{ + GroupKind: schema.GroupKind{ + Group: v1beta1.SchemeGroupVersion.Group, + Kind: configsync.RepoSyncKind, + }, + ObjectKey: client.ObjectKey{ + Name: name, + Namespace: namespace, + }, + } +} + // IsReconcilerTemplateConfigMap returns true if passed obj is the // reconciler-manager ConfigMap reconciler-manager-cm in config-management namespace. func IsReconcilerTemplateConfigMap(obj client.Object) bool { @@ -360,8 +413,19 @@ func multiRepoObjects(objects []client.Object, opts ...func(obj client.Object) e // RootSync root-sync will be re-created, if not found. func ValidateMultiRepoDeployments(nt *NT) error { // Create root-sync RootSync, if registered. - if _, found := nt.RootRepos[configsync.RootSyncName]; found { - rs := RootSyncObjectV1Beta1FromRootRepo(nt, configsync.RootSyncName) + if source, found := nt.SyncSources[DefaultRootSyncID]; found { + id := DefaultRootSyncID + var rs *v1beta1.RootSync + switch tSource := source.(type) { + case *syncsource.GitSyncSource: + rs = RootSyncObjectV1Beta1FromRootRepo(nt, id.Name) + case *syncsource.HelmSyncSource: + rs = nt.RootSyncObjectHelm(id.Name, tSource.ChartID) + // case *syncsource.OCISyncSource: + // TODO: setup OCI RootSyncs + default: + nt.T.Fatalf("Invalid RootSync source %T: %s", source, id.Name) + } if err := nt.KubeClient.Create(rs); err != nil { if !apierrors.IsAlreadyExists(err) { nt.T.Fatal(err) @@ -618,31 +682,53 @@ func setupDelegatedControl(nt *NT) { nt.T.Fatal(err) } - for rsName := range nt.RootRepos { + // Apply all the RootSyncs + for id, source := range nt.SyncSources.RootSyncs() { // The default RootSync is created manually, no need to set up again. - if rsName == configsync.RootSyncName { + if id.Name == configsync.RootSyncName { continue } - rs := RootSyncObjectV1Beta1FromRootRepo(nt, rsName) + var rs *v1beta1.RootSync + switch source.(type) { + case *syncsource.GitSyncSource: + rs = RootSyncObjectV1Beta1FromRootRepo(nt, id.Name) + // case *syncsource.HelmSyncSource: + // rs = nt.RootSyncObjectHelm(id.Name, tSource.ChartID) + // case *syncsource.OCISyncSource: + // TODO: setup OCI & Helm RootSyncs + default: + nt.T.Fatalf("Invalid %s source %T: %s", id.Kind, source, id.Name) + } if err := nt.KubeClient.Apply(rs); err != nil { nt.T.Fatal(err) } } - for nn := range nt.NonRootRepos { + // Then apply the RepoSyncs + for id, source := range nt.SyncSources.RepoSyncs() { // create namespace for namespace reconciler. - err := nt.KubeClient.Create(k8sobjects.NamespaceObject(nn.Namespace)) + err := nt.KubeClient.Create(k8sobjects.NamespaceObject(id.Namespace)) if err != nil { nt.T.Fatal(err) } - nt.Must(CreateNamespaceSecretForNonCSR(nt, nn.Namespace)) + nt.Must(CreateNamespaceSecretForNonCSR(nt, id.Namespace)) - if err := setupRepoSyncRoleBinding(nt, nn); err != nil { + if err := setupRepoSyncRoleBinding(nt, id.ObjectKey); err != nil { nt.T.Fatal(err) } - rs := RepoSyncObjectV1Beta1FromNonRootRepo(nt, nn) + var rs *v1beta1.RepoSync + switch source.(type) { + case *syncsource.GitSyncSource: + rs = RepoSyncObjectV1Beta1FromNonRootRepo(nt, id.ObjectKey) + // case *syncsource.HelmSyncSource: + // rs = nt.RepoSyncObjectHelm(id.ObjectKey, tSource.ChartID) + // case *syncsource.OCISyncSource: + // TODO: setup OCI & Helm RootSyncs + default: + nt.T.Fatalf("Invalid %s source %T: %s", id.Kind, source, id.Name) + } if err := nt.KubeClient.Apply(rs); err != nil { nt.T.Fatal(err) } @@ -681,23 +767,26 @@ func RootSyncObjectV1Alpha1(name, repoURL string, sourceFormat configsync.Source } // RootSyncObjectV1Alpha1FromRootRepo returns a v1alpha1 RootSync object which -// uses a repo from nt.RootRepos. +// uses a RootSync repo from nt.SyncSources. func RootSyncObjectV1Alpha1FromRootRepo(nt *NT, name string) *v1alpha1.RootSync { - repo, found := nt.RootRepos[name] + // TODO: Allow supplying the Repository, instead of requiring it to already exist + id := RootSyncID(name) + source, found := nt.SyncSources[id] if !found { - nt.T.Fatal("nonexistent root repo: %s", name) + nt.T.Fatal("nonexistent %s source: %s", id.Kind, id.ObjectKey) + } + gitSource, ok := source.(*syncsource.GitSyncSource) + if !ok { + nt.T.Fatal("expected SyncSources for %s to have *GitSyncSource, but got %T", id, source) } - repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName) - sourceFormat := repo.Format + repoURL := nt.GitProvider.SyncURL(gitSource.Repository.RemoteRepoName) + sourceFormat := gitSource.Repository.Format rs := RootSyncObjectV1Alpha1(name, repoURL, sourceFormat) if nt.DefaultReconcileTimeout != nil { rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout) } else if rs.Spec.Override != nil { rs.Spec.Override.ReconcileTimeout = nil } - // Unregister the Helm repo for syncing, if any - rsKey := client.ObjectKeyFromObject(rs) - delete(nt.RootSyncHelmCharts, rsKey) // TODO: delete repo? return rs } @@ -733,44 +822,50 @@ func RootSyncObjectV1Beta1(name, repoURL string, sourceFormat configsync.SourceF } // RootSyncObjectV1Beta1FromRootRepo returns a v1beta1 RootSync object which -// uses a repo from nt.RootRepos. +// uses a RootSync repo from nt.SyncSources. func RootSyncObjectV1Beta1FromRootRepo(nt *NT, name string) *v1beta1.RootSync { - repo, found := nt.RootRepos[name] + // TODO: Allow supplying the Repository, instead of requiring it to already exist + id := RootSyncID(name) + source, found := nt.SyncSources[id] if !found { - nt.T.Fatalf("nonexistent root repo: %s", name) + nt.T.Fatal("nonexistent %s source: %s", id.Kind, id.ObjectKey) } - repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName) - sourceFormat := repo.Format + gitSource, ok := source.(*syncsource.GitSyncSource) + if !ok { + nt.T.Fatal("expected SyncSources for %s to have *GitSyncSource, but got %T", id, source) + } + repoURL := nt.GitProvider.SyncURL(gitSource.Repository.RemoteRepoName) + sourceFormat := gitSource.Repository.Format rs := RootSyncObjectV1Beta1(name, repoURL, sourceFormat) if nt.DefaultReconcileTimeout != nil { rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout) } else if rs.Spec.Override != nil { rs.Spec.Override.ReconcileTimeout = nil } - // Unregister the Helm repo for syncing, if any - rsKey := client.ObjectKeyFromObject(rs) - delete(nt.RootSyncHelmCharts, rsKey) // TODO: delete repo? return rs } // RootSyncObjectV1Beta1FromOtherRootRepo returns a v1beta1 RootSync object which // uses a repo from a specific nt.RootRepo. func RootSyncObjectV1Beta1FromOtherRootRepo(nt *NT, syncName, repoName string) *v1beta1.RootSync { - repo, found := nt.RootRepos[repoName] + // TODO: Allow supplying the Repository, instead of requiring it to already exist + repoID := RootSyncID(repoName) + source, found := nt.SyncSources[repoID] if !found { - nt.T.Fatalf("nonexistent root repo: %s", repoName) + nt.T.Fatal("nonexistent %s source: %s", repoID.Kind, repoID.ObjectKey) + } + gitSource, ok := source.(*syncsource.GitSyncSource) + if !ok { + nt.T.Fatal("expected SyncSources for %s to have *GitSyncSource, but got %T", repoID, source) } - repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName) - sourceFormat := repo.Format + repoURL := nt.GitProvider.SyncURL(gitSource.Repository.RemoteRepoName) + sourceFormat := gitSource.Repository.Format rs := RootSyncObjectV1Beta1(syncName, repoURL, sourceFormat) if nt.DefaultReconcileTimeout != nil { rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout) } else if rs.Spec.Override != nil { rs.Spec.Override.ReconcileTimeout = nil } - // Unregister the Helm repo for syncing, if any - rsKey := client.ObjectKeyFromObject(rs) - delete(nt.RootSyncHelmCharts, rsKey) // TODO: delete repo? return rs } @@ -811,13 +906,19 @@ func RepoSyncObjectV1Alpha1(nn types.NamespacedName, repoURL string) *v1alpha1.R } // RepoSyncObjectV1Alpha1FromNonRootRepo returns a v1alpha1 RepoSync object which -// uses a repo from nt.NonRootRepos. +// uses a RepoSync repo from nt.SyncSources. func RepoSyncObjectV1Alpha1FromNonRootRepo(nt *NT, nn types.NamespacedName) *v1alpha1.RepoSync { - repo, found := nt.NonRootRepos[nn] + // TODO: Allow supplying the Repository, instead of requiring it to already exist + id := RepoSyncID(nn.Name, nn.Namespace) + source, found := nt.SyncSources[id] if !found { - nt.T.Fatal("nonexistent non-root repo: %s", nn) + nt.T.Fatal("nonexistent %s source: %s", id.Kind, id.ObjectKey) + } + gitSource, ok := source.(*syncsource.GitSyncSource) + if !ok { + nt.T.Fatal("expected SyncSources for %s to have *GitSyncSource, but got %T", id, source) } - repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName) + repoURL := nt.GitProvider.SyncURL(gitSource.Repository.RemoteRepoName) // RepoSync is always Unstructured. So ignore repo.Format. rs := RepoSyncObjectV1Alpha1(nn, repoURL) if nt.DefaultReconcileTimeout != nil { @@ -832,8 +933,6 @@ func RepoSyncObjectV1Alpha1FromNonRootRepo(nt *NT, nn types.NamespacedName) *v1a if err := SetRepoSyncDependencies(nt, rs); err != nil { nt.T.Fatal(err) } - // Unregister the Helm repo for syncing, if any - delete(nt.RepoSyncHelmCharts, nn) // TODO: delete repo? return rs } @@ -929,6 +1028,21 @@ func (nt *NT) RepoSyncObjectOCI(nn types.NamespacedName, image *registryprovider // RootSyncObjectHelm returns a RootSync object that syncs the provided HelmPackage func (nt *NT) RootSyncObjectHelm(name string, chartID registryproviders.HelmChartID) *v1beta1.RootSync { + id := RootSyncID(name) + source, found := nt.SyncSources[id] + if found { + if helmSource, ok := source.(*syncsource.HelmSyncSource); ok { + if helmSource.ChartID != chartID { + nt.T.Logf("Updating existing %s %T: %s", id.Kind, source, id.ObjectKey) + } + } else { + nt.T.Logf("Replacing existing %s %T with HelmSyncSource: %s", id.Kind, source, id.ObjectKey) + } + } + // Register the Helm chart for syncing + nt.SyncSources[id] = &syncsource.HelmSyncSource{ + ChartID: chartID, + } chartRepoURL, err := nt.HelmProvider.RepositoryRemoteURL() if err != nil { nt.T.Fatalf("HelmProvider.RepositoryRemoteURL: %v", err) @@ -966,16 +1080,26 @@ func (nt *NT) RootSyncObjectHelm(name string, chartID registryproviders.HelmChar // Enable automatic deletion of managed objects by default. // This helps ensure that test artifacts are cleaned up. EnableDeletionPropagation(rs) - // Register the Helm chart for syncing - rsKey := client.ObjectKeyFromObject(rs) - nt.RootSyncHelmCharts[rsKey] = chartID - // Unregister the Git repo for syncing, if any - delete(nt.RootRepos, rsKey.Name) // TODO: delete repo? return rs } // RepoSyncObjectHelm returns a RepoSync object that syncs the provided HelmPackage func (nt *NT) RepoSyncObjectHelm(nn types.NamespacedName, chartID registryproviders.HelmChartID) *v1beta1.RepoSync { + id := RepoSyncID(nn.Name, nn.Namespace) + source, found := nt.SyncSources[id] + if found { + if helmSource, ok := source.(*syncsource.HelmSyncSource); ok { + if helmSource.ChartID != chartID { + nt.T.Logf("Updating existing %s %T: %s", id.Kind, source, id.ObjectKey) + } + } else { + nt.T.Logf("Replacing existing %s %T with HelmSyncSource: %s", id.Kind, source, id.ObjectKey) + } + } + // Register the Helm chart for syncing + nt.SyncSources[id] = &syncsource.HelmSyncSource{ + ChartID: chartID, + } chartRepoURL, err := nt.HelmProvider.RepositoryRemoteURL() if err != nil { nt.T.Fatalf("HelmProvider.RepositoryRemoteURL: %v", err) @@ -1017,23 +1141,24 @@ func (nt *NT) RepoSyncObjectHelm(nn types.NamespacedName, chartID registryprovid // Enable automatic deletion of managed objects by default. // This helps ensure that test artifacts are cleaned up. EnableDeletionPropagation(rs) - // Register the Helm chart for syncing - rsKey := client.ObjectKeyFromObject(rs) - nt.RepoSyncHelmCharts[rsKey] = chartID - // Unregister the Git repo for syncing, if any - delete(nt.NonRootRepos, rsKey) // TODO: delete repo? return rs } // RepoSyncObjectV1Beta1FromNonRootRepo returns a v1beta1 RepoSync object which -// uses a repo from nt.NonRootRepos. +// uses a RepoSync repo from nt.SyncSources. func RepoSyncObjectV1Beta1FromNonRootRepo(nt *NT, nn types.NamespacedName) *v1beta1.RepoSync { - repo, found := nt.NonRootRepos[nn] + // TODO: Allow supplying the Repository, instead of requiring it to already exist + id := RepoSyncID(nn.Name, nn.Namespace) + source, found := nt.SyncSources[id] if !found { - nt.T.Fatalf("nonexistent non-root repo: %s", nn) + nt.T.Fatal("nonexistent %s source: %s", id.Kind, id.ObjectKey) } - repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName) - sourceFormat := repo.Format + gitSource, ok := source.(*syncsource.GitSyncSource) + if !ok { + nt.T.Fatal("expected SyncSources for %s to have *GitSyncSource, but got %T", id, source) + } + repoURL := nt.GitProvider.SyncURL(gitSource.Repository.RemoteRepoName) + sourceFormat := gitSource.Repository.Format rs := RepoSyncObjectV1Beta1(nn, repoURL, sourceFormat) if nt.DefaultReconcileTimeout != nil { rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout) @@ -1044,20 +1169,24 @@ func RepoSyncObjectV1Beta1FromNonRootRepo(nt *NT, nn types.NamespacedName) *v1be if err := SetRepoSyncDependencies(nt, rs); err != nil { nt.T.Fatal(err) } - // Unregister the Helm repo for syncing, if any - delete(nt.RepoSyncHelmCharts, nn) // TODO: delete repo? return rs } // RepoSyncObjectV1Beta1FromOtherRootRepo returns a v1beta1 RepoSync object which -// uses a repo from nt.RootRepos. +// uses a RootSync repo from nt.SyncSources. func RepoSyncObjectV1Beta1FromOtherRootRepo(nt *NT, nn types.NamespacedName, repoName string) *v1beta1.RepoSync { - repo, found := nt.RootRepos[repoName] + // TODO: Allow supplying the Repository, instead of requiring it to already exist + repoID := RootSyncID(repoName) + source, found := nt.SyncSources[repoID] if !found { - nt.T.Fatal("nonexistent root repo: %s", repoName) + nt.T.Fatal("nonexistent %s source: %s", repoID.Kind, repoID.ObjectKey) } - repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName) - sourceFormat := repo.Format + gitSource, ok := source.(*syncsource.GitSyncSource) + if !ok { + nt.T.Fatal("expected SyncSources for %s to have *GitSyncSource, but got %T", repoID, source) + } + repoURL := nt.GitProvider.SyncURL(gitSource.Repository.RemoteRepoName) + sourceFormat := gitSource.Repository.Format rs := RepoSyncObjectV1Beta1(nn, repoURL, sourceFormat) if nt.DefaultReconcileTimeout != nil { rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout) @@ -1068,8 +1197,6 @@ func RepoSyncObjectV1Beta1FromOtherRootRepo(nt *NT, nn types.NamespacedName, rep if err := SetRepoSyncDependencies(nt, rs); err != nil { nt.T.Fatal(err) } - // Unregister the Helm repo for syncing, if any - delete(nt.RepoSyncHelmCharts, nn) // TODO: delete repo? return rs } @@ -1078,77 +1205,86 @@ func RepoSyncObjectV1Beta1FromOtherRootRepo(nt *NT, nn types.NamespacedName, rep func setupCentralizedControl(nt *NT) { nt.T.Log("[SETUP] Centralized control") - rootSyncNN := RootSyncNN(configsync.RootSyncName) + rootSyncID := RootSyncID(configsync.RootSyncName) + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) // Add any RootSyncs specified by the test options - rootSyncs := make(map[types.NamespacedName]*v1beta1.RootSync, len(nt.RootRepos)+len(nt.RootSyncHelmCharts)) - for rsName := range nt.RootRepos { + rootSyncSources := nt.SyncSources.RootSyncs() + rootSyncs := make(map[core.ID]*v1beta1.RootSync, len(rootSyncSources)) + for id, source := range rootSyncSources { // The default RootSync is created manually, don't check it in the repo. - if rsName == configsync.RootSyncName { + if id.Name == configsync.RootSyncName { continue } - rsNN := RootSyncNN(rsName) - rootSyncs[rsNN] = RootSyncObjectV1Beta1FromRootRepo(nt, rsName) - } - for rsNN, chartID := range nt.RootSyncHelmCharts { - // The default RootSync is created manually, don't check it in the repo. - if rsNN.Name == configsync.RootSyncName { - continue + switch source.(type) { + case *syncsource.GitSyncSource: + rootSyncs[id] = RootSyncObjectV1Beta1FromRootRepo(nt, id.Name) + // case *syncsource.HelmSyncSource: + // rootSyncs[id] = nt.RootSyncObjectHelm(id.Name, tSource.ChartID) + // case *syncsource.OCISyncSource: + // TODO: setup OCI & Helm RootSyncs + default: + nt.T.Fatalf("Invalid %s source %T: %s", id.Kind, source, id.Name) } - rootSyncs[rsNN] = nt.RootSyncObjectHelm(rsNN.Name, chartID) } - for rsNN, rs := range rootSyncs { + for id, rs := range rootSyncs { // Add RootSync - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/%s.yaml", configsync.ControllerNamespace, rsNN.Name), rs)) - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rs) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/%s.yaml", id.Namespace, id.Name), rs)) + nt.MetricsExpectations.AddObjectApply(metrics.SyncKind(rootSyncID.Kind), rootSyncID.ObjectKey, rs) } if len(rootSyncs) > 0 { - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding RootSyncs")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding RootSyncs")) } - if len(nt.NonRootRepos) == 0 && len(nt.RepoSyncHelmCharts) == 0 { + repoSyncSources := nt.SyncSources.RepoSyncs() + if len(repoSyncSources) == 0 { return } // Add ClusterRole for all RepoSync reconcilers to use. // TODO: Test different permissions for different RepoSyncs. cr := nt.RepoSyncClusterRole() - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/cr.yaml", cr)) - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, cr) + nt.Must(rootSyncGitRepo.Add("acme/cluster/cr.yaml", cr)) + nt.MetricsExpectations.AddObjectApply(metrics.SyncKind(rootSyncID.Kind), rootSyncID.ObjectKey, cr) // Use a map to record the number of RepoSync namespaces rsNamespaces := map[string]struct{}{} // Add any RootSyncs specified by the test options - repoSyncs := make(map[types.NamespacedName]*v1beta1.RepoSync, len(nt.NonRootRepos)+len(nt.RepoSyncHelmCharts)) - for rsNN := range nt.NonRootRepos { - repoSyncs[rsNN] = RepoSyncObjectV1Beta1FromNonRootRepo(nt, rsNN) - } - for rsNN, chartID := range nt.RepoSyncHelmCharts { - repoSyncs[rsNN] = nt.RepoSyncObjectHelm(rsNN, chartID) + repoSyncs := make(map[core.ID]*v1beta1.RepoSync, len(repoSyncSources)) + for id, source := range repoSyncSources { + switch source.(type) { + case *syncsource.GitSyncSource: + repoSyncs[id] = RepoSyncObjectV1Beta1FromNonRootRepo(nt, id.ObjectKey) + // case *syncsource.HelmSyncSource: + // repoSyncs[id] = nt.RepoSyncObjectHelm(id.ObjectKey, tSource.ChartID) + // case *syncsource.OCISyncSource: + // TODO: setup OCI & Helm RootSyncs + default: + nt.T.Fatalf("Invalid %s source %T: %s", id.Kind, source, id.Name) + } } - for rsNN, rs := range repoSyncs { - ns := rsNN.Namespace - rsNamespaces[ns] = struct{}{} + for id, rs := range repoSyncs { + rsNamespaces[id.Namespace] = struct{}{} // Add Namespace for this RepoSync. // This may replace an existing Namespace, if there are multiple // RepoSyncs in the same namespace. - nsObj := k8sobjects.NamespaceObject(ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(StructuredNSPath(ns, ns), nsObj)) - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, nsObj) + nsObj := k8sobjects.NamespaceObject(id.Namespace) + nt.Must(rootSyncGitRepo.Add(StructuredNSPath(id.Namespace, id.Namespace), nsObj)) + nt.MetricsExpectations.AddObjectApply(metrics.SyncKind(rootSyncID.Kind), rootSyncID.ObjectKey, nsObj) // Add RoleBinding to bind the ClusterRole to the RepoSync reconciler ServiceAccount - rb := RepoSyncRoleBinding(rsNN) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(StructuredNSPath(ns, fmt.Sprintf("rb-%s", rsNN.Name)), rb)) - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rb) + rb := RepoSyncRoleBinding(id.ObjectKey) + nt.Must(rootSyncGitRepo.Add(StructuredNSPath(id.Namespace, fmt.Sprintf("rb-%s", id.Name)), rb)) + nt.MetricsExpectations.AddObjectApply(metrics.SyncKind(rootSyncID.Kind), rootSyncID.ObjectKey, rb) // Add RepoSync - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(StructuredNSPath(ns, rsNN.Name), rs)) - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rs) + nt.Must(rootSyncGitRepo.Add(StructuredNSPath(id.Namespace, id.Name), rs)) + nt.MetricsExpectations.AddObjectApply(metrics.SyncKind(rootSyncID.Kind), rootSyncID.ObjectKey, rs) } if len(repoSyncs) > 0 { - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding RepoSyncs, Namespaces, ClusterRoles, RoleBindings, and ClusterRoleBindings")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding RepoSyncs, Namespaces, ClusterRoles, RoleBindings, and ClusterRoleBindings")) } // Convert namespace set to list @@ -1169,18 +1305,18 @@ func setupCentralizedControl(nt *NT) { func validateRootSyncsExist(nt *NT) error { var err error - for rsName := range nt.RootRepos { + for id := range nt.SyncSources.RootSyncs() { err = multierr.Append(err, - nt.Validate(rsName, configsync.ControllerNamespace, &v1beta1.RootSync{})) + nt.Validate(id.Name, id.Namespace, &v1beta1.RootSync{})) } return err } func validateRepoSyncsExist(nt *NT) error { var err error - for nn := range nt.NonRootRepos { + for id := range nt.SyncSources.RepoSyncs() { err = multierr.Append(err, - nt.Validate(nn.Name, nn.Namespace, &v1beta1.RepoSync{})) + nt.Validate(id.Name, id.Namespace, &v1beta1.RepoSync{})) } return err } diff --git a/e2e/nomostest/new.go b/e2e/nomostest/new.go index d13cfa6739..e5caa7fba2 100644 --- a/e2e/nomostest/new.go +++ b/e2e/nomostest/new.go @@ -31,12 +31,14 @@ import ( testmetrics "kpt.dev/configsync/e2e/nomostest/metrics" "kpt.dev/configsync/e2e/nomostest/ntopts" "kpt.dev/configsync/e2e/nomostest/registryproviders" + "kpt.dev/configsync/e2e/nomostest/syncsource" "kpt.dev/configsync/e2e/nomostest/taskgroup" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" "kpt.dev/configsync/e2e/nomostest/testlogger" "kpt.dev/configsync/e2e/nomostest/testshell" "kpt.dev/configsync/pkg/api/configmanagement" "kpt.dev/configsync/pkg/api/configsync" + "kpt.dev/configsync/pkg/core" "kpt.dev/configsync/pkg/core/k8sobjects" "kpt.dev/configsync/pkg/kinds" "sigs.k8s.io/controller-runtime/pkg/client" @@ -168,10 +170,7 @@ func SharedTestEnv(t nomostesting.NTB, opts *ntopts.New) *NT { kubeconfigPath: sharedNt.kubeconfigPath, ReconcilerPollingPeriod: sharedNt.ReconcilerPollingPeriod, HydrationPollingPeriod: sharedNt.HydrationPollingPeriod, - RootRepos: make(map[string]*gitproviders.Repository), - NonRootRepos: make(map[types.NamespacedName]*gitproviders.Repository), - RootSyncHelmCharts: make(map[types.NamespacedName]registryproviders.HelmChartID), - RepoSyncHelmCharts: make(map[types.NamespacedName]registryproviders.HelmChartID), + SyncSources: make(map[core.ID]syncsource.SyncSource), MetricsExpectations: sharedNt.MetricsExpectations, gitPrivateKeyPath: sharedNt.gitPrivateKeyPath, gitCACertPath: sharedNt.gitCACertPath, @@ -267,10 +266,7 @@ func FreshTestEnv(t nomostesting.NTB, opts *ntopts.New) *NT { repoSyncPermissions: opts.RepoSyncPermissions, DefaultReconcileTimeout: opts.ReconcileTimeout, kubeconfigPath: opts.KubeconfigPath, - RootRepos: make(map[string]*gitproviders.Repository), - NonRootRepos: make(map[types.NamespacedName]*gitproviders.Repository), - RootSyncHelmCharts: make(map[types.NamespacedName]registryproviders.HelmChartID), - RepoSyncHelmCharts: make(map[types.NamespacedName]registryproviders.HelmChartID), + SyncSources: make(map[core.ID]syncsource.SyncSource), MetricsExpectations: testmetrics.NewSyncSetExpectations(t, scheme), Scheme: scheme, RemoteRepositories: make(map[types.NamespacedName]*gitproviders.Repository), @@ -427,10 +423,16 @@ func setupTestCase(nt *NT, opts *ntopts.New) { // - local repo is initialized and empty // - remote repo exists (except for LocalProvider, which is done in portForwardGitServer) for name := range opts.RootRepos { - nt.RootRepos[name] = initRepository(nt, gitproviders.RootRepo, RootSyncNN(name), opts.SourceFormat) + id := RootSyncID(name) + nt.SyncSources[id] = &syncsource.GitSyncSource{ + Repository: initRepository(nt, gitproviders.RootRepo, id.ObjectKey, opts.SourceFormat), + } } for nsr := range opts.NamespaceRepos { - nt.NonRootRepos[nsr] = initRepository(nt, gitproviders.NamespaceRepo, nsr, configsync.SourceFormatUnstructured) + id := RepoSyncID(nsr.Name, nsr.Namespace) + nt.SyncSources[id] = &syncsource.GitSyncSource{ + Repository: initRepository(nt, gitproviders.NamespaceRepo, id.ObjectKey, configsync.SourceFormatUnstructured), + } } // set up port forward if using in-cluster git server if *e2e.GitProvider == e2e.Local { @@ -452,16 +454,17 @@ func setupTestCase(nt *NT, opts *ntopts.New) { } if opts.InitialCommit != nil { - rootSyncNN := RootSyncNN(configsync.RootSyncName) + rootSyncID := DefaultRootSyncID + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) for path, obj := range opts.InitialCommit.Files { - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(path, obj)) + nt.Must(rootSyncGitRepo.Add(path, obj)) // Some source objects are not included in the declared resources. if testmetrics.IsObjectDeclarable(obj) { // Some source objects are included in the declared resources, but not applied. - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, obj) + nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncID.ObjectKey, obj) } } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(opts.InitialCommit.Message)) + nt.Must(rootSyncGitRepo.CommitAndPush(opts.InitialCommit.Message)) } // First wait for CRDs to be established. diff --git a/e2e/nomostest/nt.go b/e2e/nomostest/nt.go index d5b3475f53..bf0382c255 100644 --- a/e2e/nomostest/nt.go +++ b/e2e/nomostest/nt.go @@ -30,35 +30,35 @@ import ( corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/discovery" + "k8s.io/client-go/rest" + "kpt.dev/configsync/e2e" "kpt.dev/configsync/e2e/nomostest/clusterversion" "kpt.dev/configsync/e2e/nomostest/gitproviders" + testmetrics "kpt.dev/configsync/e2e/nomostest/metrics" "kpt.dev/configsync/e2e/nomostest/ntopts" "kpt.dev/configsync/e2e/nomostest/portforwarder" "kpt.dev/configsync/e2e/nomostest/registryproviders" "kpt.dev/configsync/e2e/nomostest/retry" + "kpt.dev/configsync/e2e/nomostest/syncsource" "kpt.dev/configsync/e2e/nomostest/taskgroup" + "kpt.dev/configsync/e2e/nomostest/testing" "kpt.dev/configsync/e2e/nomostest/testkubeclient" "kpt.dev/configsync/e2e/nomostest/testlogger" "kpt.dev/configsync/e2e/nomostest/testshell" "kpt.dev/configsync/e2e/nomostest/testwatcher" - "kpt.dev/configsync/pkg/core" - "kpt.dev/configsync/pkg/core/k8sobjects" - "kpt.dev/configsync/pkg/reconcilermanager/controllers" - "kpt.dev/configsync/pkg/util" - "kpt.dev/configsync/pkg/util/log" - - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "k8s.io/client-go/discovery" - "k8s.io/client-go/rest" - "kpt.dev/configsync/e2e" - testmetrics "kpt.dev/configsync/e2e/nomostest/metrics" - "kpt.dev/configsync/e2e/nomostest/testing" "kpt.dev/configsync/pkg/api/configmanagement" "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/api/configsync/v1beta1" + "kpt.dev/configsync/pkg/core" + "kpt.dev/configsync/pkg/core/k8sobjects" ocmetrics "kpt.dev/configsync/pkg/metrics" "kpt.dev/configsync/pkg/reconcilermanager" + "kpt.dev/configsync/pkg/reconcilermanager/controllers" + "kpt.dev/configsync/pkg/util" + "kpt.dev/configsync/pkg/util/log" "kpt.dev/configsync/pkg/webhook/configuration" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -128,22 +128,11 @@ type NT struct { // for object reconciliation. DefaultReconcileTimeout *time.Duration - // RootRepos is the root repositories the cluster is syncing to. - // The key is the RootSync name and the value points to the corresponding Repository object. - // Each test case was set up with a default RootSync (`root-sync`) installed. - // After the test, all other RootSync or RepoSync objects are deleted, but the default one persists. - RootRepos map[string]*gitproviders.Repository - - // NonRootRepos is the Namespace repositories the cluster is syncing to. - // Only used in multi-repo tests. - // The key is the namespace and name of the RepoSync object, the value points to the corresponding Repository object. - NonRootRepos map[types.NamespacedName]*gitproviders.Repository - - // RootSyncHelmCharts is a map of RootSyncs that sync Helm charts - RootSyncHelmCharts map[types.NamespacedName]registryproviders.HelmChartID - - // RepoSyncHelmCharts is a map of RepoSyncs that sync Helm charts - RepoSyncHelmCharts map[types.NamespacedName]registryproviders.HelmChartID + // SyncSources tracks the RootSyncs & RepoSyncs used by the current test. + // Each one is mapped to a SyncSource or nil, if no source is configured. + // The list of IDs is used for iterating over test RSyncs. + // The ID group and kind must always be either RootSync of RepoSync. + SyncSources syncsource.Set // MetricsExpectations tracks the objects expected to be declared in the // source and the operations expected to be performed on them by the set of @@ -238,28 +227,6 @@ var CSNamespaces = []string{ configmanagement.RGControllerNamespace, } -// DefaultRootReconcilerName is the root-reconciler name of the default RootSync object: "root-sync". -var DefaultRootReconcilerName = core.RootReconcilerName(configsync.RootSyncName) - -// RootSyncNN returns the NamespacedName of the RootSync object. -func RootSyncNN(name string) types.NamespacedName { - return types.NamespacedName{ - Namespace: configsync.ControllerNamespace, - Name: name, - } -} - -// RepoSyncNN returns the NamespacedName of the RepoSync object. -func RepoSyncNN(ns, name string) types.NamespacedName { - return types.NamespacedName{ - Namespace: ns, - Name: name, - } -} - -// DefaultRootRepoNamespacedName is the NamespacedName of the default RootSync object. -var DefaultRootRepoNamespacedName = RootSyncNN(configsync.RootSyncName) - var mySharedNTs *sharedNTs type sharedNT struct { @@ -411,35 +378,51 @@ func (nt *NT) MustMergePatch(obj client.Object, patch string, opts ...client.Pat // NumRepoSyncNamespaces returns the number of unique namespaces managed by RepoSyncs. func (nt *NT) NumRepoSyncNamespaces() int { - if len(nt.NonRootRepos) == 0 { + if len(nt.SyncSources) == 0 { return 0 } rsNamespaces := map[string]struct{}{} - for nn := range nt.NonRootRepos { - rsNamespaces[nn.Namespace] = struct{}{} + for id := range nt.SyncSources { + if id.Kind == configsync.RepoSyncKind { + rsNamespaces[id.Namespace] = struct{}{} + } } return len(rsNamespaces) } +// SyncSourceGitRepository returns the git Repository for the specified RSync, +// if it exists in NT.SyncSources. +func (nt *NT) SyncSourceGitRepository(id core.ID) *gitproviders.Repository { + source, found := nt.SyncSources[id] + if !found { + nt.T.Fatalf("Missing %s: %s", id.Kind, id.ObjectKey) + } + gitSource, ok := source.(*syncsource.GitSyncSource) + if !ok { + nt.T.Fatalf("Expected *GitSyncSource for %s %s but found %T: %s", id.Kind, id.ObjectKey, source) + } + return gitSource.Repository +} + // DefaultRootSha1Fn is the default function to retrieve the commit hash of the root repo. func DefaultRootSha1Fn(nt *NT, nn types.NamespacedName) (string, error) { // Get the repository this RootSync is syncing to, and ensure it is synced to HEAD. - repo, exists := nt.RootRepos[nn.Name] + source, exists := nt.SyncSources[RootSyncID(nn.Name)] if !exists { - return "", fmt.Errorf("nt.RootRepos doesn't include RootSync %q", nn.Name) + return "", fmt.Errorf("nt.SyncSources doesn't include RootSync %q", nn) } - return repo.Hash() + return source.Commit() } // DefaultRepoSha1Fn is the default function to retrieve the commit hash of the namespace repo. func DefaultRepoSha1Fn(nt *NT, nn types.NamespacedName) (string, error) { // Get the repository this RepoSync is syncing to, and ensure it is synced // to HEAD. - repo, exists := nt.NonRootRepos[nn] + source, exists := nt.SyncSources[RepoSyncID(nn.Name, nn.Namespace)] if !exists { - return "", fmt.Errorf("checked if nonexistent repo is synced") + return "", fmt.Errorf("nt.SyncSources doesn't include RepoSync %q", nn) } - return repo.Hash() + return source.Commit() } // RenewClient gets a new Client for talking to the cluster. @@ -527,29 +510,19 @@ func (nt *NT) testLogs(previousPodLog bool) { nt.PodLogs(configmanagement.ControllerNamespace, reconcilermanager.ManagerName, reconcilermanager.ManagerName, previousPodLog) nt.PodLogs(configmanagement.ControllerNamespace, configuration.ShortName, configuration.ShortName, previousPodLog) nt.PodLogs("resource-group-system", "resource-group-controller-manager", "manager", false) - for name := range nt.RootRepos { - nt.PodLogs(configmanagement.ControllerNamespace, core.RootReconcilerName(name), - reconcilermanager.Reconciler, previousPodLog) - //nt.PodLogs(configmanagement.ControllerNamespace, reconcilermanager.NsReconcilerName(ns), reconcilermanager.GitSync, previousPodLog) - nt.LogDeploymentPodResources(configmanagement.ControllerNamespace, core.RootReconcilerName(name)) - } - for nn := range nt.RootSyncHelmCharts { - nt.PodLogs(configmanagement.ControllerNamespace, core.RootReconcilerName(nn.Name), - reconcilermanager.Reconciler, previousPodLog) - //nt.PodLogs(configmanagement.ControllerNamespace, reconcilermanager.NsReconcilerName(ns), reconcilermanager.GitSync, previousPodLog) - nt.LogDeploymentPodResources(configmanagement.ControllerNamespace, core.RootReconcilerName(nn.Name)) - } - for nn := range nt.NonRootRepos { - nt.PodLogs(configmanagement.ControllerNamespace, core.NsReconcilerName(nn.Namespace, nn.Name), - reconcilermanager.Reconciler, previousPodLog) - //nt.PodLogs(configmanagement.ControllerNamespace, reconcilermanager.NsReconcilerName(ns), reconcilermanager.GitSync, previousPodLog) - nt.LogDeploymentPodResources(configmanagement.ControllerNamespace, core.NsReconcilerName(nn.Namespace, nn.Name)) - } - for nn := range nt.RepoSyncHelmCharts { - nt.PodLogs(configmanagement.ControllerNamespace, core.NsReconcilerName(nn.Namespace, nn.Name), - reconcilermanager.Reconciler, previousPodLog) + for id := range nt.SyncSources { + var reconcilerName string + switch id.Kind { + case configsync.RootSyncKind: + reconcilerName = core.RootReconcilerName(id.Name) + case configsync.RepoSyncKind: + reconcilerName = core.NsReconcilerName(id.Namespace, id.Name) + default: + nt.T.Fatalf("Invalid SyncSources key: %#v", id) + } + nt.PodLogs(configmanagement.ControllerNamespace, reconcilerName, reconcilermanager.Reconciler, previousPodLog) //nt.PodLogs(configmanagement.ControllerNamespace, reconcilermanager.NsReconcilerName(ns), reconcilermanager.GitSync, previousPodLog) - nt.LogDeploymentPodResources(configmanagement.ControllerNamespace, core.NsReconcilerName(nn.Namespace, nn.Name)) + nt.LogDeploymentPodResources(configmanagement.ControllerNamespace, reconcilerName) } } @@ -736,22 +709,19 @@ func (nt *NT) portForwardGitServer() { if prevPodName == podName { return } - // allRepos specifies the slice all repos for port forwarding. - var allRepos []types.NamespacedName - // allRepoMap is a map of repoNN->Repository for port forwarding. - allRepoMap := make(map[types.NamespacedName]*gitproviders.Repository) - for repoName, repo := range nt.RootRepos { - repoNN := RootSyncNN(repoName) - allRepos = append(allRepos, repoNN) - allRepoMap[repoNN] = repo - } - for repoNN, repo := range nt.NonRootRepos { - allRepos = append(allRepos, repoNN) - allRepoMap[repoNN] = repo + // allGitRepos specifies the slice all repos for port forwarding. + var allGitRepos []types.NamespacedName + // allGitRepoMap is a map of repoNN->Repository for port forwarding. + allGitRepoMap := make(map[types.NamespacedName]*gitproviders.Repository) + for id, source := range nt.SyncSources { + if gitSource, ok := source.(*syncsource.GitSyncSource); ok { + allGitRepos = append(allGitRepos, id.ObjectKey) + allGitRepoMap[id.ObjectKey] = gitSource.Repository + } } // re-init all repos - InitGitRepos(nt, allRepos...) - for repoNN, repo := range allRepoMap { + InitGitRepos(nt, allGitRepos...) + for repoNN, repo := range allGitRepoMap { // construct remoteURL with provided port. Calling LocalPort would lead to deadlock remoteURL, err := provider.RemoteURLWithPort(newPort, repoNN.String()) if err != nil { @@ -839,7 +809,7 @@ func (nt *NT) portForwardRegistryServer(helmTest, ociTest bool) { ) } -// portForwardGitServer forwards the prometheus deployment to a port. +// portForwardPrometheus forwards the prometheus deployment to a port. func (nt *NT) portForwardPrometheus() { nt.T.Helper() if nt.prometheusPortForwarder != nil { diff --git a/e2e/nomostest/prometheus_metrics.go b/e2e/nomostest/prometheus_metrics.go index 36bf9b938f..2122131b0c 100644 --- a/e2e/nomostest/prometheus_metrics.go +++ b/e2e/nomostest/prometheus_metrics.go @@ -27,7 +27,6 @@ import ( "k8s.io/apimachinery/pkg/types" testmetrics "kpt.dev/configsync/e2e/nomostest/metrics" "kpt.dev/configsync/e2e/nomostest/retry" - "kpt.dev/configsync/pkg/api/configmanagement" "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/kinds" "kpt.dev/configsync/pkg/metrics" @@ -73,27 +72,23 @@ func ValidateMetrics(nt *NT, predicates ...MetricsPredicate) error { } // ValidateStandardMetrics validates the set of standard metrics for the -// reconciler-manager and all registered RootSyncs (nt.RootRepos) and RepoSyncs -// (nt.NonRootRepos). +// reconciler-manager and all registered nt.SyncSources. func ValidateStandardMetrics(nt *NT) error { err := ValidateMetrics(nt, ReconcilerManagerMetrics(nt)) if err != nil { return err } - for rsName := range nt.RootRepos { + for id := range nt.SyncSources.RootSyncs() { err = ValidateStandardMetricsForRootSync(nt, testmetrics.Summary{ - Sync: types.NamespacedName{ - Name: rsName, - Namespace: configmanagement.ControllerNamespace, - }, + Sync: id.ObjectKey, }) if err != nil { return err } } - for nn := range nt.NonRootRepos { + for id := range nt.SyncSources.RepoSyncs() { err = ValidateStandardMetricsForRepoSync(nt, testmetrics.Summary{ - Sync: nn, + Sync: id.ObjectKey, }) if err != nil { return err @@ -137,10 +132,12 @@ func MetricLabelsForRepoSync(nt *NT, syncNN types.NamespacedName) (prometheusmod // ValidateStandardMetricsForRootSync validates the set of standard metrics for // the specified RootSync. func ValidateStandardMetricsForRootSync(nt *NT, summary testmetrics.Summary) error { - if _, found := nt.RootRepos[summary.Sync.Name]; !found { - return fmt.Errorf("RootRepo %q not found", summary.Sync) + id := RootSyncID(summary.Sync.Name) + source, found := nt.SyncSources[id] + if !found { + return fmt.Errorf("SyncSource not found for %s: %s", id.Kind, id.ObjectKey) } - commitHash, err := nt.RootRepos[summary.Sync.Name].Hash() + commit, err := source.Commit() if err != nil { return fmt.Errorf("hashing RootRepo for RootSync: %s: %w", summary.Sync, err) } @@ -148,16 +145,18 @@ func ValidateStandardMetricsForRootSync(nt *NT, summary testmetrics.Summary) err if err != nil { return fmt.Errorf("reading sync metric labels: %w", err) } - return ValidateStandardMetricsForSync(nt, configsync.RootSyncKind, syncLabels, commitHash, summary) + return ValidateStandardMetricsForSync(nt, configsync.RootSyncKind, syncLabels, commit, summary) } // ValidateStandardMetricsForRepoSync validates the set of standard metrics for // the specified RootSync. func ValidateStandardMetricsForRepoSync(nt *NT, summary testmetrics.Summary) error { - if _, found := nt.NonRootRepos[summary.Sync]; !found { - return fmt.Errorf("NonRootRepo %q not found", summary.Sync) + id := RepoSyncID(summary.Sync.Name, summary.Sync.Namespace) + source, found := nt.SyncSources[id] + if !found { + return fmt.Errorf("SyncSource not found for %s: %s", id.Kind, id.ObjectKey) } - commitHash, err := nt.NonRootRepos[summary.Sync].Hash() + commit, err := source.Commit() if err != nil { return fmt.Errorf("hashing NonRootRepo for RepoSync: %s", summary.Sync) } @@ -165,7 +164,7 @@ func ValidateStandardMetricsForRepoSync(nt *NT, summary testmetrics.Summary) err if err != nil { return fmt.Errorf("reading sync metric labels: %w", err) } - return ValidateStandardMetricsForSync(nt, configsync.RepoSyncKind, syncLabels, commitHash, summary) + return ValidateStandardMetricsForSync(nt, configsync.RepoSyncKind, syncLabels, commit, summary) } // ValidateStandardMetricsForSync validates the set of standard metrics for the diff --git a/e2e/nomostest/registryproviders/helm_chart.go b/e2e/nomostest/registryproviders/helm_chart.go index 2f990fd3c3..e05eb9bb9a 100644 --- a/e2e/nomostest/registryproviders/helm_chart.go +++ b/e2e/nomostest/registryproviders/helm_chart.go @@ -168,6 +168,11 @@ type HelmChartID struct { Version string } +// String returns NAME/VERSION. +func (id HelmChartID) String() string { + return fmt.Sprintf("%s/%s", id.Name, id.Version) +} + // HelmPackage represents a helm package that is pushed to a remote registry by the // test scaffolding. It uses git references as version tags to enable straightforward // integration with the git e2e tooling and to mimic how a user might leverage diff --git a/e2e/nomostest/reset.go b/e2e/nomostest/reset.go index 6f41da674a..8e01e519c3 100644 --- a/e2e/nomostest/reset.go +++ b/e2e/nomostest/reset.go @@ -131,12 +131,9 @@ func Reset(nt *NT) error { return err } - // NOTE: These git repos are not actually being deleted here, just - // unassigned to a specific RSync. All remote repos are cached in - // nt.RemoteRepositories and then reassigned in `resetRepository`. - // Repos are actually deleted by `Clean` in environment setup and teardown. - nt.NonRootRepos = make(map[types.NamespacedName]*gitproviders.Repository) - nt.RootRepos = make(map[string]*gitproviders.Repository) + // NOTE: These sources are not actually being deleted here, just + // unassigned from a specific RSync. + nt.SyncSources.Reset() // Reset expected objects nt.MetricsExpectations.Reset() diff --git a/e2e/nomostest/syncsource/set.go b/e2e/nomostest/syncsource/set.go new file mode 100644 index 0000000000..06c81f42d8 --- /dev/null +++ b/e2e/nomostest/syncsource/set.go @@ -0,0 +1,83 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package syncsource + +import ( + "kpt.dev/configsync/pkg/api/configsync" + "kpt.dev/configsync/pkg/core" +) + +// Set of RootSync & RepoSync IDs that map to SyncSources. +type Set map[core.ID]SyncSource + +// Reset clears the Set. +func (s *Set) Reset() { + clear(*s) +} + +// RootSyncs returns a Set that only contains the RootSync IDs and their SyncSources. +func (s Set) RootSyncs() Set { + set := make(map[core.ID]SyncSource) + for id, source := range s { + if id.Kind == configsync.RootSyncKind { + set[id] = source + } + } + return set +} + +// RepoSyncs returns a Set that only contains the RepoSync IDs and their SyncSources. +func (s Set) RepoSyncs() Set { + set := make(map[core.ID]SyncSource) + for id, source := range s { + if id.Kind == configsync.RepoSyncKind { + set[id] = source + } + } + return set +} + +// GitSyncSources returns a Set that only contains RootSyncs & RepoSyncs using GitSyncSources. +func (s Set) GitSyncSources() Set { + set := make(map[core.ID]SyncSource) + for id, source := range s { + if _, ok := source.(*GitSyncSource); ok { + set[id] = source + } + } + return set +} + +// HelmSyncSources returns a Set that only contains RootSyncs & RepoSyncs using HelmSyncSources. +func (s Set) HelmSyncSources() Set { + set := make(map[core.ID]SyncSource) + for id, source := range s { + if _, ok := source.(*HelmSyncSource); ok { + set[id] = source + } + } + return set +} + +// OCISyncSources returns a Set that only contains RootSyncs & RepoSyncs using OCISyncSources. +func (s Set) OCISyncSources() Set { + set := make(map[core.ID]SyncSource) + for id, source := range s { + if _, ok := source.(*OCISyncSource); ok { + set[id] = source + } + } + return set +} diff --git a/e2e/nomostest/syncsource/syncsource.go b/e2e/nomostest/syncsource/syncsource.go new file mode 100644 index 0000000000..c63eed0bcf --- /dev/null +++ b/e2e/nomostest/syncsource/syncsource.go @@ -0,0 +1,82 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package syncsource + +import ( + "fmt" + + "kpt.dev/configsync/e2e/nomostest/gitproviders" + "kpt.dev/configsync/e2e/nomostest/registryproviders" + "kpt.dev/configsync/pkg/api/configsync" +) + +// SyncSource describes the common methods available on all sources of truth. +type SyncSource interface { + // Type returns the SourceType of this source. + Type() configsync.SourceType + // Commit returns the current/latest "commit" for this source. + // The commit value is used to validate RSync status and metrics. + Commit() (string, error) +} + +// GitSyncSource is the "git" source, backed by a Git repository. +type GitSyncSource struct { + // Repository is a local clone of the remote Git repository that contains + // the current/latest commit. + Repository *gitproviders.Repository + // TODO: Add SyncPath and Branch/Revision to uniquely identify part of a repo +} + +// Type returns the SourceType of this source. +func (s *GitSyncSource) Type() configsync.SourceType { + return configsync.GitSource +} + +// Commit returns the current commit hash targeted by the local git repository. +func (s *GitSyncSource) Commit() (string, error) { + return s.Repository.Hash() +} + +// HelmSyncSource is the "helm" source, backed by a Helm chart. +type HelmSyncSource struct { + ChartID registryproviders.HelmChartID + // TODO: Add HelmRegistryProvider to allow for chart modifications +} + +// Type returns the SourceType of this source. +func (s *HelmSyncSource) Type() configsync.SourceType { + return configsync.HelmSource +} + +// Commit returns the version of the current chart. +func (s *HelmSyncSource) Commit() (string, error) { + return s.ChartID.Version, nil +} + +// OCISyncSource is the "oci" source, backed by an OCI image. +type OCISyncSource struct { + // TODO: add an OCI-specific image ID & migrate OCI RSyncs to use OCISyncSource + // TODO: Add OCIRegistryProvider to allow for chart modifications +} + +// Type returns the SourceType of this source. +func (s *OCISyncSource) Type() configsync.SourceType { + return configsync.OciSource +} + +// Commit is not yet implemented. +func (s *OCISyncSource) Commit() (string, error) { + return "", fmt.Errorf("not yet implemented: OCISyncSource.Commit") +} diff --git a/e2e/nomostest/wait_for_sync.go b/e2e/nomostest/wait_for_sync.go index 34993e3b07..7c2944719f 100644 --- a/e2e/nomostest/wait_for_sync.go +++ b/e2e/nomostest/wait_for_sync.go @@ -23,6 +23,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "kpt.dev/configsync/e2e/nomostest/gitproviders" + "kpt.dev/configsync/e2e/nomostest/syncsource" "kpt.dev/configsync/e2e/nomostest/taskgroup" "kpt.dev/configsync/e2e/nomostest/testpredicates" "kpt.dev/configsync/e2e/nomostest/testwatcher" @@ -140,7 +141,7 @@ func syncDirectory(syncDirectoryMap map[types.NamespacedName]string, nn types.Na return gitproviders.DefaultSyncDir } -// WatchForAllSyncs calls WatchForSync on all Syncs in nt.RootRepos & nt.NonRootRepos. +// WatchForAllSyncs calls WatchForSync on all Syncs in nt.SyncSources. // // If you want to validate specific fields of a Sync object, use // nt.Watcher.WatchObject() instead. @@ -171,50 +172,54 @@ func (nt *NT) WatchForAllSyncs(options ...WatchForAllSyncsOptions) error { tg := taskgroup.New() if opts.syncRootRepos { - for name := range nt.RootRepos { - if _, ok := opts.skipRootRepos[name]; ok { + for id, source := range nt.SyncSources.RootSyncs() { + if _, ok := opts.skipRootRepos[id.Name]; ok { continue } - nn := RootSyncNN(name) - syncDir := syncDirectory(opts.syncDirectoryMap, nn) + // TODO: Move SyncPath logic into a SyncSource method + var syncPath string + switch tSource := source.(type) { + case *syncsource.GitSyncSource: + syncPath = syncDirectory(opts.syncDirectoryMap, id.ObjectKey) + case *syncsource.HelmSyncSource: + syncPath = tSource.ChartID.Name + // case *syncsource.OCISyncSource: + // TODO: setup OCI RootSyncs + default: + nt.T.Fatalf("Invalid %s source %T: %s", id.Kind, source, id.Name) + } + idPtr := id tg.Go(func() error { - return nt.WatchForSync(kinds.RootSyncV1Beta1(), nn.Name, nn.Namespace, + return nt.WatchForSync(kinds.RootSyncV1Beta1(), idPtr.Name, idPtr.Namespace, opts.rootSha1Fn, RootSyncHasStatusSyncCommit, - &SyncDirPredicatePair{Dir: syncDir, Predicate: RootSyncHasStatusSyncDirectory}, - testwatcher.WatchTimeout(opts.timeout)) - }) - } - for nn, chart := range nt.RootSyncHelmCharts { - tg.Go(func() error { - return nt.WatchForSync(kinds.RootSyncV1Beta1(), nn.Name, nn.Namespace, - HelmChartVersionShaFn(chart.Version), - RootSyncHasStatusSyncCommit, - &SyncDirPredicatePair{Dir: chart.Name, Predicate: RootSyncHasStatusSyncDirectory}, + &SyncDirPredicatePair{Dir: syncPath, Predicate: RootSyncHasStatusSyncDirectory}, testwatcher.WatchTimeout(opts.timeout)) }) } } if opts.syncNamespaceRepos { - for nn := range nt.NonRootRepos { - if _, ok := opts.skipNonRootRepos[nn]; ok { + for id, source := range nt.SyncSources.RepoSyncs() { + if _, ok := opts.skipNonRootRepos[id.ObjectKey]; ok { continue } - syncDir := syncDirectory(opts.syncDirectoryMap, nn) - nnPtr := nn + // TODO: Move SyncPath logic into a SyncSource method + var syncPath string + switch tSource := source.(type) { + case *syncsource.GitSyncSource: + syncPath = syncDirectory(opts.syncDirectoryMap, id.ObjectKey) + case *syncsource.HelmSyncSource: + syncPath = tSource.ChartID.Name + // case *syncsource.OCISyncSource: + // TODO: setup OCI RootSyncs + default: + nt.T.Fatalf("Invalid %s source %T: %s", id.Kind, source, id.Name) + } + idPtr := id tg.Go(func() error { - return nt.WatchForSync(kinds.RepoSyncV1Beta1(), nnPtr.Name, nnPtr.Namespace, + return nt.WatchForSync(kinds.RepoSyncV1Beta1(), idPtr.Name, idPtr.Namespace, opts.repoSha1Fn, RepoSyncHasStatusSyncCommit, - &SyncDirPredicatePair{Dir: syncDir, Predicate: RepoSyncHasStatusSyncDirectory}, - testwatcher.WatchTimeout(opts.timeout)) - }) - } - for nn, chart := range nt.RepoSyncHelmCharts { - tg.Go(func() error { - return nt.WatchForSync(kinds.RepoSyncV1Beta1(), nn.Name, nn.Namespace, - HelmChartVersionShaFn(chart.Version), - RepoSyncHasStatusSyncCommit, - &SyncDirPredicatePair{Dir: chart.Name, Predicate: RepoSyncHasStatusSyncDirectory}, + &SyncDirPredicatePair{Dir: syncPath, Predicate: RepoSyncHasStatusSyncDirectory}, testwatcher.WatchTimeout(opts.timeout)) }) } diff --git a/e2e/testcases/acme_test.go b/e2e/testcases/acme_test.go index c2bf83bb9f..4668ac2521 100644 --- a/e2e/testcases/acme_test.go +++ b/e2e/testcases/acme_test.go @@ -20,7 +20,6 @@ import ( nomostesting "kpt.dev/configsync/e2e/nomostest/testing" "kpt.dev/configsync/pkg/api/configmanagement" - "kpt.dev/configsync/pkg/api/configsync" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -45,15 +44,18 @@ func configSyncManagementLabels(namespace, folder string) map[string]string { func TestAcmeCorpRepo(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + nsToFolder := map[string]string{ - "analytics": "eng", - "backend": "eng", - "frontend": "eng", - "new-prj": "rnd", - "newer-prj": "rnd", - nt.RootRepos[configsync.RootSyncName].SafetyNSName: ""} - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../../examples/acme", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Initialize the acme directory")) + "analytics": "eng", + "backend": "eng", + "frontend": "eng", + "new-prj": "rnd", + "newer-prj": "rnd", + rootSyncGitRepo.SafetyNSName: "", + } + nt.Must(rootSyncGitRepo.Copy("../../examples/acme", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("Initialize the acme directory")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -170,10 +172,10 @@ func TestAcmeCorpRepo(t *testing.T) { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster")) // Add back the safety ClusterRole to pass the safety check (KNV2006). - nt.Must(nt.RootRepos[configsync.RootSyncName].AddSafetyClusterRole()) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Reset the acme directory")) + nt.Must(rootSyncGitRepo.AddSafetyClusterRole()) + nt.Must(rootSyncGitRepo.CommitAndPush("Reset the acme directory")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -183,8 +185,10 @@ func TestAcmeCorpRepo(t *testing.T) { func TestObjectInCMSNamespace(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/object-in-cms-namespace", "acme")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("adding resource to config-management-system namespace")) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + + nt.Must(rootSyncGitRepo.Copy("../testdata/object-in-cms-namespace", "acme")) + nt.Must(rootSyncGitRepo.CommitAndPush("adding resource to config-management-system namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/admission_test.go b/e2e/testcases/admission_test.go index 09c07c8ca0..c1f30da743 100644 --- a/e2e/testcases/admission_test.go +++ b/e2e/testcases/admission_test.go @@ -45,9 +45,11 @@ import ( func TestAdmission(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/hello/ns.yaml", + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + + nt.Must(rootSyncGitRepo.Add("acme/namespaces/hello/ns.yaml", k8sobjects.NamespaceObject("hello", core.Annotation("goodbye", "moon")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add Namespace")) + nt.Must(rootSyncGitRepo.CommitAndPush("add Namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -155,8 +157,10 @@ func TestDisableWebhookConfigurationUpdateHierarchy(t *testing.T) { // Test starts with Admission Webhook already installed nomostest.WaitForWebhookReadiness(nt) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/hello/ns.yaml", k8sobjects.NamespaceObject("hello"))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add test namespace")) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + + nt.Must(rootSyncGitRepo.Add("acme/namespaces/hello/ns.yaml", k8sobjects.NamespaceObject("hello"))) + nt.Must(rootSyncGitRepo.CommitAndPush("add test namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -221,10 +225,12 @@ func TestDisableWebhookConfigurationUpdateHierarchy(t *testing.T) { func TestDisableWebhookConfigurationUpdateUnstructured(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource, ntopts.NamespaceRepo(namespaceRepo, configsync.RepoSyncName), ntopts.RepoSyncPermissions(policy.CoreAdmin())) - repoSyncNN := nomostest.RepoSyncNN(namespaceRepo, configsync.RepoSyncName) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, namespaceRepo) + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + sa := k8sobjects.ServiceAccountObject("store", core.Namespace(namespaceRepo)) - nt.Must(nt.NonRootRepos[repoSyncNN].Add("acme/sa.yaml", sa)) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("Adding test service account")) + nt.Must(repoSyncGitRepo.Add("acme/sa.yaml", sa)) + nt.Must(repoSyncGitRepo.CommitAndPush("Adding test service account")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/adopt_client_side_applied_test.go b/e2e/testcases/adopt_client_side_applied_test.go index 5175cd747c..9dd5fb80dc 100644 --- a/e2e/testcases/adopt_client_side_applied_test.go +++ b/e2e/testcases/adopt_client_side_applied_test.go @@ -22,7 +22,6 @@ import ( rbacv1 "k8s.io/api/rbac/v1" "kpt.dev/configsync/e2e/nomostest" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" - "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/core" "kpt.dev/configsync/pkg/core/k8sobjects" ) @@ -30,6 +29,8 @@ import ( func TestAdoptClientSideAppliedResource(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + // Declare a ClusterRole and `kubectl apply -f` it to the cluster. nsViewerName := "ns-viewer" nsViewer := k8sobjects.ClusterRoleObject(core.Name(nsViewerName), @@ -40,8 +41,8 @@ func TestAdoptClientSideAppliedResource(t *testing.T) { Verbs: []string{"get", "list"}, }} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("ns-viewer-client-side-applied.yaml", nsViewer)) - nt.MustKubectl("apply", "-f", filepath.Join(nt.RootRepos[configsync.RootSyncName].Root, "ns-viewer-client-side-applied.yaml")) + nt.Must(rootSyncGitRepo.Add("ns-viewer-client-side-applied.yaml", nsViewer)) + nt.MustKubectl("apply", "-f", filepath.Join(rootSyncGitRepo.Root, "ns-viewer-client-side-applied.yaml")) // Validate the ClusterRole exist. err := nt.Validate(nsViewerName, "", &rbacv1.ClusterRole{}) @@ -55,8 +56,8 @@ func TestAdoptClientSideAppliedResource(t *testing.T) { Resources: []string{"namespaces"}, Verbs: []string{"get"}, }} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/ns-viewer-cr.yaml", nsViewer)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add namespace-viewer ClusterRole")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/ns-viewer-cr.yaml", nsViewer)) + nt.Must(rootSyncGitRepo.CommitAndPush("add namespace-viewer ClusterRole")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/apiservice_test.go b/e2e/testcases/apiservice_test.go index fe358ea692..fdd967a666 100644 --- a/e2e/testcases/apiservice_test.go +++ b/e2e/testcases/apiservice_test.go @@ -22,7 +22,6 @@ import ( "kpt.dev/configsync/e2e/nomostest/ntopts" "kpt.dev/configsync/e2e/nomostest/taskgroup" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" - "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/kinds" ) @@ -36,17 +35,18 @@ func TestCreateAPIServiceAndEndpointInTheSameCommit(t *testing.T) { // Increase the timeout from 1m to 5m to avoid reconcile timeout for the // custom-metrics-stackdriver-adapter Deployment on Autopilot cluster. ntopts.WithReconcileTimeout(5*time.Minute)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) t.Cleanup(func() { if t.Failed() { nt.PodLogs(adapterNamespace, adapterName, "pod-custom-metrics-stackdriver-adapter", true) } }) nt.T.Log("Creating commit with APIService and Deployment") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/apiservice/rbac.yaml", "acme/cluster/rbac.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/apiservice/namespace.yaml", "acme/namespaces/custom-metrics/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/apiservice/namespace-custom-metrics.yaml", "acme/namespaces/custom-metrics/namespace-custom-metrics.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/apiservice/apiservice.yaml", "acme/cluster/apiservice.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("adding apiservice resources")) + nt.Must(rootSyncGitRepo.Copy("../testdata/apiservice/rbac.yaml", "acme/cluster/rbac.yaml")) + nt.Must(rootSyncGitRepo.Copy("../testdata/apiservice/namespace.yaml", "acme/namespaces/custom-metrics/namespace.yaml")) + nt.Must(rootSyncGitRepo.Copy("../testdata/apiservice/namespace-custom-metrics.yaml", "acme/namespaces/custom-metrics/namespace-custom-metrics.yaml")) + nt.Must(rootSyncGitRepo.Copy("../testdata/apiservice/apiservice.yaml", "acme/cluster/apiservice.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("adding apiservice resources")) nt.T.Log("Waiting for nomos to sync new APIService") if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -59,16 +59,16 @@ func TestCreateAPIServiceAndEndpointInTheSameCommit(t *testing.T) { // Test done, removing the test APIService first to prevent Discovery failure blocking // the test repo from cleaning up - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster/apiservice.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove custom metric stackdriver adapter API service")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster/apiservice.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove custom metric stackdriver adapter API service")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } // Remove the backend Deployment of test APIService - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/custom-metrics/namespace-custom-metrics.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/custom-metrics/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove custom metric stackdriver adapter namespace")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/custom-metrics/namespace-custom-metrics.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/custom-metrics/namespace.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove custom metric stackdriver adapter namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -80,6 +80,7 @@ func TestReconcilerResilientToFlakyAPIService(t *testing.T) { // Increase the timeout from 1m to 5m to avoid reconcile timeout for the // custom-metrics-stackdriver-adapter Deployment on Autopilot cluster. ntopts.WithReconcileTimeout(5*time.Minute)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Cleanup(func() { nt.MustKubectl("delete", "-f", "../testdata/apiservice/apiservice.yaml", "--ignore-not-found") nt.MustKubectl("delete", "-f", "../testdata/apiservice/namespace-custom-metrics.yaml", "--ignore-not-found") @@ -95,8 +96,8 @@ func TestReconcilerResilientToFlakyAPIService(t *testing.T) { nt.MustKubectl("apply", "-f", "../testdata/apiservice/apiservice.yaml") nt.T.Log("Creating commit with test resources") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/apiservice/namespace-resilient.yaml", "acme/namespaces/resilient/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add testing resources")) + nt.Must(rootSyncGitRepo.Copy("../testdata/apiservice/namespace-resilient.yaml", "acme/namespaces/resilient/namespace.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("add testing resources")) nt.T.Log("Wait for test resource to have status CURRENT") if err := nt.WatchForAllSyncs(); err != nil { diff --git a/e2e/testcases/basic_test.go b/e2e/testcases/basic_test.go index 41c823093f..55e26a1487 100644 --- a/e2e/testcases/basic_test.go +++ b/e2e/testcases/basic_test.go @@ -25,7 +25,6 @@ import ( "kpt.dev/configsync/e2e/nomostest/ntopts" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" "kpt.dev/configsync/e2e/nomostest/testpredicates" - "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/core" "kpt.dev/configsync/pkg/core/k8sobjects" ) @@ -36,9 +35,10 @@ const ( func TestNamespaceGarbageCollection(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/accounting-namespace.yaml", yamlDir), "acme/namespaces/accounting/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add accounting namespace")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/accounting-namespace.yaml", yamlDir), "acme/namespaces/accounting/namespace.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add accounting namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -47,8 +47,8 @@ func TestNamespaceGarbageCollection(t *testing.T) { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/accounting/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove accounting namespace")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/accounting/namespace.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove accounting namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -60,9 +60,10 @@ func TestNamespaceGarbageCollection(t *testing.T) { func TestNamespacePolicyspaceConversion(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/dir-namespace.yaml", yamlDir), "acme/namespaces/dir/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add dir namespace")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/dir-namespace.yaml", yamlDir), "acme/namespaces/dir/namespace.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add dir namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -71,9 +72,9 @@ func TestNamespacePolicyspaceConversion(t *testing.T) { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/dir/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/subdir-namespace.yaml", yamlDir), "acme/namespaces/dir/subdir/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove dir namespace, add subdir namespace")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/dir/namespace.yaml")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/subdir-namespace.yaml", yamlDir), "acme/namespaces/dir/subdir/namespace.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove dir namespace, add subdir namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -89,15 +90,16 @@ func TestNamespacePolicyspaceConversion(t *testing.T) { func TestSyncDeploymentAndReplicaSet(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Test the ability to fix a mistake: overlapping replicaset and deployment. // Readiness behavior is undefined for this race condition. // One or both of the Deployment and ReplicaSet may become unhealthy. // But regardless, the user should be able to correct the situation. nt.T.Log("Add a replicaset") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/dir-namespace.yaml", yamlDir), "acme/namespaces/dir/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/replicaset-helloworld.yaml", yamlDir), "acme/namespaces/dir/replicaset.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add replicaset")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/dir-namespace.yaml", yamlDir), "acme/namespaces/dir/namespace.yaml")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/replicaset-helloworld.yaml", yamlDir), "acme/namespaces/dir/replicaset.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add replicaset")) // This sync may block until reconcile timeout is reached, // because ReplicaSet or Deployment may never reconcile. @@ -111,8 +113,8 @@ func TestSyncDeploymentAndReplicaSet(t *testing.T) { } nt.T.Log("Add a corresponding deployment") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/deployment-helloworld.yaml", yamlDir), "acme/namespaces/dir/deployment.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add corresponding deployment")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/deployment-helloworld.yaml", yamlDir), "acme/namespaces/dir/deployment.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add corresponding deployment")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -123,8 +125,8 @@ func TestSyncDeploymentAndReplicaSet(t *testing.T) { } nt.T.Log("Remove the deployment") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/dir/deployment.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove deployment")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/dir/deployment.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove deployment")) // This sync may block until reconcile timeout is reached, // because the ReplicaSet is re-applied before deleting the Deployment. // So this wait timeout must be longer than the reconcile timeout (5m). @@ -143,10 +145,11 @@ func TestSyncDeploymentAndReplicaSet(t *testing.T) { func TestRolebindingsUpdated(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../../examples/acme/namespaces/eng/backend/namespace.yaml", "acme/namespaces/eng/backend/namespace.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../../examples/acme/namespaces/eng/backend/bob-rolebinding.yaml", "acme/namespaces/eng/backend/br.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add bob rolebinding")) + nt.Must(rootSyncGitRepo.Copy("../../examples/acme/namespaces/eng/backend/namespace.yaml", "acme/namespaces/eng/backend/namespace.yaml")) + nt.Must(rootSyncGitRepo.Copy("../../examples/acme/namespaces/eng/backend/bob-rolebinding.yaml", "acme/namespaces/eng/backend/br.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add bob rolebinding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -154,8 +157,8 @@ func TestRolebindingsUpdated(t *testing.T) { nt.T.Fatal("bob-rolebinding not found") } - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/robert-rolebinding.yaml", yamlDir), "acme/namespaces/eng/backend/br.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Replace bob with robert rolebinding")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/robert-rolebinding.yaml", yamlDir), "acme/namespaces/eng/backend/br.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Replace bob with robert rolebinding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -170,6 +173,7 @@ func TestRolebindingsUpdated(t *testing.T) { } func manageNamespace(nt *nomostest.NT, namespace string) { + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add an unmanaged resource into the namespace as a control") nt.T.Log("We should never modify this resource") _, err := nt.Shell.Kubectl("apply", "-f", fmt.Sprintf("%s/reserved_namespaces/unmanaged-service.%s.yaml", yamlDir, namespace)) @@ -185,10 +189,10 @@ func manageNamespace(nt *nomostest.NT, namespace string) { }) nt.T.Log("Add resource to manage") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/reserved_namespaces/service.yaml", yamlDir), fmt.Sprintf("acme/namespaces/%s/service.yaml", namespace))) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/reserved_namespaces/service.yaml", yamlDir), fmt.Sprintf("acme/namespaces/%s/service.yaml", namespace))) nt.T.Log("Start managing the namespace") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/reserved_namespaces/namespace.%s.yaml", yamlDir, namespace), fmt.Sprintf("acme/namespaces/%s/namespace.yaml", namespace))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Start managing the namespace")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/reserved_namespaces/namespace.%s.yaml", yamlDir, namespace), fmt.Sprintf("acme/namespaces/%s/namespace.yaml", namespace))) + nt.Must(rootSyncGitRepo.CommitAndPush("Start managing the namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -199,8 +203,8 @@ func manageNamespace(nt *nomostest.NT, namespace string) { } nt.T.Log("Remove the namespace directory from the repo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(fmt.Sprintf("acme/namespaces/%s", namespace))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the namespace from the managed set of namespaces")) + nt.Must(rootSyncGitRepo.Remove(fmt.Sprintf("acme/namespaces/%s", namespace))) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the namespace from the managed set of namespaces")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -217,9 +221,10 @@ func manageNamespace(nt *nomostest.NT, namespace string) { } func unmanageNamespace(nt *nomostest.NT, namespace string) { + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("stop managing the system namespace") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(fmt.Sprintf("%s/reserved_namespaces/unmanaged-namespace.%s.yaml", yamlDir, namespace), fmt.Sprintf("acme/namespaces/%s/namespace.yaml", namespace))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Stop managing the namespace")) + nt.Must(rootSyncGitRepo.Copy(fmt.Sprintf("%s/reserved_namespaces/unmanaged-namespace.%s.yaml", yamlDir, namespace), fmt.Sprintf("acme/namespaces/%s/namespace.yaml", namespace))) + nt.Must(rootSyncGitRepo.CommitAndPush("Stop managing the namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/cli_test.go b/e2e/testcases/cli_test.go index 04db443e94..681aeab6ee 100644 --- a/e2e/testcases/cli_test.go +++ b/e2e/testcases/cli_test.go @@ -489,6 +489,8 @@ func testNomosHydrateWithClusterSelectors(t *testing.T, configPath string, sourc } func testSyncFromNomosHydrateOutput(nt *nomostest.NT, config string) { + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + if err := nt.ValidateNotFound("bookstore1", "", &corev1.Namespace{}); err != nil { nt.T.Fatal(err) } @@ -497,8 +499,8 @@ func testSyncFromNomosHydrateOutput(nt *nomostest.NT, config string) { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy(config, "acme")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add cluster-dev configs")) + nt.Must(rootSyncGitRepo.Copy(config, "acme")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add cluster-dev configs")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/cluster_resources_test.go b/e2e/testcases/cluster_resources_test.go index 144daf60e2..80103df4b6 100644 --- a/e2e/testcases/cluster_resources_test.go +++ b/e2e/testcases/cluster_resources_test.go @@ -75,6 +75,7 @@ func managerFieldsNonEmpty() testpredicates.Predicate { // changes to cluster-scoped objects. func TestRevertClusterRole(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crName := "e2e-test-clusterrole" @@ -93,8 +94,8 @@ func TestRevertClusterRole(t *testing.T) { } declaredCr := k8sobjects.ClusterRoleObject(core.Name(crName)) declaredCr.Rules = declaredRules - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/clusterrole.yaml", declaredCr)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add get/list/create ClusterRole")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/clusterrole.yaml", declaredCr)) + nt.Must(rootSyncGitRepo.CommitAndPush("add get/list/create ClusterRole")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -143,6 +144,7 @@ func TestRevertClusterRole(t *testing.T) { // resources. func TestClusterRoleLifecycle(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crName := "e2e-test-clusterrole" @@ -161,8 +163,8 @@ func TestClusterRoleLifecycle(t *testing.T) { } declaredCr := k8sobjects.ClusterRoleObject(core.Name(crName)) declaredCr.Rules = declaredRules - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/clusterrole.yaml", declaredCr)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add get/list/create ClusterRole")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/clusterrole.yaml", declaredCr)) + nt.Must(rootSyncGitRepo.CommitAndPush("add get/list/create ClusterRole")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -194,8 +196,8 @@ func TestClusterRoleLifecycle(t *testing.T) { } updatedCr := k8sobjects.ClusterRoleObject(core.Name(crName)) updatedCr.Rules = updatedRules - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/clusterrole.yaml", updatedCr)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("update ClusterRole to get/list")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/clusterrole.yaml", updatedCr)) + nt.Must(rootSyncGitRepo.CommitAndPush("update ClusterRole to get/list")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -216,8 +218,8 @@ func TestClusterRoleLifecycle(t *testing.T) { } // Delete the ClusterRole from the SOT. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster/clusterrole.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("deleting ClusterRole")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster/clusterrole.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("deleting ClusterRole")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/cluster_selectors_test.go b/e2e/testcases/cluster_selectors_test.go index f2b48bec48..ee40fc4d76 100644 --- a/e2e/testcases/cluster_selectors_test.go +++ b/e2e/testcases/cluster_selectors_test.go @@ -103,14 +103,15 @@ func namespaceObject(name string, annotations map[string]string) *corev1.Namespa func TestTargetingDifferentResourceQuotasToDifferentClusters(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) configMapName := clusterNameConfigMapName(nt) nt.T.Log("Add test cluster, and cluster registry data") testCluster := clusterObject(testClusterName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/cluster-test.yaml", testCluster)) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/cluster-test.yaml", testCluster)) testClusterSelector := clusterSelector(testClusterSelectorName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add test cluster and cluster registry data")) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add test cluster and cluster registry data")) nt.T.Log("Add a valid cluster selector annotation to a resource quota") resourceQuotaName := "pod-quota" @@ -119,11 +120,11 @@ func TestTargetingDifferentResourceQuotasToDifferentClusters(t *testing.T) { rqInline := resourceQuota(resourceQuotaName, frontendNamespace, prodPodsQuota, inlineProdClusterSelectorAnnotation) rqLegacy := resourceQuota(resourceQuotaName, frontendNamespace, testPodsQuota, legacyTestClusterSelectorAnnotation) nsObj := namespaceObject(frontendNamespace, map[string]string{}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/eng/%s/namespace.yaml", frontendNamespace), nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/frontend/quota-inline.yaml", rqInline)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/frontend/quota-legacy.yaml", rqLegacy)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a valid cluster selector annotation to a resource quota")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/frontend/quota-inline.yaml", rqInline)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/frontend/quota-legacy.yaml", rqLegacy)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a valid cluster selector annotation to a resource quota")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -180,16 +181,17 @@ func TestTargetingDifferentResourceQuotasToDifferentClusters(t *testing.T) { func TestClusterSelectorOnObjects(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) configMapName := clusterNameConfigMapName(nt) nt.T.Log("Add a valid cluster selector annotation to a role binding") rb := roleBinding(roleBindingName, backendNamespace, inlineProdClusterSelectorAnnotation) nsObj := namespaceObject(backendNamespace, map[string]string{}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/eng/%s/namespace.yaml", backendNamespace), nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a valid cluster selector annotation to a role binding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a valid cluster selector annotation to a role binding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -199,15 +201,15 @@ func TestClusterSelectorOnObjects(t *testing.T) { nt.T.Log("Add test cluster, and cluster registry data") testCluster := clusterObject(testClusterName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/cluster-test.yaml", testCluster)) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/cluster-test.yaml", testCluster)) testClusterSelector := clusterSelector(testClusterSelectorName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add test cluster and cluster registry data")) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add test cluster and cluster registry data")) nt.T.Log("Change cluster selector to match test cluster") rb.Annotations = legacyTestClusterSelectorAnnotation - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Change cluster selector to match test cluster")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Change cluster selector to match test cluster")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -233,8 +235,8 @@ func TestClusterSelectorOnObjects(t *testing.T) { nt.T.Log("Revert cluster selector to match prod cluster") rb.Annotations = inlineProdClusterSelectorAnnotation - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Revert cluster selector to match prod cluster")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Revert cluster selector to match prod cluster")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -272,15 +274,16 @@ func TestClusterSelectorOnObjects(t *testing.T) { func TestClusterSelectorOnNamespaces(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) configMapName := clusterNameConfigMapName(nt) nt.T.Log("Add a valid cluster selector annotation to a namespace") namespace := namespaceObject(backendNamespace, inlineProdClusterSelectorAnnotation) rb := roleBinding(roleBindingName, backendNamespace, inlineProdClusterSelectorAnnotation) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/namespace.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a valid cluster selector annotation to a namespace and a role binding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/namespace.yaml", namespace)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a valid cluster selector annotation to a namespace and a role binding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -305,15 +308,15 @@ func TestClusterSelectorOnNamespaces(t *testing.T) { nt.T.Log("Add test cluster, and cluster registry data") testCluster := clusterObject(testClusterName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/cluster-test.yaml", testCluster)) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/cluster-test.yaml", testCluster)) testClusterSelector := clusterSelector(testClusterSelectorName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add test cluster and cluster registry data")) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add test cluster and cluster registry data")) nt.T.Log("Change namespace to match test cluster") namespace.Annotations = legacyTestClusterSelectorAnnotation - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/namespace.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Change namespace to match test cluster")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/namespace.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Change namespace to match test cluster")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -371,8 +374,8 @@ func TestClusterSelectorOnNamespaces(t *testing.T) { nt.T.Log("Updating bob-rolebinding to NOT have cluster-selector") rb.Annotations = map[string]string{} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update bob-rolebinding to NOT have cluster-selector")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update bob-rolebinding to NOT have cluster-selector")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -392,8 +395,8 @@ func TestClusterSelectorOnNamespaces(t *testing.T) { nt.T.Log("Revert namespace to match prod cluster") namespace.Annotations = inlineProdClusterSelectorAnnotation - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/namespace.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Revert namespace to match prod cluster")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/namespace.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Revert namespace to match prod cluster")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -451,14 +454,15 @@ func TestClusterSelectorOnNamespaces(t *testing.T) { func TestObjectReactsToChangeInInlineClusterSelector(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add a valid cluster selector annotation to a role binding") rb := roleBinding(roleBindingName, backendNamespace, inlineProdClusterSelectorAnnotation) nsObj := namespaceObject(backendNamespace, map[string]string{}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/eng/%s/namespace.yaml", backendNamespace), nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a valid cluster selector annotation to a role binding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a valid cluster selector annotation to a role binding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -480,8 +484,8 @@ func TestObjectReactsToChangeInInlineClusterSelector(t *testing.T) { nt.T.Log("Modify the cluster selector to select an excluded cluster list") rb.Annotations = map[string]string{metadata.ClusterNameSelectorAnnotationKey: "a, b, c"} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Modify the cluster selector to select an excluded cluster list")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Modify the cluster selector to select an excluded cluster list")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -502,21 +506,22 @@ func TestObjectReactsToChangeInInlineClusterSelector(t *testing.T) { func TestObjectReactsToChangeInLegacyClusterSelector(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add prod cluster, and cluster registry data") prodCluster := clusterObject(prodClusterName, environmentLabelKey, prodEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/cluster-prod.yaml", prodCluster)) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/cluster-prod.yaml", prodCluster)) prodClusterSelector := clusterSelector(prodClusterSelectorName, environmentLabelKey, prodEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/clusterselector-prod.yaml", prodClusterSelector)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add prod cluster and cluster registry data")) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/clusterselector-prod.yaml", prodClusterSelector)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add prod cluster and cluster registry data")) nt.T.Log("Add a valid cluster selector annotation to a role binding") rb := roleBinding(roleBindingName, backendNamespace, map[string]string{metadata.LegacyClusterSelectorAnnotationKey: prodClusterSelectorName}) nsObj := namespaceObject(backendNamespace, map[string]string{}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/eng/%s/namespace.yaml", backendNamespace), nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a valid cluster selector annotation to a role binding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a valid cluster selector annotation to a role binding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -537,8 +542,8 @@ func TestObjectReactsToChangeInLegacyClusterSelector(t *testing.T) { nt.T.Log("Modify the cluster selector to select a different environment") prodClusterWithADifferentSelector := clusterSelector(prodClusterSelectorName, environmentLabelKey, "other") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/clusterselector-prod.yaml", prodClusterWithADifferentSelector)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Modify the cluster selector to select a different environment")) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/clusterselector-prod.yaml", prodClusterWithADifferentSelector)) + nt.Must(rootSyncGitRepo.CommitAndPush("Modify the cluster selector to select a different environment")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -559,25 +564,26 @@ func TestObjectReactsToChangeInLegacyClusterSelector(t *testing.T) { func TestImporterIgnoresNonSelectedCustomResources(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add test cluster, and cluster registry data") testCluster := clusterObject(testClusterName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/cluster-test.yaml", testCluster)) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/cluster-test.yaml", testCluster)) testClusterSelector := clusterSelector(testClusterSelectorName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add test cluster and cluster registry data")) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add test cluster and cluster registry data")) nt.T.Log("Add CRs (not targeted to this cluster) without its CRD") cr := anvilCR("v1", "e2e-test-anvil", 10) cr.SetAnnotations(map[string]string{metadata.ClusterNameSelectorAnnotationKey: testClusterSelectorName}) nsObj := namespaceObject(backendNamespace, map[string]string{}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/eng/%s/namespace.yaml", backendNamespace), nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/anvil.yaml", cr)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/anvil.yaml", cr)) cr2 := anvilCR("v1", "e2e-test-anvil-2", 10) cr2.SetAnnotations(legacyTestClusterSelectorAnnotation) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/anvil-2.yaml", cr2)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a custom resource without its CRD")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/anvil-2.yaml", cr2)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a custom resource without its CRD")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -601,12 +607,14 @@ func TestClusterSelectorOnNamespaceRepos(t *testing.T) { ntopts.NamespaceRepo(namespaceRepo, configsync.RepoSyncName), ntopts.RepoSyncPermissions(policy.RBACAdmin()), // NS reconciler manages rolebindings ) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, namespaceRepo) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) nt.T.Log("Add a valid cluster selector annotation to a role binding") rb := roleBinding(roleBindingName, namespaceRepo, inlineProdClusterSelectorAnnotation) - nn := nomostest.RepoSyncNN(namespaceRepo, configsync.RepoSyncName) - nt.Must(nt.NonRootRepos[nn].Add("acme/bob-rolebinding.yaml", rb)) - nt.Must(nt.NonRootRepos[nn].CommitAndPush("Add a valid cluster selector annotation to a role binding")) + nt.Must(repoSyncGitRepo.Add("acme/bob-rolebinding.yaml", rb)) + nt.Must(repoSyncGitRepo.CommitAndPush("Add a valid cluster selector annotation to a role binding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -614,11 +622,11 @@ func TestClusterSelectorOnNamespaceRepos(t *testing.T) { nt.T.Fatal(err) } - nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, nn, rb) + nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncKey, rb) // Validate metrics. err := nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: nn, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) @@ -626,8 +634,8 @@ func TestClusterSelectorOnNamespaceRepos(t *testing.T) { nt.T.Log("Modify the cluster selector to select an excluded cluster list") rb.Annotations = map[string]string{metadata.ClusterNameSelectorAnnotationKey: "a,b,,,c,d"} - nt.Must(nt.NonRootRepos[nn].Add("acme/bob-rolebinding.yaml", rb)) - nt.Must(nt.NonRootRepos[nn].CommitAndPush("Modify the cluster selector to select an excluded cluster list")) + nt.Must(repoSyncGitRepo.Add("acme/bob-rolebinding.yaml", rb)) + nt.Must(repoSyncGitRepo.CommitAndPush("Modify the cluster selector to select an excluded cluster list")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -636,11 +644,11 @@ func TestClusterSelectorOnNamespaceRepos(t *testing.T) { } // Delete the object, since it's no longer specified for this cluster - nt.MetricsExpectations.AddObjectDelete(configsync.RepoSyncKind, nn, rb) + nt.MetricsExpectations.AddObjectDelete(configsync.RepoSyncKind, repoSyncKey, rb) // Validate metrics. err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: nn, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) @@ -648,12 +656,12 @@ func TestClusterSelectorOnNamespaceRepos(t *testing.T) { nt.T.Log("Switch to use ClusterSelector objects") clusterObj := clusterObject(prodClusterName, environmentLabelKey, prodEnvironment) - nt.Must(nt.NonRootRepos[nn].Add("acme/cluster.yaml", clusterObj)) + nt.Must(repoSyncGitRepo.Add("acme/cluster.yaml", clusterObj)) clusterSelectorObj := clusterSelector(prodClusterSelectorName, environmentLabelKey, prodEnvironment) - nt.Must(nt.NonRootRepos[nn].Add("acme/clusterselector.yaml", clusterSelectorObj)) + nt.Must(repoSyncGitRepo.Add("acme/clusterselector.yaml", clusterSelectorObj)) rb.Annotations = map[string]string{metadata.LegacyClusterSelectorAnnotationKey: prodClusterSelectorName} - nt.Must(nt.NonRootRepos[nn].Add("acme/bob-rolebinding.yaml", rb)) - nt.Must(nt.NonRootRepos[nn].CommitAndPush("Add cluster registry data and use the legacy ClusterSelector")) + nt.Must(repoSyncGitRepo.Add("acme/bob-rolebinding.yaml", rb)) + nt.Must(repoSyncGitRepo.CommitAndPush("Add cluster registry data and use the legacy ClusterSelector")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -663,11 +671,11 @@ func TestClusterSelectorOnNamespaceRepos(t *testing.T) { // Expect ClusterObject & ClusterSelector to be excluded from declared // resources and not applied. - nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, nn, rb) + nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncKey, rb) // Validate metrics. err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: nn, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) @@ -676,6 +684,7 @@ func TestClusterSelectorOnNamespaceRepos(t *testing.T) { func TestInlineClusterSelectorFormat(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) configMapName := clusterNameConfigMapName(nt) renameCluster(nt, configMapName, "") @@ -683,10 +692,10 @@ func TestInlineClusterSelectorFormat(t *testing.T) { nt.T.Log("Add a role binding without any cluster selectors") rb := roleBinding(roleBindingName, backendNamespace, map[string]string{}) nsObj := namespaceObject(backendNamespace, map[string]string{}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/eng/%s/namespace.yaml", backendNamespace), nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a role binding without any cluster selectors")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a role binding without any cluster selectors")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -708,8 +717,8 @@ func TestInlineClusterSelectorFormat(t *testing.T) { nt.T.Logf("Add a prod cluster selector to the role binding") rb.Annotations = inlineProdClusterSelectorAnnotation - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a prod cluster selector to the role binding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a prod cluster selector to the role binding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -755,8 +764,8 @@ func TestInlineClusterSelectorFormat(t *testing.T) { nt.T.Log("Add an empty cluster selector annotation to a role binding") rb.Annotations = map[string]string{metadata.ClusterNameSelectorAnnotationKey: ""} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add an empty cluster selector annotation to a role binding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add an empty cluster selector annotation to a role binding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -776,8 +785,8 @@ func TestInlineClusterSelectorFormat(t *testing.T) { nt.T.Log("Add a cluster selector annotation to a role binding with a list of included clusters") rb.Annotations = map[string]string{metadata.ClusterNameSelectorAnnotationKey: fmt.Sprintf("a,%s,b", prodClusterName)} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a cluster selector annotation to a role binding with a list of included clusters")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a cluster selector annotation to a role binding with a list of included clusters")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -797,8 +806,8 @@ func TestInlineClusterSelectorFormat(t *testing.T) { nt.T.Log("Add a cluster selector annotation to a role binding that does not include the current cluster") rb.Annotations = map[string]string{metadata.ClusterNameSelectorAnnotationKey: "a,,b"} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a cluster selector annotation to a role binding with a list of excluded clusters")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a cluster selector annotation to a role binding with a list of excluded clusters")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -818,8 +827,8 @@ func TestInlineClusterSelectorFormat(t *testing.T) { nt.T.Log("Add a cluster selector annotation to a role binding with a list of included clusters (with spaces)") rb.Annotations = map[string]string{metadata.ClusterNameSelectorAnnotationKey: fmt.Sprintf("a , %s , b", prodClusterName)} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a cluster selector annotation to a role binding with a list of included clusters (with spaces)")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a cluster selector annotation to a role binding with a list of included clusters (with spaces)")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -840,17 +849,18 @@ func TestInlineClusterSelectorFormat(t *testing.T) { func TestClusterSelectorAnnotationConflicts(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add both cluster selector annotations to a role binding") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/eng/%s/namespace.yaml", backendNamespace), namespaceObject(backendNamespace, map[string]string{}))) rb := roleBinding(roleBindingName, backendNamespace, map[string]string{ metadata.ClusterNameSelectorAnnotationKey: prodClusterName, metadata.LegacyClusterSelectorAnnotationKey: prodClusterSelectorName, }) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add both cluster selector annotations to a role binding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/eng/backend/bob-rolebinding.yaml", rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add both cluster selector annotations to a role binding")) nt.WaitForRootSyncSourceError(configsync.RootSyncName, selectors.ClusterSelectorAnnotationConflictErrorCode, "") rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) @@ -858,7 +868,7 @@ func TestClusterSelectorAnnotationConflicts(t *testing.T) { if err != nil { nt.T.Fatal(err) } - commitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + commitHash := rootSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerErrorMetrics(nt, rootSyncLabels, commitHash, metrics.ErrorSummary{ @@ -871,11 +881,12 @@ func TestClusterSelectorAnnotationConflicts(t *testing.T) { func TestClusterSelectorForCRD(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add CRD without ClusterSelectors or cluster-name-selector annotation") crd := anvilV1CRD() - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/anvil-crd.yaml", crd)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a custom resource definition")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/anvil-crd.yaml", crd)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a custom resource definition")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -897,8 +908,8 @@ func TestClusterSelectorForCRD(t *testing.T) { // Test inline cluster-name-selector annotation nt.T.Log("Set the cluster-name-selector annotation to a not-selected cluster") crd.SetAnnotations(map[string]string{metadata.ClusterNameSelectorAnnotationKey: testClusterName}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/anvil-crd.yaml", crd)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a custom resource definition with an unselected cluster-name-selector annotation")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/anvil-crd.yaml", crd)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a custom resource definition with an unselected cluster-name-selector annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -921,8 +932,8 @@ func TestClusterSelectorForCRD(t *testing.T) { nt.T.Log("Set the cluster-name-selector annotation to a selected cluster") crd.SetAnnotations(map[string]string{metadata.ClusterNameSelectorAnnotationKey: prodClusterName}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/anvil-crd.yaml", crd)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a custom resource definition with an selected cluster-name-selector annotation")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/anvil-crd.yaml", crd)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a custom resource definition with an selected cluster-name-selector annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -943,17 +954,17 @@ func TestClusterSelectorForCRD(t *testing.T) { // Test legacy ClusterSelectors nt.T.Log("Add cluster, and cluster registry data") prodCluster := clusterObject(prodClusterName, environmentLabelKey, prodEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/cluster-prod.yaml", prodCluster)) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/cluster-prod.yaml", prodCluster)) prodClusterSelector := clusterSelector(prodClusterSelectorName, environmentLabelKey, prodEnvironment) testClusterSelector := clusterSelector(testClusterSelectorName, environmentLabelKey, testEnvironment) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/clusterselector-prod.yaml", prodClusterSelector)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add cluster and cluster registry data")) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/clusterselector-prod.yaml", prodClusterSelector)) + nt.Must(rootSyncGitRepo.Add("acme/clusterregistry/clusterselector-test.yaml", testClusterSelector)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add cluster and cluster registry data")) nt.T.Log("Set ClusterSelector to a not-selected cluster") crd.SetAnnotations(legacyTestClusterSelectorAnnotation) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/anvil-crd.yaml", crd)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a custom resource definition with an unselected ClusterSelector")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/anvil-crd.yaml", crd)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a custom resource definition with an unselected ClusterSelector")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -976,8 +987,8 @@ func TestClusterSelectorForCRD(t *testing.T) { nt.T.Log("Set ClusterSelector to a selected cluster") crd.SetAnnotations(map[string]string{metadata.LegacyClusterSelectorAnnotationKey: prodClusterSelectorName}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/anvil-crd.yaml", crd)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a custom resource definition with an selected ClusterSelector")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/anvil-crd.yaml", crd)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a custom resource definition with an selected ClusterSelector")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/composition_test.go b/e2e/testcases/composition_test.go index dd3efc5705..d4dafc0236 100644 --- a/e2e/testcases/composition_test.go +++ b/e2e/testcases/composition_test.go @@ -37,7 +37,6 @@ import ( "kpt.dev/configsync/e2e/nomostest/testpredicates" "kpt.dev/configsync/e2e/nomostest/testwatcher" "kpt.dev/configsync/pkg/api/configmanagement" - "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/api/configsync/v1beta1" "kpt.dev/configsync/pkg/core" "kpt.dev/configsync/pkg/core/k8sobjects" @@ -78,20 +77,21 @@ import ( // 3. RepoSyncs can share an ssh-key secret // 4. R*Sync status isn't updated after sync without external input. func TestComposition(t *testing.T) { + lvl0ID := nomostest.DefaultRootSyncID nt := nomostest.New(t, nomostesting.MultiRepos, ntopts.Unstructured, ntopts.WithDelegatedControl, ntopts.RepoSyncPermissions(policy.RepoSyncAdmin(), policy.CoreAdmin()), // NS reconciler manages RepoSyncs and ConfigMaps - ntopts.RootRepo(configsync.RootSyncName)) + ntopts.RootRepo(lvl0ID.Name)) - lvl0NN := nomostest.RootSyncNN(configsync.RootSyncName) + lvl0NN := lvl0ID.ObjectKey lvl1NN := nomostest.RootSyncNN("level-1") lvl2NN := types.NamespacedName{Namespace: testNs, Name: "level-2"} lvl3NN := types.NamespacedName{Namespace: testNs, Name: "level-3"} lvl4NN := types.NamespacedName{Namespace: testNs, Name: "level-4"} - lvl0Repo := nt.RootRepos[lvl0NN.Name] + lvl0Repo := nt.SyncSourceGitRepository(lvl0ID) lvl0Sync := nomostest.RootSyncObjectV1Beta1FromRootRepo(nt, lvl0NN.Name) lvl0Sync.Spec.Git.Dir = gitproviders.DefaultSyncDir @@ -138,7 +138,7 @@ func TestComposition(t *testing.T) { t.Cleanup(func() { cleanupManagedSync(nt, lvl0Repo, lvl3Sync.Spec.Git.Dir, lvl3Sync) }) - // Print reconciler logs for R*Syncs that aren't in nt.RootRepos or nt.NonRootRepos. + // Print reconciler logs for R*Syncs that aren't in nt.SyncSources. t.Cleanup(func() { if t.Failed() { nt.PodLogs(configmanagement.ControllerNamespace, core.RootReconcilerName(lvl1NN.Name), @@ -353,8 +353,8 @@ func (id gvknn) String() string { // waitForSync waits for the specified R*Syncs to be Synced. // // The reason we can't just use nt.WaitForRepoSyncs is that the R*Syncs for this -// test are not all in nt.RootRepos or nt.NonRootRepos, because they're all -// sharing the same repository. +// test are not all in nt.SyncSources, because they're all sharing the same +// repository. // // So this function uses the same sha1Func for all R*Syncs. func waitForSync(nt *nomostest.NT, sha1Func nomostest.Sha1Func, objs ...client.Object) { diff --git a/e2e/testcases/custom_resource_definitions_schema_test.go b/e2e/testcases/custom_resource_definitions_schema_test.go index 7255b633ce..5b07893ae0 100644 --- a/e2e/testcases/custom_resource_definitions_schema_test.go +++ b/e2e/testcases/custom_resource_definitions_schema_test.go @@ -23,12 +23,12 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "kpt.dev/configsync/e2e/nomostest" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" - "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/core/k8sobjects" ) func TestChangeCustomResourceDefinitionSchema(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) oldCRDFile := filepath.Join(".", "..", "testdata", "customresources", "changed_schema_crds", "old_schema_crd.yaml") newCRDFile := filepath.Join(".", "..", "testdata", "customresources", "changed_schema_crds", "new_schema_crd.yaml") @@ -44,10 +44,10 @@ func TestChangeCustomResourceDefinitionSchema(t *testing.T) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/crd.yaml", crdContent)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", k8sobjects.NamespaceObject("foo"))) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/namespaces/foo/cr.yaml", crContent)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding a CRD and CR")) + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/crd.yaml", crdContent)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", k8sobjects.NamespaceObject("foo"))) + nt.Must(rootSyncGitRepo.AddFile("acme/namespaces/foo/cr.yaml", crContent)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding a CRD and CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -73,9 +73,9 @@ func TestChangeCustomResourceDefinitionSchema(t *testing.T) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/crd.yaml", crdContent)) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/namespaces/foo/cr.yaml", crContent)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding the CRD with new schema and a CR using the new schema")) + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/crd.yaml", crdContent)) + nt.Must(rootSyncGitRepo.AddFile("acme/namespaces/foo/cr.yaml", crContent)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding the CRD with new schema and a CR using the new schema")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/custom_resource_definitions_test.go b/e2e/testcases/custom_resource_definitions_test.go index 016f436dc4..0650d3001f 100644 --- a/e2e/testcases/custom_resource_definitions_test.go +++ b/e2e/testcases/custom_resource_definitions_test.go @@ -39,12 +39,13 @@ import ( ) func mustRemoveCustomResourceWithDefinition(nt *nomostest.NT, crd client.Object) { - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/anvil-crd.yaml", crd)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + nt.Must(rootSyncGitRepo.Add("acme/cluster/anvil-crd.yaml", crd)) nsObj := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) anvilObj := anvilCR("v1", "heavy", 10) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvil-v1.yaml", anvilObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding Anvil CRD and one Anvil CR")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvil-v1.yaml", anvilObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding Anvil CRD and one Anvil CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -74,8 +75,8 @@ func mustRemoveCustomResourceWithDefinition(nt *nomostest.NT, crd client.Object) } // This should cause an error. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster/anvil-crd.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing Anvil CRD but leaving Anvil CR")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster/anvil-crd.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing Anvil CRD but leaving Anvil CR")) err = nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), rootSyncNN.Name, rootSyncNN.Namespace, []testpredicates.Predicate{ testpredicates.RootSyncHasSourceError(nonhierarchical.UnsupportedCRDRemovalErrorCode, ""), @@ -88,7 +89,7 @@ func mustRemoveCustomResourceWithDefinition(nt *nomostest.NT, crd client.Object) if err != nil { nt.T.Fatal(err) } - commitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + commitHash := rootSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerErrorMetrics(nt, rootSyncLabels, commitHash, metrics.ErrorSummary{ @@ -99,8 +100,8 @@ func mustRemoveCustomResourceWithDefinition(nt *nomostest.NT, crd client.Object) } // This should fix the error. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/foo/anvil-v1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing the Anvil CR as well")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/foo/anvil-v1.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing the Anvil CR as well")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -123,18 +124,19 @@ func TestMustRemoveCustomResourceWithDefinitionV1(t *testing.T) { } func addAndRemoveCustomResource(nt *nomostest.NT, dir string, crd string) { + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crdFile := filepath.Join(".", "..", "testdata", "customresources", dir, crd) crdContent, err := os.ReadFile(crdFile) if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/anvil-crd.yaml", crdContent)) - crdObj := nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/cluster/anvil-crd.yaml") + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/anvil-crd.yaml", crdContent)) + crdObj := rootSyncGitRepo.MustGet(nt.T, "acme/cluster/anvil-crd.yaml") nsObj := k8sobjects.NamespaceObject("prod") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/prod/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/prod/ns.yaml", nsObj)) anvilObj := anvilCR("v1", "e2e-test-anvil", 10) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/prod/anvil.yaml", anvilObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding Anvil CRD and one Anvil CR")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/prod/anvil.yaml", anvilObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding Anvil CRD and one Anvil CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -158,8 +160,8 @@ func addAndRemoveCustomResource(nt *nomostest.NT, dir string, crd string) { } // Remove the CustomResource. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/prod/anvil.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing Anvil CR but leaving Anvil CRD")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/prod/anvil.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing Anvil CR but leaving Anvil CRD")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -178,8 +180,8 @@ func addAndRemoveCustomResource(nt *nomostest.NT, dir string, crd string) { } // Remove the CustomResourceDefinition. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster/anvil-crd.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing the Anvil CRD as well")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster/anvil-crd.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing the Anvil CRD as well")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -204,16 +206,17 @@ func TestAddAndRemoveCustomResourceV1(t *testing.T) { } func mustRemoveUnManagedCustomResource(nt *nomostest.NT, dir string, crd string) { + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crdFile := filepath.Join(".", "..", "testdata", "customresources", dir, crd) crdContent, err := os.ReadFile(crdFile) if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/anvil-crd.yaml", crdContent)) - crdObj := nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/cluster/anvil-crd.yaml") + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/anvil-crd.yaml", crdContent)) + crdObj := rootSyncGitRepo.MustGet(nt.T, "acme/cluster/anvil-crd.yaml") nsObj := k8sobjects.NamespaceObject("prod") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/prod/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding Anvil CRD")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/prod/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding Anvil CRD")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -244,8 +247,8 @@ func mustRemoveUnManagedCustomResource(nt *nomostest.NT, dir string, crd string) } // Remove the CustomResourceDefinition. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster/anvil-crd.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing the Anvil CRD")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster/anvil-crd.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing the Anvil CRD")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -270,16 +273,17 @@ func TestMustRemoveUnManagedCustomResourceV1(t *testing.T) { } func addUpdateRemoveClusterScopedCRD(nt *nomostest.NT, dir string, crd string) { + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crdFile := filepath.Join(".", "..", "testdata", "customresources", dir, crd) crdContent, err := os.ReadFile(crdFile) if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/clusteranvil-crd.yaml", crdContent)) - crdObj := nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/cluster/clusteranvil-crd.yaml") + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/clusteranvil-crd.yaml", crdContent)) + crdObj := rootSyncGitRepo.MustGet(nt.T, "acme/cluster/clusteranvil-crd.yaml") clusteranvilObj := clusteranvilCR("v1", "e2e-test-clusteranvil", 10) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/clusteranvil.yaml", clusteranvilObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding clusterscoped Anvil CRD and CR")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/clusteranvil.yaml", clusteranvilObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding clusterscoped Anvil CRD and CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -307,8 +311,8 @@ func addUpdateRemoveClusterScopedCRD(nt *nomostest.NT, dir string, crd string) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/clusteranvil-crd.yaml", crdContent)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Updating the Anvil CRD")) + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/clusteranvil-crd.yaml", crdContent)) + nt.Must(rootSyncGitRepo.CommitAndPush("Updating the Anvil CRD")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -326,10 +330,10 @@ func addUpdateRemoveClusterScopedCRD(nt *nomostest.NT, dir string, crd string) { } // Remove the CR and CRD. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster")) // Add back the safety ClusterRole to pass the safety check (KNV2006). - nt.Must(nt.RootRepos[configsync.RootSyncName].AddSafetyClusterRole()) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing the Anvil CRD as well")) + nt.Must(rootSyncGitRepo.AddSafetyClusterRole()) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing the Anvil CRD as well")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -351,18 +355,19 @@ func TestAddUpdateRemoveClusterScopedCRDV1(t *testing.T) { } func addUpdateNamespaceScopedCRD(nt *nomostest.NT, dir string, crd string) { + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crdFile := filepath.Join(".", "..", "testdata", "customresources", dir, crd) crdContent, err := os.ReadFile(crdFile) if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/anvil-crd.yaml", crdContent)) - crdObj := nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/cluster/anvil-crd.yaml") + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/anvil-crd.yaml", crdContent)) + crdObj := rootSyncGitRepo.MustGet(nt.T, "acme/cluster/anvil-crd.yaml") anvilObj := anvilCR("v1", "e2e-test-anvil", 10) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/prod/anvil.yaml", anvilObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/prod/anvil.yaml", anvilObj)) nsObj := k8sobjects.NamespaceObject("prod") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/prod/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding namespacescoped Anvil CRD and CR")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/prod/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding namespacescoped Anvil CRD and CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -391,8 +396,8 @@ func addUpdateNamespaceScopedCRD(nt *nomostest.NT, dir string, crd string) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/anvil-crd.yaml", crdContent)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Updating the Anvil CRD")) + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/anvil-crd.yaml", crdContent)) + nt.Must(rootSyncGitRepo.CommitAndPush("Updating the Anvil CRD")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -412,9 +417,9 @@ func addUpdateNamespaceScopedCRD(nt *nomostest.NT, dir string, crd string) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/anvil-crd.yaml", crdContent)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/prod/anvil.yaml", anvilCR("v2", "e2e-test-anvil", 10))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update the Anvil CRD and CR")) + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/anvil-crd.yaml", crdContent)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/prod/anvil.yaml", anvilCR("v2", "e2e-test-anvil", 10))) + nt.Must(rootSyncGitRepo.CommitAndPush("Update the Anvil CRD and CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -430,9 +435,9 @@ func addUpdateNamespaceScopedCRD(nt *nomostest.NT, dir string, crd string) { } // Remove CRD and CR - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster/anvil-crd.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/prod/anvil.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the Anvil CRD and CR")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster/anvil-crd.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/prod/anvil.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the Anvil CRD and CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -450,6 +455,7 @@ func TestAddUpdateNamespaceScopedCRDV1(t *testing.T) { func TestLargeCRD(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) for _, file := range []string{"challenges-acme-cert-manager-io.yaml", "solrclouds-solr-apache-org.yaml"} { crdFile := filepath.Join(".", "..", "testdata", "customresources", file) @@ -457,9 +463,9 @@ func TestLargeCRD(t *testing.T) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile(fmt.Sprintf("acme/cluster/%s", file), crdContent)) + nt.Must(rootSyncGitRepo.AddFile(fmt.Sprintf("acme/cluster/%s", file), crdContent)) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding two large CRDs")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding two large CRDs")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -478,8 +484,8 @@ func TestLargeCRD(t *testing.T) { } rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/cluster/challenges-acme-cert-manager-io.yaml")) - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/cluster/solrclouds-solr-apache-org.yaml")) + nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rootSyncGitRepo.MustGet(nt.T, "acme/cluster/challenges-acme-cert-manager-io.yaml")) + nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rootSyncGitRepo.MustGet(nt.T, "acme/cluster/solrclouds-solr-apache-org.yaml")) err = nomostest.ValidateStandardMetricsForRootSync(nt, metrics.Summary{ Sync: nomostest.RootSyncNN(configsync.RootSyncName), @@ -494,8 +500,8 @@ func TestLargeCRD(t *testing.T) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/challenges-acme-cert-manager-io.yaml", crdContent)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update label for one CRD")) + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/challenges-acme-cert-manager-io.yaml", crdContent)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update label for one CRD")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/custom_resources_test.go b/e2e/testcases/custom_resources_test.go index 6cfafd71c9..49561f4f5f 100644 --- a/e2e/testcases/custom_resources_test.go +++ b/e2e/testcases/custom_resources_test.go @@ -41,6 +41,7 @@ import ( func TestCRDDeleteBeforeRemoveCustomResourceV1(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crdFile := filepath.Join(".", "..", "testdata", "customresources", "v1_crds", "anvil-crd.yaml") clusterFile := filepath.Join(".", "..", "testdata", "customresources", "v1_crds", "clusteranvil-crd.yaml") @@ -58,11 +59,11 @@ func TestCRDDeleteBeforeRemoveCustomResourceV1(t *testing.T) { nt.Must(nt.Watcher.WatchForCurrentStatus(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace)) nsObj := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) anvilObj := anvilCR("v1", "heavy", 10) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvil-v1.yaml", anvilObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding Anvil CR")) - firstCommitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvil-v1.yaml", anvilObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding Anvil CR")) + firstCommitHash := rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.WatchForAllSyncs()) @@ -125,9 +126,9 @@ func TestCRDDeleteBeforeRemoveCustomResourceV1(t *testing.T) { // Modify the Anvil yaml to trigger immediate re-sync, instead of waiting // for automatic retry (1hr default). anvilObj = anvilCR("v1", "heavy", 100) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvil-v1.yaml", anvilObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Modify Anvil CR")) - secondCommitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvil-v1.yaml", anvilObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Modify Anvil CR")) + secondCommitHash := rootSyncGitRepo.MustHash(nt.T) nt.WaitForRootSyncSourceError(configsync.RootSyncName, status.UnknownKindErrorCode, "") @@ -146,8 +147,8 @@ func TestCRDDeleteBeforeRemoveCustomResourceV1(t *testing.T) { // Remove the CR. // This should fix the error and the conflict. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/foo/anvil-v1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing the Anvil CR as well")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/foo/anvil-v1.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing the Anvil CR as well")) nt.Must(nt.WatchForAllSyncs()) // CR wasn't added to the inventory, so it won't be deleted. @@ -161,6 +162,7 @@ func TestCRDDeleteBeforeRemoveCustomResourceV1(t *testing.T) { func TestSyncUpdateCustomResource(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crdFile := filepath.Join(".", "..", "testdata", "customresources", "v1_crds", "anvil-crd.yaml") _, err := nt.Shell.Kubectl("apply", "-f", crdFile) @@ -188,9 +190,9 @@ func TestSyncUpdateCustomResource(t *testing.T) { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", k8sobjects.NamespaceObject("foo"))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvil-v1.yaml", anvilCR("v1", "heavy", 10))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding Anvil CR")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", k8sobjects.NamespaceObject("foo"))) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvil-v1.yaml", anvilCR("v1", "heavy", 10))) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding Anvil CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -202,8 +204,8 @@ func TestSyncUpdateCustomResource(t *testing.T) { } // Update CustomResource - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvil-v1.yaml", anvilCR("v1", "heavy", 100))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Updating Anvil CR")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvil-v1.yaml", anvilCR("v1", "heavy", 100))) + nt.Must(rootSyncGitRepo.CommitAndPush("Updating Anvil CR")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/declared_fields_test.go b/e2e/testcases/declared_fields_test.go index 2e99bb70bc..8521ef1409 100644 --- a/e2e/testcases/declared_fields_test.go +++ b/e2e/testcases/declared_fields_test.go @@ -21,20 +21,20 @@ import ( "kpt.dev/configsync/e2e/nomostest" "kpt.dev/configsync/e2e/nomostest/ntopts" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" - "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/core/k8sobjects" "kpt.dev/configsync/pkg/kinds" ) func TestDeclaredFieldsPod(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) // We use literal YAML here instead of an object as: // 1) If we used a literal struct the protocol field would implicitly be added. // 2) It's really annoying to specify this as Unstructureds. - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/pod.yaml", []byte(` + nt.Must(rootSyncGitRepo.AddFile("acme/pod.yaml", []byte(` apiVersion: v1 kind: Pod metadata: @@ -47,21 +47,21 @@ spec: ports: - containerPort: 80 `))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add pod missing protocol from port")) + nt.Must(rootSyncGitRepo.CommitAndPush("add pod missing protocol from port")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } // Parse the pod yaml into an object - pod := nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/pod.yaml") + pod := rootSyncGitRepo.MustGet(nt.T, "acme/pod.yaml") err := nt.Validate(pod.GetName(), pod.GetNamespace(), &corev1.Pod{}) if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/pod.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the pod")) + nt.Must(rootSyncGitRepo.Remove("acme/pod.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the pod")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/gatekeeper_test.go b/e2e/testcases/gatekeeper_test.go index 9d2d4be934..7ed21ef4cf 100644 --- a/e2e/testcases/gatekeeper_test.go +++ b/e2e/testcases/gatekeeper_test.go @@ -51,6 +51,7 @@ func emptyConstraintTemplate() unstructured.Unstructured { func TestConstraintTemplateAndConstraintInSameCommit(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) crdName := "k8sallowedrepos.constraints.gatekeeper.sh" nt.T.Logf("Delete the %q CRD if needed", crdName) @@ -62,18 +63,18 @@ func TestConstraintTemplateAndConstraintInSameCommit(t *testing.T) { } nt.T.Log("Adding ConstraintTemplate & Constraint in one commit") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/gatekeeper/constraint-template.yaml", "acme/cluster/constraint-template.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/gatekeeper/constraint.yaml", "acme/cluster/constraint.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add ConstraintTemplate & Constraint")) + nt.Must(rootSyncGitRepo.Copy("../testdata/gatekeeper/constraint-template.yaml", "acme/cluster/constraint-template.yaml")) + nt.Must(rootSyncGitRepo.Copy("../testdata/gatekeeper/constraint.yaml", "acme/cluster/constraint.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add ConstraintTemplate & Constraint")) // Cleanup if waiting for sync error fails. nt.T.Cleanup(func() { if nt.T.Failed() { // Cleanup before deleting the ConstraintTemplate CRDs to avoid resource conflict errors from the webhook. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster")) // Add back the safety ClusterRole to pass the safety check (KNV2006). - nt.Must(nt.RootRepos[configsync.RootSyncName].AddSafetyClusterRole()) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Reset the acme directory")) + nt.Must(rootSyncGitRepo.AddSafetyClusterRole()) + nt.Must(rootSyncGitRepo.CommitAndPush("Reset the acme directory")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -98,10 +99,10 @@ func TestConstraintTemplateAndConstraintInSameCommit(t *testing.T) { } // Cleanup before deleting the ConstraintTemplate and Constraint CRDs to avoid resource conflict errors from the webhook. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster")) // Add back the safety ClusterRole to pass the safety check (KNV2006). - nt.Must(nt.RootRepos[configsync.RootSyncName].AddSafetyClusterRole()) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Reset the acme directory")) + nt.Must(rootSyncGitRepo.AddSafetyClusterRole()) + nt.Must(rootSyncGitRepo.CommitAndPush("Reset the acme directory")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/gcenode_test.go b/e2e/testcases/gcenode_test.go index c82157b23c..04ba9dcbf6 100644 --- a/e2e/testcases/gcenode_test.go +++ b/e2e/testcases/gcenode_test.go @@ -56,14 +56,18 @@ func TestGCENodeCSR(t *testing.T) { ntopts.NamespaceRepo(testNs, configsync.RepoSyncName), ntopts.RepoSyncPermissions(policy.AllAdmin()), // NS reconciler manages a bunch of resources. ntopts.WithDelegatedControl) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, testNs) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) if err := workloadidentity.ValidateDisabled(nt); err != nil { nt.T.Fatal(err) } nt.T.Log("Add the kustomize-components root directory to RootSync's repo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/kustomize-components", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/kustomize-components", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) rootSync := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) nt.MustMergePatch(rootSync, `{ "spec": { @@ -75,9 +79,8 @@ func TestGCENodeCSR(t *testing.T) { nt.T.Log("Add the namespace-repo directory to RepoSync's repo") repoSync := k8sobjects.RepoSyncObjectV1Beta1(testNs, configsync.RepoSyncName) - repoSyncRef := nomostest.RepoSyncNN(testNs, configsync.RepoSyncName) - nt.Must(nt.NonRootRepos[repoSyncRef].Copy("../testdata/hydration/namespace-repo", ".")) - nt.Must(nt.NonRootRepos[repoSyncRef].CommitAndPush("add DRY configs to the repository")) + nt.Must(repoSyncGitRepo.Copy("../testdata/hydration/namespace-repo", ".")) + nt.Must(repoSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.MustMergePatch(repoSync, `{ "spec": { "git": { @@ -89,7 +92,7 @@ func TestGCENodeCSR(t *testing.T) { err := nt.WatchForAllSyncs( nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{ nomostest.DefaultRootRepoNamespacedName: "kustomize-components", - repoSyncRef: "namespace-repo", + repoSyncKey: "namespace-repo", })) if err != nil { nt.T.Fatal(err) @@ -98,7 +101,7 @@ func TestGCENodeCSR(t *testing.T) { if err := testutils.ReconcilerPodMissingFWICredsAnnotation(nt, nomostest.DefaultRootReconcilerName); err != nil { nt.T.Fatal(err) } - kustomizecomponents.ValidateTenant(nt, repoSyncRef.Namespace, repoSyncRef.Namespace, "base") + kustomizecomponents.ValidateTenant(nt, repoSyncKey.Namespace, repoSyncKey.Namespace, "base") } // TestGCENodeOCI tests the `gcenode` auth type for the OCI image. diff --git a/e2e/testcases/git_sync_test.go b/e2e/testcases/git_sync_test.go index 4100ac2890..8e74c16052 100644 --- a/e2e/testcases/git_sync_test.go +++ b/e2e/testcases/git_sync_test.go @@ -27,6 +27,7 @@ import ( func TestMultipleRemoteBranchesOutOfSync(t *testing.T) { nt := nomostest.New(t, nomostesting.ACMController) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rs := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) if err := nt.KubeClient.Get(configsync.RootSyncName, configmanagement.ControllerNamespace, rs); err != nil { @@ -34,11 +35,11 @@ func TestMultipleRemoteBranchesOutOfSync(t *testing.T) { } nt.T.Log("Create an extra remote tracking branch") - nt.Must(nt.RootRepos[configsync.RootSyncName].Push("HEAD:upstream/main")) + nt.Must(rootSyncGitRepo.Push("HEAD:upstream/main")) nt.T.Logf("Update the remote main branch by adding a test namespace") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/hello/ns.yaml", k8sobjects.NamespaceObject("hello"))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add Namespace")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/hello/ns.yaml", k8sobjects.NamespaceObject("hello"))) + nt.Must(rootSyncGitRepo.CommitAndPush("add Namespace")) nt.T.Logf("Verify git-sync can pull the latest commit with the default branch and revision") // WatchForAllSyncs validates RootSync's lastSyncedCommit is updated to the @@ -51,8 +52,8 @@ func TestMultipleRemoteBranchesOutOfSync(t *testing.T) { } nt.T.Logf("Remove the test namespace to make sure git-sync can fetch newer commit") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/hello/ns.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove Namespace")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/hello/ns.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("remove Namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/helm_sync_test.go b/e2e/testcases/helm_sync_test.go index c317692c53..296901ea49 100644 --- a/e2e/testcases/helm_sync_test.go +++ b/e2e/testcases/helm_sync_test.go @@ -38,6 +38,7 @@ import ( "kpt.dev/configsync/e2e/nomostest/ntopts" "kpt.dev/configsync/e2e/nomostest/policy" "kpt.dev/configsync/e2e/nomostest/registryproviders" + "kpt.dev/configsync/e2e/nomostest/syncsource" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" "kpt.dev/configsync/e2e/nomostest/testpredicates" "kpt.dev/configsync/pkg/api/configsync" @@ -330,7 +331,7 @@ func TestHelmDefaultNamespace(t *testing.T) { nt.T.Log("Update RootSync to sync from a helm chart") // Switch from Git to Helm rs := nt.RootSyncObjectHelm(configsync.RootSyncName, chart.HelmChartID) - nt.T.Log("Manually update the RepoSync object to sync from helm") + nt.T.Log("Manually update the RootSync object to sync from helm") nt.Must(nt.KubeClient.Apply(rs)) nt.T.Log("Wait for RootSync to sync from a helm chart") @@ -356,6 +357,7 @@ func TestHelmDefaultNamespace(t *testing.T) { // // 4. The following environment variables are set: GCP_PROJECT, GCP_CLUSTER, GCP_REGION|GCP_ZONE. func TestHelmLatestVersion(t *testing.T) { + rootSyncID := nomostest.DefaultRootSyncID nt := nomostest.New(t, nomostesting.WorkloadIdentity, ntopts.Unstructured, @@ -363,7 +365,7 @@ func TestHelmLatestVersion(t *testing.T) { ) newVersion := "1.0.0" - chart, err := nt.BuildAndPushHelmPackage(nomostest.RootSyncNN(configsync.RootSyncName), + chart, err := nt.BuildAndPushHelmPackage(rootSyncID.ObjectKey, registryproviders.HelmSourceChart(privateSimpleHelmChart), registryproviders.HelmChartVersion(newVersion)) if err != nil { @@ -378,7 +380,7 @@ func TestHelmLatestVersion(t *testing.T) { nt.T.Log("Update RootSync to sync from a helm chart") nt.Must(nt.KubeClient.Apply(rs)) - nt.T.Log("Wait for RootSync to sync from a helm chart") + nt.T.Logf("Wait for RootSync to sync from helm chart: %s", chart.HelmChartID) nt.Must(nt.WatchForAllSyncs()) nt.T.Log("Validate version label of a deployment from the helm chart") @@ -387,16 +389,17 @@ func TestHelmLatestVersion(t *testing.T) { // helm-sync automatically detects and updates to the new helm chart version newVersion = "2.5.9" - chart, err = nt.BuildAndPushHelmPackage(nomostest.RootSyncNN(configsync.RootSyncName), + chart, err = nt.BuildAndPushHelmPackage(rootSyncID.ObjectKey, registryproviders.HelmSourceChart(privateSimpleHelmChart), registryproviders.HelmChartVersion(newVersion)) if err != nil { nt.T.Fatalf("failed to push helm chart: %v", err) } - nt.T.Log("Wait for RootSync to sync from a helm chart") - rsKey := client.ObjectKeyFromObject(rs) - nt.RootSyncHelmCharts[rsKey] = chart.HelmChartID + nt.T.Logf("Wait for RootSync to sync from helm chart: %s", chart.HelmChartID) + nt.SyncSources[rootSyncID] = &syncsource.HelmSyncSource{ + ChartID: chart.HelmChartID, + } nt.Must(nt.WatchForAllSyncs()) nt.T.Log("Validate version label of a deployment from the helm chart") @@ -404,15 +407,17 @@ func TestHelmLatestVersion(t *testing.T) { testpredicates.HasLabel("version", chart.Version))) newVersion = "3.0.0" - chart, err = nt.BuildAndPushHelmPackage(nomostest.RootSyncNN(configsync.RootSyncName), + chart, err = nt.BuildAndPushHelmPackage(rootSyncID.ObjectKey, registryproviders.HelmSourceChart(privateSimpleHelmChart), registryproviders.HelmChartVersion(newVersion)) if err != nil { nt.T.Fatalf("failed to push helm chart: %v", err) } - nt.T.Log("Wait for RootSync to sync from a helm chart") - nt.RootSyncHelmCharts[rsKey] = chart.HelmChartID + nt.T.Logf("Wait for RootSync to sync from helm chart: %s", chart.HelmChartID) + nt.SyncSources[rootSyncID] = &syncsource.HelmSyncSource{ + ChartID: chart.HelmChartID, + } nt.Must(nt.WatchForAllSyncs()) nt.T.Log("Validate version label of a deployment from the helm chart") @@ -432,9 +437,18 @@ func TestHelmVersionRange(t *testing.T) { nt.T.Logf("Updating RootSync to sync from public helm chart with version range") nt.Must(nt.KubeClient.Apply(rs)) - nt.T.Log("Wait for RootSync to sync from a helm chart") - rsKey := client.ObjectKeyFromObject(rs) - nt.RootSyncHelmCharts[rsKey] = registryproviders.HelmChartID{Name: rs.Spec.Helm.Chart, Version: "15.4.1"} + rootSyncID := core.ID{ + GroupKind: nomostest.DefaultRootSyncID.GroupKind, + ObjectKey: client.ObjectKeyFromObject(rs), + } + chartID := registryproviders.HelmChartID{ + Name: rs.Spec.Helm.Chart, + Version: "15.4.1", // latest minor+patch with the same major version + } + nt.T.Logf("Wait for RootSync to sync from helm chart: %s", chartID) + nt.SyncSources[rootSyncID] = &syncsource.HelmSyncSource{ + ChartID: chartID, + } nt.Must(nt.WatchForAllSyncs()) nt.T.Log("Validate Deployment from chart exists") @@ -450,6 +464,7 @@ func TestHelmNamespaceRepo(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource, ntopts.RequireHelmProvider, ntopts.RepoSyncPermissions(policy.AllAdmin()), // NS reconciler manages a bunch of resources. ntopts.NamespaceRepo(repoSyncNN.Namespace, repoSyncNN.Name)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Build a Helm chart with cluster-scoped resources") chart, err := nt.BuildAndPushHelmPackage(repoSyncNN, @@ -460,8 +475,8 @@ func TestHelmNamespaceRepo(t *testing.T) { nt.T.Log("Update RepoSync to sync from helm repo, should fail due to cluster-scope resource") rs := nt.RepoSyncObjectHelm(repoSyncNN, chart.HelmChartID) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update RepoSync to sync from a Helm Chart with cluster-scoped resources")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name), rs)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update RepoSync to sync from a Helm Chart with cluster-scoped resources")) nt.WaitForRepoSyncSourceError(repoSyncNN.Namespace, repoSyncNN.Name, nonhierarchical.BadScopeErrCode, "must be Namespace-scoped type") nt.T.Log("Update the helm chart with only a namespace-scope resource") @@ -472,8 +487,8 @@ func TestHelmNamespaceRepo(t *testing.T) { nt.T.Fatalf("failed to push helm chart: %v", err) } rs = nt.RepoSyncObjectHelm(repoSyncNN, validChart.HelmChartID) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update RepoSync to sync from a Helm Chart with namespace-scoped resources")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name), rs)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update RepoSync to sync from a Helm Chart with namespace-scoped resources")) nt.T.Log("Wait for RepoSync to sync from a helm chart") nt.Must(nt.WatchForAllSyncs()) @@ -492,6 +507,7 @@ func TestHelmConfigMapNamespaceRepo(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource, ntopts.RequireHelmProvider, ntopts.RepoSyncPermissions(policy.AppsAdmin(), policy.CoreAdmin()), ntopts.NamespaceRepo(repoSyncNN.Namespace, repoSyncNN.Name)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) cmName := "helm-cm-ns-repo-1" chart, err := nt.BuildAndPushHelmPackage(repoSyncNN, @@ -504,8 +520,8 @@ func TestHelmConfigMapNamespaceRepo(t *testing.T) { rs := nt.RepoSyncObjectHelm(repoSyncNN, chart.HelmChartID) rs.Spec.Helm.ReleaseName = "test" rs.Spec.Helm.ValuesFileRefs = []v1beta1.ValuesFileRef{{Name: cmName, DataKey: "foo.yaml"}} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update RepoSync to sync from a Helm Chart without cluster scoped resources")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name), rs)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update RepoSync to sync from a Helm Chart without cluster scoped resources")) nt.WaitForRepoSyncStalledError(rs.Namespace, rs.Name, "Validation", "KNV1061: RepoSyncs must reference valid ConfigMaps in spec.helm.valuesFileRefs: ConfigMap \"helm-cm-ns-repo-1\" not found") nt.T.Log("Create a ConfigMap that is not immutable (which should not be allowed)") @@ -557,8 +573,8 @@ func TestHelmConfigMapNamespaceRepo(t *testing.T) { nt.T.Log("Update ValuesFileRefs to reference new ConfigMap`") rs.Spec.Helm.ValuesFileRefs = []v1beta1.ValuesFileRef{{Name: cmName2, DataKey: "foo.yaml"}} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update RepoSync to reference new ConfigMap")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name), rs)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update RepoSync to reference new ConfigMap")) nt.T.Log("Wait for RepoSync to sync from a helm chart") nt.Must(nt.WatchForAllSyncs()) diff --git a/e2e/testcases/hydration_test.go b/e2e/testcases/hydration_test.go index 0d9c4c39c4..e8fa388076 100644 --- a/e2e/testcases/hydration_test.go +++ b/e2e/testcases/hydration_test.go @@ -46,6 +46,7 @@ func TestHydrateKustomizeComponents(t *testing.T) { nomostesting.Hydration, ntopts.Unstructured, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncDirMap := map[types.NamespacedName]string{ nomostest.DefaultRootRepoNamespacedName: "kustomize-components", @@ -73,8 +74,8 @@ func TestHydrateKustomizeComponents(t *testing.T) { nt.Must(tg.Wait()) nt.T.Log("Add the kustomize components root directory") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/kustomize-components", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/kustomize-components", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the kustomize-components directory") rs := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) @@ -103,16 +104,16 @@ func TestHydrateKustomizeComponents(t *testing.T) { nt.Must(tg.Wait()) // Validate nomos status - latestCommit := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + latestCommit := rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Validate(configsync.RootSyncName, configsync.ControllerNamespace, &v1beta1.RootSync{}, testpredicates.RootSyncHasNomosStatus(latestCommit, "SYNCED"))) kustomizecomponents.ValidateAllTenants(nt, string(declared.RootScope), "base", "tenant-a", "tenant-b", "tenant-c") nt.T.Log("Remove kustomization.yaml to make the sync fail") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("./kustomize-components/kustomization.yml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove the Kustomize configuration to make the sync fail")) - latestCommit = nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + nt.Must(rootSyncGitRepo.Remove("./kustomize-components/kustomization.yml")) + nt.Must(rootSyncGitRepo.CommitAndPush("remove the Kustomize configuration to make the sync fail")) + latestCommit = rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, []testpredicates.Predicate{ testpredicates.RootSyncHasRenderingError(status.ActionableHydrationErrorCode, "Kustomization config file is missing from the sync directory"), @@ -120,20 +121,20 @@ func TestHydrateKustomizeComponents(t *testing.T) { })) nt.T.Log("Add kustomization.yaml back") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/kustomize-components/kustomization.yml", "./kustomize-components/kustomization.yml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add kustomization.yml back")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/kustomize-components/kustomization.yml", "./kustomize-components/kustomization.yml")) + nt.Must(rootSyncGitRepo.CommitAndPush("add kustomization.yml back")) nt.Must(nt.WatchForAllSyncs(nomostest.WithSyncDirectoryMap(syncDirMap))) // Validate nomos status - latestCommit = nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + latestCommit = rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Validate(configsync.RootSyncName, configsync.ControllerNamespace, &v1beta1.RootSync{}, testpredicates.RootSyncHasNomosStatus(latestCommit, "SYNCED"))) nt.T.Log("Make kustomization.yaml invalid") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/invalid-kustomization.yaml", "./kustomize-components/kustomization.yml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("update kustomization.yaml to make it invalid")) - latestCommit = nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/invalid-kustomization.yaml", "./kustomize-components/kustomization.yml")) + nt.Must(rootSyncGitRepo.CommitAndPush("update kustomization.yaml to make it invalid")) + latestCommit = rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, []testpredicates.Predicate{ testpredicates.RootSyncHasRenderingError(status.ActionableHydrationErrorCode, "failed to run kustomize build"), @@ -142,9 +143,9 @@ func TestHydrateKustomizeComponents(t *testing.T) { // one final validation to ensure hydration-controller can be re-disabled nt.T.Log("Remove all dry configs") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("./kustomize-components")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/compiled/kustomize-components", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Replace dry configs with wet configs")) + nt.Must(rootSyncGitRepo.Remove("./kustomize-components")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/compiled/kustomize-components", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("Replace dry configs with wet configs")) nt.Must(nt.WatchForAllSyncs(nomostest.WithSyncDirectoryMap(syncDirMap))) nt.T.Log("Verify the hydration-controller is omitted after dry configs were removed") @@ -175,14 +176,15 @@ func TestHydrateExternalFiles(t *testing.T) { nomostesting.Hydration, ntopts.Unstructured, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncDirMap := map[types.NamespacedName]string{ nomostest.DefaultRootRepoNamespacedName: "external-files", } nt.T.Log("Add the external files root directory") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/external-files", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/external-files", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the external-files directory") rs := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) @@ -206,10 +208,11 @@ func TestHydrateHelmComponents(t *testing.T) { nomostesting.Hydration, ntopts.Unstructured, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add the helm components root directory") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/helm-components", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/helm-components", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the helm-components directory") rs := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) @@ -223,7 +226,7 @@ func TestHydrateHelmComponents(t *testing.T) { nt.Must(nt.WatchForAllSyncs(nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "helm-components"}))) // Validate nomos status - latestCommit := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + latestCommit := rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Validate(configsync.RootSyncName, configsync.ControllerNamespace, &v1beta1.RootSync{}, testpredicates.RootSyncHasNomosStatus(latestCommit, "SYNCED"))) @@ -245,8 +248,8 @@ func TestHydrateHelmComponents(t *testing.T) { nt.Must(tg.Wait()) nt.T.Log("Use a remote values.yaml file from a public repo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/helm-components-remote-values-kustomization.yaml", "./helm-components/kustomization.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Render with a remote values.yaml file from a public repo")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/helm-components-remote-values-kustomization.yaml", "./helm-components/kustomization.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Render with a remote values.yaml file from a public repo")) nt.Must(nt.WatchForAllSyncs(nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "helm-components"}))) @@ -256,7 +259,7 @@ func TestHydrateHelmComponents(t *testing.T) { testpredicates.HasAnnotation(metadata.KustomizeOrigin, expectedBuiltinOrigin))) // Validate nomos status - latestCommit = nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + latestCommit = rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Validate(configsync.RootSyncName, configsync.ControllerNamespace, &v1beta1.RootSync{}, testpredicates.RootSyncHasNomosStatus(latestCommit, "SYNCED"))) } @@ -266,10 +269,11 @@ func TestHydrateHelmOverlay(t *testing.T) { nomostesting.Hydration, ntopts.Unstructured, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add the helm-overlay root directory") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/helm-overlay", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/helm-overlay", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the helm-overlay directory") rs := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) @@ -292,15 +296,15 @@ func TestHydrateHelmOverlay(t *testing.T) { testpredicates.DeploymentContainerPullPolicyEquals("coredns", "Always"))) // Validate nomos status - latestCommit := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + latestCommit := rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Validate(configsync.RootSyncName, configsync.ControllerNamespace, &v1beta1.RootSync{}, testpredicates.RootSyncHasNomosStatus(latestCommit, "SYNCED"))) nt.T.Log("Make the hydration fail by checking in an invalid kustomization.yaml") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/resource-duplicate/kustomization.yaml", "./helm-overlay/kustomization.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/resource-duplicate/namespace_tenant-a.yaml", "./helm-overlay/namespace_tenant-a.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update kustomization.yaml with duplicated resources")) - latestCommit = nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/resource-duplicate/kustomization.yaml", "./helm-overlay/kustomization.yaml")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/resource-duplicate/namespace_tenant-a.yaml", "./helm-overlay/namespace_tenant-a.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Update kustomization.yaml with duplicated resources")) + latestCommit = rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, []testpredicates.Predicate{ testpredicates.RootSyncHasRenderingError(status.ActionableHydrationErrorCode, "failed to run kustomize build"), @@ -308,9 +312,9 @@ func TestHydrateHelmOverlay(t *testing.T) { })) nt.T.Log("Make the parsing fail by checking in a deprecated group and kind") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/deprecated-GK/kustomization.yaml", "./helm-overlay/kustomization.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update kustomization.yaml to render a deprecated group and kind")) - latestCommit = nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/deprecated-GK/kustomization.yaml", "./helm-overlay/kustomization.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Update kustomization.yaml to render a deprecated group and kind")) + latestCommit = rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, []testpredicates.Predicate{ testpredicates.RootSyncHasSourceError(nonhierarchical.DeprecatedGroupKindErrorCode, "The config is using a deprecated Group and Kind"), @@ -323,10 +327,11 @@ func TestHydrateRemoteResources(t *testing.T) { nomostesting.Hydration, ntopts.Unstructured, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add the remote-base root directory") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/remote-base", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/remote-base", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the remote-base directory without enable shell in hydration controller") rs := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) nt.MustMergePatch(rs, `{"spec": {"git": {"dir": "remote-base"}}}`) @@ -353,8 +358,8 @@ func TestHydrateRemoteResources(t *testing.T) { kustomizecomponents.ValidateNamespaces(nt, expectedNamespaces, expectedOrigin) nt.T.Log("Update kustomization.yaml to use a remote overlay") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/remote-overlay-kustomization.yaml", "./remote-base/kustomization.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update kustomization.yaml to use a remote overlay")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/remote-overlay-kustomization.yaml", "./remote-base/kustomization.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Update kustomization.yaml to use a remote overlay")) nt.Must(nt.WatchForAllSyncs(nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "remote-base"}))) @@ -363,8 +368,8 @@ func TestHydrateRemoteResources(t *testing.T) { kustomizecomponents.ValidateNamespaces(nt, expectedNamespaces, expectedOrigin) // Update kustomization.yaml to use remote resources - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/remote-resources-kustomization.yaml", "./remote-base/kustomization.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update kustomization.yaml to use remote resources")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/remote-resources-kustomization.yaml", "./remote-base/kustomization.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Update kustomization.yaml to use remote resources")) nt.Must(nt.WatchForAllSyncs(nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "remote-base"}))) nt.T.Log("Validate resources are synced") @@ -372,14 +377,14 @@ func TestHydrateRemoteResources(t *testing.T) { expectedOrigin = "path: notCloned/base/namespace.yaml\nrepo: https://github.com/config-sync-examples/kustomize-components\nref: main\n" kustomizecomponents.ValidateNamespaces(nt, expectedNamespaces, expectedOrigin) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("./remote-base")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove remote-base repository")) + nt.Must(rootSyncGitRepo.Remove("./remote-base")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove remote-base repository")) nt.T.Log("Disable shell in hydration controller") nt.MustMergePatch(rs, `{"spec": {"override": {"enableShellInRendering": false}, "git": {"dir": "acme"}}}`) nt.Must(nt.WatchForAllSyncs()) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/remote-base", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/remote-base", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the remote-base directory when disable shell in hydration controller") nt.MustMergePatch(rs, `{"spec": {"git": {"dir": "remote-base"}}}`) nt.Must(nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, @@ -395,10 +400,11 @@ func TestHydrateResourcesInRelativePath(t *testing.T) { nomostesting.Hydration, ntopts.Unstructured, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Log("Add the root directory") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/relative-path", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/relative-path", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the relative-path directory") rs := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) @@ -407,7 +413,7 @@ func TestHydrateResourcesInRelativePath(t *testing.T) { nt.Must(nt.WatchForAllSyncs(nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "relative-path/overlays/dev"}))) // Validate nomos status - latestCommit := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + latestCommit := rootSyncGitRepo.MustHash(nt.T) nt.Must(nt.Validate(configsync.RootSyncName, configsync.ControllerNamespace, &v1beta1.RootSync{}, testpredicates.RootSyncHasNomosStatus(latestCommit, "SYNCED"))) diff --git a/e2e/testcases/invalid_auth_test.go b/e2e/testcases/invalid_auth_test.go index 9d4e44fe3e..0ac57cff08 100644 --- a/e2e/testcases/invalid_auth_test.go +++ b/e2e/testcases/invalid_auth_test.go @@ -55,7 +55,9 @@ func TestInvalidAuth(t *testing.T) { if err != nil { nt.T.Fatal(err) } - commitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + // TODO: Fix commit to be UNKNOWN (b/361182373) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + commitHash := rootSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerErrorMetrics(nt, rootSyncLabels, commitHash, metrics.ErrorSummary{ diff --git a/e2e/testcases/invalid_git_branch_test.go b/e2e/testcases/invalid_git_branch_test.go index 9393174835..ed43769b3f 100644 --- a/e2e/testcases/invalid_git_branch_test.go +++ b/e2e/testcases/invalid_git_branch_test.go @@ -30,6 +30,7 @@ import ( func TestInvalidRootSyncBranchStatus(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Update RootSync to invalid branch name nomostest.SetGitBranch(nt, configsync.RootSyncName, "invalid-branch") @@ -41,7 +42,7 @@ func TestInvalidRootSyncBranchStatus(t *testing.T) { if err != nil { nt.T.Fatal(err) } - commitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + commitHash := rootSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerErrorMetrics(nt, rootSyncLabels, commitHash, metrics.ErrorSummary{ @@ -65,11 +66,15 @@ func TestInvalidRootSyncBranchStatus(t *testing.T) { func TestInvalidRepoSyncBranchStatus(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource, ntopts.NamespaceRepo(namespaceRepo, configsync.RepoSyncName)) - repoSyncNN := nomostest.RepoSyncNN(namespaceRepo, configsync.RepoSyncName) - repoSync := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, repoSyncNN) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, namespaceRepo) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + + repoSync := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, repoSyncKey) repoSync.Spec.Branch = "invalid-branch" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(namespaceRepo, repoSync.Name), repoSync)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update RepoSync to invalid branch name")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(namespaceRepo, repoSync.Name), repoSync)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update RepoSync to invalid branch name")) nt.WaitForRepoSyncSourceError(namespaceRepo, configsync.RepoSyncName, status.SourceErrorCode, "") @@ -81,11 +86,12 @@ func TestInvalidRepoSyncBranchStatus(t *testing.T) { nt.T.Fatal(err) } - repoSyncLabels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncNN) + repoSyncLabels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncKey) if err != nil { nt.T.Fatal(err) } - commitHash := nt.NonRootRepos[repoSyncNN].MustHash(nt.T) + // TODO: Fix commit to be UNKNOWN (b/361182373) + commitHash := repoSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, // Source error prevents apply, so don't wait for a sync with the current commit. @@ -97,11 +103,11 @@ func TestInvalidRepoSyncBranchStatus(t *testing.T) { } repoSync.Spec.Branch = gitproviders.MainBranch - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(namespaceRepo, repoSync.Name), repoSync)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update RepoSync to valid branch name")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(namespaceRepo, repoSync.Name), repoSync)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update RepoSync to valid branch name")) // Ensure RepoSync's active branch is checked out, so the correct commit is used for validation. - nt.Must(nt.NonRootRepos[repoSyncNN].CheckoutBranch(gitproviders.MainBranch)) + nt.Must(repoSyncGitRepo.CheckoutBranch(gitproviders.MainBranch)) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -116,7 +122,7 @@ func TestInvalidRepoSyncBranchStatus(t *testing.T) { } err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN, + Sync: repoSyncKey, ObjectCount: 0, // no additional managed objects }) if err != nil { @@ -126,9 +132,10 @@ func TestInvalidRepoSyncBranchStatus(t *testing.T) { func TestSyncFailureAfterSuccessfulSyncs(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Cleanup(func() { nt.T.Log("Resetting all RootSync branches to main") - nt.Must(nt.RootRepos[configsync.RootSyncName].CheckoutBranch(gitproviders.MainBranch)) + nt.Must(rootSyncGitRepo.CheckoutBranch(gitproviders.MainBranch)) nomostest.SetGitBranch(nt, configsync.RootSyncName, gitproviders.MainBranch) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -140,12 +147,12 @@ func TestSyncFailureAfterSuccessfulSyncs(t *testing.T) { // The test will delete the branch later, but the main branch can't be deleted // on some Git providers (e.g. Bitbucket), so using a develop branch. devBranch := "develop" - nt.Must(nt.RootRepos[configsync.RootSyncName].CreateBranch(devBranch)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CheckoutBranch(devBranch)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.CreateBranch(devBranch)) + nt.Must(rootSyncGitRepo.CheckoutBranch(devBranch)) + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s/ns.yaml", auditNS), k8sobjects.NamespaceObject(auditNS))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPushBranch("add namespace to acme directory", devBranch)) + nt.Must(rootSyncGitRepo.CommitAndPushBranch("add namespace to acme directory", devBranch)) // Update RootSync to sync from the dev branch nomostest.SetGitBranch(nt, configsync.RootSyncName, devBranch) @@ -160,11 +167,11 @@ func TestSyncFailureAfterSuccessfulSyncs(t *testing.T) { } // Make the sync fail by invalidating the source repo. - nt.Must(nt.RootRepos[configsync.RootSyncName].RenameBranch(devBranch, "invalid-branch")) + nt.Must(rootSyncGitRepo.RenameBranch(devBranch, "invalid-branch")) nt.WaitForRootSyncSourceError(configsync.RootSyncName, status.SourceErrorCode, "") // Change the remote branch name back to the original name. - nt.Must(nt.RootRepos[configsync.RootSyncName].RenameBranch("invalid-branch", devBranch)) + nt.Must(rootSyncGitRepo.RenameBranch("invalid-branch", devBranch)) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/kptfile_test.go b/e2e/testcases/kptfile_test.go index 5d198d1e24..9c5985847a 100644 --- a/e2e/testcases/kptfile_test.go +++ b/e2e/testcases/kptfile_test.go @@ -26,14 +26,15 @@ import ( func TestIgnoreKptfiles(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Add multiple Kptfiles - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/Kptfile", []byte("random content"))) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/namespaces/foo/Kptfile", nil)) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/namespaces/foo/subdir/Kptfile", []byte("# some comment"))) + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/Kptfile", []byte("random content"))) + nt.Must(rootSyncGitRepo.AddFile("acme/namespaces/foo/Kptfile", nil)) + nt.Must(rootSyncGitRepo.AddFile("acme/namespaces/foo/subdir/Kptfile", []byte("# some comment"))) nsObj := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding multiple Kptfiles")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding multiple Kptfiles")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/lifecycle_directives_test.go b/e2e/testcases/lifecycle_directives_test.go index ca617cc093..ea25b91f71 100644 --- a/e2e/testcases/lifecycle_directives_test.go +++ b/e2e/testcases/lifecycle_directives_test.go @@ -39,6 +39,7 @@ var preventDeletion = core.Annotation(common.LifecycleDeleteAnnotation, common.P func TestPreventDeletionNamespace(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Lifecycle) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Ensure the Namespace doesn't already exist. err := nt.ValidateNotFound("shipping", "", &corev1.Namespace{}) @@ -55,9 +56,9 @@ func TestPreventDeletionNamespace(t *testing.T) { // Declare the Namespace with the lifecycle annotation, and ensure it is created. nsObj := k8sobjects.NamespaceObject("shipping", preventDeletion) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/shipping/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/shipping/role.yaml", role)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("declare Namespace with prevent deletion lifecycle annotation")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/shipping/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/shipping/role.yaml", role)) + nt.Must(rootSyncGitRepo.CommitAndPush("declare Namespace with prevent deletion lifecycle annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -81,9 +82,9 @@ func TestPreventDeletionNamespace(t *testing.T) { } // Delete the declaration and ensure the Namespace isn't deleted. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/shipping/ns.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/shipping/role.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove Namespace shipping declaration")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/shipping/ns.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/shipping/role.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("remove Namespace shipping declaration")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -114,8 +115,8 @@ func TestPreventDeletionNamespace(t *testing.T) { // Remove the lifecycle annotation from the namespace so that the namespace can be deleted after the test case. nsObj = k8sobjects.NamespaceObject("shipping") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/shipping/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove the lifecycle annotation from Namespace")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/shipping/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("remove the lifecycle annotation from Namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -134,6 +135,7 @@ func TestPreventDeletionNamespace(t *testing.T) { func TestPreventDeletionRole(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Lifecycle) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Ensure the Namespace doesn't already exist. err := nt.ValidateNotFound("shipping-admin", "shipping", &rbacv1.Role{}) @@ -149,9 +151,9 @@ func TestPreventDeletionRole(t *testing.T) { Verbs: []string{"get"}, }} nsObj := k8sobjects.NamespaceObject("shipping") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/shipping/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/shipping/role.yaml", role)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("declare Role with prevent deletion lifecycle annotation")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/shipping/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/shipping/role.yaml", role)) + nt.Must(rootSyncGitRepo.CommitAndPush("declare Role with prevent deletion lifecycle annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -177,8 +179,8 @@ func TestPreventDeletionRole(t *testing.T) { } // Delete the declaration and ensure the Namespace isn't deleted. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/shipping/role.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove Role declaration")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/shipping/role.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("remove Role declaration")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -208,8 +210,8 @@ func TestPreventDeletionRole(t *testing.T) { // Remove the lifecycle annotation from the role so that the role can be deleted after the test case. delete(role.Annotations, common.LifecycleDeleteAnnotation) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/shipping/role.yaml", role)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove the lifecycle annotation from Role")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/shipping/role.yaml", role)) + nt.Must(rootSyncGitRepo.CommitAndPush("remove the lifecycle annotation from Role")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -236,6 +238,7 @@ func TestPreventDeletionRole(t *testing.T) { func TestPreventDeletionClusterRole(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Lifecycle) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Ensure the ClusterRole doesn't already exist. err := nt.ValidateNotFound("test-admin", "", &rbacv1.ClusterRole{}) @@ -250,8 +253,8 @@ func TestPreventDeletionClusterRole(t *testing.T) { Resources: []string{"configmaps"}, Verbs: []string{"get"}, }} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/cr.yaml", clusterRole)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("declare ClusterRole with prevent deletion lifecycle annotation")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/cr.yaml", clusterRole)) + nt.Must(rootSyncGitRepo.CommitAndPush("declare ClusterRole with prevent deletion lifecycle annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -265,8 +268,8 @@ func TestPreventDeletionClusterRole(t *testing.T) { } // Delete the declaration and ensure the ClusterRole isn't deleted. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cluster/cr.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove ClusterRole bar declaration")) + nt.Must(rootSyncGitRepo.Remove("acme/cluster/cr.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("remove ClusterRole bar declaration")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -281,8 +284,8 @@ func TestPreventDeletionClusterRole(t *testing.T) { // Remove the lifecycle annotation from the cluster-role so that it can be deleted after the test case. delete(clusterRole.Annotations, common.LifecycleDeleteAnnotation) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/cr.yaml", clusterRole)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove the lifecycle annotation from ClusterRole")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/cr.yaml", clusterRole)) + nt.Must(rootSyncGitRepo.CommitAndPush("remove the lifecycle annotation from ClusterRole")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -313,6 +316,7 @@ func skipAutopilotManagedNamespace(nt *nomostest.NT, ns string) bool { func TestPreventDeletionSpecialNamespaces(t *testing.T) { nt := nomostest.New(t, nomostesting.Lifecycle, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Build list of special namespaces to test. // Skip namespaces managed by GKE Autopilot, if on an Autopilot cluster @@ -325,11 +329,11 @@ func TestPreventDeletionSpecialNamespaces(t *testing.T) { for ns := range specialNamespaces { checkpointProtectedNamespace(nt, ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/ns-%s.yaml", ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/ns-%s.yaml", ns), k8sobjects.NamespaceObject(ns))) } bookstoreNS := k8sobjects.NamespaceObject("bookstore") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns-bookstore.yaml", bookstoreNS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add special namespaces and one non-special namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns-bookstore.yaml", bookstoreNS)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add special namespaces and one non-special namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -354,10 +358,10 @@ func TestPreventDeletionSpecialNamespaces(t *testing.T) { } for ns := range specialNamespaces { - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(fmt.Sprintf("acme/ns-%s.yaml", ns))) + nt.Must(rootSyncGitRepo.Remove(fmt.Sprintf("acme/ns-%s.yaml", ns))) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/ns-bookstore.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove namespaces")) + nt.Must(rootSyncGitRepo.Remove("acme/ns-bookstore.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove namespaces")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/local_config_test.go b/e2e/testcases/local_config_test.go index 8ca53f017e..095accf89c 100644 --- a/e2e/testcases/local_config_test.go +++ b/e2e/testcases/local_config_test.go @@ -20,7 +20,6 @@ import ( corev1 "k8s.io/api/core/v1" "kpt.dev/configsync/e2e/nomostest" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" - "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/core" "kpt.dev/configsync/pkg/core/k8sobjects" "kpt.dev/configsync/pkg/metadata" @@ -31,17 +30,18 @@ var LocalConfigValue = "true" func TestLocalConfig(t *testing.T) { nt := nomostest.New(t, nomostesting.Lifecycle) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) ns := "local-config" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( "acme/namespaces/local-config/ns.yaml", k8sobjects.NamespaceObject(ns))) cmName := "e2e-test-configmap" cmPath := "acme/namespaces/local-config/configmap.yaml" cm := k8sobjects.ConfigMapObject(core.Name(cmName), core.Annotation(metadata.LocalConfigAnnotationKey, LocalConfigValue)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding ConfigMap as local config")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding ConfigMap as local config")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -54,8 +54,8 @@ func TestLocalConfig(t *testing.T) { // Remove the local-config annotation cm = k8sobjects.ConfigMapObject(core.Name(cmName)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding ConfigMap without local-config annotation")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding ConfigMap without local-config annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -69,8 +69,8 @@ func TestLocalConfig(t *testing.T) { // Add the local-config annotation again. // This will make the object pruned. cm = k8sobjects.ConfigMapObject(core.Name(cmName), core.Annotation(metadata.LocalConfigAnnotationKey, LocalConfigValue)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Changing ConfigMap to local config")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Changing ConfigMap to local config")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -84,17 +84,18 @@ func TestLocalConfig(t *testing.T) { func TestLocalConfigWithManagementDisabled(t *testing.T) { nt := nomostest.New(t, nomostesting.Lifecycle) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) ns := "local-config" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( "acme/namespaces/local-config/ns.yaml", k8sobjects.NamespaceObject(ns))) cmName := "e2e-test-configmap" cmPath := "acme/namespaces/local-config/configmap.yaml" cm := k8sobjects.ConfigMapObject(core.Name(cmName)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding ConfigMap")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding ConfigMap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -107,8 +108,8 @@ func TestLocalConfigWithManagementDisabled(t *testing.T) { // Add the management disabled annotation. cm = k8sobjects.ConfigMapObject(core.Name(cmName), syncertest.ManagementDisabled) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Disable the management of ConfigMap")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Disable the management of ConfigMap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -122,8 +123,8 @@ func TestLocalConfigWithManagementDisabled(t *testing.T) { // Add the local-config annotation to the unmanaged configmap cm = k8sobjects.ConfigMapObject(core.Name(cmName), syncertest.ManagementDisabled, core.Annotation(metadata.LocalConfigAnnotationKey, LocalConfigValue)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Change the ConfigMap to local config")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Change the ConfigMap to local config")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -136,8 +137,8 @@ func TestLocalConfigWithManagementDisabled(t *testing.T) { // Remove the management disabled annotation cm = k8sobjects.ConfigMapObject(core.Name(cmName), core.Annotation(metadata.LocalConfigAnnotationKey, LocalConfigValue)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the managed disabled annotation and keep the local-config annotation")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the managed disabled annotation and keep the local-config annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/managed_resources_test.go b/e2e/testcases/managed_resources_test.go index 414acd20eb..93fddaaafc 100644 --- a/e2e/testcases/managed_resources_test.go +++ b/e2e/testcases/managed_resources_test.go @@ -55,6 +55,7 @@ import ( // cluster-scoped changes are made with kubectl. func TestDriftKubectlApplyClusterScoped(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSync2Name := "abcdef" rootSync1ApplySetID := applyset.IDFromSync(configsync.RootSyncName, declared.RootScope) @@ -63,8 +64,8 @@ func TestDriftKubectlApplyClusterScoped(t *testing.T) { rootSync2Manager := declared.ResourceManager(declared.RootScope, rootSync2Name) namespace := k8sobjects.NamespaceObject("bookstore") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) nt.Must(nt.WatchForAllSyncs()) /* A new test */ @@ -244,6 +245,7 @@ func TestDriftKubectlApplyClusterScoped(t *testing.T) { // namespace-scoped changes are made with kubectl. func TestDriftKubectlApplyNamespaceScoped(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSync2Name := "abcdef" rootSync1ApplySetID := applyset.IDFromSync(configsync.RootSyncName, declared.RootScope) @@ -252,14 +254,14 @@ func TestDriftKubectlApplyNamespaceScoped(t *testing.T) { rootSync2Manager := declared.ResourceManager(declared.RootScope, rootSync2Name) namespace := k8sobjects.NamespaceObject("bookstore") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm.yaml", k8sobjects.ConfigMapObject(core.Name("cm-1"), core.Namespace("bookstore")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a configmap")) + nt.Must(rootSyncGitRepo.Add("acme/cm.yaml", k8sobjects.ConfigMapObject(core.Name("cm-1"), core.Namespace("bookstore")))) + nt.Must(rootSyncGitRepo.CommitAndPush("add a configmap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -492,16 +494,17 @@ func TestDriftKubectlApplyNamespaceScoped(t *testing.T) { // that Config Sync recreates the deleted object. func TestDriftKubectlDelete(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm.yaml", k8sobjects.ConfigMapObject(core.Name("cm-1"), core.Namespace("bookstore")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a configmap")) + nt.Must(rootSyncGitRepo.Add("acme/cm.yaml", k8sobjects.ConfigMapObject(core.Name("cm-1"), core.Namespace("bookstore")))) + nt.Must(rootSyncGitRepo.CommitAndPush("add a configmap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -552,16 +555,17 @@ func TestDriftKubectlDelete(t *testing.T) { // annotation, and verifies that Config Sync recreates the deleted object. func TestDriftKubectlDeleteWithIgnoreMutationAnnotation(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore", core.Annotation(metadata.LifecycleMutationAnnotation, metadata.IgnoreMutation)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm.yaml", k8sobjects.ConfigMapObject(core.Name("cm-1"), core.Namespace("bookstore")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a configmap")) + nt.Must(rootSyncGitRepo.Add("acme/cm.yaml", k8sobjects.ConfigMapObject(core.Name("cm-1"), core.Namespace("bookstore")))) + nt.Must(rootSyncGitRepo.CommitAndPush("add a configmap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -612,10 +616,11 @@ func TestDriftKubectlDeleteWithIgnoreMutationAnnotation(t *testing.T) { // does not remove this field. func TestDriftKubectlAnnotateUnmanagedField(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -672,10 +677,11 @@ func TestDriftKubectlAnnotateUnmanagedField(t *testing.T) { // Config Sync does not remove this field. func TestDriftKubectlAnnotateUnmanagedFieldWithIgnoreMutationAnnotation(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore", core.Annotation(metadata.LifecycleMutationAnnotation, metadata.IgnoreMutation)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -701,10 +707,11 @@ func TestDriftKubectlAnnotateUnmanagedFieldWithIgnoreMutationAnnotation(t *testi // that Config Sync corrects it. func TestDriftKubectlAnnotateManagedField(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore", core.Annotation("season", "summer")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -763,12 +770,13 @@ func TestDriftKubectlAnnotateManagedField(t *testing.T) { // Config Sync does not correct it. func TestDriftKubectlAnnotateManagedFieldWithIgnoreMutationAnnotation(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore", core.Annotation("season", "summer"), core.Annotation(metadata.LifecycleMutationAnnotation, metadata.IgnoreMutation)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -810,10 +818,11 @@ func TestDriftKubectlAnnotateManagedFieldWithIgnoreMutationAnnotation(t *testing // verifies that Config Sync corrects it. func TestDriftKubectlAnnotateDeleteManagedFields(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore", core.Annotation("season", "summer")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -872,12 +881,13 @@ func TestDriftKubectlAnnotateDeleteManagedFields(t *testing.T) { // Config Sync does not correct it. func TestDriftKubectlAnnotateDeleteManagedFieldsWithIgnoreMutationAnnotation(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespace := k8sobjects.NamespaceObject("bookstore", core.Annotation("season", "summer"), core.Annotation(metadata.LifecycleMutationAnnotation, metadata.IgnoreMutation)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -920,6 +930,7 @@ func TestDriftKubectlAnnotateDeleteManagedFieldsWithIgnoreMutationAnnotation(t * // Config Sync re-adds it. func TestDriftRemoveApplySetPartOfLabel(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSync1ApplySetID := applyset.IDFromSync(configsync.RootSyncName, declared.RootScope) @@ -932,8 +943,8 @@ func TestDriftRemoveApplySetPartOfLabel(t *testing.T) { nsObj := k8sobjects.NamespaceObject(namespace, core.Annotation("season", "summer")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("add a namespace")) nt.Must(nt.WatchForAllSyncs()) nt.T.Log("Changing the ApplySet ID label value") diff --git a/e2e/testcases/multi_sync_test.go b/e2e/testcases/multi_sync_test.go index cd9f7e015c..bfced38583 100644 --- a/e2e/testcases/multi_sync_test.go +++ b/e2e/testcases/multi_sync_test.go @@ -32,6 +32,7 @@ import ( "kpt.dev/configsync/e2e/nomostest/metrics" "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" @@ -52,35 +53,46 @@ import ( const testNs = "test-ns" // TestMultiSyncs_Unstructured_MixedControl tests multiple syncs created in the mixed control mode. -// - root-sync is created using k8s api. -// - rr1 is created using k8s api. This is to validate multiple RootSyncs can be created in the delegated mode. -// - rr2 is a v1alpha1 version of RootSync declared in the root repo of root-sync. This is to validate RootSync can be managed in a root repo and validate the v1alpha1 version API. -// - rr3 is a v1alpha1 version of RootSync declared in rs-2. This is to validate RootSync can be managed in a different root repo and validate the v1alpha1 version API. -// - nr1 is created using k8s api. This is to validate RepoSyncs can be created in the delegated mode. -// - nr2 is a v1alpha1 version of RepoSync created using k8s api. This is to validate v1alpha1 version of RepoSync can be created in the delegated mode. -// - nr3 is declared in the root repo of root-sync. This is to validate RepoSync can be managed in a root repo. -// - nr4 is a v1alpha1 version of RepoSync declared in the namespace repo of nn2. This is to validate RepoSync can be managed in a namespace repo in the same namespace. -// - nr5 is declared in the root repo of rr1. This is to validate implicit namespace won't cause conflict between two root reconcilers (rr1 and root-sync). -// - nr6 is created using k8s api in a different namespace but with the same name "nr1". +// - rootSync0 is created using k8s api. +// - rootSync1 is created using k8s api. This is to validate multiple RootSyncs can be created in the delegated mode. +// - rootSync2 is a v1alpha1 version of RootSync declared in the root repo of root-sync. This is to validate RootSync can be managed in a root repo and validate the v1alpha1 version API. +// - rootSync3 is a v1alpha1 version of RootSync declared in rs-2. This is to validate RootSync can be managed in a different root repo and validate the v1alpha1 version API. +// - repoSync1 is created using k8s api. This is to validate RepoSyncs can be created in the delegated mode. +// - repoSync2 is a v1alpha1 version of RepoSync created using k8s api. This is to validate v1alpha1 version of RepoSync can be created in the delegated mode. +// - repoSync3 is declared in the root repo of root-sync. This is to validate RepoSync can be managed in a root repo. +// - repoSync4 is a v1alpha1 version of RepoSync declared in the namespace repo of nn2. This is to validate RepoSync can be managed in a namespace repo in the same namespace. +// - repoSync5 is declared in the root repo of rr1. This is to validate implicit namespace won't cause conflict between two root reconcilers (rr1 and root-sync). +// - repoSync6 is created using k8s api in a different namespace but with the same name "nr1". func TestMultiSyncs_Unstructured_MixedControl(t *testing.T) { - rr1 := "rr1" - rr2 := "rr2" - rr3 := "rr3" - nr1 := "nr1" - nn1 := nomostest.RepoSyncNN(testNs, nr1) - nn2 := nomostest.RepoSyncNN(testNs, "nr2") - nn3 := nomostest.RepoSyncNN(testNs, "nr3") - nn4 := nomostest.RepoSyncNN(testNs, "nr4") - nn5 := nomostest.RepoSyncNN(testNs, "nr5") + rootSync0ID := nomostest.DefaultRootSyncID + rootSync1ID := nomostest.RootSyncID("rr1") + rootSync2ID := nomostest.RootSyncID("rr2") + rootSync3ID := nomostest.RootSyncID("rr3") + // rootSync1Key := rootSync1ID.ObjectKey // unused + rootSync2Key := rootSync2ID.ObjectKey + rootSync3Key := rootSync3ID.ObjectKey + repoSync1ID := nomostest.RepoSyncID("nr1", testNs) + repoSync2ID := nomostest.RepoSyncID("nr2", testNs) + repoSync3ID := nomostest.RepoSyncID("nr3", testNs) + repoSync4ID := nomostest.RepoSyncID("nr4", testNs) + repoSync5ID := nomostest.RepoSyncID("nr5", testNs) + repoSync1Key := repoSync1ID.ObjectKey + repoSync2Key := repoSync2ID.ObjectKey + repoSync3Key := repoSync3ID.ObjectKey + repoSync4Key := repoSync4ID.ObjectKey + repoSync5Key := repoSync5ID.ObjectKey testNs2 := "ns-2" - nn6 := nomostest.RepoSyncNN(testNs2, nr1) + repoSync6ID := nomostest.RepoSyncID(repoSync1ID.Name, testNs2) + repoSync6Key := repoSync6ID.ObjectKey nt := nomostest.New(t, nomostesting.MultiRepos, ntopts.Unstructured, - ntopts.WithDelegatedControl, ntopts.RootRepo(rr1), + ntopts.WithDelegatedControl, ntopts.RootRepo(rootSync1ID.Name), // NS reconciler allowed to manage RepoSyncs but not RoleBindings ntopts.RepoSyncPermissions(policy.RepoSyncAdmin()), - ntopts.NamespaceRepo(nn1.Namespace, nn1.Name), - ntopts.NamespaceRepo(nn6.Namespace, nn6.Name)) + ntopts.NamespaceRepo(repoSync1Key.Namespace, repoSync1Key.Name), + ntopts.NamespaceRepo(repoSync6Key.Namespace, repoSync6Key.Name)) + rootSync0GitRepo := nt.SyncSourceGitRepository(rootSync0ID) + rootSync1GitRepo := nt.SyncSourceGitRepository(rootSync1ID) // Cleanup all unmanaged RepoSyncs BEFORE the root-sync is deleted! // Otherwise, the test Namespace will be deleted while still containing @@ -90,7 +102,7 @@ func TestMultiSyncs_Unstructured_MixedControl(t *testing.T) { nt.T.Cleanup(func() { nt.T.Log("[CLEANUP] Deleting test RepoSyncs") var rsList []v1beta1.RepoSync - rsNNs := []types.NamespacedName{nn1, nn2, nn4} + rsNNs := []types.NamespacedName{repoSync1Key, repoSync2Key, repoSync4Key} for _, rsNN := range rsNNs { rs := &v1beta1.RepoSync{} err := nt.KubeClient.Get(rsNN.Name, rsNN.Namespace, rs) @@ -108,101 +120,109 @@ func TestMultiSyncs_Unstructured_MixedControl(t *testing.T) { }) var newRepos []types.NamespacedName - newRepos = append(newRepos, nomostest.RootSyncNN(rr2)) - newRepos = append(newRepos, nomostest.RootSyncNN(rr3)) - newRepos = append(newRepos, nn2) - newRepos = append(newRepos, nn3) - newRepos = append(newRepos, nn4) - newRepos = append(newRepos, nn5) + newRepos = append(newRepos, rootSync2Key) + newRepos = append(newRepos, rootSync3Key) + newRepos = append(newRepos, repoSync2Key) + newRepos = append(newRepos, repoSync3Key) + newRepos = append(newRepos, repoSync4Key) + newRepos = append(newRepos, repoSync5Key) if nt.GitProvider.Type() == e2e.Local { nomostest.InitGitRepos(nt, newRepos...) } - nt.RootRepos[rr2] = nomostest.ResetRepository(nt, gitproviders.RootRepo, nomostest.RootSyncNN(rr2), configsync.SourceFormatUnstructured) - nt.RootRepos[rr3] = nomostest.ResetRepository(nt, gitproviders.RootRepo, nomostest.RootSyncNN(rr3), configsync.SourceFormatUnstructured) - nt.NonRootRepos[nn2] = nomostest.ResetRepository(nt, gitproviders.NamespaceRepo, nn2, configsync.SourceFormatUnstructured) - nt.NonRootRepos[nn3] = nomostest.ResetRepository(nt, gitproviders.NamespaceRepo, nn3, configsync.SourceFormatUnstructured) - nt.NonRootRepos[nn4] = nomostest.ResetRepository(nt, gitproviders.NamespaceRepo, nn4, configsync.SourceFormatUnstructured) - nt.NonRootRepos[nn5] = nomostest.ResetRepository(nt, gitproviders.NamespaceRepo, nn5, configsync.SourceFormatUnstructured) - nrb2 := nomostest.RepoSyncRoleBinding(nn2) - nrb3 := nomostest.RepoSyncRoleBinding(nn3) - nrb4 := nomostest.RepoSyncRoleBinding(nn4) - nrb5 := nomostest.RepoSyncRoleBinding(nn5) + rootSync2GitRepo := nomostest.ResetRepository(nt, gitproviders.RootRepo, rootSync2Key, configsync.SourceFormatUnstructured) + rootSync3GitRepo := nomostest.ResetRepository(nt, gitproviders.RootRepo, rootSync3Key, configsync.SourceFormatUnstructured) + repoSync2GitRepo := nomostest.ResetRepository(nt, gitproviders.NamespaceRepo, repoSync2Key, configsync.SourceFormatUnstructured) + repoSync3GitRepo := nomostest.ResetRepository(nt, gitproviders.NamespaceRepo, repoSync3Key, configsync.SourceFormatUnstructured) + repoSync4GitRepo := nomostest.ResetRepository(nt, gitproviders.NamespaceRepo, repoSync4Key, configsync.SourceFormatUnstructured) + repoSync5GitRepo := nomostest.ResetRepository(nt, gitproviders.NamespaceRepo, repoSync5Key, configsync.SourceFormatUnstructured) + + nt.SyncSources[rootSync2ID] = &syncsource.GitSyncSource{Repository: rootSync2GitRepo} + nt.SyncSources[rootSync3ID] = &syncsource.GitSyncSource{Repository: rootSync3GitRepo} + nt.SyncSources[repoSync2ID] = &syncsource.GitSyncSource{Repository: repoSync2GitRepo} + nt.SyncSources[repoSync3ID] = &syncsource.GitSyncSource{Repository: repoSync3GitRepo} + nt.SyncSources[repoSync4ID] = &syncsource.GitSyncSource{Repository: repoSync4GitRepo} + nt.SyncSources[repoSync5ID] = &syncsource.GitSyncSource{Repository: repoSync5GitRepo} + + nrb2 := nomostest.RepoSyncRoleBinding(repoSync2Key) + nrb3 := nomostest.RepoSyncRoleBinding(repoSync3Key) + nrb4 := nomostest.RepoSyncRoleBinding(repoSync4Key) + nrb5 := nomostest.RepoSyncRoleBinding(repoSync5Key) nt.T.Logf("Adding Namespace & RoleBindings for RepoSyncs") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/cluster/ns-%s.yaml", testNs), k8sobjects.NamespaceObject(testNs))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/rb-%s.yaml", testNs, nn2.Name), nrb2)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/rb-%s.yaml", testNs, nn4.Name), nrb4)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding Namespace & RoleBindings for RepoSyncs")) + nt.Must(rootSync0GitRepo.Add(fmt.Sprintf("acme/cluster/ns-%s.yaml", testNs), k8sobjects.NamespaceObject(testNs))) + nt.Must(rootSync0GitRepo.Add(fmt.Sprintf("acme/namespaces/%s/rb-%s.yaml", testNs, repoSync2Key.Name), nrb2)) + nt.Must(rootSync0GitRepo.Add(fmt.Sprintf("acme/namespaces/%s/rb-%s.yaml", testNs, repoSync4Key.Name), nrb4)) + nt.Must(rootSync0GitRepo.CommitAndPush("Adding Namespace & RoleBindings for RepoSyncs")) - nt.T.Logf("Add RootSync %s to the repository of RootSync %s", rr2, configsync.RootSyncName) + nt.T.Logf("Add RootSync %s to the repository of RootSync %s", rootSync2ID.Name, configsync.RootSyncName) - rs2 := nomostest.RootSyncObjectV1Alpha1FromRootRepo(nt, rr2) - rs2ConfigFile := fmt.Sprintf("acme/rootsyncs/%s.yaml", rr2) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(rs2ConfigFile, rs2)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding RootSync: " + rr2)) - // Wait for all RootSyncs and RepoSyncs to be synced, including the new RootSync rr2. - if err := nt.WatchForAllSyncs(nomostest.SkipRootRepos(rr3), nomostest.SkipNonRootRepos(nn2, nn3, nn4, nn5)); err != nil { + rs2 := nomostest.RootSyncObjectV1Alpha1FromRootRepo(nt, rootSync2ID.Name) + rs2ConfigFile := fmt.Sprintf("acme/rootsyncs/%s.yaml", rootSync2ID.Name) + nt.Must(rootSync0GitRepo.Add(rs2ConfigFile, rs2)) + nt.Must(rootSync0GitRepo.CommitAndPush("Adding RootSync: " + rootSync2ID.Name)) + // Wait for all RootSyncs and RepoSyncs to be synced, including the new rootSync2. + if err := nt.WatchForAllSyncs(nomostest.SkipRootRepos(rootSync3ID.Name), nomostest.SkipNonRootRepos(repoSync2Key, repoSync3Key, repoSync4Key, repoSync5Key)); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Add RootSync %s to the repository of RootSync %s", rr3, rr2) - rs3 := nomostest.RootSyncObjectV1Alpha1FromRootRepo(nt, rr3) - rs3ConfigFile := fmt.Sprintf("acme/rootsyncs/%s.yaml", rr3) - nt.Must(nt.RootRepos[rr2].Add(rs3ConfigFile, rs3)) - nt.Must(nt.RootRepos[rr2].CommitAndPush("Adding RootSync: " + rr3)) - // Wait for all RootSyncs and RepoSyncs to be synced, including the new RootSync rr3. - if err := nt.WatchForAllSyncs(nomostest.SkipNonRootRepos(nn2, nn3, nn4, nn5)); err != nil { + nt.T.Logf("Add RootSync %s to the repository of RootSync %s", rootSync3ID.Name, rootSync2ID.Name) + rs3 := nomostest.RootSyncObjectV1Alpha1FromRootRepo(nt, rootSync3ID.Name) + rs3ConfigFile := fmt.Sprintf("acme/rootsyncs/%s.yaml", rootSync3ID.Name) + nt.Must(rootSync2GitRepo.Add(rs3ConfigFile, rs3)) + nt.Must(rootSync2GitRepo.CommitAndPush("Adding RootSync: " + rootSync3ID.Name)) + // Wait for all RootSyncs and RepoSyncs to be synced, including the new rootSync3. + if err := nt.WatchForAllSyncs(nomostest.SkipNonRootRepos(repoSync2Key, repoSync3Key, repoSync4Key, repoSync5Key)); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Create RepoSync %s", nn2) - nrs2 := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, nn2) + nt.T.Logf("Create RepoSync %s", repoSync2Key) + nrs2 := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, repoSync2Key) if err := nt.KubeClient.Create(nrs2); err != nil { nt.T.Fatal(err) } // RoleBinding (nrb2) managed by RootSync root-sync, because the namespace // tenant does not have permission to manage RBAC. // Wait for all RootSyncs and RepoSyncs to be synced, including the new RepoSync nr2. - if err := nt.WatchForAllSyncs(nomostest.SkipNonRootRepos(nn3, nn4, nn5)); err != nil { + if err := nt.WatchForAllSyncs(nomostest.SkipNonRootRepos(repoSync3Key, repoSync4Key, repoSync5Key)); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Add RepoSync %s to RootSync %s", nn3, configsync.RootSyncName) - nrs3 := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, nn3) + nt.T.Logf("Add RepoSync %s to RootSync %s", repoSync3Key, configsync.RootSyncName) + nrs3 := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, repoSync3Key) // Ensure the RoleBinding is deleted after the RepoSync if err := nomostest.SetDependencies(nrs3, nrb3); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/reposyncs/%s.yaml", nn3.Name), nrs3)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/rb-%s.yaml", testNs, nn3.Name), nrb3)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding RepoSync: " + nn3.String())) + nt.Must(rootSync0GitRepo.Add(fmt.Sprintf("acme/reposyncs/%s.yaml", repoSync3Key.Name), nrs3)) + nt.Must(rootSync0GitRepo.Add(fmt.Sprintf("acme/namespaces/%s/rb-%s.yaml", testNs, repoSync3Key.Name), nrb3)) + nt.Must(rootSync0GitRepo.CommitAndPush("Adding RepoSync: " + repoSync3Key.String())) // Wait for all RootSyncs and RepoSyncs to be synced, including the new RepoSync nr3. - if err := nt.WatchForAllSyncs(nomostest.SkipNonRootRepos(nn4, nn5)); err != nil { + if err := nt.WatchForAllSyncs(nomostest.SkipNonRootRepos(repoSync4Key, repoSync5Key)); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Add RepoSync %s to RepoSync %s", nn4, nn2) - nrs4 := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, nn4) - nt.Must(nt.NonRootRepos[nn2].Add(fmt.Sprintf("acme/reposyncs/%s.yaml", nn4.Name), nrs4)) + nt.T.Logf("Add RepoSync %s to RepoSync %s", repoSync4Key, repoSync2Key) + nrs4 := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, repoSync4Key) + nt.Must(repoSync2GitRepo.Add(fmt.Sprintf("acme/reposyncs/%s.yaml", repoSync4Key.Name), nrs4)) // RoleBinding (nrb4) managed by RootSync root-sync, because RepoSync (nr2) // does not have permission to manage RBAC. - nt.Must(nt.NonRootRepos[nn2].CommitAndPush("Adding RepoSync: " + nn4.String())) + nt.Must(repoSync2GitRepo.CommitAndPush("Adding RepoSync: " + repoSync4Key.String())) // Wait for all RootSyncs and RepoSyncs to be synced, including the new RepoSync nr4. - if err := nt.WatchForAllSyncs(nomostest.SkipNonRootRepos(nn5)); err != nil { + if err := nt.WatchForAllSyncs(nomostest.SkipNonRootRepos(repoSync5Key)); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Add RepoSync %s to RootSync %s", nn5, rr1) - nrs5 := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, nn5) + nt.T.Logf("Add RepoSync %s to RootSync %s", repoSync5Key, rootSync1ID.Name) + nrs5 := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, repoSync5Key) // Ensure the RoleBinding is deleted after the RepoSync if err := nomostest.SetDependencies(nrs5, nrb5); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[rr1].Add(fmt.Sprintf("acme/reposyncs/%s.yaml", nn5.Name), nrs5)) - nt.Must(nt.RootRepos[rr1].Add(fmt.Sprintf("acme/namespaces/%s/rb-%s.yaml", testNs, nn5.Name), nrb5)) - nt.Must(nt.RootRepos[rr1].CommitAndPush("Adding RepoSync: " + nn5.String())) + nt.Must(rootSync1GitRepo.Add(fmt.Sprintf("acme/reposyncs/%s.yaml", repoSync5Key.Name), nrs5)) + nt.Must(rootSync1GitRepo.Add(fmt.Sprintf("acme/namespaces/%s/rb-%s.yaml", testNs, repoSync5Key.Name), nrb5)) + nt.Must(rootSync1GitRepo.CommitAndPush("Adding RepoSync: " + repoSync5Key.String())) // Wait for all RootSyncs and RepoSyncs to be synced, including the new RepoSync nr5. if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -213,8 +233,8 @@ func TestMultiSyncs_Unstructured_MixedControl(t *testing.T) { validateReconcilerResource(nt, kinds.Deployment(), map[string]string{metadata.SyncNamespaceLabel: configsync.ControllerNamespace}, 4) validateReconcilerResource(nt, kinds.Deployment(), map[string]string{metadata.SyncNamespaceLabel: testNs}, 5) validateReconcilerResource(nt, kinds.Deployment(), map[string]string{metadata.SyncNamespaceLabel: testNs2}, 1) - validateReconcilerResource(nt, kinds.Deployment(), map[string]string{metadata.SyncNameLabel: rr1}, 1) - validateReconcilerResource(nt, kinds.Deployment(), map[string]string{metadata.SyncNameLabel: nr1}, 2) + validateReconcilerResource(nt, kinds.Deployment(), map[string]string{metadata.SyncNameLabel: rootSync1ID.Name}, 1) + validateReconcilerResource(nt, kinds.Deployment(), map[string]string{metadata.SyncNameLabel: repoSync1ID.Name}, 2) // Deployments may still be reconciling, wait before checking Pods if err := waitForResourcesCurrent(nt, kinds.Deployment(), map[string]string{"app": "reconciler"}, 10); err != nil { @@ -224,14 +244,14 @@ func TestMultiSyncs_Unstructured_MixedControl(t *testing.T) { validateReconcilerResource(nt, kinds.Pod(), map[string]string{metadata.SyncNamespaceLabel: configsync.ControllerNamespace}, 4) validateReconcilerResource(nt, kinds.Pod(), map[string]string{metadata.SyncNamespaceLabel: testNs}, 5) validateReconcilerResource(nt, kinds.Pod(), map[string]string{metadata.SyncNamespaceLabel: testNs2}, 1) - validateReconcilerResource(nt, kinds.Pod(), map[string]string{metadata.SyncNameLabel: rr1}, 1) - validateReconcilerResource(nt, kinds.Pod(), map[string]string{metadata.SyncNameLabel: nr1}, 2) + validateReconcilerResource(nt, kinds.Pod(), map[string]string{metadata.SyncNameLabel: rootSync1ID.Name}, 1) + validateReconcilerResource(nt, kinds.Pod(), map[string]string{metadata.SyncNameLabel: repoSync1ID.Name}, 2) validateReconcilerResource(nt, kinds.ServiceAccount(), map[string]string{metadata.SyncNamespaceLabel: configsync.ControllerNamespace}, 4) validateReconcilerResource(nt, kinds.ServiceAccount(), map[string]string{metadata.SyncNamespaceLabel: testNs}, 5) validateReconcilerResource(nt, kinds.ServiceAccount(), map[string]string{metadata.SyncNamespaceLabel: testNs2}, 1) - validateReconcilerResource(nt, kinds.ServiceAccount(), map[string]string{metadata.SyncNameLabel: rr1}, 1) - validateReconcilerResource(nt, kinds.ServiceAccount(), map[string]string{metadata.SyncNameLabel: nr1}, 2) + validateReconcilerResource(nt, kinds.ServiceAccount(), map[string]string{metadata.SyncNameLabel: rootSync1ID.Name}, 1) + validateReconcilerResource(nt, kinds.ServiceAccount(), map[string]string{metadata.SyncNameLabel: repoSync1ID.Name}, 2) // Reconciler-manager doesn't copy the secret of RootSync's secretRef. validateReconcilerResource(nt, kinds.Secret(), map[string]string{metadata.SyncNamespaceLabel: configsync.ControllerNamespace}, 0) @@ -239,7 +259,7 @@ func TestMultiSyncs_Unstructured_MixedControl(t *testing.T) { if nt.GitProvider.Type() != e2e.CSR { validateReconcilerResource(nt, kinds.Secret(), map[string]string{metadata.SyncNamespaceLabel: testNs}, 5) validateReconcilerResource(nt, kinds.Secret(), map[string]string{metadata.SyncNamespaceLabel: testNs2}, 1) - validateReconcilerResource(nt, kinds.Secret(), map[string]string{metadata.SyncNameLabel: nr1}, 2) + validateReconcilerResource(nt, kinds.Secret(), map[string]string{metadata.SyncNameLabel: repoSync1ID.Name}, 2) } // TODO: validate sync-generation label @@ -276,42 +296,46 @@ func waitForResourcesCurrent(nt *nomostest.NT, gvk schema.GroupVersionKind, labe } func TestConflictingDefinitions_RootToNamespace(t *testing.T) { - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) - repoSyncNN := nomostest.RepoSyncNN(testNs, "rs-test") + rootSyncID := nomostest.DefaultRootSyncID + repoSyncID := nomostest.RepoSyncID("rs-test", testNs) + rootSyncKey := rootSyncID.ObjectKey + repoSyncKey := repoSyncID.ObjectKey nt := nomostest.New(t, nomostesting.MultiRepos, - ntopts.NamespaceRepo(repoSyncNN.Namespace, repoSyncNN.Name), + ntopts.NamespaceRepo(repoSyncKey.Namespace, repoSyncKey.Name), ntopts.RepoSyncPermissions(policy.RBACAdmin()), // NS Reconciler manages Roles ) + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) podRoleFilePath := fmt.Sprintf("acme/namespaces/%s/pod-role.yaml", testNs) - nt.T.Logf("Add a Role to root: %s", configsync.RootSyncName) + nt.T.Logf("Add a Role to root: %s", rootSyncKey.Name) roleObj := rootPodRole() - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(podRoleFilePath, roleObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add pod viewer role")) + nt.Must(rootSyncGitRepo.Add(podRoleFilePath, roleObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("add pod viewer role")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } // Add Role to the RootSync, NOT the RepoSync - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, roleObj) + nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncKey, roleObj) err := nomostest.ValidateStandardMetricsForRootSync(nt, metrics.Summary{ - Sync: rootSyncNN, + Sync: rootSyncKey, }) if err != nil { nt.T.Fatal(err) } err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) } - nt.T.Logf("Declare a conflicting Role in the Namespace repo: %s", repoSyncNN) - nt.Must(nt.NonRootRepos[repoSyncNN].Add(podRoleFilePath, namespacePodRole())) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("add conflicting pod owner role")) + nt.T.Logf("Declare a conflicting Role in the Namespace repo: %s", repoSyncKey) + nt.Must(repoSyncGitRepo.Add(podRoleFilePath, namespacePodRole())) + nt.Must(repoSyncGitRepo.CommitAndPush("add conflicting pod owner role")) nt.T.Logf("The RootSync should report no problems") err = nt.WatchForAllSyncs(nomostest.RootSyncOnly()) @@ -319,15 +343,15 @@ func TestConflictingDefinitions_RootToNamespace(t *testing.T) { nt.T.Fatal(err) } - nt.T.Logf("The RepoSync %s reports a problem since it can't sync the declaration.", repoSyncNN) - nt.WaitForRepoSyncSyncError(repoSyncNN.Namespace, repoSyncNN.Name, status.ManagementConflictErrorCode, "detected a management conflict", nil) + nt.T.Logf("The RepoSync %s reports a problem since it can't sync the declaration.", repoSyncKey) + nt.WaitForRepoSyncSyncError(repoSyncKey.Namespace, repoSyncKey.Name, status.ManagementConflictErrorCode, "detected a management conflict", nil) - nt.T.Logf("Validate conflict metric is emitted from Namespace reconciler %s", repoSyncNN) - repoSyncLabels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncNN) + nt.T.Logf("Validate conflict metric is emitted from Namespace reconciler %s", repoSyncKey) + repoSyncLabels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncKey) if err != nil { nt.T.Fatal(err) } - commitHash := nt.NonRootRepos[repoSyncNN].MustHash(nt.T) + commitHash := repoSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, // ManagementConflictErrorWrap is recorded by the remediator, while @@ -343,44 +367,44 @@ func TestConflictingDefinitions_RootToNamespace(t *testing.T) { nt.T.Fatal(err) } - nt.T.Logf("Ensure the Role matches the one in the Root repo %s", configsync.RootSyncName) + nt.T.Logf("Ensure the Role matches the one in the Root repo %s", rootSyncKey.Name) err = nt.Validate("pods", testNs, &rbacv1.Role{}, roleHasRules(rootPodRole().Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, configsync.RootSyncName)) + testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, rootSyncKey.Name)) if err != nil { nt.T.Fatal(err) } - nt.T.Logf("Remove the declaration from the Root repo %s", configsync.RootSyncName) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(podRoleFilePath)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove conflicting pod role from Root")) + nt.T.Logf("Remove the declaration from the Root repo %s", rootSyncKey.Name) + nt.Must(rootSyncGitRepo.Remove(podRoleFilePath)) + nt.Must(rootSyncGitRepo.CommitAndPush("remove conflicting pod role from Root")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Ensure the Role is updated to the one in the Namespace repo %s", repoSyncNN) + nt.T.Logf("Ensure the Role is updated to the one in the Namespace repo %s", repoSyncKey) err = nt.Validate("pods", testNs, &rbacv1.Role{}, roleHasRules(namespacePodRole().Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.Scope(repoSyncNN.Namespace), repoSyncNN.Name)) + testpredicates.IsManagedBy(nt.Scheme, declared.Scope(repoSyncKey.Namespace), repoSyncKey.Name)) if err != nil { nt.T.Fatal(err) } // Delete Role from the RootSync, and add it to the RepoSync. // RootSync will delete the object, because it was in the inventory, due to the AdoptAll strategy. - nt.MetricsExpectations.AddObjectDelete(configsync.RootSyncKind, rootSyncNN, roleObj) + nt.MetricsExpectations.AddObjectDelete(configsync.RootSyncKind, rootSyncKey, roleObj) // RepoSync will recreate the object. - nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncNN, roleObj) + nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncKey, roleObj) err = nomostest.ValidateStandardMetricsForRootSync(nt, metrics.Summary{ - Sync: rootSyncNN, + Sync: rootSyncKey, }) if err != nil { nt.T.Fatal(err) } err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN, + Sync: repoSyncKey, Errors: metrics.ErrorSummary{ // resource_conflicts_total is cumulative and ony resets whe the commit changes // TODO: Fix resource_conflicts_total to reflect the actual current total number of conflicts. @@ -393,35 +417,39 @@ func TestConflictingDefinitions_RootToNamespace(t *testing.T) { } func TestConflictingDefinitions_NamespaceToRoot(t *testing.T) { - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) - repoSyncNN := nomostest.RepoSyncNN(testNs, "rs-test") + rootSyncID := nomostest.DefaultRootSyncID + repoSyncID := nomostest.RepoSyncID("rs-test", testNs) + rootSyncKey := rootSyncID.ObjectKey + repoSyncKey := repoSyncID.ObjectKey nt := nomostest.New(t, nomostesting.MultiRepos, - ntopts.NamespaceRepo(repoSyncNN.Namespace, repoSyncNN.Name), + ntopts.NamespaceRepo(repoSyncKey.Namespace, repoSyncKey.Name), ntopts.RepoSyncPermissions(policy.RBACAdmin()), // NS reconciler manages Roles ) + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) podRoleFilePath := fmt.Sprintf("acme/namespaces/%s/pod-role.yaml", testNs) - nt.T.Logf("Add a Role to Namespace repo: %s", configsync.RootSyncName) + nt.T.Logf("Add a Role to Namespace repo: %s", rootSyncKey.Name) nsRoleObj := namespacePodRole() - nt.Must(nt.NonRootRepos[repoSyncNN].Add(podRoleFilePath, nsRoleObj)) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("declare Role")) + nt.Must(repoSyncGitRepo.Add(podRoleFilePath, nsRoleObj)) + nt.Must(repoSyncGitRepo.CommitAndPush("declare Role")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } err := nt.Validate("pods", testNs, &rbacv1.Role{}, roleHasRules(nsRoleObj.Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.Scope(repoSyncNN.Namespace), repoSyncNN.Name)) + testpredicates.IsManagedBy(nt.Scheme, declared.Scope(repoSyncKey.Namespace), repoSyncKey.Name)) if err != nil { nt.T.Fatal(err) } // Test Role managed by the RepoSync, NOT the RootSync - nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncNN, nsRoleObj) + nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncKey, nsRoleObj) // Validate no errors from root reconciler. err = nomostest.ValidateStandardMetricsForRootSync(nt, metrics.Summary{ - Sync: rootSyncNN, + Sync: rootSyncKey, }) if err != nil { nt.T.Fatal(err) @@ -429,16 +457,16 @@ func TestConflictingDefinitions_NamespaceToRoot(t *testing.T) { // Validate no errors from namespace reconciler. err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) } - nt.T.Logf("Declare a conflicting Role in the Root repo: %s", configsync.RootSyncName) + nt.T.Logf("Declare a conflicting Role in the Root repo: %s", rootSyncKey.Name) rootRoleObj := rootPodRole() - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(podRoleFilePath, rootRoleObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add conflicting pod role to Root")) + nt.Must(rootSyncGitRepo.Add(podRoleFilePath, rootRoleObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("add conflicting pod role to Root")) nt.T.Logf("The RootSync should update the Role") err = nt.WatchForAllSyncs(nomostest.RootSyncOnly()) @@ -447,24 +475,24 @@ func TestConflictingDefinitions_NamespaceToRoot(t *testing.T) { } nt.T.Log("The RepoSync remediator should report a conflict error") - nt.WaitForRepoSyncSyncError(repoSyncNN.Namespace, repoSyncNN.Name, status.ManagementConflictErrorCode, "detected a management conflict", nil) + nt.WaitForRepoSyncSyncError(repoSyncKey.Namespace, repoSyncKey.Name, status.ManagementConflictErrorCode, "detected a management conflict", nil) - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rootRoleObj) + nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncKey, rootRoleObj) // Validate no errors from root reconciler. err = nomostest.ValidateStandardMetricsForRootSync(nt, metrics.Summary{ - Sync: rootSyncNN, + Sync: rootSyncKey, }) if err != nil { nt.T.Fatal(err) } - nt.T.Logf("Validate conflict metric is emitted from Namespace reconciler %s", repoSyncNN) - repoSyncLabels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncNN) + nt.T.Logf("Validate conflict metric is emitted from Namespace reconciler %s", repoSyncKey) + repoSyncLabels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncKey) if err != nil { nt.T.Fatal(err) } - commitHash := nt.NonRootRepos[repoSyncNN].MustHash(nt.T) + commitHash := repoSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerSyncError(nt, repoSyncLabels, commitHash), @@ -476,37 +504,37 @@ func TestConflictingDefinitions_NamespaceToRoot(t *testing.T) { nt.T.Fatal(err) } - nt.T.Logf("Ensure the Role matches the one in the Root repo %s", configsync.RootSyncName) + nt.T.Logf("Ensure the Role matches the one in the Root repo %s", rootSyncKey.Name) err = nt.Validate("pods", testNs, &rbacv1.Role{}, roleHasRules(rootPodRole().Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, configsync.RootSyncName)) + testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, rootSyncKey.Name)) if err != nil { nt.T.Fatal(err) } - nt.T.Logf("Remove the Role from the Namespace repo %s", repoSyncNN) - nt.Must(nt.NonRootRepos[repoSyncNN].Remove(podRoleFilePath)) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("remove conflicting pod role from Namespace repo")) + nt.T.Logf("Remove the Role from the Namespace repo %s", repoSyncKey) + nt.Must(repoSyncGitRepo.Remove(podRoleFilePath)) + nt.Must(repoSyncGitRepo.CommitAndPush("remove conflicting pod role from Namespace repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Ensure the Role still matches the one in the Root repo %s", configsync.RootSyncName) + nt.T.Logf("Ensure the Role still matches the one in the Root repo %s", rootSyncKey.Name) err = nt.Validate("pods", testNs, &rbacv1.Role{}, roleHasRules(rootPodRole().Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, configsync.RootSyncName)) + testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, rootSyncKey.Name)) if err != nil { nt.T.Fatal(err) } // Test Role managed by the RootSync, NOT the RepoSync - nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rootRoleObj) + nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncKey, rootRoleObj) // RepoSync won't delete the object, because it doesn't own it, due to the AdoptIfNoInventory strategy. - nt.MetricsExpectations.RemoveObject(configsync.RepoSyncKind, repoSyncNN, nsRoleObj) + nt.MetricsExpectations.RemoveObject(configsync.RepoSyncKind, repoSyncKey, nsRoleObj) // Validate no errors from root reconciler. err = nomostest.ValidateStandardMetricsForRootSync(nt, metrics.Summary{ - Sync: rootSyncNN, + Sync: rootSyncKey, }) if err != nil { nt.T.Fatal(err) @@ -514,7 +542,7 @@ func TestConflictingDefinitions_NamespaceToRoot(t *testing.T) { // Validate no errors from namespace reconciler. err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) @@ -522,35 +550,39 @@ func TestConflictingDefinitions_NamespaceToRoot(t *testing.T) { } func TestConflictingDefinitions_RootToRoot(t *testing.T) { - rootSync2 := "root-test" + rootSyncID := nomostest.DefaultRootSyncID + rootSync2ID := nomostest.RootSyncID("root-test") // If declaring RootSync in a Root repo, the source format has to be unstructured. // Otherwise, the hierarchical validator will complain that the config-management-system has configs but missing a Namespace config. - nt := nomostest.New(t, nomostesting.MultiRepos, ntopts.Unstructured, ntopts.RootRepo(rootSync2)) + nt := nomostest.New(t, nomostesting.MultiRepos, ntopts.Unstructured, + ntopts.RootRepo(rootSync2ID.Name)) + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + rootSync2GitRepo := nt.SyncSourceGitRepository(rootSync2ID) podRoleFilePath := fmt.Sprintf("acme/namespaces/%s/pod-role.yaml", testNs) - nt.T.Logf("Add a Role to RootSync: %s", configsync.RootSyncName) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(podRoleFilePath, rootPodRole())) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add pod viewer role")) + nt.T.Logf("Add a Role to RootSync: %s", rootSyncID.Name) + nt.Must(rootSyncGitRepo.Add(podRoleFilePath, rootPodRole())) + nt.Must(rootSyncGitRepo.CommitAndPush("add pod viewer role")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Ensure the Role is managed by RootSync %s", configsync.RootSyncName) + nt.T.Logf("Ensure the Role is managed by RootSync %s", rootSyncID.Name) role := &rbacv1.Role{} err := nt.Validate("pods", testNs, role, roleHasRules(rootPodRole().Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, configsync.RootSyncName)) + testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, rootSyncID.Name)) if err != nil { nt.T.Fatal(err) } roleResourceVersion := role.ResourceVersion - nt.T.Logf("Declare a conflicting Role in RootSync %s", rootSync2) - nt.Must(nt.RootRepos[rootSync2].Add(podRoleFilePath, rootPodRole())) - nt.Must(nt.RootRepos[rootSync2].CommitAndPush("add conflicting pod owner role")) + nt.T.Logf("Declare a conflicting Role in RootSync %s", rootSync2ID.Name) + nt.Must(rootSync2GitRepo.Add(podRoleFilePath, rootPodRole())) + nt.Must(rootSync2GitRepo.CommitAndPush("add conflicting pod owner role")) // When the webhook is enabled, it will block adoption of managed objects. - nt.T.Logf("Only RootSync %s should report a conflict with the webhook enabled", rootSync2) + nt.T.Logf("Only RootSync %s should report a conflict with the webhook enabled", rootSync2ID.Name) tg := taskgroup.New() // The first reconciler never encounters any conflict. // The second reconciler pauses its remediator before applying, but then its @@ -558,13 +590,13 @@ func TestConflictingDefinitions_RootToRoot(t *testing.T) { // So there's no need to report the error to the first reconciler. // So the first reconciler apply succeeds and no further error is expected. tg.Go(func() error { - return nt.Watcher.WatchForCurrentStatus(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace) + return nt.Watcher.WatchForCurrentStatus(kinds.RootSyncV1Beta1(), rootSyncID.Name, rootSyncID.Namespace) }) // The second reconciler's applier will report the conflict, when the update // is rejected by the webhook. // https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/errors/statuserror.go#L29 tg.Go(func() error { - return nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), rootSync2, configsync.ControllerNamespace, + return nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), rootSync2ID.Name, rootSync2ID.Namespace, []testpredicates.Predicate{ testpredicates.RootSyncHasSyncError(applier.ApplierErrorCode, "denied the request"), }) @@ -591,8 +623,8 @@ func TestConflictingDefinitions_RootToRoot(t *testing.T) { nt.T.Logf("Both RootSyncs should still report conflicts with the webhook disabled") tg = taskgroup.New() // Watch the Role until it has been updated by both remediators - manager1 := declared.ResourceManager(declared.RootScope, configsync.RootSyncName) - manager2 := declared.ResourceManager(declared.RootScope, rootSync2) + manager1 := declared.ResourceManager(declared.RootScope, rootSyncID.Name) + manager2 := declared.ResourceManager(declared.RootScope, rootSync2ID.Name) tg.Go(func() error { return nt.Watcher.WatchObject(kinds.Role(), "pods", testNs, []testpredicates.Predicate{ @@ -601,14 +633,14 @@ func TestConflictingDefinitions_RootToRoot(t *testing.T) { }) // Reconciler conflict, detected by the first reconciler's applier OR reported by the second reconciler tg.Go(func() error { - return nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, + return nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), rootSyncID.Name, rootSyncID.Namespace, []testpredicates.Predicate{ testpredicates.RootSyncHasSyncError(status.ManagementConflictErrorCode, "detected a management conflict"), }) }) // Reconciler conflict, detected by the second reconciler's applier OR reported by the first reconciler tg.Go(func() error { - return nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), rootSync2, configsync.ControllerNamespace, + return nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), rootSync2ID.Name, rootSync2ID.Namespace, []testpredicates.Predicate{ testpredicates.RootSyncHasSyncError(status.ManagementConflictErrorCode, "detected a management conflict"), }) @@ -617,20 +649,20 @@ func TestConflictingDefinitions_RootToRoot(t *testing.T) { nt.T.Fatal(err) } - nt.T.Logf("Remove the declaration from RootSync %s", configsync.RootSyncName) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(podRoleFilePath)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove conflicting pod role")) + nt.T.Logf("Remove the declaration from RootSync %s", rootSyncID.Name) + nt.Must(rootSyncGitRepo.Remove(podRoleFilePath)) + nt.Must(rootSyncGitRepo.CommitAndPush("remove conflicting pod role")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Ensure the Role is managed by RootSync %s", rootSync2) + nt.T.Logf("Ensure the Role is managed by RootSync %s", rootSync2ID.Name) // The pod role may be deleted from the cluster after it was removed from the `root-sync` Root repo. // Therefore, we need to retry here to wait until the `root-test` Root repo recreates the pod role. err = nt.Watcher.WatchObject(kinds.Role(), "pods", testNs, []testpredicates.Predicate{ roleHasRules(rootPodRole().Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, rootSync2), + testpredicates.IsManagedBy(nt.Scheme, declared.RootScope, rootSync2ID.Name), }) if err != nil { nt.T.Fatal(err) @@ -638,28 +670,33 @@ func TestConflictingDefinitions_RootToRoot(t *testing.T) { } func TestConflictingDefinitions_NamespaceToNamespace(t *testing.T) { - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) - repoSyncNN1 := nomostest.RepoSyncNN(testNs, "rs-test-1") - repoSyncNN2 := nomostest.RepoSyncNN(testNs, "rs-test-2") + rootSyncKey := nomostest.DefaultRootSyncID.ObjectKey + repoSync1ID := nomostest.RepoSyncID("rs-test-1", testNs) + repoSync2ID := nomostest.RepoSyncID("rs-test-2", testNs) + repoSync1Key := repoSync1ID.ObjectKey + repoSync2Key := repoSync2ID.ObjectKey nt := nomostest.New(t, nomostesting.MultiRepos, ntopts.RepoSyncPermissions(policy.RBACAdmin()), // NS reconciler manages Roles - ntopts.NamespaceRepo(repoSyncNN1.Namespace, repoSyncNN1.Name), - ntopts.NamespaceRepo(repoSyncNN2.Namespace, repoSyncNN2.Name)) + ntopts.NamespaceRepo(repoSync1ID.Namespace, repoSync1ID.Name), + ntopts.NamespaceRepo(repoSync2ID.Namespace, repoSync2ID.Name)) + + repoSync1GitRepo := nt.SyncSourceGitRepository(repoSync1ID) + repoSync2GitRepo := nt.SyncSourceGitRepository(repoSync2ID) podRoleFilePath := fmt.Sprintf("acme/namespaces/%s/pod-role.yaml", testNs) - nt.T.Logf("Add a Role to Namespace: %s", repoSyncNN1) + nt.T.Logf("Add a Role to Namespace: %s", repoSync1Key) roleObj := namespacePodRole() - nt.Must(nt.NonRootRepos[repoSyncNN1].Add(podRoleFilePath, roleObj)) - nt.Must(nt.NonRootRepos[repoSyncNN1].CommitAndPush("add pod viewer role")) + nt.Must(repoSync1GitRepo.Add(podRoleFilePath, roleObj)) + nt.Must(repoSync1GitRepo.CommitAndPush("add pod viewer role")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } role := &rbacv1.Role{} - nt.T.Logf("Ensure the Role is managed by Namespace Repo %s", repoSyncNN1) + nt.T.Logf("Ensure the Role is managed by Namespace Repo %s", repoSync1Key) err := nt.Validate("pods", testNs, role, roleHasRules(roleObj.Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.Scope(repoSyncNN1.Namespace), repoSyncNN1.Name)) + testpredicates.IsManagedBy(nt.Scheme, declared.Scope(repoSync1Key.Namespace), repoSync1Key.Name)) if err != nil { nt.T.Fatal(err) } @@ -667,18 +704,18 @@ func TestConflictingDefinitions_NamespaceToNamespace(t *testing.T) { // Validate no errors from root reconciler. err = nomostest.ValidateStandardMetricsForRootSync(nt, metrics.Summary{ - Sync: rootSyncNN, + Sync: rootSyncKey, // RepoSync already included in the default resource count and operations }) if err != nil { nt.T.Fatal(err) } - nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncNN1, roleObj) + nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSync1Key, roleObj) // Validate no errors from namespace reconciler #1. err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN1, + Sync: repoSync1Key, }) if err != nil { nt.T.Fatal(err) @@ -686,19 +723,19 @@ func TestConflictingDefinitions_NamespaceToNamespace(t *testing.T) { // Validate no errors from namespace reconciler #2. err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN2, + Sync: repoSync2Key, }) if err != nil { nt.T.Fatal(err) } - nt.T.Logf("Declare a conflicting Role in another Namespace repo: %s", repoSyncNN2) - nt.Must(nt.NonRootRepos[repoSyncNN2].Add(podRoleFilePath, roleObj)) - nt.Must(nt.NonRootRepos[repoSyncNN2].CommitAndPush("add conflicting pod owner role")) + nt.T.Logf("Declare a conflicting Role in another Namespace repo: %s", repoSync2Key) + nt.Must(repoSync2GitRepo.Add(podRoleFilePath, roleObj)) + nt.Must(repoSync2GitRepo.CommitAndPush("add conflicting pod owner role")) - nt.T.Logf("Only RepoSync %s reports the conflict error because kpt_applier won't update the resource", repoSyncNN2) - nt.WaitForRepoSyncSyncError(repoSyncNN2.Namespace, repoSyncNN2.Name, status.ManagementConflictErrorCode, "detected a management conflict", nil) - err = nt.WatchForSync(kinds.RepoSyncV1Beta1(), repoSyncNN1.Name, repoSyncNN1.Namespace, + nt.T.Logf("Only RepoSync %s reports the conflict error because kpt_applier won't update the resource", repoSync2Key) + nt.WaitForRepoSyncSyncError(repoSync2Key.Namespace, repoSync2Key.Name, status.ManagementConflictErrorCode, "detected a management conflict", nil) + err = nt.WatchForSync(kinds.RepoSyncV1Beta1(), repoSync1Key.Name, repoSync1Key.Namespace, nomostest.DefaultRepoSha1Fn, nomostest.RepoSyncHasStatusSyncCommit, nil) if err != nil { nt.T.Fatal(err) @@ -712,18 +749,18 @@ func TestConflictingDefinitions_NamespaceToNamespace(t *testing.T) { nt.T.Logf("Stop the admission webhook, the remediator should not be affected, which still reports the conflicts") nomostest.StopWebhook(nt) - nt.WaitForRepoSyncSyncError(repoSyncNN2.Namespace, repoSyncNN2.Name, status.ManagementConflictErrorCode, "detected a management conflict", nil) - err = nt.WatchForSync(kinds.RepoSyncV1Beta1(), repoSyncNN1.Name, repoSyncNN1.Namespace, + nt.WaitForRepoSyncSyncError(repoSync2Key.Namespace, repoSync2Key.Name, status.ManagementConflictErrorCode, "detected a management conflict", nil) + err = nt.WatchForSync(kinds.RepoSyncV1Beta1(), repoSync1Key.Name, repoSync1Key.Namespace, nomostest.DefaultRepoSha1Fn, nomostest.RepoSyncHasStatusSyncCommit, nil) if err != nil { nt.T.Fatal(err) } - nt.T.Logf("Validate conflict metric is emitted from Namespace reconciler %s", repoSyncNN2) - repoSync2Labels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncNN2) + nt.T.Logf("Validate conflict metric is emitted from Namespace reconciler %s", repoSync2Key) + repoSync2Labels, err := nomostest.MetricLabelsForRepoSync(nt, repoSync2Key) if err != nil { nt.T.Fatal(err) } - commitHash := nt.NonRootRepos[repoSyncNN2].MustHash(nt.T) + commitHash := repoSync2GitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerSyncError(nt, repoSync2Labels, commitHash), @@ -735,45 +772,45 @@ func TestConflictingDefinitions_NamespaceToNamespace(t *testing.T) { nt.T.Fatal(err) } - nt.T.Logf("Remove the declaration from one Namespace repo %s", repoSyncNN1) - nt.Must(nt.NonRootRepos[repoSyncNN1].Remove(podRoleFilePath)) - nt.Must(nt.NonRootRepos[repoSyncNN1].CommitAndPush("remove conflicting pod role from Namespace")) + nt.T.Logf("Remove the declaration from one Namespace repo %s", repoSync1Key) + nt.Must(repoSync1GitRepo.Remove(podRoleFilePath)) + nt.Must(repoSync1GitRepo.CommitAndPush("remove conflicting pod role from Namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.T.Logf("Ensure the Role is managed by the other Namespace repo %s", repoSyncNN2) + nt.T.Logf("Ensure the Role is managed by the other Namespace repo %s", repoSync2Key) err = nt.Validate("pods", testNs, &rbacv1.Role{}, roleHasRules(roleObj.Rules), - testpredicates.IsManagedBy(nt.Scheme, declared.Scope(repoSyncNN2.Namespace), repoSyncNN2.Name)) + testpredicates.IsManagedBy(nt.Scheme, declared.Scope(repoSync2Key.Namespace), repoSync2Key.Name)) if err != nil { nt.T.Fatal(err) } // Validate no errors from root reconciler. err = nomostest.ValidateStandardMetricsForRootSync(nt, metrics.Summary{ - Sync: rootSyncNN, + Sync: rootSyncKey, // RepoSync already included in the default resource count and operations }) if err != nil { nt.T.Fatal(err) } - nt.MetricsExpectations.AddObjectDelete(configsync.RepoSyncKind, repoSyncNN1, roleObj) + nt.MetricsExpectations.AddObjectDelete(configsync.RepoSyncKind, repoSync1Key, roleObj) // Validate no errors from namespace reconciler #1. err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN1, + Sync: repoSync1Key, }) if err != nil { nt.T.Fatal(err) } - nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncNN2, roleObj) + nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSync2Key, roleObj) // Validate no errors from namespace reconciler #2. err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN2, + Sync: repoSync2Key, Errors: metrics.ErrorSummary{ // resource_conflicts_total is cumulative and ony resets whe the commit changes // TODO: Fix resource_conflicts_total to reflect the actual current total number of conflicts. diff --git a/e2e/testcases/multiversion_test.go b/e2e/testcases/multiversion_test.go index 760759884d..c7a295eb78 100644 --- a/e2e/testcases/multiversion_test.go +++ b/e2e/testcases/multiversion_test.go @@ -36,11 +36,12 @@ import ( func TestMultipleVersions_CustomResourceV1(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Add the Anvil CRD. crdObj := anvilV1CRD() - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/anvil-crd.yaml", crdObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding Anvil CRD")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/anvil-crd.yaml", crdObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding Anvil CRD")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -48,12 +49,12 @@ func TestMultipleVersions_CustomResourceV1(t *testing.T) { // Add the v1 Anvils and verify they are created. nsObj := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) anvilv1Obj := anvilCR("v1", "first", 10) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvilv1.yaml", anvilv1Obj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvilv1.yaml", anvilv1Obj)) anvilv2Obj := anvilCR("v2", "second", 100) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvilv2.yaml", anvilv2Obj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding v1 and v2 Anvil CRs")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvilv2.yaml", anvilv2Obj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding v1 and v2 Anvil CRs")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -69,10 +70,10 @@ func TestMultipleVersions_CustomResourceV1(t *testing.T) { // Modify the v1 Anvils and verify they are updated. anvilv1Obj = anvilCR("v1", "first", 20) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvilv1.yaml", anvilv1Obj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvilv1.yaml", anvilv1Obj)) anvilv2Obj = anvilCR("v2", "second", 200) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/anvilv2.yaml", anvilv2Obj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Modifying v1 and v2 Anvil CRs")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/anvilv2.yaml", anvilv2Obj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Modifying v1 and v2 Anvil CRs")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -185,6 +186,7 @@ func anvilGVK(version string) schema.GroupVersionKind { func TestMultipleVersions_RoleBinding(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Reconciliation1) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rbV1 := k8sobjects.RoleBindingObject(core.Name("v1user")) rbV1.RoleRef = rbacv1.RoleRef{ @@ -200,9 +202,9 @@ func TestMultipleVersions_RoleBinding(t *testing.T) { // Add the v1 RoleBinding and verify it is created. nsObj := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/rbv1.yaml", rbV1)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding v1 RoleBinding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/rbv1.yaml", rbV1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding v1 RoleBinding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -231,8 +233,8 @@ func TestMultipleVersions_RoleBinding(t *testing.T) { Name: "v1admin@acme.com", }) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/rbv1.yaml", rbV1)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Modifying v1 RoleBinding")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/rbv1.yaml", rbV1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Modifying v1 RoleBinding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -254,8 +256,8 @@ func TestMultipleVersions_RoleBinding(t *testing.T) { } // Remove the v1 RoleBinding and verify that it is also deleted. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/foo/rbv1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing v1 RoleBinding")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/foo/rbv1.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing v1 RoleBinding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/namespace_repo_test.go b/e2e/testcases/namespace_repo_test.go index d24506f3c6..b6127a4fc8 100644 --- a/e2e/testcases/namespace_repo_test.go +++ b/e2e/testcases/namespace_repo_test.go @@ -49,7 +49,6 @@ import ( func TestNamespaceRepo_Centralized(t *testing.T) { bsNamespace := "bookstore" - repoSyncNN := nomostest.RepoSyncNN(bsNamespace, configsync.RepoSyncName) nt := nomostest.New( t, nomostesting.MultiRepos, @@ -57,6 +56,9 @@ func TestNamespaceRepo_Centralized(t *testing.T) { ntopts.RepoSyncPermissions(policy.CoreAdmin()), // NS Reconciler manages ServiceAccounts ntopts.WithCentralizedControl, ) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, bsNamespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) // Validate status condition "Reconciling" and "Stalled "is set to "False" // after the reconciler deployment is successfully created. @@ -74,11 +76,6 @@ func TestNamespaceRepo_Centralized(t *testing.T) { nt.T.Errorf("RepoSync did not finish reconciling: %v", err) } - repo, exist := nt.NonRootRepos[repoSyncNN] - if !exist { - nt.T.Fatal("nonexistent repo") - } - // Validate service account 'store' not present. err = nt.ValidateNotFound("store", bsNamespace, &corev1.ServiceAccount{}) if err != nil { @@ -86,8 +83,8 @@ func TestNamespaceRepo_Centralized(t *testing.T) { } sa := k8sobjects.ServiceAccountObject("store", core.Namespace(bsNamespace)) - nt.Must(repo.Add("acme/sa.yaml", sa)) - nt.Must(repo.CommitAndPush("Adding service account")) + nt.Must(repoSyncGitRepo.Add("acme/sa.yaml", sa)) + nt.Must(repoSyncGitRepo.CommitAndPush("Adding service account")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -99,16 +96,16 @@ func TestNamespaceRepo_Centralized(t *testing.T) { nt.T.Fatalf("service account store not found: %v", err) } - nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncNN, sa) + nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncKey, sa) err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) } - validateRepoSyncRBAC(nt, bsNamespace, repo, configureRBACInCentralizedMode) + validateRepoSyncRBAC(nt, bsNamespace, repoSyncGitRepo, configureRBACInCentralizedMode) } func validateRepoSyncRBAC(nt *nomostest.NT, ns string, nsRepo *gitproviders.Repository, configureRBAC configureRBACFunc) { @@ -199,6 +196,7 @@ func validateRepoSyncRBAC(nt *nomostest.NT, ns string, nsRepo *gitproviders.Repo type configureRBACFunc func(nt *nomostest.NT, ns string, verbs []string) func configureRBACInCentralizedMode(nt *nomostest.NT, ns string, verbs []string) { + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rules := []rbacv1.PolicyRule{ { APIGroups: []string{appsv1.GroupName}, @@ -211,7 +209,7 @@ func configureRBACInCentralizedMode(nt *nomostest.NT, ns string, verbs []string) core.Namespace(ns), ) rsRole.Rules = rules - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(ns, fmt.Sprintf("role-%s", rsRole.Name)), rsRole)) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(ns, fmt.Sprintf("role-%s", rsRole.Name)), rsRole)) rsRoleRef := rbacv1.RoleRef{ APIGroup: rsRole.GroupVersionKind().Group, Kind: rsRole.Kind, @@ -227,8 +225,8 @@ func configureRBACInCentralizedMode(nt *nomostest.NT, ns string, verbs []string) } rb.Subjects = sb rb.RoleRef = rsRoleRef - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(ns, fmt.Sprintf("rb-%s", rb.Name)), rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding restricted role and rolebinding for RepoSync")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(ns, fmt.Sprintf("rb-%s", rb.Name)), rb)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding restricted role and rolebinding for RepoSync")) } func configureRBACInDelegatedMode(nt *nomostest.NT, ns string, verbs []string) { @@ -323,7 +321,6 @@ func hasStalledStatus(r metav1.ConditionStatus) testpredicates.Predicate { func TestNamespaceRepo_Delegated(t *testing.T) { bsNamespaceRepo := "bookstore" - repoSyncNN := nomostest.RepoSyncNN(bsNamespaceRepo, configsync.RepoSyncName) nt := nomostest.New( t, nomostesting.MultiRepos, @@ -331,6 +328,9 @@ func TestNamespaceRepo_Delegated(t *testing.T) { ntopts.WithDelegatedControl, ntopts.RepoSyncPermissions(policy.CoreAdmin()), // NS Reconciler manages ServiceAccounts ) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, bsNamespaceRepo) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) // Validate service account 'store' not present. err := nt.ValidateNotFound("store", bsNamespaceRepo, &corev1.ServiceAccount{}) @@ -339,8 +339,8 @@ func TestNamespaceRepo_Delegated(t *testing.T) { } sa := k8sobjects.ServiceAccountObject("store", core.Namespace(bsNamespaceRepo)) - nt.Must(nt.NonRootRepos[repoSyncNN].Add("acme/sa.yaml", sa)) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("Adding service account")) + nt.Must(repoSyncGitRepo.Add("acme/sa.yaml", sa)) + nt.Must(repoSyncGitRepo.CommitAndPush("Adding service account")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -351,16 +351,16 @@ func TestNamespaceRepo_Delegated(t *testing.T) { nt.T.Error(err) } - nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncNN, sa) + nt.MetricsExpectations.AddObjectApply(configsync.RepoSyncKind, repoSyncKey, sa) err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: repoSyncNN, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) } - validateRepoSyncRBAC(nt, bsNamespaceRepo, nt.NonRootRepos[repoSyncNN], configureRBACInDelegatedMode) + validateRepoSyncRBAC(nt, bsNamespaceRepo, repoSyncGitRepo, configureRBACInDelegatedMode) } func TestDeleteRepoSync_Delegated_AndRepoSyncV1Alpha1(t *testing.T) { @@ -406,21 +406,26 @@ func TestDeleteRepoSync_Centralized_AndRepoSyncV1Alpha1(t *testing.T) { ntopts.NamespaceRepo(bsNamespace, configsync.RepoSyncName), ntopts.WithCentralizedControl, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, bsNamespace) + repoSyncKey := repoSyncID.ObjectKey secretNames := getNsReconcilerSecrets(nt, bsNamespace) repoSyncPath := nomostest.StructuredNSPath(bsNamespace, configsync.RepoSyncName) - repoSyncObj := nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, repoSyncPath) + repoSyncObj := rootSyncGitRepo.MustGet(nt.T, repoSyncPath) // Remove RepoSync resource from Root Repository. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(repoSyncPath)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing RepoSync from the Root Repository")) + nt.Must(rootSyncGitRepo.Remove(repoSyncPath)) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing RepoSync from the Root Repository")) // Remove from NamespaceRepos so we don't try to check that it is syncing, // as we've just deleted it. - nn := nomostest.RepoSyncNN(bsNamespace, configsync.RepoSyncName) - nsRepo := nt.NonRootRepos[nn] - delete(nt.NonRootRepos, nn) + repoSyncSource, found := nt.SyncSources[repoSyncID] + if !found { + nt.T.Fatalf("Missing %s: %s", repoSyncID.Kind, repoSyncID.ObjectKey) + } + delete(nt.SyncSources, repoSyncID) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -437,10 +442,10 @@ func TestDeleteRepoSync_Centralized_AndRepoSyncV1Alpha1(t *testing.T) { } nt.T.Log("Test RepoSync v1alpha1 version in central control mode") - nt.NonRootRepos[nn] = nsRepo - rs := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, nn) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(bsNamespace, rs.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add RepoSync v1alpha1")) + nt.SyncSources[repoSyncID] = repoSyncSource + rs := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, repoSyncKey) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(bsNamespace, rs.Name), rs)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add RepoSync v1alpha1")) // Add the bookstore namespace repo back to NamespaceRepos to verify that it is synced. if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -456,7 +461,7 @@ func TestDeleteRepoSync_Centralized_AndRepoSyncV1Alpha1(t *testing.T) { } err = nomostest.ValidateStandardMetricsForRepoSync(nt, metrics.Summary{ - Sync: nn, + Sync: repoSyncKey, }) if err != nil { nt.T.Fatal(err) @@ -468,16 +473,17 @@ func TestManageSelfRepoSync(t *testing.T) { nt := nomostest.New(t, nomostesting.MultiRepos, ntopts.RepoSyncPermissions(policy.CoreAdmin()), // NS Reconciler manages ServiceAccounts ntopts.NamespaceRepo(bsNamespace, configsync.RepoSyncName)) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, bsNamespace) + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) rs := &v1beta1.RepoSync{} - if err := nt.KubeClient.Get(configsync.RepoSyncName, bsNamespace, rs); err != nil { + if err := nt.KubeClient.Get(repoSyncID.Name, repoSyncID.Namespace, rs); err != nil { nt.T.Fatal(err) } sanitizedRs := k8sobjects.RepoSyncObjectV1Beta1(rs.Namespace, rs.Name) sanitizedRs.Spec = rs.Spec - rsNN := nomostest.RepoSyncNN(rs.Namespace, rs.Name) - nt.Must(nt.NonRootRepos[rsNN].Add("acme/repo-sync.yaml", sanitizedRs)) - nt.Must(nt.NonRootRepos[rsNN].CommitAndPush("add the repo-sync object that configures the reconciler")) + nt.Must(repoSyncGitRepo.Add("acme/repo-sync.yaml", sanitizedRs)) + nt.Must(repoSyncGitRepo.CommitAndPush("add the repo-sync object that configures the reconciler")) nt.WaitForRepoSyncSourceError(rs.Namespace, rs.Name, validate.SelfReconcileErrorCode, "RepoSync bookstore/repo-sync must not manage itself in its repo") } @@ -531,16 +537,20 @@ func checkRepoSyncResourcesNotPresent(nt *nomostest.NT, namespace string, secret func TestDeleteNamespaceReconcilerDeployment(t *testing.T) { bsNamespace := "bookstore" - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) - repoSyncNN := nomostest.RepoSyncNN(bsNamespace, configsync.RepoSyncName) nt := nomostest.New( t, nomostesting.MultiRepos, ntopts.NamespaceRepo(bsNamespace, configsync.RepoSyncName), ntopts.WithCentralizedControl, ) + rootSyncID := nomostest.DefaultRootSyncID + rootSyncKey := rootSyncID.ObjectKey + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, bsNamespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) - nsReconciler := core.NsReconcilerName(bsNamespace, configsync.RepoSyncName) + nsReconciler := core.NsReconcilerName(repoSyncID.Namespace, repoSyncID.Name) // Validate status condition "Reconciling" and Stalled is set to "False" after // the reconciler deployment is successfully created. @@ -551,7 +561,7 @@ func TestDeleteNamespaceReconcilerDeployment(t *testing.T) { // conditions. // Here we are checking for false condition which requires atleast 2 reconcile // request to be processed by the controller. - err := nt.Watcher.WatchObject(kinds.RepoSyncV1Beta1(), configsync.RepoSyncName, bsNamespace, + err := nt.Watcher.WatchObject(kinds.RepoSyncV1Beta1(), repoSyncID.Name, repoSyncID.Namespace, []testpredicates.Predicate{ hasReconcilingStatus(metav1.ConditionFalse), hasStalledStatus(metav1.ConditionFalse), @@ -568,7 +578,7 @@ func TestDeleteNamespaceReconcilerDeployment(t *testing.T) { // Verify that the deployment is re-created after deletion by checking the // Reconciling and Stalled condition in RepoSync resource. - err = nt.Watcher.WatchObject(kinds.RepoSyncV1Beta1(), configsync.RepoSyncName, bsNamespace, + err = nt.Watcher.WatchObject(kinds.RepoSyncV1Beta1(), repoSyncID.Name, repoSyncID.Namespace, []testpredicates.Predicate{ hasReconcilingStatus(metav1.ConditionFalse), hasStalledStatus(metav1.ConditionFalse), @@ -577,16 +587,16 @@ func TestDeleteNamespaceReconcilerDeployment(t *testing.T) { nt.T.Errorf("RepoSync did not finish reconciling: %v", err) } - rootSyncLabels, err := nomostest.MetricLabelsForRootSync(nt, rootSyncNN) + rootSyncLabels, err := nomostest.MetricLabelsForRootSync(nt, rootSyncKey) if err != nil { nt.T.Fatal(err) } - repoSyncLabels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncNN) + repoSyncLabels, err := nomostest.MetricLabelsForRepoSync(nt, repoSyncKey) if err != nil { nt.T.Fatal(err) } - rootCommitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) - nnCommitHash := nt.NonRootRepos[repoSyncNN].MustHash(nt.T) + rootCommitHash := rootSyncGitRepo.MustHash(nt.T) + nnCommitHash := repoSyncGitRepo.MustHash(nt.T) // Skip sync & ops metrics and just validate reconciler-manager and reconciler errors. err = nomostest.ValidateMetrics(nt, diff --git a/e2e/testcases/namespace_selectors_test.go b/e2e/testcases/namespace_selectors_test.go index a750244f3a..07bee8bfb1 100644 --- a/e2e/testcases/namespace_selectors_test.go +++ b/e2e/testcases/namespace_selectors_test.go @@ -77,6 +77,7 @@ var ( func TestNamespaceSelectorHierarchicalFormat(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) bookstoreNSS := k8sobjects2.NamespaceSelectorObject(core.Name(bookstoreNSSName)) bookstoreCM := k8sobjects2.ConfigMapObject(core.Name(bookstoreCMName), @@ -95,21 +96,21 @@ func TestNamespaceSelectorHierarchicalFormat(t *testing.T) { shoestoreNSS.Spec.Selector.MatchLabels = map[string]string{"app": shoestoreNS} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/namespace-selector-bookstore.yaml", bookstoreNSS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/namespace-selector-shoestore.yaml", shoestoreNSS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/bookstore/ns.yaml", k8sobjects2.NamespaceObject(bookstoreNS, core.Label("app", bookstoreNS)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/shoestore/ns.yaml", k8sobjects2.NamespaceObject(shoestoreNS, core.Label("app", shoestoreNS)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/cm-bookstore.yaml", bookstoreCM)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/rq-bookstore.yaml", bookstoreRQ)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/cm-shoestore.yaml", shoestoreCM)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add Namespaces, NamespaceSelectors and Namespace-scoped resources")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/namespace-selector-bookstore.yaml", bookstoreNSS)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/namespace-selector-shoestore.yaml", shoestoreNSS)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/bookstore/ns.yaml", k8sobjects2.NamespaceObject(bookstoreNS, core.Label("app", bookstoreNS)))) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/shoestore/ns.yaml", k8sobjects2.NamespaceObject(shoestoreNS, core.Label("app", shoestoreNS)))) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/cm-bookstore.yaml", bookstoreCM)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/rq-bookstore.yaml", bookstoreRQ)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/cm-shoestore.yaml", shoestoreCM)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add Namespaces, NamespaceSelectors and Namespace-scoped resources")) nt.WaitForRootSyncSourceError(configsync.RootSyncName, selectors.InvalidSelectorErrorCode, "NamespaceSelector MUST NOT use the dynamic mode with the hierarchy source format") nt.T.Log("Update NamespaceSelector to use static mode with the hierarchy format") bookstoreNSS.Spec.Mode = v1.NSSelectorStaticMode - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/namespace-selector-bookstore.yaml", bookstoreNSS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update NamespaceSelector to use static mode")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/namespace-selector-bookstore.yaml", bookstoreNSS)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update NamespaceSelector to use static mode")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -123,6 +124,7 @@ func TestNamespaceSelectorHierarchicalFormat(t *testing.T) { func TestNamespaceSelectorUnstructuredFormat(t *testing.T) { nt := nomostest.New(t, nomostesting.Selector, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) bookstoreNSS := k8sobjects2.NamespaceSelectorObject(core.Name(bookstoreNSSName)) bookstoreCM := k8sobjects2.ConfigMapObject(core.Name(bookstoreCMName), @@ -140,13 +142,13 @@ func TestNamespaceSelectorUnstructuredFormat(t *testing.T) { shoestoreNSS.Spec.Selector.MatchLabels = map[string]string{"app": shoestoreNS} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespace-selector-bookstore.yaml", bookstoreNSS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespace-selector-shoestore.yaml", shoestoreNSS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/shoestore-ns.yaml", k8sobjects2.NamespaceObject(shoestoreNS, core.Label("app", shoestoreNS)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm-bookstore.yaml", bookstoreCM)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/rq-bookstore.yaml", bookstoreRQ)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm-shoestore.yaml", shoestoreCM)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add Namespaces, NamespaceSelectors and Namespace-scoped resources")) + nt.Must(rootSyncGitRepo.Add("acme/namespace-selector-bookstore.yaml", bookstoreNSS)) + nt.Must(rootSyncGitRepo.Add("acme/namespace-selector-shoestore.yaml", shoestoreNSS)) + nt.Must(rootSyncGitRepo.Add("acme/shoestore-ns.yaml", k8sobjects2.NamespaceObject(shoestoreNS, core.Label("app", shoestoreNS)))) + nt.Must(rootSyncGitRepo.Add("acme/cm-bookstore.yaml", bookstoreCM)) + nt.Must(rootSyncGitRepo.Add("acme/rq-bookstore.yaml", bookstoreRQ)) + nt.Must(rootSyncGitRepo.Add("acme/cm-shoestore.yaml", shoestoreCM)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add Namespaces, NamespaceSelectors and Namespace-scoped resources")) nt.Logger.Info("Only resources in shoestore are created because bookstore Namespace is not declared") if err := nt.WatchForAllSyncs(); err != nil { @@ -176,8 +178,8 @@ func TestNamespaceSelectorUnstructuredFormat(t *testing.T) { nt.Logger.Info("Update NamespaceSelector to use dynamic mode") bookstoreNSS.Spec.Mode = v1.NSSelectorDynamicMode - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespace-selector-bookstore.yaml", bookstoreNSS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update NamespaceSelector to use dynamic mode")) + nt.Must(rootSyncGitRepo.Add("acme/namespace-selector-bookstore.yaml", bookstoreNSS)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update NamespaceSelector to use dynamic mode")) if err := nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, @@ -241,8 +243,8 @@ func TestNamespaceSelectorUnstructuredFormat(t *testing.T) { nt.Logger.Info("Update NamespaceSelector to use static mode") bookstoreNSS.Spec.Mode = v1.NSSelectorStaticMode - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespace-selector-bookstore.yaml", bookstoreNSS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update NamespaceSelector to use static mode")) + nt.Must(rootSyncGitRepo.Add("acme/namespace-selector-bookstore.yaml", bookstoreNSS)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update NamespaceSelector to use static mode")) if err := nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, @@ -273,8 +275,8 @@ func TestNamespaceSelectorUnstructuredFormat(t *testing.T) { nt.Logger.Info("Update NamespaceSelector back to use dynamic mode") bookstoreNSS.Spec.Mode = v1.NSSelectorDynamicMode - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespace-selector-bookstore.yaml", bookstoreNSS)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update NamespaceSelector to use dynamic mode again")) + nt.Must(rootSyncGitRepo.Add("acme/namespace-selector-bookstore.yaml", bookstoreNSS)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update NamespaceSelector to use dynamic mode again")) if err := nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, diff --git a/e2e/testcases/namespace_strategy_test.go b/e2e/testcases/namespace_strategy_test.go index ff9cae92fd..5180c736f5 100644 --- a/e2e/testcases/namespace_strategy_test.go +++ b/e2e/testcases/namespace_strategy_test.go @@ -48,6 +48,7 @@ import ( // - Prune "cm1" from git. The Namespace and ConfigMap should be successfully pruned. func TestNamespaceStrategy(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) rootReconcilerNN := core.RootReconcilerObjectKey(rootSyncNN.Name) @@ -70,8 +71,8 @@ func TestNamespaceStrategy(t *testing.T) { // add a resource for which the namespace is not declared/created fooNamespace := k8sobjects.NamespaceObject("foo-implicit") cm1 := k8sobjects.ConfigMapObject(core.Name("cm1"), core.Namespace(fooNamespace.Name)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", cm1)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add cm1")) + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", cm1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add cm1")) // check for error nt.WaitForRootSyncSyncError(rootSyncNN.Name, applier.ApplierErrorCode, @@ -117,8 +118,8 @@ func TestNamespaceStrategy(t *testing.T) { nt.T.Fatal(err) } // explicitly declare the namespace in git - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespace-foo.yaml", fooNamespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Explicitly manage fooNamespace")) + nt.Must(rootSyncGitRepo.Add("acme/namespace-foo.yaml", fooNamespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Explicitly manage fooNamespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -137,14 +138,14 @@ func TestNamespaceStrategy(t *testing.T) { nt.T.Fatal(err) } // prune the namespace - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespace-foo.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Prune namespace-foo")) + nt.Must(rootSyncGitRepo.Remove("acme/namespace-foo.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Prune namespace-foo")) // check for error nt.WaitForRootSyncSyncError(rootSyncNN.Name, applier.ApplierErrorCode, "skipped delete of Namespace, /foo-implicit: namespace still in use: foo-implicit", nil) // prune the ConfigMap - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Prune cm1")) + nt.Must(rootSyncGitRepo.Remove("acme/cm1.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Prune cm1")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -166,33 +167,42 @@ func TestNamespaceStrategy(t *testing.T) { // When using multiple RootSyncs that declare resources in the same namespace, // the namespace should only be created if declared explicitly in a sync source. func TestNamespaceStrategyMultipleRootSyncs(t *testing.T) { + rootSyncID := nomostest.DefaultRootSyncID + rootSyncAID := nomostest.RootSyncID("sync-a") + rootSyncXID := nomostest.RootSyncID("sync-x") + rootSyncYID := nomostest.RootSyncID("sync-y") namespaceA := k8sobjects.NamespaceObject("namespace-a") nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.Unstructured, - ntopts.RootRepo("sync-a"), // will declare namespace-a explicitly - ntopts.RootRepo("sync-x"), // will declare resources in namespace-a, but not namespace-a itself - ntopts.RootRepo("sync-y"), // will declare resources in namespace-a, but not namespace-a itself + ntopts.RootRepo(rootSyncAID.Name), // will declare namespace-a explicitly + ntopts.RootRepo(rootSyncXID.Name), // will declare resources in namespace-a, but not namespace-a itself + ntopts.RootRepo(rootSyncYID.Name), // will declare resources in namespace-a, but not namespace-a itself ) - rootSyncA := nomostest.RootSyncObjectV1Beta1FromRootRepo(nt, "sync-a") - rootSyncX := nomostest.RootSyncObjectV1Beta1FromRootRepo(nt, "sync-x") - rootSyncY := nomostest.RootSyncObjectV1Beta1FromRootRepo(nt, "sync-y") + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + rootSyncAGitRepo := nt.SyncSourceGitRepository(rootSyncAID) + rootSyncXGitRepo := nt.SyncSourceGitRepository(rootSyncXID) + rootSyncYGitRepo := nt.SyncSourceGitRepository(rootSyncYID) + + rootSyncA := nomostest.RootSyncObjectV1Beta1FromRootRepo(nt, rootSyncAID.Name) + rootSyncX := nomostest.RootSyncObjectV1Beta1FromRootRepo(nt, rootSyncXID.Name) + rootSyncY := nomostest.RootSyncObjectV1Beta1FromRootRepo(nt, rootSyncYID.Name) rootSyncA.Spec.SafeOverride().NamespaceStrategy = configsync.NamespaceStrategyExplicit rootSyncX.Spec.SafeOverride().NamespaceStrategy = configsync.NamespaceStrategyExplicit rootSyncY.Spec.SafeOverride().NamespaceStrategy = configsync.NamespaceStrategyExplicit // set the NamespaceStrategy to explicit - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s/%s.yaml", configsync.ControllerNamespace, rootSyncA.Name), rootSyncA, )) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s/%s.yaml", configsync.ControllerNamespace, rootSyncX.Name), rootSyncX, )) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s/%s.yaml", configsync.ControllerNamespace, rootSyncY.Name), rootSyncY, )) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush( + nt.Must(rootSyncGitRepo.CommitAndPush( fmt.Sprintf("Adding RootSyncs (%s, %s, %s) with namespaceStrategy=explicit", rootSyncA.Name, rootSyncX.Name, rootSyncY.Name), )) @@ -221,19 +231,19 @@ func TestNamespaceStrategyMultipleRootSyncs(t *testing.T) { } // add a resource for which the namespace is not declared/created cmX := k8sobjects.ConfigMapObject(core.Name("cm-x"), core.Namespace(namespaceA.Name)) - nt.Must(nt.RootRepos[rootSyncX.Name].Add("acme/cm-x.yaml", cmX)) - nt.Must(nt.RootRepos[rootSyncX.Name].CommitAndPush("Add cm-x")) + nt.Must(rootSyncXGitRepo.Add("acme/cm-x.yaml", cmX)) + nt.Must(rootSyncXGitRepo.CommitAndPush("Add cm-x")) cmY := k8sobjects.ConfigMapObject(core.Name("cm-y"), core.Namespace(namespaceA.Name)) - nt.Must(nt.RootRepos[rootSyncY.Name].Add("acme/cm-y.yaml", cmY)) - nt.Must(nt.RootRepos[rootSyncY.Name].CommitAndPush("Add cm-y")) + nt.Must(rootSyncYGitRepo.Add("acme/cm-y.yaml", cmY)) + nt.Must(rootSyncYGitRepo.CommitAndPush("Add cm-y")) // check for error nt.WaitForRootSyncSyncError(rootSyncX.Name, applier.ApplierErrorCode, "failed to apply ConfigMap, namespace-a/cm-x: namespaces \"namespace-a\" not found", nil) nt.WaitForRootSyncSyncError(rootSyncY.Name, applier.ApplierErrorCode, "failed to apply ConfigMap, namespace-a/cm-y: namespaces \"namespace-a\" not found", nil) // declare the namespace in sync-a - nt.Must(nt.RootRepos[rootSyncA.Name].Add("acme/namespace-a.yaml", namespaceA)) - nt.Must(nt.RootRepos[rootSyncA.Name].CommitAndPush("Add namespace-a")) + nt.Must(rootSyncAGitRepo.Add("acme/namespace-a.yaml", namespaceA)) + nt.Must(rootSyncAGitRepo.CommitAndPush("Add namespace-a")) // check for success if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) diff --git a/e2e/testcases/namespaces_test.go b/e2e/testcases/namespaces_test.go index a9edbcb620..4eb3823982 100644 --- a/e2e/testcases/namespaces_test.go +++ b/e2e/testcases/namespaces_test.go @@ -43,6 +43,7 @@ import ( // TestDeclareNamespace runs a test that ensures ACM syncs Namespaces to clusters. func TestDeclareNamespace(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) err := nt.ValidateNotFound("foo", "", &corev1.Namespace{}) if err != nil { @@ -51,8 +52,8 @@ func TestDeclareNamespace(t *testing.T) { } nsObj := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add Namespace")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("add Namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -76,11 +77,12 @@ func TestDeclareNamespace(t *testing.T) { func TestNamespaceLabelAndAnnotationLifecycle(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Create foo namespace without any labels or annotations. nsObj := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Create foo namespace")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Create foo namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -104,8 +106,8 @@ func TestNamespaceLabelAndAnnotationLifecycle(t *testing.T) { // Add label and annotation to namespace. nsObj.Labels["label"] = "test-label" nsObj.Annotations["annotation"] = "test-annotation" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Updated foo namespace to include label and annotation")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Updated foo namespace to include label and annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -128,8 +130,8 @@ func TestNamespaceLabelAndAnnotationLifecycle(t *testing.T) { // Update label and annotation to namespace. nsObj.Labels["label"] = "updated-test-label" nsObj.Annotations["annotation"] = "updated-test-annotation" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Updated foo namespace to include label and annotation")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Updated foo namespace to include label and annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -152,8 +154,8 @@ func TestNamespaceLabelAndAnnotationLifecycle(t *testing.T) { // Remove label and annotation to namespace and commit. delete(nsObj.Labels, "label") delete(nsObj.Annotations, "annotation") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Updated foo namespace, removing label and annotation")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Updated foo namespace, removing label and annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -176,12 +178,13 @@ func TestNamespaceLabelAndAnnotationLifecycle(t *testing.T) { func TestNamespaceExistsAndDeclared(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Create nsObj using kubectl first then commit. nsObj := k8sobjects.NamespaceObject("decl-namespace-annotation-none") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/decl-namespace-annotation-none/ns.yaml", nsObj)) - nt.MustKubectl("apply", "-f", filepath.Join(nt.RootRepos[configsync.RootSyncName].Root, "acme/namespaces/decl-namespace-annotation-none/ns.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add namespace")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/decl-namespace-annotation-none/ns.yaml", nsObj)) + nt.MustKubectl("apply", "-f", filepath.Join(rootSyncGitRepo.Root, "acme/namespaces/decl-namespace-annotation-none/ns.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -206,13 +209,14 @@ func TestNamespaceExistsAndDeclared(t *testing.T) { func TestNamespaceEnabledAnnotationNotDeclared(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Create nsObj with managed annotation using kubectl. nsObj := k8sobjects.NamespaceObject("undeclared-annotation-enabled") nsObj.Annotations["configmanagement.gke.io/managed"] = "enabled" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("ns.yaml", nsObj)) - nt.MustKubectl("apply", "-f", filepath.Join(nt.RootRepos[configsync.RootSyncName].Root, "ns.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("ns.yaml")) + nt.Must(rootSyncGitRepo.Add("ns.yaml", nsObj)) + nt.MustKubectl("apply", "-f", filepath.Join(rootSyncGitRepo.Root, "ns.yaml")) + nt.Must(rootSyncGitRepo.Remove("ns.yaml")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -236,6 +240,7 @@ func TestNamespaceEnabledAnnotationNotDeclared(t *testing.T) { // TestManagementDisabledNamespace tests https://cloud.google.com/anthos-config-management/docs/how-to/managing-objects#unmanaged-namespaces. func TestManagementDisabledNamespace(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) checkpointProtectedNamespace(nt, metav1.NamespaceDefault) @@ -246,9 +251,9 @@ func TestManagementDisabledNamespace(t *testing.T) { // Create nsObj. nsObj := k8sobjects.NamespaceObject(nsName) cm1 := k8sobjects.ConfigMapObject(core.Namespace(nsName), core.Name("cm1")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsName), nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/cm1.yaml", nsName), cm1)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Create a namespace and a configmap")) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsName), nsObj)) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/cm1.yaml", nsName), cm1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Create a namespace and a configmap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -278,9 +283,9 @@ func TestManagementDisabledNamespace(t *testing.T) { // Update the namespace and the configmap to be no longer be managed nsObj.Annotations[metadata.ResourceManagementKey] = metadata.ResourceManagementDisabled cm1.Annotations[metadata.ResourceManagementKey] = metadata.ResourceManagementDisabled - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsName), nsObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/cm1.yaml", nsName), cm1)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Unmanage the namespace and the configmap")) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsName), nsObj)) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/cm1.yaml", nsName), cm1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Unmanage the namespace and the configmap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -308,8 +313,8 @@ func TestManagementDisabledNamespace(t *testing.T) { } // Remove the namspace and the configmap from the repository - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(fmt.Sprintf("acme/namespaces/%s", nsName))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the namespace and the configmap")) + nt.Must(rootSyncGitRepo.Remove(fmt.Sprintf("acme/namespaces/%s", nsName))) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the namespace and the configmap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -356,6 +361,7 @@ func TestManagementDisabledConfigMap(t *testing.T) { "acme/namespaces/foo/cm3.yaml": cm3, }, })) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Test that the namespace exists with expected config management labels and annotations. err := nt.Validate(fooNamespace.Name, "", &corev1.Namespace{}, testpredicates.HasAllNomosMetadata()) @@ -397,9 +403,9 @@ func TestManagementDisabledConfigMap(t *testing.T) { // Update the configmap to be no longer be managed cm1.Annotations[metadata.ResourceManagementKey] = metadata.ResourceManagementDisabled - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/cm1.yaml", cm1)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/foo/cm3.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Unmanage cm1 and remove cm3")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/cm1.yaml", cm1)) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/foo/cm3.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Unmanage cm1 and remove cm3")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -432,8 +438,8 @@ func TestManagementDisabledConfigMap(t *testing.T) { } // Remove the configmap from the repository - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/foo/cm1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the configmap")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/foo/cm1.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the configmap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -469,6 +475,7 @@ func TestManagementDisabledConfigMap(t *testing.T) { func TestSyncLabelsAndAnnotationsOnKubeSystem(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2, ntopts.SkipAutopilotCluster) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) checkpointProtectedNamespace(nt, metav1.NamespaceSystem) @@ -476,8 +483,8 @@ func TestSyncLabelsAndAnnotationsOnKubeSystem(t *testing.T) { kubeSystemNamespace := k8sobjects.NamespaceObject(metav1.NamespaceSystem) kubeSystemNamespace.Labels["test-corp.com/awesome-controller-flavour"] = "fuzzy" kubeSystemNamespace.Annotations["test-corp.com/awesome-controller-mixin"] = "green" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/kube-system/ns.yaml", kubeSystemNamespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add namespace")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/kube-system/ns.yaml", kubeSystemNamespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Add namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -504,8 +511,8 @@ func TestSyncLabelsAndAnnotationsOnKubeSystem(t *testing.T) { // Remove label and annotation from the kube-system namespace. delete(kubeSystemNamespace.Labels, "test-corp.com/awesome-controller-flavour") delete(kubeSystemNamespace.Annotations, "test-corp.com/awesome-controller-mixin") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/kube-system/ns.yaml", kubeSystemNamespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove label and annotation")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/kube-system/ns.yaml", kubeSystemNamespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove label and annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -528,8 +535,8 @@ func TestSyncLabelsAndAnnotationsOnKubeSystem(t *testing.T) { // Update kube-system namespace to be no longer be managed. kubeSystemNamespace.Annotations["configmanagement.gke.io/managed"] = "disabled" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/kube-system/ns.yaml", kubeSystemNamespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update namespace to no longer be managed")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/kube-system/ns.yaml", kubeSystemNamespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update namespace to no longer be managed")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -552,13 +559,14 @@ func TestSyncLabelsAndAnnotationsOnKubeSystem(t *testing.T) { func TestDoNotRemoveManagedByLabelExceptForConfigManagement(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Create namespace using kubectl with managed by helm label. helmManagedNamespace := k8sobjects.NamespaceObject("helm-managed-namespace") helmManagedNamespace.Labels["app.kubernetes.io/managed-by"] = "helm" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("ns.yaml", helmManagedNamespace)) - nt.MustKubectl("apply", "-f", filepath.Join(nt.RootRepos[configsync.RootSyncName].Root, "ns.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("ns.yaml")) + nt.Must(rootSyncGitRepo.Add("ns.yaml", helmManagedNamespace)) + nt.MustKubectl("apply", "-f", filepath.Join(rootSyncGitRepo.Root, "ns.yaml")) + nt.Must(rootSyncGitRepo.Remove("ns.yaml")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -583,6 +591,7 @@ func TestDoNotRemoveManagedByLabelExceptForConfigManagement(t *testing.T) { func TestDeclareImplicitNamespace(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) var unixMilliseconds = time.Now().UnixNano() / 1000000 var implicitNamespace = "shipping-" + fmt.Sprint(unixMilliseconds) @@ -596,8 +605,8 @@ func TestDeclareImplicitNamespace(t *testing.T) { // Phase 1: Declare a Role in a Namespace that doesn't exist, and ensure it // gets created. roleObj := k8sobjects.RoleObject(core.Name("admin"), core.Namespace(implicitNamespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/role.yaml", roleObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add Role in implicit Namespace " + implicitNamespace)) + nt.Must(rootSyncGitRepo.Add("acme/role.yaml", roleObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("add Role in implicit Namespace " + implicitNamespace)) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -624,8 +633,8 @@ func TestDeclareImplicitNamespace(t *testing.T) { } // Phase 2: Remove the Role, and ensure the implicit Namespace is NOT deleted. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/role.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove Role")) + nt.Must(rootSyncGitRepo.Remove("acme/role.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("remove Role")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -658,14 +667,15 @@ func TestDeclareImplicitNamespace(t *testing.T) { func TestDontDeleteAllNamespaces(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Test Setup + Preconditions. // Declare two Namespaces. fooNS := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/foo/ns.yaml", k8sobjects.NamespaceObject("foo"))) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/foo/ns.yaml", k8sobjects.NamespaceObject("foo"))) barNS := k8sobjects.NamespaceObject("bar") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/bar/ns.yaml", k8sobjects.NamespaceObject("bar"))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("declare multiple Namespaces")) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/bar/ns.yaml", k8sobjects.NamespaceObject("bar"))) + nt.Must(rootSyncGitRepo.CommitAndPush("declare multiple Namespaces")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -692,10 +702,10 @@ func TestDontDeleteAllNamespaces(t *testing.T) { // Remove the all declared Namespaces. // We expect this to fail. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/foo/ns.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/namespaces/bar/ns.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].RemoveSafetyNamespace()) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("undeclare all Namespaces")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/foo/ns.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/namespaces/bar/ns.yaml")) + nt.Must(rootSyncGitRepo.RemoveSafetyNamespace()) + nt.Must(rootSyncGitRepo.CommitAndPush("undeclare all Namespaces")) require.NoError(nt.T, nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, []testpredicates.Predicate{ @@ -721,14 +731,14 @@ func TestDontDeleteAllNamespaces(t *testing.T) { // we do expect them to have been removed from the declared_resources metric. nt.MetricsExpectations.RemoveObject(configsync.RootSyncKind, rootSyncNN, fooNS) nt.MetricsExpectations.RemoveObject(configsync.RootSyncKind, rootSyncNN, barNS) - safetyNSObj := k8sobjects.NamespaceObject(nt.RootRepos[configsync.RootSyncName].SafetyNSName) + safetyNSObj := k8sobjects.NamespaceObject(rootSyncGitRepo.SafetyNSName) nt.MetricsExpectations.RemoveObject(configsync.RootSyncKind, rootSyncNN, safetyNSObj) rootSyncLabels, err := nomostest.MetricLabelsForRootSync(nt, rootSyncNN) if err != nil { nt.T.Fatal(err) } - commitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + commitHash := rootSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerSyncError(nt, rootSyncLabels, commitHash), @@ -744,9 +754,9 @@ func TestDontDeleteAllNamespaces(t *testing.T) { } // Add safety back so we resume syncing. - safetyNs := nt.RootRepos[configsync.RootSyncName].SafetyNSName - nt.Must(nt.RootRepos[configsync.RootSyncName].AddSafetyNamespace()) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("re-declare safety Namespace")) + safetyNs := rootSyncGitRepo.SafetyNSName + nt.Must(rootSyncGitRepo.AddSafetyNamespace()) + nt.Must(rootSyncGitRepo.CommitAndPush("re-declare safety Namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -777,8 +787,8 @@ func TestDontDeleteAllNamespaces(t *testing.T) { // Undeclare safety. We expect this to succeed since the user unambiguously wants // all Namespaces to be removed. - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(nt.RootRepos[configsync.RootSyncName].SafetyNSPath)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("undeclare safety Namespace")) + nt.Must(rootSyncGitRepo.Remove(rootSyncGitRepo.SafetyNSPath)) + nt.Must(rootSyncGitRepo.CommitAndPush("undeclare safety Namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/no_ssl_verify_test.go b/e2e/testcases/no_ssl_verify_test.go index 511a8c4e39..d854a50480 100644 --- a/e2e/testcases/no_ssl_verify_test.go +++ b/e2e/testcases/no_ssl_verify_test.go @@ -35,6 +35,8 @@ import ( func TestNoSSLVerifyV1Alpha1(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -76,8 +78,8 @@ func TestNoSSLVerifyV1Alpha1(t *testing.T) { // Set noSSLVerify to true for ns-reconciler-backend repoSyncBackend.Spec.NoSSLVerify = true - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync NoSSLVerify to true")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync NoSSLVerify to true")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -98,8 +100,8 @@ func TestNoSSLVerifyV1Alpha1(t *testing.T) { // Set noSSLVerify to false from repoSyncBackend repoSyncBackend.Spec.NoSSLVerify = false - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync NoSSLVerify to false")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync NoSSLVerify to false")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -114,6 +116,8 @@ func TestNoSSLVerifyV1Alpha1(t *testing.T) { func TestNoSSLVerifyV1Beta1(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -155,8 +159,8 @@ func TestNoSSLVerifyV1Beta1(t *testing.T) { // Set noSSLVerify to true for ns-reconciler-backend repoSyncBackend.Spec.NoSSLVerify = true - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync NoSSLVerify to true")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync NoSSLVerify to true")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -177,8 +181,8 @@ func TestNoSSLVerifyV1Beta1(t *testing.T) { // Set noSSLVerify to false from repoSyncBackend repoSyncBackend.Spec.NoSSLVerify = false - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync NoSSLVerify to false")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync NoSSLVerify to false")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/oci_sync_test.go b/e2e/testcases/oci_sync_test.go index b6b9bea1b4..3498712ab5 100644 --- a/e2e/testcases/oci_sync_test.go +++ b/e2e/testcases/oci_sync_test.go @@ -118,22 +118,23 @@ func TestSwitchFromGitToOciCentralized(t *testing.T) { // bookinfo repo contains ServiceAccount ntopts.RepoSyncPermissions(policy.RBACAdmin(), policy.CoreAdmin()), ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, namespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + var err error // file path to the RepoSync config in the root repository. repoSyncPath := nomostest.StructuredNSPath(namespace, configsync.RepoSyncName) - rsNN := types.NamespacedName{ - Name: configsync.RepoSyncName, - Namespace: namespace, - } // Remote git branch will only contain the bookinfo-sa ServiceAccount bookinfoSA := k8sobjects.ServiceAccountObject("bookinfo-sa", core.Namespace(namespace)) - nt.Must(nt.NonRootRepos[rsNN].Add("acme/sa.yaml", bookinfoSA)) - nt.Must(nt.NonRootRepos[rsNN].CommitAndPush("Add ServiceAccount")) + nt.Must(repoSyncGitRepo.Add("acme/sa.yaml", bookinfoSA)) + nt.Must(repoSyncGitRepo.CommitAndPush("Add ServiceAccount")) // OCI image will only contain the bookinfo-admin role bookinfoRole := k8sobjects.RoleObject(core.Name("bookinfo-admin")) - image, err := nt.BuildAndPushOCIImage(rsNN, registryproviders.ImageInputObjects(nt.Scheme, bookinfoRole)) + image, err := nt.BuildAndPushOCIImage(repoSyncKey, registryproviders.ImageInputObjects(nt.Scheme, bookinfoRole)) if err != nil { nt.T.Fatal(err) } @@ -151,14 +152,14 @@ func TestSwitchFromGitToOciCentralized(t *testing.T) { // Switch from Git to OCI nt.T.Log("Update the RepoSync object to sync from OCI") - repoSyncOCI := nt.RepoSyncObjectOCI(rsNN, image) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(repoSyncPath, repoSyncOCI)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("configure RepoSync to sync from OCI in the root repository")) + repoSyncOCI := nt.RepoSyncObjectOCI(repoSyncKey, image) + nt.Must(rootSyncGitRepo.Add(repoSyncPath, repoSyncOCI)) + nt.Must(rootSyncGitRepo.CommitAndPush("configure RepoSync to sync from OCI in the root repository")) if err := nt.WatchForAllSyncs( nomostest.WithRepoSha1Func(imageDigestFuncByDigest(image.Digest)), nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{ - rsNN: ".", + repoSyncKey: ".", })); err != nil { nt.T.Fatal(err) } @@ -183,19 +184,18 @@ func TestSwitchFromGitToOciDelegated(t *testing.T) { // bookinfo repo contains ServiceAccount ntopts.RepoSyncPermissions(policy.RBACAdmin(), policy.CoreAdmin()), ) - rsNN := types.NamespacedName{ - Name: configsync.RepoSyncName, - Namespace: namespace, - } + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, namespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) // Remote git branch will only contain the bookinfo-sa ServiceAccount bookinfoSA := k8sobjects.ServiceAccountObject("bookinfo-sa", core.Namespace(namespace)) - nt.Must(nt.NonRootRepos[rsNN].Add("acme/sa.yaml", bookinfoSA)) - nt.Must(nt.NonRootRepos[rsNN].CommitAndPush("Add ServiceAccount")) + nt.Must(repoSyncGitRepo.Add("acme/sa.yaml", bookinfoSA)) + nt.Must(repoSyncGitRepo.CommitAndPush("Add ServiceAccount")) // OCI image will only contain the bookinfo-admin role bookinfoRole := k8sobjects.RoleObject(core.Name("bookinfo-admin")) - image, err := nt.BuildAndPushOCIImage(rsNN, registryproviders.ImageInputObjects(nt.Scheme, bookinfoRole)) + image, err := nt.BuildAndPushOCIImage(repoSyncKey, registryproviders.ImageInputObjects(nt.Scheme, bookinfoRole)) if err != nil { nt.T.Fatal(err) } @@ -215,7 +215,7 @@ func TestSwitchFromGitToOciDelegated(t *testing.T) { } // Switch from Git to OCI - repoSyncOCI := nt.RepoSyncObjectOCI(rsNN, image) + repoSyncOCI := nt.RepoSyncObjectOCI(repoSyncKey, image) nt.T.Log("Manually update the RepoSync object to sync from OCI") if err := nt.KubeClient.Apply(repoSyncOCI); err != nil { nt.T.Fatal(err) diff --git a/e2e/testcases/otel_collector_test.go b/e2e/testcases/otel_collector_test.go index 50ca517780..aa1c96dc5f 100644 --- a/e2e/testcases/otel_collector_test.go +++ b/e2e/testcases/otel_collector_test.go @@ -116,6 +116,7 @@ func TestOtelCollectorDeployment(t *testing.T) { ntopts.RequireGKE(t), ntopts.Unstructured, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Cleanup(func() { if t.Failed() { nt.PodLogs("config-management-monitoring", csmetrics.OtelCollectorName, "", false) @@ -131,8 +132,8 @@ func TestOtelCollectorDeployment(t *testing.T) { nt.T.Log("Adding test commit after otel-collector is started up so multiple commit hashes are processed in pipelines") namespace := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding foo namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding foo namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -183,8 +184,8 @@ func TestOtelCollectorDeployment(t *testing.T) { // Change the RootSync to sync from kustomize-components dir to enable Kustomize metrics nt.T.Log("Add the kustomize components root directory to enable kustomize metrics") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/kustomize-components", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/kustomize-components", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the kustomize-components directory") rs := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) @@ -237,6 +238,7 @@ func TestGCMMetrics(t *testing.T) { ntopts.RequireGKE(t), ntopts.Unstructured, ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Cleanup(func() { if t.Failed() { nt.PodLogs("config-management-monitoring", csmetrics.OtelCollectorName, "", false) @@ -273,8 +275,8 @@ func TestGCMMetrics(t *testing.T) { nt.T.Log("Adding test namespace") namespace := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding foo namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding foo namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -290,8 +292,8 @@ func TestGCMMetrics(t *testing.T) { } nt.T.Log("Remove the test resource") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/ns.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the test namespace")) + nt.Must(rootSyncGitRepo.Remove("acme/ns.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the test namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -320,14 +322,15 @@ func TestGCMMetrics(t *testing.T) { // - roles/iam.workloadIdentityUser on config-management-monitoring/default for e2e-test-metric-writer func TestOtelCollectorGCMLabelAggregation(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.RequireGKE(t)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) setupMetricsServiceAccount(nt) startTime := time.Now().UTC() nt.T.Log("Adding test commit") namespace := k8sobjects.NamespaceObject("foo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding foo namespace")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding foo namespace")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/override_git_sync_depth_test.go b/e2e/testcases/override_git_sync_depth_test.go index a27217cf30..af3fc0c8ef 100644 --- a/e2e/testcases/override_git_sync_depth_test.go +++ b/e2e/testcases/override_git_sync_depth_test.go @@ -37,6 +37,8 @@ import ( func TestOverrideGitSyncDepthV1Alpha1(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -79,8 +81,8 @@ func TestOverrideGitSyncDepthV1Alpha1(t *testing.T) { // Override the git sync depth setting for ns-reconciler-backend var depth int64 = 33 repoSyncBackend.Spec.SafeOverride().GitSyncDepth = &depth - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync git sync depth to 33")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync git sync depth to 33")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -105,8 +107,8 @@ func TestOverrideGitSyncDepthV1Alpha1(t *testing.T) { // Override the git sync depth setting for ns-reconciler-backend to 0 depth = 0 repoSyncBackend.Spec.SafeOverride().GitSyncDepth = &depth - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync git sync depth to 0")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync git sync depth to 0")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -119,8 +121,8 @@ func TestOverrideGitSyncDepthV1Alpha1(t *testing.T) { // Clear `spec.override` from repoSyncBackend repoSyncBackend.Spec.Override = &v1alpha1.RepoSyncOverrideSpec{} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Clear `spec.override` from repoSyncBackend")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Clear `spec.override` from repoSyncBackend")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -135,6 +137,8 @@ func TestOverrideGitSyncDepthV1Alpha1(t *testing.T) { func TestOverrideGitSyncDepthV1Beta1(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -177,8 +181,8 @@ func TestOverrideGitSyncDepthV1Beta1(t *testing.T) { // Override the git sync depth setting for ns-reconciler-backend var depth int64 = 33 repoSyncBackend.Spec.SafeOverride().GitSyncDepth = &depth - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync git sync depth to 33")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync git sync depth to 33")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -203,8 +207,8 @@ func TestOverrideGitSyncDepthV1Beta1(t *testing.T) { // Override the git sync depth setting for ns-reconciler-backend to 0 depth = 0 repoSyncBackend.Spec.SafeOverride().GitSyncDepth = &depth - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync git sync depth to 0")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync git sync depth to 0")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -217,8 +221,8 @@ func TestOverrideGitSyncDepthV1Beta1(t *testing.T) { // Clear `spec.override` from repoSyncBackend repoSyncBackend.Spec.Override = &v1beta1.RepoSyncOverrideSpec{} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Clear `spec.override` from repoSyncBackend")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Clear `spec.override` from repoSyncBackend")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/override_log_level_test.go b/e2e/testcases/override_log_level_test.go index 438a686f19..5ba47fc107 100644 --- a/e2e/testcases/override_log_level_test.go +++ b/e2e/testcases/override_log_level_test.go @@ -34,6 +34,7 @@ import ( func TestOverrideRootSyncLogLevel(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSyncName := nomostest.RootSyncNN(configsync.RootSyncName) rootReconcilerName := core.RootReconcilerObjectKey(rootSyncName.Name) @@ -41,8 +42,8 @@ func TestOverrideRootSyncLogLevel(t *testing.T) { // add kustomize to enable hydration controller container in root-sync nt.T.Log("Add the kustomize components root directory") - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../testdata/hydration/kustomize-components", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add DRY configs to the repository")) + nt.Must(rootSyncGitRepo.Copy("../testdata/hydration/kustomize-components", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RootSync to sync from the kustomize-components directory") nt.MustMergePatch(rootSyncV1, `{"spec": {"git": {"dir": "kustomize-components"}}}`) @@ -143,20 +144,25 @@ func TestOverrideRootSyncLogLevel(t *testing.T) { } func TestOverrideRepoSyncLogLevel(t *testing.T) { - nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.Unstructured, ntopts.NamespaceRepo(frontendNamespace, configsync.RepoSyncName)) + nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.Unstructured, + ntopts.NamespaceRepo(frontendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, frontendNamespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + frontendReconcilerNN := core.NsReconcilerObjectKey(frontendNamespace, configsync.RepoSyncName) - frontendNN := nomostest.RepoSyncNN(frontendNamespace, configsync.RepoSyncName) - repoSyncFrontend := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, frontendNN) + repoSyncFrontend := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, repoSyncKey) // add kustomize to enable hydration controller container in repo-sync nt.T.Log("Add the kustomize components root repo directory") - nt.Must(nt.NonRootRepos[frontendNN].Copy("../testdata/hydration/kustomize-components", ".")) - nt.Must(nt.NonRootRepos[frontendNN].CommitAndPush("add DRY configs to the repository")) + nt.Must(repoSyncGitRepo.Copy("../testdata/hydration/kustomize-components", ".")) + nt.Must(repoSyncGitRepo.CommitAndPush("add DRY configs to the repository")) nt.T.Log("Update RepoSync to sync from the kustomize-components directory") repoSyncFrontend.Spec.Git.Dir = "kustomize-components" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update RepoSync to sync from the kustomize directory")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update RepoSync to sync from the kustomize directory")) // Verify ns-reconciler-frontend uses the default log level err := nt.Watcher.WatchObject(kinds.Deployment(), @@ -185,8 +191,8 @@ func TestOverrideRepoSyncLogLevel(t *testing.T) { }, }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update log level of frontend Reposync")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update log level of frontend Reposync")) // validate override and make sure other containers are unaffected err = nt.Watcher.WatchObject(kinds.Deployment(), @@ -225,8 +231,8 @@ func TestOverrideRepoSyncLogLevel(t *testing.T) { }, }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update log level of frontend Reposync")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update log level of frontend Reposync")) // validate override for all containers err = nt.Watcher.WatchObject(kinds.Deployment(), @@ -244,8 +250,8 @@ func TestOverrideRepoSyncLogLevel(t *testing.T) { // Clear override from repoSync Frontend repoSyncFrontend.Spec.Override = nil - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Clear override from repoSync Frontend")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Clear override from repoSync Frontend")) // validate log level value are back to default for all containers err = nt.Watcher.WatchObject(kinds.Deployment(), diff --git a/e2e/testcases/override_reconcile_timeout_test.go b/e2e/testcases/override_reconcile_timeout_test.go index 11cb648c7b..e6e60add58 100644 --- a/e2e/testcases/override_reconcile_timeout_test.go +++ b/e2e/testcases/override_reconcile_timeout_test.go @@ -37,6 +37,7 @@ import ( // TestOverrideReconcileTimeout tests that a misconfigured pod will never reconcile (timeout). func TestOverrideReconcileTimeout(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSync := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) // Override reconcileTimeout to a short time 30s, only actuation should succeed, reconcile should time out. @@ -93,9 +94,9 @@ func TestOverrideReconcileTimeout(t *testing.T) { pod1 := k8sobjects.PodObject(pod1Name, []corev1.Container{container}, core.Namespace(namespaceName)) idToVerify := core.IDOf(pod1) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/pod-1.yaml", pod1)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns-1.yaml", k8sobjects.NamespaceObject(namespaceName))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Add namespace/%s & pod/%s (never ready)", namespaceName, pod1Name))) + nt.Must(rootSyncGitRepo.Add("acme/pod-1.yaml", pod1)) + nt.Must(rootSyncGitRepo.Add("acme/ns-1.yaml", k8sobjects.NamespaceObject(namespaceName))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Add namespace/%s & pod/%s (never ready)", namespaceName, pod1Name))) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -116,8 +117,8 @@ func TestOverrideReconcileTimeout(t *testing.T) { testpredicates.RootSyncHasObservedGenerationNoLessThan(rootSync.Generation), })) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/pod-1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Remove pod/%s", pod1Name))) + nt.Must(rootSyncGitRepo.Remove("acme/pod-1.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Remove pod/%s", pod1Name))) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -127,8 +128,8 @@ func TestOverrideReconcileTimeout(t *testing.T) { nt.T.Fatal(err) } pod1.Spec.Containers[0].ReadinessProbe.InitialDelaySeconds = 30 - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/pod-1.yaml", pod1)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Add pod/%s (ready after 30s)", pod1Name))) + nt.Must(rootSyncGitRepo.Add("acme/pod-1.yaml", pod1)) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Add pod/%s (ready after 30s)", pod1Name))) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/override_resource_limits_test.go b/e2e/testcases/override_resource_limits_test.go index c5dba0ba99..e59aaea4be 100644 --- a/e2e/testcases/override_resource_limits_test.go +++ b/e2e/testcases/override_resource_limits_test.go @@ -40,6 +40,7 @@ func TestOverrideReconcilerResourcesV1Alpha1(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.SkipAutopilotCluster, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName), ntopts.NamespaceRepo(frontendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) rootReconcilerNN := core.RootReconcilerObjectKey(rootSyncNN.Name) @@ -169,7 +170,7 @@ func TestOverrideReconcilerResourcesV1Alpha1(t *testing.T) { }, }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) // Override the CPU/memory requests and limits of the reconciler container of ns-reconciler-frontend repoSyncFrontend.Spec.Override = &v1alpha1.RepoSyncOverrideSpec{ @@ -192,8 +193,8 @@ func TestOverrideReconcilerResourcesV1Alpha1(t *testing.T) { }, }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend and frontend RepoSync resource limits")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend and frontend RepoSync resource limits")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -324,8 +325,8 @@ func TestOverrideReconcilerResourcesV1Alpha1(t *testing.T) { // Clear `spec.override` from repoSyncBackend repoSyncBackend.Spec.Override = nil - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Clear `spec.override` from repoSyncBackend")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Clear `spec.override` from repoSyncBackend")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -363,8 +364,8 @@ func TestOverrideReconcilerResourcesV1Alpha1(t *testing.T) { // Clear `spec.override` from repoSyncFrontend repoSyncFrontend.Spec.Override = nil - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Clear `spec.override` from repoSyncFrontend")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Clear `spec.override` from repoSyncFrontend")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -408,6 +409,7 @@ func TestOverrideReconcilerResourcesV1Beta1(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.SkipAutopilotCluster, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName), ntopts.NamespaceRepo(frontendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) rootReconcilerNN := core.RootReconcilerObjectKey(rootSyncNN.Name) @@ -537,7 +539,7 @@ func TestOverrideReconcilerResourcesV1Beta1(t *testing.T) { }, }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) // Override the CPU/memory requests and limits of the reconciler container of ns-reconciler-frontend repoSyncFrontend.Spec.Override = &v1beta1.RepoSyncOverrideSpec{ @@ -560,8 +562,8 @@ func TestOverrideReconcilerResourcesV1Beta1(t *testing.T) { }, }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend and frontend RepoSync resource limits")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend and frontend RepoSync resource limits")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -690,8 +692,8 @@ func TestOverrideReconcilerResourcesV1Beta1(t *testing.T) { // Clear `spec.override` from repoSyncBackend repoSyncBackend.Spec.Override = nil - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Clear `spec.override` from repoSyncBackend")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Clear `spec.override` from repoSyncBackend")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -729,8 +731,8 @@ func TestOverrideReconcilerResourcesV1Beta1(t *testing.T) { // Clear `spec.override` from repoSyncFrontend repoSyncFrontend.Spec.Override = nil - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Clear `spec.override` from repoSyncFrontend")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(frontendNamespace, configsync.RepoSyncName), repoSyncFrontend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Clear `spec.override` from repoSyncFrontend")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/override_role_refs_test.go b/e2e/testcases/override_role_refs_test.go index 4550b21d1d..baa0a28948 100644 --- a/e2e/testcases/override_role_refs_test.go +++ b/e2e/testcases/override_role_refs_test.go @@ -37,6 +37,7 @@ func TestRootSyncRoleRefs(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.Unstructured, ntopts.RootRepo("sync-a"), ) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rootSyncA := nomostest.RootSyncObjectV1Beta1FromRootRepo(nt, "sync-a") syncAReconcilerName := core.RootReconcilerName(rootSyncA.Name) syncANN := types.NamespacedName{ @@ -83,23 +84,23 @@ func TestRootSyncRoleRefs(t *testing.T) { }, } clusterRoleObject2 := k8sobjects.ClusterRoleObject(core.Name("bar-role")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( nomostest.StructuredNSPath(rootSyncA.Namespace, rootSyncA.Name), rootSyncA, )) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s/%s.yaml", roleObject.Namespace, roleObject.Name), roleObject, )) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s.yaml", clusterRoleObject.Name), clusterRoleObject, )) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s.yaml", clusterRoleObject2.Name), clusterRoleObject2, )) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add Roles and RoleRefs")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add Roles and RoleRefs")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -126,11 +127,11 @@ func TestRootSyncRoleRefs(t *testing.T) { Name: "foo-role", }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s/%s.yaml", configsync.ControllerNamespace, rootSyncA.Name), rootSyncA, )) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Reduce RoleRefs")) + nt.Must(rootSyncGitRepo.CommitAndPush("Reduce RoleRefs")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -151,10 +152,10 @@ func TestRootSyncRoleRefs(t *testing.T) { } nt.T.Logf("Delete the RootSync %s to verify garbage collection", syncANN.Name) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove( + nt.Must(rootSyncGitRepo.Remove( nomostest.StructuredNSPath(rootSyncA.Namespace, rootSyncA.Name), )) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Prune RootSync")) + nt.Must(rootSyncGitRepo.CommitAndPush("Prune RootSync")) if err := nt.WatchForSync(kinds.RootSyncV1Beta1(), configsync.RootSyncName, configsync.ControllerNamespace, nomostest.DefaultRootSha1Fn, nomostest.RootSyncHasStatusSyncCommit, nil); err != nil { nt.T.Fatal(err) diff --git a/e2e/testcases/policy_dir_test.go b/e2e/testcases/policy_dir_test.go index ccca3599a4..cda5ef5898 100755 --- a/e2e/testcases/policy_dir_test.go +++ b/e2e/testcases/policy_dir_test.go @@ -35,6 +35,7 @@ func TestMissingRepoErrorWithHierarchicalFormat(t *testing.T) { func TestPolicyDirUnset(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // There are 6 cluster-scoped objects under `../../examples/acme/cluster`. // // Copying the whole `../../examples/acme/cluster` dir would cause the Config Sync mono-repo mode CI job to fail, @@ -45,10 +46,10 @@ func TestPolicyDirUnset(t *testing.T) { // and generates a KNV 2006 error (as shown in http://b/210525686#comment3 and http://b/210525686#comment5). // // Therefore, we only copy `../../examples/acme/cluster/admin-clusterrole.yaml` here. - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../../examples/acme/cluster/admin-clusterrole.yaml", "./cluster")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../../examples/acme/namespaces", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Copy("../../examples/acme/system", ".")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Initialize the root directory")) + nt.Must(rootSyncGitRepo.Copy("../../examples/acme/cluster/admin-clusterrole.yaml", "./cluster")) + nt.Must(rootSyncGitRepo.Copy("../../examples/acme/namespaces", ".")) + nt.Must(rootSyncGitRepo.Copy("../../examples/acme/system", ".")) + nt.Must(rootSyncGitRepo.CommitAndPush("Initialize the root directory")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/preserve_fields_test.go b/e2e/testcases/preserve_fields_test.go index 798009b989..391a4e1c0b 100644 --- a/e2e/testcases/preserve_fields_test.go +++ b/e2e/testcases/preserve_fields_test.go @@ -41,11 +41,12 @@ import ( func TestPreserveGeneratedServiceFields(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Declare the Service's Namespace ns := "autogen-fields" nsObj := k8sobjects.NamespaceObject(ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", ns), nsObj)) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", ns), nsObj)) // Declare the Service. serviceName := "e2e-test-service" @@ -65,9 +66,9 @@ func TestPreserveGeneratedServiceFields(t *testing.T) { TargetPort: intstr.FromInt(targetPort1), }}, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/service.yaml", ns), serviceObj)) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/service.yaml", ns), serviceObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("declare Namespace and Service")) + nt.Must(rootSyncGitRepo.CommitAndPush("declare Namespace and Service")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -131,8 +132,8 @@ func TestPreserveGeneratedServiceFields(t *testing.T) { updatedService := serviceObj.DeepCopy() updatedService.Spec.Ports[0].TargetPort = intstr.FromInt(targetPort2) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/service.yaml", ns), updatedService)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("update declared Service")) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/service.yaml", ns), updatedService)) + nt.Must(rootSyncGitRepo.CommitAndPush("update declared Service")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -157,6 +158,7 @@ func TestPreserveGeneratedServiceFields(t *testing.T) { func TestPreserveGeneratedClusterRoleFields(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nsViewerName := "namespace-viewer" nsViewer := k8sobjects.ClusterRoleObject(core.Name(nsViewerName), @@ -166,7 +168,7 @@ func TestPreserveGeneratedClusterRoleFields(t *testing.T) { Resources: []string{"namespaces"}, Verbs: []string{"get", "list"}, }} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/ns-viewer-cr.yaml", nsViewer)) + nt.Must(rootSyncGitRepo.Add("acme/cluster/ns-viewer-cr.yaml", nsViewer)) rbacViewerName := "rbac-viewer" rbacViewer := k8sobjects.ClusterRoleObject(core.Name(rbacViewerName), @@ -176,12 +178,12 @@ func TestPreserveGeneratedClusterRoleFields(t *testing.T) { Resources: []string{"roles", "rolebindings", "clusterroles", "clusterrolebindings"}, Verbs: []string{"get", "list"}, }} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/rbac-viewer-cr.yaml", rbacViewer)) + nt.Must(rootSyncGitRepo.Add("acme/cluster/rbac-viewer-cr.yaml", rbacViewer)) aggregateRoleName := "aggregate" // We have to declare the YAML explicitly because otherwise the declaration // explicitly declares "rules: []" due to how Go handles empty/unset fields. - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/aggregate-viewer-cr.yaml", []byte(` + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/aggregate-viewer-cr.yaml", []byte(` kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: @@ -190,9 +192,9 @@ aggregationRule: clusterRoleSelectors: - matchLabels: permissions: viewer`))) - aggregateViewer := nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/cluster/aggregate-viewer-cr.yaml") + aggregateViewer := rootSyncGitRepo.MustGet(nt.T, "acme/cluster/aggregate-viewer-cr.yaml") - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("declare ClusterRoles")) + nt.Must(rootSyncGitRepo.CommitAndPush("declare ClusterRoles")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -222,7 +224,7 @@ aggregationRule: } // Update aggregateRole with a new label. - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile("acme/cluster/aggregate-viewer-cr.yaml", []byte(` + nt.Must(rootSyncGitRepo.AddFile("acme/cluster/aggregate-viewer-cr.yaml", []byte(` kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: @@ -233,8 +235,8 @@ aggregationRule: clusterRoleSelectors: - matchLabels: permissions: viewer`))) - aggregateViewer = nt.RootRepos[configsync.RootSyncName].MustGet(nt.T, "acme/cluster/aggregate-viewer-cr.yaml") - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add label to aggregate ClusterRole")) + aggregateViewer = rootSyncGitRepo.MustGet(nt.T, "acme/cluster/aggregate-viewer-cr.yaml") + nt.Must(rootSyncGitRepo.CommitAndPush("add label to aggregate ClusterRole")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -265,6 +267,7 @@ aggregationRule: func TestPreserveLastApplied(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Declare a ClusterRole and wait for it to sync. nsViewerName := "namespace-viewer" @@ -275,8 +278,8 @@ func TestPreserveLastApplied(t *testing.T) { Resources: []string{"namespaces"}, Verbs: []string{"get", "list"}, }} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cluster/ns-viewer-cr.yaml", nsViewer)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add namespace-viewer ClusterRole")) + nt.Must(rootSyncGitRepo.Add("acme/cluster/ns-viewer-cr.yaml", nsViewer)) + nt.Must(rootSyncGitRepo.CommitAndPush("add namespace-viewer ClusterRole")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -289,10 +292,10 @@ func TestPreserveLastApplied(t *testing.T) { annotationKeys := metadata.GetNomosAnnotationKeys() nsViewer.Annotations[corev1.LastAppliedConfigAnnotation] = `{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"ClusterRole","metadata":{"annotations":{"configmanagement.gke.io/cluster-name":"e2e-test-cluster","configmanagement.gke.io/managed":"enabled","configmanagement.gke.io/source-path":"cluster/namespace-viewer-clusterrole.yaml"},"labels":{"app.kubernetes.io/managed-by":"configmanagement.gke.io","permissions":"viewer"},"name":"namespace-viewer"},"rules":[{"apiGroups":[""],"resources":["namespaces"],"verbs":["get","list"]}]}` - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("ns-viewer-cr-replace.yaml", nsViewer)) + nt.Must(rootSyncGitRepo.Add("ns-viewer-cr-replace.yaml", nsViewer)) // Admission webhook denies change. We don't get a "LastApplied" annotation // as we prevented the change outright. - _, err = nt.Shell.Kubectl("replace", "-f", filepath.Join(nt.RootRepos[configsync.RootSyncName].Root, "ns-viewer-cr-replace.yaml")) + _, err = nt.Shell.Kubectl("replace", "-f", filepath.Join(rootSyncGitRepo.Root, "ns-viewer-cr-replace.yaml")) if err == nil { nt.T.Fatal("got kubectl replace err = nil, want admission webhook to deny") } @@ -319,16 +322,17 @@ func TestPreserveLastApplied(t *testing.T) { func TestAddUpdateDeleteLabels(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) ns := "crud-labels" nsObj := k8sobjects.NamespaceObject(ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/crud-labels/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/crud-labels/ns.yaml", nsObj)) cmName := "e2e-test-configmap" cmPath := "acme/namespaces/crud-labels/configmap.yaml" cm := k8sobjects.ConfigMapObject(core.Name(cmName)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding ConfigMap with no labels to repo")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding ConfigMap with no labels to repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -348,8 +352,8 @@ func TestAddUpdateDeleteLabels(t *testing.T) { } cm.Labels["baz"] = "qux" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update label for ConfigMap in repo")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update label for ConfigMap in repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -363,8 +367,8 @@ func TestAddUpdateDeleteLabels(t *testing.T) { testpredicates.HasExactlyLabelKeys(updatedLabels...))) delete(cm.Labels, "baz") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Delete label for configmap in repo")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Delete label for configmap in repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -388,16 +392,17 @@ func TestAddUpdateDeleteLabels(t *testing.T) { func TestAddUpdateDeleteAnnotations(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.Reconciliation2) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) ns := "crud-annotations" nsObj := k8sobjects.NamespaceObject(ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/namespaces/crud-annotations/ns.yaml", nsObj)) + nt.Must(rootSyncGitRepo.Add("acme/namespaces/crud-annotations/ns.yaml", nsObj)) cmName := "e2e-test-configmap" cmPath := "acme/namespaces/crud-annotations/configmap.yaml" cmObj := k8sobjects.ConfigMapObject(core.Name(cmName)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cmObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding ConfigMap with no annotations to repo")) + nt.Must(rootSyncGitRepo.Add(cmPath, cmObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding ConfigMap with no annotations to repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -423,8 +428,8 @@ func TestAddUpdateDeleteAnnotations(t *testing.T) { } cmObj.Annotations["baz"] = "qux" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cmObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update annotation for ConfigMap in repo")) + nt.Must(rootSyncGitRepo.Add(cmPath, cmObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update annotation for ConfigMap in repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -449,8 +454,8 @@ func TestAddUpdateDeleteAnnotations(t *testing.T) { } delete(cmObj.Annotations, "baz") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cmObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Delete annotation for configmap in repo")) + nt.Must(rootSyncGitRepo.Add(cmPath, cmObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("Delete annotation for configmap in repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/private_cert_secret_test.go b/e2e/testcases/private_cert_secret_test.go index a1c0125d13..ae1663f7e1 100644 --- a/e2e/testcases/private_cert_secret_test.go +++ b/e2e/testcases/private_cert_secret_test.go @@ -69,6 +69,12 @@ func secretDataDeletePatch(key string) string { func TestCACertSecretRefV1Alpha1(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource, ntopts.RequireLocalGitProvider, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, backendNamespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + rootSyncReconcilerName := nomostest.DefaultRootReconcilerName + repoSyncReconcilerName := core.NsReconcilerName(repoSyncID.Namespace, repoSyncID.Name) key := controllers.GitSSLCAInfo caCertSecret := nomostest.PublicCertSecretName(nomostest.GitSyncSource) @@ -76,26 +82,24 @@ func TestCACertSecretRefV1Alpha1(t *testing.T) { var err error // verify the deployment doesn't have the key yet - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } - err = nt.Validate(core.NsReconcilerName(backendNamespace, configsync.RepoSyncName), configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + err = nt.Validate(core.NsReconcilerName(repoSyncID.Namespace, repoSyncID.Name), configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } rootSync := k8sobjects.RootSyncObjectV1Alpha1(configsync.RootSyncName) - nn := nomostest.RepoSyncNN(backendNamespace, configsync.RepoSyncName) - repoSyncBackend := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, nn) - reconcilerName := core.NsReconcilerName(backendNamespace, configsync.RepoSyncName) + repoSyncBackend := nomostest.RepoSyncObjectV1Alpha1FromNonRootRepo(nt, repoSyncKey) // Set RootSync SyncURL to use HTTPS rootSyncHTTPS := "https://test-git-server.config-management-system-test/git/config-management-system/root-sync" nt.MustMergePatch(rootSync, syncURLHTTPSPatch(rootSyncHTTPS)) // RootSync should fail without caCertSecret nt.WaitForRootSyncSourceError(configsync.RootSyncName, status.SourceErrorCode, "server certificate verification failed") - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, rootSyncHTTPS)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, rootSyncHTTPS)) if err != nil { nt.T.Fatal(err) } @@ -105,7 +109,7 @@ func TestCACertSecretRefV1Alpha1(t *testing.T) { if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, key, caCertPath)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, key, caCertPath)) if err != nil { nt.T.Fatal(err) } @@ -116,23 +120,23 @@ func TestCACertSecretRefV1Alpha1(t *testing.T) { repoSyncBackend.Spec.Git.Auth = "none" repoSyncBackend.Spec.Git.SecretRef = &v1alpha1.SecretReference{} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync use HTTPS")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync use HTTPS")) // RepoSync should fail without caCertSecret - nt.WaitForRepoSyncSourceError(backendNamespace, configsync.RepoSyncName, status.SourceErrorCode, "server certificate verification failed") - err = nt.Validate(reconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, repoSyncHTTPS)) + nt.WaitForRepoSyncSourceError(repoSyncID.Namespace, repoSyncID.Name, status.SourceErrorCode, "server certificate verification failed") + err = nt.Validate(repoSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, repoSyncHTTPS)) if err != nil { nt.T.Fatal(err) } // Set caCertSecret for RepoSync repoSyncBackend.Spec.Git.CACertSecretRef = &v1alpha1.SecretReference{Name: caCertSecret} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync set caCertSecret")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync set caCertSecret")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - err = nt.Validate(reconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, key, caCertPath)) + err = nt.Validate(repoSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, key, caCertPath)) if err != nil { nt.T.Fatal(err) } @@ -141,44 +145,44 @@ func TestCACertSecretRefV1Alpha1(t *testing.T) { nt.MustMergePatch(rootSync, caCertSecretPatch(configsync.GitSource, "")) // RootSync should fail without caCertSecret nt.WaitForRootSyncSourceError(configsync.RootSyncName, status.SourceErrorCode, "server certificate verification failed") - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } // Set RootSync to use SSH again - rootSyncSSHURL := nt.GitProvider.SyncURL(nt.RootRepos[configsync.RootSyncName].RemoteRepoName) + rootSyncSSHURL := nt.GitProvider.SyncURL(rootSyncGitRepo.RemoteRepoName) nt.MustMergePatch(rootSync, syncURLSSHPatch(rootSyncSSHURL)) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, rootSyncSSHURL)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, rootSyncSSHURL)) if err != nil { nt.T.Fatal(err) } // Unset caCertSecret for repoSyncBackend repoSyncBackend.Spec.Git.CACertSecretRef.Name = "" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync unset caCertSecret")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync unset caCertSecret")) // RepoSync should fail without caCertSecret - nt.WaitForRepoSyncSourceError(backendNamespace, configsync.RepoSyncName, status.SourceErrorCode, "server certificate verification failed") - err = nt.Validate(reconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + nt.WaitForRepoSyncSourceError(repoSyncID.Namespace, repoSyncID.Name, status.SourceErrorCode, "server certificate verification failed") + err = nt.Validate(repoSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } // Set RepoSync to use SSH again - repoSyncSSHURL := nt.GitProvider.SyncURL(nt.NonRootRepos[nn].RemoteRepoName) + repoSyncSSHURL := nt.GitProvider.SyncURL(repoSyncGitRepo.RemoteRepoName) repoSyncBackend.Spec.Git.Repo = repoSyncSSHURL repoSyncBackend.Spec.Git.Auth = "ssh" repoSyncBackend.Spec.Git.SecretRef = &v1alpha1.SecretReference{Name: "ssh-key"} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync use SSH")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync use SSH")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - err = nt.Validate(reconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, repoSyncSSHURL)) + err = nt.Validate(repoSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, repoSyncSSHURL)) if err != nil { nt.T.Fatal(err) } @@ -187,6 +191,11 @@ func TestCACertSecretRefV1Alpha1(t *testing.T) { func TestCACertSecretRefV1Beta1(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource, ntopts.RequireLocalGitProvider, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, backendNamespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + rootSyncReconcilerName := nomostest.DefaultRootReconcilerName key := controllers.GitSSLCAInfo caCertSecret := nomostest.PublicCertSecretName(nomostest.GitSyncSource) @@ -194,26 +203,25 @@ func TestCACertSecretRefV1Beta1(t *testing.T) { var err error // verify the deployment doesn't have the key yet - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } - err = nt.Validate(core.NsReconcilerName(backendNamespace, configsync.RepoSyncName), configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + err = nt.Validate(core.NsReconcilerName(repoSyncID.Namespace, repoSyncID.Name), configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } rootSync := k8sobjects.RootSyncObjectV1Beta1(configsync.RootSyncName) - nn := nomostest.RepoSyncNN(backendNamespace, configsync.RepoSyncName) - repoSyncBackend := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, nn) - reconcilerName := core.NsReconcilerName(backendNamespace, configsync.RepoSyncName) + repoSyncBackend := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, repoSyncKey) + reconcilerName := core.NsReconcilerName(repoSyncID.Namespace, repoSyncID.Name) // Set RootSync SyncURL to use HTTPS rootSyncHTTPS := "https://test-git-server.config-management-system-test/git/config-management-system/root-sync" nt.MustMergePatch(rootSync, syncURLHTTPSPatch(rootSyncHTTPS)) // RootSync should fail without caCertSecret nt.WaitForRootSyncSourceError(configsync.RootSyncName, status.SourceErrorCode, "server certificate verification failed") - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, rootSyncHTTPS)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, rootSyncHTTPS)) if err != nil { nt.T.Fatal(err) } @@ -223,7 +231,7 @@ func TestCACertSecretRefV1Beta1(t *testing.T) { if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, key, caCertPath)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, key, caCertPath)) if err != nil { nt.T.Fatal(err) } @@ -233,10 +241,10 @@ func TestCACertSecretRefV1Beta1(t *testing.T) { repoSyncBackend.Spec.Git.Repo = repoSyncHTTPS repoSyncBackend.Spec.Git.Auth = "none" repoSyncBackend.Spec.Git.SecretRef = &v1beta1.SecretReference{} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync use HTTPS")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync use HTTPS")) // RepoSync should fail without caCertSecret - nt.WaitForRepoSyncSourceError(backendNamespace, configsync.RepoSyncName, status.SourceErrorCode, "server certificate verification failed") + nt.WaitForRepoSyncSourceError(repoSyncID.Namespace, repoSyncID.Name, status.SourceErrorCode, "server certificate verification failed") err = nt.Validate(reconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, repoSyncHTTPS)) if err != nil { nt.T.Fatal(err) @@ -244,8 +252,8 @@ func TestCACertSecretRefV1Beta1(t *testing.T) { // Set caCertSecret for RepoSync repoSyncBackend.Spec.Git.CACertSecretRef = &v1beta1.SecretReference{Name: caCertSecret} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync set caCertSecret")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync set caCertSecret")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -264,40 +272,40 @@ func TestCACertSecretRefV1Beta1(t *testing.T) { nt.MustMergePatch(rootSync, caCertSecretPatch(configsync.GitSource, "")) // RootSync should fail without caCertSecret nt.WaitForRootSyncSourceError(configsync.RootSyncName, status.SourceErrorCode, "server certificate verification failed") - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } // Set RootSync to use SSH again - rootSyncSSHURL := nt.GitProvider.SyncURL(nt.RootRepos[configsync.RootSyncName].RemoteRepoName) + rootSyncSSHURL := nt.GitProvider.SyncURL(rootSyncGitRepo.RemoteRepoName) nt.MustMergePatch(rootSync, syncURLSSHPatch(rootSyncSSHURL)) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, rootSyncSSHURL)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, rootSyncSSHURL)) if err != nil { nt.T.Fatal(err) } // Unset caCertSecret for repoSyncBackend repoSyncBackend.Spec.Git.CACertSecretRef.Name = "" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync unset caCertSecret")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync unset caCertSecret")) // RepoSync should fail without caCertSecret - nt.WaitForRepoSyncSourceError(backendNamespace, configsync.RepoSyncName, status.SourceErrorCode, "server certificate verification failed") + nt.WaitForRepoSyncSourceError(repoSyncID.Namespace, repoSyncID.Name, status.SourceErrorCode, "server certificate verification failed") err = nt.Validate(reconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } // Set RepoSync to use SSH again - repoSyncSSHURL := nt.GitProvider.SyncURL(nt.NonRootRepos[nn].RemoteRepoName) + repoSyncSSHURL := nt.GitProvider.SyncURL(repoSyncGitRepo.RemoteRepoName) repoSyncBackend.Spec.Git.Repo = repoSyncSSHURL repoSyncBackend.Spec.Git.Auth = "ssh" repoSyncBackend.Spec.Git.SecretRef = &v1beta1.SecretReference{Name: "ssh-key"} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync use SSH")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync use SSH")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -310,6 +318,12 @@ func TestCACertSecretRefV1Beta1(t *testing.T) { func TestCACertSecretWatch(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource, ntopts.RequireLocalGitProvider, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, backendNamespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + rootSyncReconcilerName := nomostest.DefaultRootReconcilerName + repoSyncReconcilerName := core.NsReconcilerName(repoSyncID.Namespace, repoSyncID.Name) key := controllers.GitSSLCAInfo caCertSecret := nomostest.PublicCertSecretName(nomostest.GitSyncSource) @@ -317,18 +331,16 @@ func TestCACertSecretWatch(t *testing.T) { var err error // verify the deployment doesn't have the key yet - err = nt.Validate(nomostest.DefaultRootReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + err = nt.Validate(rootSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } - err = nt.Validate(core.NsReconcilerName(backendNamespace, configsync.RepoSyncName), configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) + err = nt.Validate(repoSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentMissingEnvVar(reconcilermanager.GitSync, key)) if err != nil { nt.T.Fatal(err) } - nn := nomostest.RepoSyncNN(backendNamespace, configsync.RepoSyncName) - repoSyncBackend := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, nn) - reconcilerName := core.NsReconcilerName(backendNamespace, configsync.RepoSyncName) + repoSyncBackend := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, repoSyncKey) // Set RepoSync to use HTTPS with caCertSecret repoSyncHTTPS := "https://test-git-server.config-management-system-test/git/backend/repo-sync" @@ -336,19 +348,19 @@ func TestCACertSecretWatch(t *testing.T) { repoSyncBackend.Spec.Git.Auth = "none" repoSyncBackend.Spec.Git.SecretRef = &v1beta1.SecretReference{} repoSyncBackend.Spec.Git.CACertSecretRef = &v1beta1.SecretReference{Name: caCertSecret} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync use HTTPS with caCertSecret")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync use HTTPS with caCertSecret")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - err = nt.Validate(reconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, key, caCertPath)) + err = nt.Validate(repoSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, key, caCertPath)) if err != nil { nt.T.Fatal(err) } // Check that the namespace secret was upserted to c-m-s namespace cmsSecret := &corev1.Secret{} - cmsSecretName := controllers.ReconcilerResourceName(reconcilerName, caCertSecret) + cmsSecretName := controllers.ReconcilerResourceName(repoSyncReconcilerName, caCertSecret) err = nt.Validate(cmsSecretName, configsync.ControllerNamespace, cmsSecret) if err != nil { nt.T.Fatal(err) @@ -373,17 +385,17 @@ func TestCACertSecretWatch(t *testing.T) { testpredicates.SecretHasKey("baz", "bat"), })) // Unset caCertSecret for repoSyncBackend and use SSH - repoSyncSSHURL := nt.GitProvider.SyncURL(nt.NonRootRepos[nn].RemoteRepoName) + repoSyncSSHURL := nt.GitProvider.SyncURL(repoSyncGitRepo.RemoteRepoName) repoSyncBackend.Spec.Git.Repo = repoSyncSSHURL repoSyncBackend.Spec.Git.Auth = "ssh" repoSyncBackend.Spec.Git.SecretRef = &v1beta1.SecretReference{Name: "ssh-key"} repoSyncBackend.Spec.Git.CACertSecretRef = &v1beta1.SecretReference{} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(nomostest.StructuredNSPath(backendNamespace, configsync.RepoSyncName), repoSyncBackend)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Update backend RepoSync unset caCertSecret and use SSH")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), repoSyncBackend)) + nt.Must(rootSyncGitRepo.CommitAndPush("Update backend RepoSync unset caCertSecret and use SSH")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - err = nt.Validate(reconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, repoSyncSSHURL)) + err = nt.Validate(repoSyncReconcilerName, configsync.ControllerNamespace, &appsv1.Deployment{}, testpredicates.DeploymentHasEnvVar(reconcilermanager.GitSync, controllers.GitSyncRepo, repoSyncSSHURL)) if err != nil { nt.T.Fatal(err) } @@ -431,16 +443,18 @@ func TestOCICACertSecretRefNamespaceRepo(t *testing.T) { ntopts.RequireLocalOCIProvider, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName), ntopts.RepoSyncPermissions(policy.CoreAdmin())) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, backendNamespace) + repoSyncKey := repoSyncID.ObjectKey + repoSyncReconcilerName := core.NsReconcilerName(repoSyncID.Namespace, repoSyncID.Name) caCertSecret := nomostest.PublicCertSecretName(nomostest.RegistrySyncSource) - nn := nomostest.RepoSyncNN(backendNamespace, configsync.RepoSyncName) - rs := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, nn) - upsertedSecret := controllers.ReconcilerResourceName( - core.NsReconcilerName(nn.Namespace, nn.Name), caCertSecret) + rs := nomostest.RepoSyncObjectV1Beta1FromNonRootRepo(nt, repoSyncKey) + upsertedSecret := controllers.ReconcilerResourceName(repoSyncReconcilerName, caCertSecret) - cm := k8sobjects.ConfigMapObject(core.Name("foo-cm"), core.Namespace(nn.Namespace)) - image, err := nt.BuildAndPushOCIImage(nn, registryproviders.ImageInputObjects(nt.Scheme, cm)) + cm := k8sobjects.ConfigMapObject(core.Name("foo-cm"), core.Namespace(repoSyncID.Namespace)) + image, err := nt.BuildAndPushOCIImage(repoSyncKey, registryproviders.ImageInputObjects(nt.Scheme, cm)) if err != nil { nt.T.Fatal(err) } @@ -455,21 +469,19 @@ func TestOCICACertSecretRefNamespaceRepo(t *testing.T) { Image: imageURL, Auth: "none", } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( - nomostest.StructuredNSPath(nn.Namespace, nn.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Set the RepoSync to use OCI without providing CA cert")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), rs)) + nt.Must(rootSyncGitRepo.CommitAndPush("Set the RepoSync to use OCI without providing CA cert")) - nt.WaitForRepoSyncSourceError(nn.Namespace, nn.Name, status.SourceErrorCode, "tls: failed to verify certificate: x509: certificate signed by unknown authority") + nt.WaitForRepoSyncSourceError(repoSyncID.Namespace, repoSyncID.Name, status.SourceErrorCode, "tls: failed to verify certificate: x509: certificate signed by unknown authority") nt.T.Log("Add caCertSecretRef to RepoSync") rs.Spec.Oci.CACertSecretRef = &v1beta1.SecretReference{Name: caCertSecret} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( - nomostest.StructuredNSPath(nn.Namespace, nn.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Set the CA cert for the RepoSync")) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), rs)) + nt.Must(rootSyncGitRepo.CommitAndPush("Set the CA cert for the RepoSync")) err = nt.WatchForAllSyncs( nomostest.WithRepoSha1Func(imageDigestFuncByDigest(image.Digest)), nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{ - nn: ".", + repoSyncKey: ".", })) if err != nil { nt.T.Fatal(err) @@ -485,9 +497,9 @@ func TestOCICACertSecretRefNamespaceRepo(t *testing.T) { nt.T.Log("Set the RepoSync to sync from git") rs.Spec.SourceType = configsync.GitSource - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( - nomostest.StructuredNSPath(nn.Namespace, nn.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Set the RepoSync to sync from Git")) + nt.Must(rootSyncGitRepo.Add( + nomostest.StructuredNSPath(repoSyncID.Namespace, repoSyncID.Name), rs)) + nt.Must(rootSyncGitRepo.CommitAndPush("Set the RepoSync to sync from Git")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -549,6 +561,7 @@ func TestHelmCACertSecretRefNamespaceRepo(t *testing.T) { ntopts.RequireLocalHelmProvider, ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName), ntopts.RepoSyncPermissions(policy.CoreAdmin())) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) caCertSecret := nomostest.PublicCertSecretName(nomostest.RegistrySyncSource) @@ -578,17 +591,17 @@ func TestHelmCACertSecretRefNamespaceRepo(t *testing.T) { Period: metav1.Duration{Duration: 15 * time.Second}, }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( nomostest.StructuredNSPath(nn.Namespace, nn.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Set the RepoSync to use Helm without providing CA cert")) + nt.Must(rootSyncGitRepo.CommitAndPush("Set the RepoSync to use Helm without providing CA cert")) nt.WaitForRepoSyncSourceError(nn.Namespace, nn.Name, status.SourceErrorCode, "tls: failed to verify certificate: x509: certificate signed by unknown authority") nt.T.Log("Add caCertSecretRef to RepoSync") rs.Spec.Helm.CACertSecretRef = &v1beta1.SecretReference{Name: caCertSecret} - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( nomostest.StructuredNSPath(nn.Namespace, nn.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Set the CA cert for the RepoSync")) + nt.Must(rootSyncGitRepo.CommitAndPush("Set the CA cert for the RepoSync")) err = nt.WatchForAllSyncs( nomostest.WithRepoSha1Func(nomostest.HelmChartVersionShaFn(chart.Version)), nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{ @@ -608,9 +621,9 @@ func TestHelmCACertSecretRefNamespaceRepo(t *testing.T) { nt.T.Log("Set the RepoSync to sync from git") rs.Spec.SourceType = configsync.GitSource - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( nomostest.StructuredNSPath(nn.Namespace, nn.Name), rs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Set the RepoSync to sync from Git")) + nt.Must(rootSyncGitRepo.CommitAndPush("Set the RepoSync to sync from Git")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) diff --git a/e2e/testcases/profiling_test.go b/e2e/testcases/profiling_test.go index cf1b0d79fa..b19f31619f 100644 --- a/e2e/testcases/profiling_test.go +++ b/e2e/testcases/profiling_test.go @@ -44,6 +44,7 @@ func TestProfilingResourcesByObjectCount(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.ProfilingTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncPath := filepath.Join(gitproviders.DefaultSyncDir, "stress-test") ns := "stress-test-ns" @@ -69,16 +70,16 @@ func TestProfilingResourcesByObjectCount(t *testing.T) { deployCount := deploysPerStep * step nt.T.Logf("Adding a test namespace and %d deployments", deployCount) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) for i := 1; i <= deployCount; i++ { name := fmt.Sprintf("pause-%d", i) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile( + nt.Must(rootSyncGitRepo.AddFile( fmt.Sprintf("%s/namespaces/%s/deployment-%s.yaml", syncPath, ns, name), []byte(pauseDeploymentYAML(name, ns)))) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Adding a test namespace and %d deployments", deployCount))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Adding a test namespace and %d deployments", deployCount))) // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. @@ -90,8 +91,8 @@ func TestProfilingResourcesByObjectCount(t *testing.T) { client.InNamespace(ns))) nt.T.Log("Removing resources from Git") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(syncPath)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing resources from Git")) + nt.Must(rootSyncGitRepo.Remove(syncPath)) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing resources from Git")) // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. @@ -109,6 +110,7 @@ func TestProfilingResourcesByObjectCountWithMultiSync(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.ProfilingTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) steps := 4 deploysPerStep := 1000 @@ -118,7 +120,7 @@ func TestProfilingResourcesByObjectCountWithMultiSync(t *testing.T) { // Use the same namespace for all other RSyncs to ensure they all show up in watches, whether it's cluster-scope or namespace-scope. ns := "stress-test-ns" nt.T.Logf("Adding test namespace: %s", ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns), k8sobjects.NamespaceObject(ns))) for syncIndex := 1; syncIndex <= syncCount; syncIndex++ { syncName := fmt.Sprintf("sync-%d", syncIndex) @@ -133,7 +135,7 @@ func TestProfilingResourcesByObjectCountWithMultiSync(t *testing.T) { }, } // Manage the RootSyncs with the parent root-sync - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("%s/namespaces/%s/rootsync-%s.yaml", gitproviders.DefaultSyncDir, configsync.ControllerNamespace, syncName), syncObj)) } @@ -165,12 +167,12 @@ func TestProfilingResourcesByObjectCountWithMultiSync(t *testing.T) { for deployIndex := 1; deployIndex <= deployCount; deployIndex++ { deployName := fmt.Sprintf("pause-%d-%d", syncIndex, deployIndex) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile( + nt.Must(rootSyncGitRepo.AddFile( fmt.Sprintf("%s/namespaces/%s/deployment-%s.yaml", syncPath, ns, deployName), []byte(pauseDeploymentYAML(deployName, ns)))) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Adding %d deployments for %d RootSyncs", deployCount, syncCount))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Adding %d deployments for %d RootSyncs", deployCount, syncCount))) // Add child RootSync rSyncRefs = append(rSyncRefs, rSyncRef{ @@ -194,11 +196,11 @@ func TestProfilingResourcesByObjectCountWithMultiSync(t *testing.T) { for syncIndex := 1; syncIndex <= syncCount; syncIndex++ { syncName := fmt.Sprintf("sync-%d", syncIndex) syncPath := syncName - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(syncPath)) + nt.Must(rootSyncGitRepo.Remove(syncPath)) // Add an empty sync directory so the reconciler doesn't error that it can't find it. - nt.Must(nt.RootRepos[configsync.RootSyncName].AddEmptyDir(syncPath)) + nt.Must(rootSyncGitRepo.AddEmptyDir(syncPath)) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing resources from Git")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing resources from Git")) // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. @@ -213,13 +215,13 @@ func TestProfilingResourcesByObjectCountWithMultiSync(t *testing.T) { nt.T.Log("Removing RootSyncs from Git") for syncIndex := 1; syncIndex <= syncCount; syncIndex++ { syncName := fmt.Sprintf("sync-%d", syncIndex) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove( + nt.Must(rootSyncGitRepo.Remove( fmt.Sprintf("%s/namespaces/%s/rootsync-%s.yaml", gitproviders.DefaultSyncDir, configsync.ControllerNamespace, syncName))) } nt.T.Logf("Removing test namespace: %s", ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing RootSyncs and test namespace")) + nt.Must(rootSyncGitRepo.Remove(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns))) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing RootSyncs and test namespace")) // Wait for root-sync to sync nt.Must(nt.WatchForAllSyncs()) @@ -236,6 +238,7 @@ func TestProfilingByObjectCountAndSyncCount(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.ProfilingTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) steps := 5 syncsPerStep := 1 @@ -245,7 +248,7 @@ func TestProfilingByObjectCountAndSyncCount(t *testing.T) { // Use the same namespace for all other RSyncs to ensure they all show up in watches, whether it's cluster-scope or namespace-scope. ns := "stress-test-ns" nt.T.Logf("Adding test namespace: %s", ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns), k8sobjects.NamespaceObject(ns))) syncIndex := 0 @@ -284,19 +287,19 @@ func TestProfilingByObjectCountAndSyncCount(t *testing.T) { }, } // Manage the RootSyncs with the parent root-sync - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("%s/namespaces/%s/rootsync-%s.yaml", gitproviders.DefaultSyncDir, configsync.ControllerNamespace, syncName), syncObj)) nt.T.Logf("Adding %d deployments for RootSync %s", deployCount, syncName) for deployIndex := 1; deployIndex <= deployCount; deployIndex++ { deployName := fmt.Sprintf("pause-%d-%d", syncIndex, deployIndex) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile( + nt.Must(rootSyncGitRepo.AddFile( fmt.Sprintf("%s/namespaces/%s/deployment-%s.yaml", syncPath, ns, deployName), []byte(pauseDeploymentYAML(deployName, ns)))) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Adding %d deployments each for %d RootSyncs", deployCount, syncCount))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Adding %d deployments each for %d RootSyncs", deployCount, syncCount))) // Add child RootSync rSyncRefs = append(rSyncRefs, rSyncRef{ @@ -319,13 +322,13 @@ func TestProfilingByObjectCountAndSyncCount(t *testing.T) { nt.T.Log("Removing RootSyncs from Git") for syncIndex := 1; syncIndex <= (syncsPerStep * steps); syncIndex++ { syncName := fmt.Sprintf("sync-%d", syncIndex) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove( + nt.Must(rootSyncGitRepo.Remove( fmt.Sprintf("%s/namespaces/%s/rootsync-%s.yaml", gitproviders.DefaultSyncDir, configsync.ControllerNamespace, syncName))) } nt.T.Logf("Removing test namespace: %s", ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing RootSyncs and test namespace")) + nt.Must(rootSyncGitRepo.Remove(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns))) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing RootSyncs and test namespace")) // Wait for root-sync to sync nt.Must(nt.WatchForAllSyncs()) @@ -341,12 +344,13 @@ func TestProfilingResourcesByRootSyncCount(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.ProfilingTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Create the namespace using the default root-sync. // Use the same namespace for all other RSyncs to ensure they all show up in watches, whether it's cluster-scope or namespace-scope. ns := "stress-test-ns" nt.T.Logf("Adding test namespace: %s", ns) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", gitproviders.DefaultSyncDir, ns), k8sobjects.NamespaceObject(ns))) syncCount := 10 deployCount := 1000 @@ -364,27 +368,27 @@ func TestProfilingResourcesByRootSyncCount(t *testing.T) { }, } // Manage the RootSyncs with the parent root-sync - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("%s/namespaces/%s/rootsync-%s.yaml", gitproviders.DefaultSyncDir, configsync.ControllerNamespace, syncName), syncObj)) // For each RootSync, make 100 Deployments with unique names for j := 1; j <= deployCount; j++ { deployName := fmt.Sprintf("pause-%d-%d", i, j) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile( + nt.Must(rootSyncGitRepo.AddFile( fmt.Sprintf("%s/namespaces/%s/deployment-%s.yaml", syncPath, ns, deployName), []byte(pauseDeploymentYAML(deployName, ns)))) } } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Adding %d RootSyncs each with %d deployments", syncCount, deployCount))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Adding %d RootSyncs each with %d deployments", syncCount, deployCount))) // Wait for root-sync to sync nt.Must(nt.WatchForAllSyncs()) // Wait for the other RootSyncs to sync nt.T.Log("Waiting for RootSyncs to be synced...") - latestCommit := commitForRepo(nt.RootRepos[configsync.RootSyncName]) + latestCommit := commitForRepo(rootSyncGitRepo) for i := 1; i <= syncCount; i++ { syncName := fmt.Sprintf("sync-%d", i) syncPath := syncName @@ -401,11 +405,11 @@ func TestProfilingResourcesByRootSyncCount(t *testing.T) { nt.T.Log("Removing Deployments from Git") for i := 1; i <= syncCount; i++ { syncPath := fmt.Sprintf("sync-%d", i) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(syncPath)) + nt.Must(rootSyncGitRepo.Remove(syncPath)) // Add an empty sync directory so the reconciler doesn't error that it can't find it. - nt.Must(nt.RootRepos[configsync.RootSyncName].AddEmptyDir(syncPath)) + nt.Must(rootSyncGitRepo.AddEmptyDir(syncPath)) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing resources from Git")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing resources from Git")) // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. @@ -414,7 +418,7 @@ func TestProfilingResourcesByRootSyncCount(t *testing.T) { nt.T.Log("Removing RootSyncs from Git") for i := 1; i <= syncCount; i++ { syncName := fmt.Sprintf("sync-%d", i) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove( + nt.Must(rootSyncGitRepo.Remove( fmt.Sprintf("%s/namespaces/%s/rootsync-%s.yaml", gitproviders.DefaultSyncDir, configsync.ControllerNamespace, syncName))) } diff --git a/e2e/testcases/reconciler_finalizer_test.go b/e2e/testcases/reconciler_finalizer_test.go index da91b7550b..0f0dbcfc3c 100644 --- a/e2e/testcases/reconciler_finalizer_test.go +++ b/e2e/testcases/reconciler_finalizer_test.go @@ -37,7 +37,6 @@ import ( nomostesting "kpt.dev/configsync/e2e/nomostest/testing" "kpt.dev/configsync/e2e/nomostest/testpredicates" "kpt.dev/configsync/e2e/nomostest/testutils" - "kpt.dev/configsync/pkg/api/configsync" "kpt.dev/configsync/pkg/api/configsync/v1beta1" "kpt.dev/configsync/pkg/applier" "kpt.dev/configsync/pkg/core" @@ -53,32 +52,33 @@ import ( // TestReconcilerFinalizer_Orphan tests that the reconciler's finalizer // correctly handles Orphan deletion propagation. func TestReconcilerFinalizer_Orphan(t *testing.T) { - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.MultiRepos) + rootSyncID := nomostest.DefaultRootSyncID + rootSyncKey := rootSyncID.ObjectKey + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) - rootRepo := nt.RootRepos[rootSyncNN.Name] deployment1NN := types.NamespacedName{Name: "helloworld-1", Namespace: testNs} namespace1NN := types.NamespacedName{Name: testNs} - safetyNamespace1NN := types.NamespacedName{Name: rootRepo.SafetyNSName} + safetyNamespace1NN := types.NamespacedName{Name: rootSyncGitRepo.SafetyNSName} nt.T.Cleanup(func() { cleanupSingleLevel(nt, - rootSyncNN, + rootSyncKey, deployment1NN, namespace1NN, safetyNamespace1NN) }) // Add namespace to RootSync namespace1 := k8sobjects.NamespaceObject(namespace1NN.Name) - nt.Must(rootRepo.Add(nomostest.StructuredNSPath(namespace1NN.Name, namespace1NN.Name), namespace1)) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(namespace1NN.Name, namespace1NN.Name), namespace1)) // Add deployment-helloworld-1 to RootSync deployment1Path := nomostest.StructuredNSPath(deployment1NN.Namespace, "deployment-helloworld-1") deployment1 := loadDeployment(nt, "../testdata/deployment-helloworld.yaml") deployment1.SetName(deployment1NN.Name) deployment1.SetNamespace(deployment1NN.Namespace) - nt.Must(rootRepo.Add(deployment1Path, deployment1)) - nt.Must(rootRepo.CommitAndPush("Adding deployment helloworld-1 to RootSync")) + nt.Must(rootSyncGitRepo.Add(deployment1Path, deployment1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding deployment helloworld-1 to RootSync")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -92,10 +92,10 @@ func TestReconcilerFinalizer_Orphan(t *testing.T) { // Start here to catch both the finalizer injection and deletion behavior. ctx, cancel := context.WithCancel(context.Background()) defer cancel() - go nomostest.TailReconcilerLogs(ctx, nt, nomostest.RootReconcilerObjectKey(rootSyncNN.Name)) + go nomostest.TailReconcilerLogs(ctx, nt, nomostest.RootReconcilerObjectKey(rootSyncKey.Name)) nt.T.Log("Disabling RootSync deletion propagation") - rootSync := k8sobjects.RootSyncObjectV1Beta1(rootSyncNN.Name) + rootSync := k8sobjects.RootSyncObjectV1Beta1(rootSyncKey.Name) err := nt.KubeClient.Get(rootSync.GetName(), rootSync.GetNamespace(), rootSync) if err != nil { nt.T.Fatal(err) @@ -142,32 +142,33 @@ func TestReconcilerFinalizer_Orphan(t *testing.T) { // TestReconcilerFinalizer_Foreground tests that the reconciler's finalizer // correctly handles Foreground deletion propagation. func TestReconcilerFinalizer_Foreground(t *testing.T) { - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.MultiRepos) + rootSyncID := nomostest.DefaultRootSyncID + rootSyncKey := rootSyncID.ObjectKey + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) - rootRepo := nt.RootRepos[rootSyncNN.Name] deployment1NN := types.NamespacedName{Name: "helloworld-1", Namespace: testNs} namespace1NN := types.NamespacedName{Name: testNs} - safetyNamespace1NN := types.NamespacedName{Name: rootRepo.SafetyNSName} + safetyNamespace1NN := types.NamespacedName{Name: rootSyncGitRepo.SafetyNSName} nt.T.Cleanup(func() { cleanupSingleLevel(nt, - rootSyncNN, + rootSyncKey, deployment1NN, namespace1NN, safetyNamespace1NN) }) // Add namespace to RootSync namespace1 := k8sobjects.NamespaceObject(namespace1NN.Name) - nt.Must(rootRepo.Add(nomostest.StructuredNSPath(namespace1NN.Name, namespace1NN.Name), namespace1)) + nt.Must(rootSyncGitRepo.Add(nomostest.StructuredNSPath(namespace1NN.Name, namespace1NN.Name), namespace1)) // Add deployment-helloworld-1 to RootSync deployment1Path := nomostest.StructuredNSPath(deployment1NN.Namespace, "deployment-helloworld-1") deployment1 := loadDeployment(nt, "../testdata/deployment-helloworld.yaml") deployment1.SetName(deployment1NN.Name) deployment1.SetNamespace(deployment1NN.Namespace) - nt.Must(rootRepo.Add(deployment1Path, deployment1)) - nt.Must(rootRepo.CommitAndPush("Adding deployment helloworld-1 to RootSync")) + nt.Must(rootSyncGitRepo.Add(deployment1Path, deployment1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding deployment helloworld-1 to RootSync")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -181,10 +182,10 @@ func TestReconcilerFinalizer_Foreground(t *testing.T) { // Start here to catch both the finalizer injection and deletion behavior. ctx, cancel := context.WithCancel(context.Background()) defer cancel() - go nomostest.TailReconcilerLogs(ctx, nt, nomostest.RootReconcilerObjectKey(rootSyncNN.Name)) + go nomostest.TailReconcilerLogs(ctx, nt, nomostest.RootReconcilerObjectKey(rootSyncKey.Name)) nt.T.Log("Enabling RootSync deletion propagation") - rootSync := k8sobjects.RootSyncObjectV1Beta1(rootSyncNN.Name) + rootSync := k8sobjects.RootSyncObjectV1Beta1(rootSyncKey.Name) err := nt.KubeClient.Get(rootSync.Name, rootSync.Namespace, rootSync) if err != nil { nt.T.Fatal(err) @@ -228,40 +229,42 @@ func TestReconcilerFinalizer_Foreground(t *testing.T) { // TestReconcilerFinalizer_MultiLevelForeground tests that the reconciler's // finalizer correctly handles multiple layers of Foreground deletion propagation. func TestReconcilerFinalizer_MultiLevelForeground(t *testing.T) { - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) - repoSyncNN := nomostest.RepoSyncNN(testNs, "rs-test") + rootSyncID := nomostest.DefaultRootSyncID + repoSyncID := nomostest.RepoSyncID("rs-test", testNs) nt := nomostest.New(t, nomostesting.MultiRepos, - ntopts.NamespaceRepo(repoSyncNN.Namespace, repoSyncNN.Name), + ntopts.NamespaceRepo(repoSyncID.Namespace, repoSyncID.Name), ntopts.RepoSyncPermissions(policy.AppsAdmin(), policy.CoreAdmin()), // NS Reconciler manages Deployments ) - - rootRepo := nt.RootRepos[rootSyncNN.Name] - nsRepo := nt.NonRootRepos[repoSyncNN] - repoSyncPath := nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name) - deployment1NN := types.NamespacedName{Name: "helloworld-1", Namespace: repoSyncNN.Namespace} - deployment2NN := types.NamespacedName{Name: "helloworld-2", Namespace: repoSyncNN.Namespace} - namespace1NN := types.NamespacedName{Name: repoSyncNN.Namespace} - safetyNamespace1NN := types.NamespacedName{Name: rootRepo.SafetyNSName} - safetyNamespace2NN := types.NamespacedName{Name: nsRepo.SafetyNSName} + rootSyncKey := rootSyncID.ObjectKey + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + + repoSyncPath := nomostest.StructuredNSPath(repoSyncKey.Namespace, repoSyncKey.Name) + deployment1NN := types.NamespacedName{Name: "helloworld-1", Namespace: repoSyncKey.Namespace} + deployment2NN := types.NamespacedName{Name: "helloworld-2", Namespace: repoSyncKey.Namespace} + namespace1NN := types.NamespacedName{Name: repoSyncKey.Namespace} + safetyNamespace1NN := types.NamespacedName{Name: rootSyncGitRepo.SafetyNSName} + safetyNamespace2NN := types.NamespacedName{Name: repoSyncGitRepo.SafetyNSName} nt.T.Cleanup(func() { cleanupMultiLevel(nt, - rootSyncNN, repoSyncNN, + rootSyncKey, repoSyncKey, deployment1NN, deployment2NN, namespace1NN, safetyNamespace1NN, safetyNamespace2NN) }) // Namespace created for the RepoSync by test setup - namespace1 := rootRepo.MustGet(nt.T, nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Namespace)) + namespace1 := rootSyncGitRepo.MustGet(nt.T, nomostest.StructuredNSPath(repoSyncKey.Namespace, repoSyncKey.Namespace)) // Add deployment-helloworld-1 to RootSync deployment1Path := nomostest.StructuredNSPath(deployment1NN.Namespace, "deployment-helloworld-1") deployment1 := loadDeployment(nt, "../testdata/deployment-helloworld.yaml") deployment1.SetName(deployment1NN.Name) deployment1.SetNamespace(deployment1NN.Namespace) - nt.Must(rootRepo.Add(deployment1Path, deployment1)) - nt.Must(rootRepo.CommitAndPush("Adding deployment helloworld-1 to RootSync")) + nt.Must(rootSyncGitRepo.Add(deployment1Path, deployment1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding deployment helloworld-1 to RootSync")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -274,8 +277,8 @@ func TestReconcilerFinalizer_MultiLevelForeground(t *testing.T) { deployment2 := loadDeployment(nt, "../testdata/deployment-helloworld.yaml") deployment2.SetName(deployment2NN.Name) deployment2.SetNamespace(deployment1NN.Namespace) - nt.Must(nsRepo.Add(deployment2Path, deployment2)) - nt.Must(nsRepo.CommitAndPush("Adding deployment helloworld-2 to RepoSync")) + nt.Must(repoSyncGitRepo.Add(deployment2Path, deployment2)) + nt.Must(repoSyncGitRepo.CommitAndPush("Adding deployment helloworld-2 to RepoSync")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -289,11 +292,11 @@ func TestReconcilerFinalizer_MultiLevelForeground(t *testing.T) { // Start here to catch both the finalizer injection and deletion behavior. ctx, cancel := context.WithCancel(context.Background()) defer cancel() - go nomostest.TailReconcilerLogs(ctx, nt, nomostest.RootReconcilerObjectKey(rootSyncNN.Name)) - go nomostest.TailReconcilerLogs(ctx, nt, nomostest.NsReconcilerObjectKey(repoSyncNN.Namespace, repoSyncNN.Name)) + go nomostest.TailReconcilerLogs(ctx, nt, nomostest.RootReconcilerObjectKey(rootSyncKey.Name)) + go nomostest.TailReconcilerLogs(ctx, nt, nomostest.NsReconcilerObjectKey(repoSyncKey.Namespace, repoSyncKey.Name)) nt.T.Log("Enabling RootSync deletion propagation") - rootSync := k8sobjects.RootSyncObjectV1Beta1(rootSyncNN.Name) + rootSync := k8sobjects.RootSyncObjectV1Beta1(rootSyncKey.Name) err := nt.KubeClient.Get(rootSync.Name, rootSync.Namespace, rootSync) if err != nil { nt.T.Fatal(err) @@ -311,10 +314,10 @@ func TestReconcilerFinalizer_MultiLevelForeground(t *testing.T) { })) nt.T.Log("Enabling RepoSync deletion propagation") - repoSync := rootRepo.MustGet(nt.T, repoSyncPath) + repoSync := rootSyncGitRepo.MustGet(nt.T, repoSyncPath) if nomostest.SetDeletionPropagationPolicy(repoSync, metadata.DeletionPropagationPolicyForeground) { - nt.Must(rootRepo.Add(repoSyncPath, repoSync)) - nt.Must(rootRepo.CommitAndPush("Enabling RepoSync deletion propagation")) + nt.Must(rootSyncGitRepo.Add(repoSyncPath, repoSync)) + nt.Must(rootSyncGitRepo.CommitAndPush("Enabling RepoSync deletion propagation")) } if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -356,26 +359,28 @@ func TestReconcilerFinalizer_MultiLevelForeground(t *testing.T) { // correctly handles multiple layers of deletion propagation. // The RootSync has Foreground policy, but manages a RepoSync with Orphan policy. func TestReconcilerFinalizer_MultiLevelMixed(t *testing.T) { - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) - repoSyncNN := nomostest.RepoSyncNN(testNs, "rs-test") + rootSyncID := nomostest.DefaultRootSyncID + repoSyncID := nomostest.RepoSyncID("rs-test", testNs) nt := nomostest.New(t, nomostesting.MultiRepos, - ntopts.NamespaceRepo(repoSyncNN.Namespace, repoSyncNN.Name), + ntopts.NamespaceRepo(repoSyncID.Namespace, repoSyncID.Name), ntopts.RepoSyncPermissions(policy.AppsAdmin(), policy.CoreAdmin()), // NS Reconciler manages Deployments ) - - rootRepo := nt.RootRepos[rootSyncNN.Name] - nsRepo := nt.NonRootRepos[repoSyncNN] - repoSyncPath := nomostest.StructuredNSPath(repoSyncNN.Namespace, repoSyncNN.Name) - deployment1NN := types.NamespacedName{Name: "helloworld-1", Namespace: repoSyncNN.Namespace} - deployment2NN := types.NamespacedName{Name: "helloworld-2", Namespace: repoSyncNN.Namespace} - namespace1NN := types.NamespacedName{Name: repoSyncNN.Namespace} - safetyNamespace1NN := types.NamespacedName{Name: rootRepo.SafetyNSName} - safetyNamespace2NN := types.NamespacedName{Name: nsRepo.SafetyNSName} + rootSyncKey := rootSyncID.ObjectKey + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + + repoSyncPath := nomostest.StructuredNSPath(repoSyncKey.Namespace, repoSyncKey.Name) + deployment1NN := types.NamespacedName{Name: "helloworld-1", Namespace: repoSyncKey.Namespace} + deployment2NN := types.NamespacedName{Name: "helloworld-2", Namespace: repoSyncKey.Namespace} + namespace1NN := types.NamespacedName{Name: repoSyncKey.Namespace} + safetyNamespace1NN := types.NamespacedName{Name: rootSyncGitRepo.SafetyNSName} + safetyNamespace2NN := types.NamespacedName{Name: repoSyncGitRepo.SafetyNSName} nt.T.Cleanup(func() { cleanupMultiLevel(nt, - rootSyncNN, repoSyncNN, + rootSyncKey, repoSyncKey, deployment1NN, deployment2NN, namespace1NN, safetyNamespace1NN, safetyNamespace2NN) }) @@ -385,8 +390,8 @@ func TestReconcilerFinalizer_MultiLevelMixed(t *testing.T) { deployment1 := loadDeployment(nt, "../testdata/deployment-helloworld.yaml") deployment1.SetName(deployment1NN.Name) deployment1.SetNamespace(deployment2NN.Namespace) - nt.Must(rootRepo.Add(deployment1Path, deployment1)) - nt.Must(rootRepo.CommitAndPush("Adding deployment helloworld-1 to RootSync")) + nt.Must(rootSyncGitRepo.Add(deployment1Path, deployment1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding deployment helloworld-1 to RootSync")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -399,8 +404,8 @@ func TestReconcilerFinalizer_MultiLevelMixed(t *testing.T) { deployment2 := loadDeployment(nt, "../testdata/deployment-helloworld.yaml") deployment2.SetName(deployment2NN.Name) deployment2.SetNamespace(deployment2NN.Namespace) - nt.Must(nsRepo.Add(deployment2Path, deployment2)) - nt.Must(nsRepo.CommitAndPush("Adding deployment helloworld-2 to RepoSync")) + nt.Must(repoSyncGitRepo.Add(deployment2Path, deployment2)) + nt.Must(repoSyncGitRepo.CommitAndPush("Adding deployment helloworld-2 to RepoSync")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -414,11 +419,11 @@ func TestReconcilerFinalizer_MultiLevelMixed(t *testing.T) { // Start here to catch both the finalizer injection and deletion behavior. ctx, cancel := context.WithCancel(context.Background()) defer cancel() - go nomostest.TailReconcilerLogs(ctx, nt, nomostest.RootReconcilerObjectKey(rootSyncNN.Name)) - go nomostest.TailReconcilerLogs(ctx, nt, nomostest.NsReconcilerObjectKey(repoSyncNN.Namespace, repoSyncNN.Name)) + go nomostest.TailReconcilerLogs(ctx, nt, nomostest.RootReconcilerObjectKey(rootSyncKey.Name)) + go nomostest.TailReconcilerLogs(ctx, nt, nomostest.NsReconcilerObjectKey(repoSyncKey.Namespace, repoSyncKey.Name)) nt.T.Log("Enabling RootSync deletion propagation") - rootSync := k8sobjects.RootSyncObjectV1Beta1(rootSyncNN.Name) + rootSync := k8sobjects.RootSyncObjectV1Beta1(rootSyncKey.Name) err := nt.KubeClient.Get(rootSync.Name, rootSync.Namespace, rootSync) if err != nil { nt.T.Fatal(err) @@ -436,10 +441,10 @@ func TestReconcilerFinalizer_MultiLevelMixed(t *testing.T) { })) nt.T.Log("Disabling RepoSync deletion propagation") - repoSync := rootRepo.MustGet(nt.T, repoSyncPath) + repoSync := rootSyncGitRepo.MustGet(nt.T, repoSyncPath) if nomostest.RemoveDeletionPropagationPolicy(repoSync) { - nt.Must(rootRepo.Add(repoSyncPath, repoSync)) - nt.Must(rootRepo.CommitAndPush("Disabling RepoSync deletion propagation")) + nt.Must(rootSyncGitRepo.Add(repoSyncPath, repoSync)) + nt.Must(rootSyncGitRepo.CommitAndPush("Disabling RepoSync deletion propagation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -452,10 +457,10 @@ func TestReconcilerFinalizer_MultiLevelMixed(t *testing.T) { // Abandon the test namespace, otherwise it will block the finalizer namespace1Path := nomostest.StructuredNSPath(namespace1NN.Name, namespace1NN.Name) - namespace1 := rootRepo.MustGet(nt.T, namespace1Path) + namespace1 := rootSyncGitRepo.MustGet(nt.T, namespace1Path) core.SetAnnotation(namespace1, common.LifecycleDeleteAnnotation, common.PreventDeletion) - nt.Must(rootRepo.Add(namespace1Path, namespace1)) - nt.Must(rootRepo.CommitAndPush("Adding annotation to keep test namespace on removal from git")) + nt.Must(rootSyncGitRepo.Add(namespace1Path, namespace1)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding annotation to keep test namespace on removal from git")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -505,21 +510,24 @@ func TestReconcilerFinalizer_MultiLevelMixed(t *testing.T) { // is added to that Namespace from the test. Deletion of both the Namespace and // RootSync should be blocked until the Namespace finalizer is removed. func TestReconcileFinalizerReconcileTimeout(t *testing.T) { - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) - nestedRootSyncNN := nomostest.RootSyncNN("nested-root-sync") + rootSyncID := nomostest.DefaultRootSyncID + rootSync2ID := nomostest.RootSyncID("nested-root-sync") namespaceNN := types.NamespacedName{Name: "managed-ns"} contrivedFinalizer := "e2e-test" nt := nomostest.New(t, nomostesting.MultiRepos, ntopts.Unstructured, - ntopts.RootRepo(nestedRootSyncNN.Name), // Create a nested RootSync to delete mid-test + ntopts.RootRepo(rootSync2ID.Name), // Create a nested RootSync to delete mid-test ntopts.WithCentralizedControl, // This test assumes centralized control ntopts.WithReconcileTimeout(10*time.Second), // Reconcile expected to fail, so use a short timeout ) + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + rootSync2GitRepo := nt.SyncSourceGitRepository(rootSync2ID) + // add a Namespace to the nested RootSync namespace := k8sobjects.NamespaceObject(namespaceNN.Name) nsPath := nomostest.StructuredNSPath(namespace.GetNamespace(), namespaceNN.Name) - nt.Must(nt.RootRepos[nestedRootSyncNN.Name].Add(nsPath, namespace)) - nt.Must(nt.RootRepos[nestedRootSyncNN.Name].CommitAndPush(fmt.Sprintf("add Namespace %s", namespaceNN.Name))) + nt.Must(rootSync2GitRepo.Add(nsPath, namespace)) + nt.Must(rootSync2GitRepo.CommitAndPush(fmt.Sprintf("add Namespace %s", namespaceNN.Name))) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -563,7 +571,7 @@ func TestReconcileFinalizerReconcileTimeout(t *testing.T) { tg := taskgroup.New() tg.Go(func() error { return nt.Watcher.WatchForNotFound(kinds.RootSyncV1Beta1(), - nestedRootSyncNN.Name, nestedRootSyncNN.Namespace) + rootSync2ID.Name, rootSync2ID.Namespace) }) tg.Go(func() error { return nt.Watcher.WatchForNotFound(kinds.Namespace(), @@ -576,9 +584,9 @@ func TestReconcileFinalizerReconcileTimeout(t *testing.T) { // Try to remove the nested RootSync. Deletion should be blocked by ns finalizer nestedRootSyncPath := fmt.Sprintf("acme/namespaces/%s/%s.yaml", - configsync.ControllerNamespace, nestedRootSyncNN.Name) - nt.Must(nt.RootRepos[rootSyncNN.Name].Remove(nestedRootSyncPath)) - nt.Must(nt.RootRepos[rootSyncNN.Name].CommitAndPush(fmt.Sprintf("remove Namespace %s", namespaceNN.Name))) + rootSync2ID.Namespace, rootSync2ID.Name) + nt.Must(rootSyncGitRepo.Remove(nestedRootSyncPath)) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("remove Namespace %s", namespaceNN.Name))) expectedCondition := &v1beta1.RootSyncCondition{ Type: v1beta1.RootSyncReconcilerFinalizerFailure, Status: "True", @@ -592,13 +600,13 @@ func TestReconcileFinalizerReconcileTimeout(t *testing.T) { }, } // Finalizer currently only sets condition, not sync status - if err := nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), nestedRootSyncNN.Name, nestedRootSyncNN.Namespace, + if err := nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), rootSync2ID.Name, rootSync2ID.Namespace, []testpredicates.Predicate{testpredicates.RootSyncHasCondition(expectedCondition)}); err != nil { nt.T.Fatal(err) } // Wait a fixed duration for RootSync deletion to be blocked time.Sleep(30 * time.Second) - if err := nt.Validate(nestedRootSyncNN.Name, nestedRootSyncNN.Namespace, &v1beta1.RootSync{}); err != nil { + if err := nt.Validate(rootSync2ID.Name, rootSync2ID.Namespace, &v1beta1.RootSync{}); err != nil { nt.T.Fatal(err) } if err := nt.Validate(namespaceNN.Name, namespaceNN.Namespace, &corev1.Namespace{}); err != nil { diff --git a/e2e/testcases/reconciler_manager_test.go b/e2e/testcases/reconciler_manager_test.go index 50a72838c2..db151c4a7c 100644 --- a/e2e/testcases/reconciler_manager_test.go +++ b/e2e/testcases/reconciler_manager_test.go @@ -1169,14 +1169,19 @@ func filterResourceMap(resourceMap map[string]v1beta1.ContainerResourcesSpec, co // 7. Recreate RootSync CRD // 8. Validate RootSync syncing works func TestReconcilerManagerRootSyncCRDMissing(t *testing.T) { + rootSyncID := nomostest.DefaultRootSyncID repoSyncNS := "bookstore" - repoSyncNN := nomostest.RepoSyncNN(repoSyncNS, configsync.RepoSyncName) + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, repoSyncNS) nt := nomostest.New(t, nomostesting.ACMController, ntopts.WithDelegatedControl, // Delegated so deleting the RootSync doesn't delete the RepoSyncs. ntopts.Unstructured, - ntopts.NamespaceRepo(repoSyncNN.Namespace, repoSyncNN.Name), + ntopts.NamespaceRepo(repoSyncID.Namespace, repoSyncID.Name), ntopts.RepoSyncPermissions(policy.CoreAdmin()), // NS Reconciler manages ServiceAccounts ) + rootSyncKey := rootSyncID.ObjectKey + rootSyncGitRepo := nt.SyncSourceGitRepository(rootSyncID) + repoSyncKey := repoSyncID.ObjectKey + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) reconcilerManagerKey := client.ObjectKey{ Name: reconcilermanager.ManagerName, @@ -1188,9 +1193,8 @@ func TestReconcilerManagerRootSyncCRDMissing(t *testing.T) { testpredicates.StatusEquals(nt.Scheme, kstatus.CurrentStatus))) // Enable RootSync deletion propagation, if not enabled - rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) rootSync := &v1beta1.RootSync{} - nt.Must(nt.KubeClient.Get(rootSyncNN.Name, rootSyncNN.Namespace, rootSync)) + nt.Must(nt.KubeClient.Get(rootSyncKey.Name, rootSyncKey.Namespace, rootSync)) if nomostest.EnableDeletionPropagation(rootSync) { nt.Must(nt.KubeClient.Update(rootSync)) nt.Must(nt.Watcher.WatchObject(kinds.RootSyncV1Beta1(), rootSync.Name, rootSync.Namespace, []testpredicates.Predicate{ @@ -1202,9 +1206,9 @@ func TestReconcilerManagerRootSyncCRDMissing(t *testing.T) { nsName1 := "root-sync-1" rootSyncDir1 := gitproviders.DefaultSyncDir nt.Must(nt.ValidateNotFound(nsName1, "", &corev1.Namespace{})) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", rootSyncDir1, nsName1), + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", rootSyncDir1, nsName1), k8sobjects.NamespaceObject(nsName1))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding namespace 1")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding namespace 1")) nt.Must(nt.WatchForAllSyncs()) nt.Must(nt.Validate(nsName1, "", &corev1.Namespace{})) @@ -1222,9 +1226,9 @@ func TestReconcilerManagerRootSyncCRDMissing(t *testing.T) { saName1 := "repo-sync-1" repoSyncDir1 := gitproviders.DefaultSyncDir nt.Must(nt.ValidateNotFound(saName1, repoSyncNS, &corev1.ServiceAccount{})) - nt.Must(nt.NonRootRepos[repoSyncNN].Add(fmt.Sprintf("%s/sa-%s.yaml", repoSyncDir1, saName1), + nt.Must(repoSyncGitRepo.Add(fmt.Sprintf("%s/sa-%s.yaml", repoSyncDir1, saName1), k8sobjects.ServiceAccountObject(saName1, core.Namespace(repoSyncNS)))) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("Adding service account 1")) + nt.Must(repoSyncGitRepo.CommitAndPush("Adding service account 1")) nt.Must(nt.WatchForAllSyncs( nomostest.SkipReadyCheck(), // Skip ready check because it requires the RootSync CRD to exist. nomostest.RepoSyncOnly())) @@ -1243,17 +1247,17 @@ func TestReconcilerManagerRootSyncCRDMissing(t *testing.T) { saName2 := "repo-sync-2" repoSyncDir2 := "acme-2" nt.Must(nt.ValidateNotFound(saName2, repoSyncNS, &corev1.ServiceAccount{})) - nt.Must(nt.NonRootRepos[repoSyncNN].Add(fmt.Sprintf("%s/sa-%s.yaml", repoSyncDir2, saName2), + nt.Must(repoSyncGitRepo.Add(fmt.Sprintf("%s/sa-%s.yaml", repoSyncDir2, saName2), k8sobjects.ServiceAccountObject(saName2, core.Namespace(repoSyncNS)))) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("Adding service account 2")) + nt.Must(repoSyncGitRepo.CommitAndPush("Adding service account 2")) // Change RepoSync sync dir to trigger reconciler-manager to update the reconciler - repoSync := k8sobjects.RepoSyncObjectV1Beta1(repoSyncNN.Namespace, repoSyncNN.Name) + repoSync := k8sobjects.RepoSyncObjectV1Beta1(repoSyncKey.Namespace, repoSyncKey.Name) nt.MustMergePatch(repoSync, fmt.Sprintf(`{"spec":{"git":{"dir":%q}}}`, repoSyncDir2)) nt.Must(nt.WatchForAllSyncs( nomostest.SkipReadyCheck(), // Skip ready check because it requires the RootSync CRD to exist. nomostest.RepoSyncOnly(), nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{ - repoSyncNN: repoSyncDir2, + repoSyncKey: repoSyncDir2, }))) nt.Must(nt.Validate(saName2, repoSyncNS, &corev1.ServiceAccount{})) @@ -1274,8 +1278,8 @@ func TestReconcilerManagerRootSyncCRDMissing(t *testing.T) { nt.Must(nt.KubeClient.Create(rootSync)) nt.Must(nt.WatchForAllSyncs( nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{ - rootSyncNN: rootSyncDir1, - repoSyncNN: repoSyncDir2, + rootSyncKey: rootSyncDir1, + repoSyncKey: repoSyncDir2, }))) nt.Must(nt.Validate(nsName1, "", &corev1.Namespace{})) } diff --git a/e2e/testcases/remediator_test.go b/e2e/testcases/remediator_test.go index 8decc684f4..2844209d18 100644 --- a/e2e/testcases/remediator_test.go +++ b/e2e/testcases/remediator_test.go @@ -30,17 +30,18 @@ import ( func TestSurfaceFightError(t *testing.T) { nt := nomostest.New(t, nomostesting.DriftControl) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nt.T.Logf("Stop the admission webhook to generate the fights") nomostest.StopWebhook(nt) ns := k8sobjects.NamespaceObject("test-ns", core.Annotation("foo", "bar")) rb := roleBinding("test-rb", ns.Name, map[string]string{"foo": "bar"}) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s/ns.yaml", ns.Name), ns)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("acme/namespaces/%s/rb.yaml", ns.Name), rb)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add Namespace and RoleBinding")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add Namespace and RoleBinding")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -63,7 +64,7 @@ func TestSurfaceFightError(t *testing.T) { if err != nil { nt.T.Fatal(err) } - commitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + commitHash := rootSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerErrorMetrics(nt, rootSyncLabels, commitHash, metrics.ErrorSummary{ diff --git a/e2e/testcases/resource_group_controller_test.go b/e2e/testcases/resource_group_controller_test.go index 1498a0f300..d1121d1501 100644 --- a/e2e/testcases/resource_group_controller_test.go +++ b/e2e/testcases/resource_group_controller_test.go @@ -39,17 +39,18 @@ import ( func TestResourceGroupController(t *testing.T) { nt := nomostest.New(t, nomostesting.ACMController) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) ns := "rg-test" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( "acme/namespaces/rg-test/ns.yaml", k8sobjects.NamespaceObject(ns))) cmName := "e2e-test-configmap" cmPath := "acme/namespaces/rg-test/configmap.yaml" cm := k8sobjects.ConfigMapObject(core.Name(cmName), core.Namespace(ns)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding a ConfigMap to repo")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding a ConfigMap to repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/root_sync_test.go b/e2e/testcases/root_sync_test.go index 64110796f4..37d7faa3ae 100644 --- a/e2e/testcases/root_sync_test.go +++ b/e2e/testcases/root_sync_test.go @@ -89,6 +89,7 @@ func TestDeleteRootSyncAndRootSyncV1Alpha1(t *testing.T) { func TestUpdateRootSyncGitDirectory(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.SyncSource) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) // Validate RootSync is present. var rs v1beta1.RootSync @@ -101,21 +102,21 @@ func TestUpdateRootSyncGitDirectory(t *testing.T) { auditNS := "audit" auditNSObj := k8sobjects.NamespaceObject(auditNS) auditNSPath := fmt.Sprintf("%s/namespaces/%s/ns.yaml", rs.Spec.Git.Dir, auditNS) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(auditNSPath, auditNSObj)) + nt.Must(rootSyncGitRepo.Add(auditNSPath, auditNSObj)) // Add namespace in policy directory 'foo'. fooDir := "foo" fooNS := "shipping" fooNSPath := fmt.Sprintf("%s/namespaces/%s/ns.yaml", fooDir, fooNS) fooNSObj := k8sobjects.NamespaceObject(fooNS) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fooNSPath, fooNSObj)) + nt.Must(rootSyncGitRepo.Add(fooNSPath, fooNSObj)) // Add repo resource in policy directory 'foo'. - nt.Must(nt.RootRepos[configsync.RootSyncName].Add( + nt.Must(rootSyncGitRepo.Add( fmt.Sprintf("%s/system/repo.yaml", fooDir), k8sobjects.RepoObject())) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add namespace to acme directory")) + nt.Must(rootSyncGitRepo.CommitAndPush("add namespace to acme directory")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -179,6 +180,7 @@ func TestUpdateRootSyncGitDirectory(t *testing.T) { func TestUpdateRootSyncGitBranch(t *testing.T) { rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName) nt := nomostest.New(t, nomostesting.SyncSource) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) nsA := "ns-a" nsB := "ns-b" @@ -188,8 +190,8 @@ func TestUpdateRootSyncGitBranch(t *testing.T) { branchB := "test-branch" // Add "ns-a" namespace. - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsA), nsAObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add namespace to acme directory")) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsA), nsAObj)) + nt.Must(rootSyncGitRepo.CommitAndPush("add namespace to acme directory")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -211,14 +213,14 @@ func TestUpdateRootSyncGitBranch(t *testing.T) { } // Add a 'test-branch' branch with 'ns-b' namespace. - nt.Must(nt.RootRepos[configsync.RootSyncName].CreateBranch(branchB)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CheckoutBranch(branchB)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsA))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsB), nsBObj)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPushBranch("add ns-b to acme directory", branchB)) + nt.Must(rootSyncGitRepo.CreateBranch(branchB)) + nt.Must(rootSyncGitRepo.CheckoutBranch(branchB)) + nt.Must(rootSyncGitRepo.Remove(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsA))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("acme/namespaces/%s/ns.yaml", nsB), nsBObj)) + nt.Must(rootSyncGitRepo.CommitAndPushBranch("add ns-b to acme directory", branchB)) // Checkout back to 'main' branch to get the correct HEAD commit sha1. - nt.Must(nt.RootRepos[configsync.RootSyncName].CheckoutBranch(branchA)) + nt.Must(rootSyncGitRepo.CheckoutBranch(branchA)) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -248,7 +250,7 @@ func TestUpdateRootSyncGitBranch(t *testing.T) { nomostest.SetGitBranch(nt, configsync.RootSyncName, branchB) // Checkout 'test-branch' branch to get the correct HEAD commit sha1. - nt.Must(nt.RootRepos[configsync.RootSyncName].CheckoutBranch(branchB)) + nt.Must(rootSyncGitRepo.CheckoutBranch(branchB)) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -280,7 +282,7 @@ func TestUpdateRootSyncGitBranch(t *testing.T) { nomostest.SetGitBranch(nt, configsync.RootSyncName, branchA) // Checkout back to 'main' branch to get the correct HEAD commit sha1. - nt.Must(nt.RootRepos[configsync.RootSyncName].CheckoutBranch(branchA)) + nt.Must(rootSyncGitRepo.CheckoutBranch(branchA)) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -311,9 +313,10 @@ func TestUpdateRootSyncGitBranch(t *testing.T) { func TestForceRevert(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/system/repo.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Cause source error")) + nt.Must(rootSyncGitRepo.Remove("acme/system/repo.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Cause source error")) nt.WaitForRootSyncSourceError(configsync.RootSyncName, system.MissingRepoErrorCode, "") @@ -322,7 +325,7 @@ func TestForceRevert(t *testing.T) { if err != nil { nt.T.Fatal(err) } - commitHash := nt.RootRepos[configsync.RootSyncName].MustHash(nt.T) + commitHash := rootSyncGitRepo.MustHash(nt.T) err = nomostest.ValidateMetrics(nt, nomostest.ReconcilerErrorMetrics(nt, rootSyncLabels, commitHash, metrics.ErrorSummary{ @@ -332,8 +335,8 @@ func TestForceRevert(t *testing.T) { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Git("reset", "--hard", "HEAD^")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Push(syncBranch, "-f")) + nt.Must(rootSyncGitRepo.Git("reset", "--hard", "HEAD^")) + nt.Must(rootSyncGitRepo.Push(syncBranch, "-f")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) @@ -368,14 +371,15 @@ func TestRootSyncReconcilingStatus(t *testing.T) { func TestManageSelfRootSync(t *testing.T) { nt := nomostest.New(t, nomostesting.ACMController, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) rs := &v1beta1.RootSync{} if err := nt.KubeClient.Get(configsync.RootSyncName, configsync.ControllerNamespace, rs); err != nil { nt.T.Fatal(err) } sanitizedRs := k8sobjects.RootSyncObjectV1Beta1(rs.Name) sanitizedRs.Spec = rs.Spec - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/root-sync.yaml", sanitizedRs)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add the root-sync object that configures the reconciler")) + nt.Must(rootSyncGitRepo.Add("acme/root-sync.yaml", sanitizedRs)) + nt.Must(rootSyncGitRepo.CommitAndPush("add the root-sync object that configures the reconciler")) nt.WaitForRootSyncSourceError(configsync.RootSyncName, validate.SelfReconcileErrorCode, "RootSync config-management-system/root-sync must not manage itself in its repo") } diff --git a/e2e/testcases/ssh_known_hosts_test.go b/e2e/testcases/ssh_known_hosts_test.go index 74c481f571..49c6e4e7e9 100644 --- a/e2e/testcases/ssh_known_hosts_test.go +++ b/e2e/testcases/ssh_known_hosts_test.go @@ -34,6 +34,8 @@ import ( func TestRootSyncSSHKnownHost(t *testing.T) { nt := nomostest.New(t, nomostesting.SyncSource, ntopts.RequireLocalGitProvider, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + var err error rootSecret := &corev1.Secret{} nt.T.Cleanup(func() { @@ -86,8 +88,8 @@ func TestRootSyncSSHKnownHost(t *testing.T) { cmName := "configmap-test" cmPath := "acme/configmap.yaml" cm := k8sobjects.ConfigMapObject(core.Name(cmName)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(cmPath, cm)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding test ConfigMap")) + nt.Must(rootSyncGitRepo.Add(cmPath, cm)) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding test ConfigMap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -95,8 +97,8 @@ func TestRootSyncSSHKnownHost(t *testing.T) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(cmPath)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing test ConfigMap")) + nt.Must(rootSyncGitRepo.Remove(cmPath)) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing test ConfigMap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -125,13 +127,15 @@ func TestRootSyncSSHKnownHost(t *testing.T) { } func TestRepoSyncSSHKnownHost(t *testing.T) { + repoSyncID := nomostest.RepoSyncID(configsync.RepoSyncName, backendNamespace) nt := nomostest.New(t, nomostesting.SyncSource, ntopts.RequireLocalGitProvider, ntopts.Unstructured, - ntopts.NamespaceRepo(backendNamespace, configsync.RepoSyncName), ntopts.WithDelegatedControl, + ntopts.NamespaceRepo(repoSyncID.Namespace, repoSyncID.Name), ntopts.WithDelegatedControl, ntopts.RepoSyncPermissions(policy.AppsAdmin(), policy.CoreAdmin())) + repoSyncGitRepo := nt.SyncSourceGitRepository(repoSyncID) + var err error repoSecret := &corev1.Secret{} - repoReconcilerName := core.NsReconcilerName(backendNamespace, configsync.RepoSyncName) - repoSyncNN := nomostest.RepoSyncNN(backendNamespace, configsync.RepoSyncName) + repoReconcilerName := core.NsReconcilerName(repoSyncID.Namespace, repoSyncID.Name) nt.T.Cleanup(func() { nt.MustMergePatch(repoSecret, secretDataDeletePatch(controllers.KnownHostsKey)) err = nt.Watcher.WatchObject(kinds.Deployment(), @@ -182,8 +186,8 @@ func TestRepoSyncSSHKnownHost(t *testing.T) { cmName := "configmap-test" cmPath := "acme/configmap.yaml" cm := k8sobjects.ConfigMapObject(core.Name(cmName)) - nt.Must(nt.NonRootRepos[repoSyncNN].Add(cmPath, cm)) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("Adding test ConfigMap")) + nt.Must(repoSyncGitRepo.Add(cmPath, cm)) + nt.Must(repoSyncGitRepo.CommitAndPush("Adding test ConfigMap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -191,8 +195,8 @@ func TestRepoSyncSSHKnownHost(t *testing.T) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.NonRootRepos[repoSyncNN].Remove(cmPath)) - nt.Must(nt.NonRootRepos[repoSyncNN].CommitAndPush("Removing test ConfigMap")) + nt.Must(repoSyncGitRepo.Remove(cmPath)) + nt.Must(repoSyncGitRepo.CommitAndPush("Removing test ConfigMap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/status_enablement_test.go b/e2e/testcases/status_enablement_test.go index e42bfeb5cd..87641dd813 100644 --- a/e2e/testcases/status_enablement_test.go +++ b/e2e/testcases/status_enablement_test.go @@ -39,6 +39,7 @@ import ( func TestStatusEnabledAndDisabled(t *testing.T) { nt := nomostest.New(t, nomostesting.OverrideAPI, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) id := applier.InventoryID(configsync.RootSyncName, configsync.ControllerNamespace) rootSync := k8sobjects.RootSyncObjectV1Alpha1(configsync.RootSyncName) @@ -49,9 +50,9 @@ func TestStatusEnabledAndDisabled(t *testing.T) { } namespaceName := "status-test" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespaceObject(namespaceName, nil))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name("cm1"), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a namespace and a configmap")) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespaceObject(namespaceName, nil))) + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name("cm1"), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a namespace and a configmap")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/stress_test.go b/e2e/testcases/stress_test.go index aae1823b3b..12d7cc76d3 100644 --- a/e2e/testcases/stress_test.go +++ b/e2e/testcases/stress_test.go @@ -38,6 +38,7 @@ import ( "kpt.dev/configsync/e2e/nomostest/iam" "kpt.dev/configsync/e2e/nomostest/ntopts" "kpt.dev/configsync/e2e/nomostest/registryproviders" + "kpt.dev/configsync/e2e/nomostest/syncsource" nomostesting "kpt.dev/configsync/e2e/nomostest/testing" "kpt.dev/configsync/e2e/nomostest/testpredicates" "kpt.dev/configsync/e2e/nomostest/testresourcegroup" @@ -76,6 +77,7 @@ func crontabCR(namespace, name string) (*unstructured.Unstructured, error) { func TestStressCRD(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.StressTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncPath := gitproviders.DefaultSyncDir @@ -93,24 +95,24 @@ func TestStressCRD(t *testing.T) { if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile(fmt.Sprintf("%s/crontab-crd.yaml", syncPath), crdContent)) + nt.Must(rootSyncGitRepo.AddFile(fmt.Sprintf("%s/crontab-crd.yaml", syncPath), crdContent)) labelKey := "StressTestName" labelValue := "TestStressCRD" for i := 1; i <= 1000; i++ { ns := fmt.Sprintf("foo%d", i) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%d.yaml", syncPath, i), k8sobjects.NamespaceObject( + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%d.yaml", syncPath, i), k8sobjects.NamespaceObject( ns, core.Label(labelKey, labelValue)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/cm-%d.yaml", syncPath, i), k8sobjects.ConfigMapObject( + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/cm-%d.yaml", syncPath, i), k8sobjects.ConfigMapObject( core.Name("cm1"), core.Namespace(ns), core.Label(labelKey, labelValue)))) cr, err := crontabCR(ns, "cr1") if err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/crontab-cr-%d.yaml", syncPath, i), cr)) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/crontab-cr-%d.yaml", syncPath, i), cr)) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add configs (one CRD and 1000 Namespaces (every namespace has one ConfigMap and one CR)")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add configs (one CRD and 1000 Namespaces (every namespace has one ConfigMap and one CR)")) err = nt.WatchForAllSyncs(nomostest.WithTimeout(30 * time.Minute)) if err != nil { nt.T.Fatal(err) @@ -138,6 +140,7 @@ func TestStressCRD(t *testing.T) { func TestStressLargeNamespace(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.StressTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncPath := gitproviders.DefaultSyncDir ns := "my-ns-1" @@ -152,15 +155,15 @@ func TestStressLargeNamespace(t *testing.T) { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) labelKey := "StressTestName" labelValue := "TestStressLargeNamespace" for i := 1; i <= 5000; i++ { - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/cm-%d.yaml", syncPath, i), k8sobjects.ConfigMapObject( + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/cm-%d.yaml", syncPath, i), k8sobjects.ConfigMapObject( core.Name(fmt.Sprintf("cm-%d", i)), core.Namespace(ns), core.Label(labelKey, labelValue)))) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add configs (5000 ConfigMaps and 1 Namespace")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add configs (5000 ConfigMaps and 1 Namespace")) err := nt.WatchForAllSyncs(nomostest.WithTimeout(10 * time.Minute)) if err != nil { nt.T.Fatal(err) @@ -176,6 +179,7 @@ func TestStressLargeNamespace(t *testing.T) { func TestStressFrequentGitCommits(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.StressTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncPath := gitproviders.DefaultSyncDir ns := "bookstore" @@ -183,8 +187,8 @@ func TestStressFrequentGitCommits(t *testing.T) { nt.T.Log("Stop the CS webhook by removing the webhook configuration") nomostest.StopWebhook(nt) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("add a namespace: %s", ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("add a namespace: %s", ns))) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -194,9 +198,9 @@ func TestStressFrequentGitCommits(t *testing.T) { labelValue := "TestStressFrequentGitCommits" for i := 0; i < 100; i++ { cmName := fmt.Sprintf("cm-%v", i) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/%s.yaml", syncPath, cmName), + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/%s.yaml", syncPath, cmName), k8sobjects.ConfigMapObject(core.Name(cmName), core.Namespace(ns), core.Label(labelKey, labelValue)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("add %s", cmName))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("add %s", cmName))) } err := nt.WatchForAllSyncs(nomostest.WithTimeout(10 * time.Minute)) if err != nil { @@ -292,6 +296,7 @@ func TestStressLargeRequest(t *testing.T) { func TestStress100CRDs(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.StressTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncPath := gitproviders.DefaultSyncDir ns := "stress-test-ns" @@ -319,8 +324,8 @@ func TestStress100CRDs(t *testing.T) { nomostest.DeletePodByLabel(nt, "app", reconcilermanager.Reconciler, true) nt.T.Log("Adding a test namespace to the repo to trigger a new sync") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add a test namespace to trigger a new sync")) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.CommitAndPush("Add a test namespace to trigger a new sync")) nt.T.Logf("Waiting for the sync to complete") if err := nt.WatchForAllSyncs(); err != nil { @@ -346,6 +351,7 @@ func TestStressManyDeployments(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.StressTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncPath := filepath.Join(gitproviders.DefaultSyncDir, "stress-test") ns := "stress-test-ns" @@ -353,16 +359,16 @@ func TestStressManyDeployments(t *testing.T) { deployCount := 1000 nt.T.Logf("Adding a test namespace and %d deployments", deployCount) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) for i := 1; i <= deployCount; i++ { name := fmt.Sprintf("pause-%d", i) - nt.Must(nt.RootRepos[configsync.RootSyncName].AddFile( + nt.Must(rootSyncGitRepo.AddFile( fmt.Sprintf("%s/namespaces/%s/deployment-%s.yaml", syncPath, ns, name), []byte(pauseDeploymentYAML(name, ns)))) } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Adding a test namespace and %d deployments", deployCount))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Adding a test namespace and %d deployments", deployCount))) // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. @@ -376,8 +382,8 @@ func TestStressManyDeployments(t *testing.T) { client.InNamespace(ns))) nt.T.Log("Removing resources from Git") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(syncPath)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing resources from Git")) + nt.Must(rootSyncGitRepo.Remove(syncPath)) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing resources from Git")) // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. @@ -392,6 +398,7 @@ func TestStressManyDeployments(t *testing.T) { func TestStressMemoryUsageGit(t *testing.T) { nt := nomostest.New(t, nomostesting.Reconciliation1, ntopts.Unstructured, ntopts.StressTest, ntopts.WithReconcileTimeout(configsync.DefaultReconcileTimeout)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) syncPath := filepath.Join(gitproviders.DefaultSyncDir, "stress-test") ns := "stress-test-ns" @@ -401,12 +408,12 @@ func TestStressMemoryUsageGit(t *testing.T) { crCount := 50 nt.T.Logf("Adding a test namespace, %d crds, and %d objects per crd", crdCount, crCount) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/ns-%s.yaml", syncPath, ns), k8sobjects.NamespaceObject(ns))) for i := 1; i <= crdCount; i++ { group := fmt.Sprintf("acme-%d.com", i) crd := fakeCRD(kind, group) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/crd-%s.yaml", syncPath, crd.Name), crd)) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/crd-%s.yaml", syncPath, crd.Name), crd)) gvk := schema.GroupVersionKind{ Group: group, Kind: kind, @@ -414,11 +421,11 @@ func TestStressMemoryUsageGit(t *testing.T) { } for j := 1; j <= crCount; j++ { cr := fakeCR(fmt.Sprintf("%s-%d", strings.ToLower(kind), j), ns, gvk) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("%s/namespaces/%s/%s-%s.yaml", syncPath, ns, crd.Name, cr.GetName()), cr)) + nt.Must(rootSyncGitRepo.Add(fmt.Sprintf("%s/namespaces/%s/%s-%s.yaml", syncPath, ns, crd.Name, cr.GetName()), cr)) } } - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush(fmt.Sprintf("Adding a test namespace, %d crds, and %d objects per crd", crdCount, crCount))) + nt.Must(rootSyncGitRepo.CommitAndPush(fmt.Sprintf("Adding a test namespace, %d crds, and %d objects per crd", crdCount, crCount))) // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. @@ -440,8 +447,8 @@ func TestStressMemoryUsageGit(t *testing.T) { } nt.T.Log("Removing resources from Git") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove(syncPath)) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing resources from Git")) + nt.Must(rootSyncGitRepo.Remove(syncPath)) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing resources from Git")) // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. @@ -568,6 +575,8 @@ func TestStressMemoryUsageOCI(t *testing.T) { // 7. IAM for the test runner to write to Artifact Registry repo // 8. gcloud & helm func TestStressMemoryUsageHelm(t *testing.T) { + rootSyncID := nomostest.DefaultRootSyncID + rootSyncKey := rootSyncID.ObjectKey nt := nomostest.New(t, nomostesting.WorkloadIdentity, ntopts.Unstructured, ntopts.StressTest, ntopts.RequireHelmProvider, ntopts.WithReconcileTimeout(30*time.Second)) @@ -580,7 +589,7 @@ func TestStressMemoryUsageHelm(t *testing.T) { nt.T.Fatal(err) } - chart, err := nt.BuildAndPushHelmPackage(nomostest.RootSyncNN(configsync.RootSyncName), + chart, err := nt.BuildAndPushHelmPackage(rootSyncKey, registryproviders.HelmSourceChart("anvil-set")) if err != nil { nt.T.Fatalf("failed to push helm chart: %v", err) @@ -593,7 +602,7 @@ func TestStressMemoryUsageHelm(t *testing.T) { kind := "Anvil" nt.T.Logf("Updating RootSync to sync from the Helm chart: %s:%s", chart.Name, chart.Version) - rs := nt.RootSyncObjectHelm(configsync.RootSyncName, chart.HelmChartID) + rs := nt.RootSyncObjectHelm(rootSyncID.Name, chart.HelmChartID) rs.Spec.Helm.Namespace = ns rs.Spec.Helm.Values = &apiextensionsv1.JSON{ Raw: []byte(fmt.Sprintf(`{"resources": %d, "replicas": %d}`, crdCount, crCount)), @@ -620,7 +629,7 @@ func TestStressMemoryUsageHelm(t *testing.T) { client.InNamespace(ns))) } - emptyChart, err := nt.BuildAndPushHelmPackage(nomostest.RootSyncNN(configsync.RootSyncName), + emptyChart, err := nt.BuildAndPushHelmPackage(rootSyncKey, registryproviders.HelmSourceChart("empty"), registryproviders.HelmChartVersion("v1.1.0")) if err != nil { @@ -632,8 +641,9 @@ func TestStressMemoryUsageHelm(t *testing.T) { emptyChart.Name, emptyChart.Version)) // Update the expected helm chart - rsKey := client.ObjectKeyFromObject(rs) - nt.RootSyncHelmCharts[rsKey] = emptyChart.HelmChartID + nt.SyncSources[rootSyncID] = &syncsource.HelmSyncSource{ + ChartID: emptyChart.HelmChartID, + } // Validate that the resources sync without the reconciler running out of // memory, getting OOMKilled, and crash looping. diff --git a/e2e/testcases/sync_ordering_test.go b/e2e/testcases/sync_ordering_test.go index b29cd869f0..1ff1de3b1d 100644 --- a/e2e/testcases/sync_ordering_test.go +++ b/e2e/testcases/sync_ordering_test.go @@ -45,6 +45,7 @@ import ( func TestMultiDependencies(t *testing.T) { nt := nomostest.New(t, nomostesting.Lifecycle, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespaceName := "bookstore" nt.T.Logf("Remove the namespace %q if it already exists", namespaceName) @@ -55,12 +56,12 @@ func TestMultiDependencies(t *testing.T) { namespace := k8sobjects.NamespaceObject(namespaceName) cm1Name := "cm1" cm2Name := "cm2" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", namespace)) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", namespace)) + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName)))) // cm2 depends on cm1 - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm2.yaml", k8sobjects.ConfigMapObject(core.Name(cm2Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm2.yaml", k8sobjects.ConfigMapObject(core.Name(cm2Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm1")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add the namespace, cm1, and cm2 (cm2 depends on cm1)")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add the namespace, cm1, and cm2 (cm2 depends on cm1)")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -106,9 +107,9 @@ func TestMultiDependencies(t *testing.T) { nt.T.Log("Add cm3, which depends on an existing object, cm1") // cm3 depends on cm1 cm3Name := "cm3" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm3.yaml", k8sobjects.ConfigMapObject(core.Name(cm3Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm3.yaml", k8sobjects.ConfigMapObject(core.Name(cm3Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm1")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add cm3, which depends on an existing object, cm1")) + nt.Must(rootSyncGitRepo.CommitAndPush("add cm3, which depends on an existing object, cm1")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -136,10 +137,10 @@ func TestMultiDependencies(t *testing.T) { nt.T.Log("add a new configmap, cm0; and add the dependsOn annotation to cm1") // cm1 depends on cm0 cm0Name := "cm0" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("add a new configmap, cm0; and add the dependsOn annotation to cm1")) + nt.Must(rootSyncGitRepo.CommitAndPush("add a new configmap, cm0; and add the dependsOn annotation to cm1")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -166,9 +167,9 @@ func TestMultiDependencies(t *testing.T) { nt.T.Log("A new test: verify that Config Sync reports an error when a cyclic dependency is encountered (a cyclic dependency between cm0, cm1, and cm2. cm1 depends on cm0; cm2 depends on cm1; cm0 depends on cm2)") nt.T.Log("Create a cyclic dependency between cm0, cm1, and cm2") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm2")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Create a cyclic dependency between cm0, cm1, and cm2")) + nt.Must(rootSyncGitRepo.CommitAndPush("Create a cyclic dependency between cm0, cm1, and cm2")) nt.WaitForRootSyncSyncError(configsync.RootSyncName, applier.ApplierErrorCode, "cyclic dependency", nil) nt.T.Log("Verify that cm0 does not have the dependsOn annotation") @@ -177,8 +178,8 @@ func TestMultiDependencies(t *testing.T) { } nt.T.Log("Remove the cyclic dependency from the Git repo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the cyclic dependency from the Git repo")) + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the cyclic dependency from the Git repo")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -191,8 +192,8 @@ func TestMultiDependencies(t *testing.T) { nt.T.Log("A new test: verify that an object can be removed without affecting its dependency (cm3 depends on cm1, and both cm3 and cm1 exist in the Git repo and on the cluster.)") nt.T.Log("Remove cm3") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm3.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove cm3")) + nt.Must(rootSyncGitRepo.Remove("acme/cm3.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove cm3")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -215,9 +216,9 @@ func TestMultiDependencies(t *testing.T) { nt.T.Log("A new test: verify that an object and its dependency can be removed together (cm1 and cm2 both exist in the Git repo and on the cluster. cm2 depends on cm1.)") nt.T.Log("Remove cm1 and cm2") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm2.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove cm1 and cm2")) + nt.Must(rootSyncGitRepo.Remove("acme/cm1.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/cm2.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove cm1 and cm2")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -237,13 +238,13 @@ func TestMultiDependencies(t *testing.T) { // There are 1 configmap in the namespace at this point: cm0. nt.T.Log("Add cm1, cm2, and cm3") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm2.yaml", k8sobjects.ConfigMapObject(core.Name(cm2Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm2.yaml", k8sobjects.ConfigMapObject(core.Name(cm2Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm3.yaml", k8sobjects.ConfigMapObject(core.Name(cm3Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm3.yaml", k8sobjects.ConfigMapObject(core.Name(cm3Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add cm1, cm2, and cm3")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add cm1, cm2, and cm3")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -271,10 +272,10 @@ func TestMultiDependencies(t *testing.T) { nt.T.Log("A new test: verify that an object can be disabled without affecting its dependency") nt.T.Log("Disable cm3 by adding the `configmanagement.gke.io/managed: disabled` annotation") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm3.yaml", k8sobjects.ConfigMapObject(core.Name(cm3Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm3.yaml", k8sobjects.ConfigMapObject(core.Name(cm3Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0"), core.Annotation(metadata.ResourceManagementKey, metadata.ResourceManagementDisabled)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Disable cm3 by adding the `configmanagement.gke.io/managed: disabled` annotation")) + nt.Must(rootSyncGitRepo.CommitAndPush("Disable cm3 by adding the `configmanagement.gke.io/managed: disabled` annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -296,8 +297,8 @@ func TestMultiDependencies(t *testing.T) { nt.T.Log("A new test: verify that the dependsOn annotation can be removed from an object without affecting its dependency") nt.T.Log("Remove the dependsOn annotation from cm2") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm2.yaml", k8sobjects.ConfigMapObject(core.Name(cm2Name), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove the dependsOn annotation from cm2")) + nt.Must(rootSyncGitRepo.Add("acme/cm2.yaml", k8sobjects.ConfigMapObject(core.Name(cm2Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove the dependsOn annotation from cm2")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -313,12 +314,12 @@ func TestMultiDependencies(t *testing.T) { nt.T.Log("A new test: verify that an object and its dependency can be disabled together") nt.T.Log("Disable both cm1 and cm0 by adding the `configmanagement.gke.io/managed: disabled` annotation") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName), core.Annotation(metadata.ResourceManagementKey, metadata.ResourceManagementDisabled)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0"), core.Annotation(metadata.ResourceManagementKey, metadata.ResourceManagementDisabled)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Disable both cm1 and cm0 by adding the `configmanagement.gke.io/managed: disabled` annotation")) + nt.Must(rootSyncGitRepo.CommitAndPush("Disable both cm1 and cm0 by adding the `configmanagement.gke.io/managed: disabled` annotation")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -337,6 +338,7 @@ func TestMultiDependencies(t *testing.T) { func TestExternalDependencyError(t *testing.T) { nt := nomostest.New(t, nomostesting.Lifecycle, ntopts.Unstructured) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespaceName := "bookstore" nt.T.Logf("Remove the namespace %q if it already exists", namespaceName) @@ -348,69 +350,69 @@ func TestExternalDependencyError(t *testing.T) { // Both exist in the repo and in the cluster. // Delete cm0 from the repo, expected a DependencyActuationMismatchError nt.T.Log("A new test: verify that removing a dependant from the git repo cause a dependency error") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", k8sobjects.NamespaceObject(namespaceName))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", k8sobjects.NamespaceObject(namespaceName))) + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding cm1 and cm0: cm1 depends on cm0")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding cm1 and cm0: cm1 depends on cm0")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm0.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing cm0 from the git repo")) + nt.Must(rootSyncGitRepo.Remove("acme/cm0.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing cm0 from the git repo")) nt.WaitForRootSyncSyncError(configsync.RootSyncName, applier.ApplierErrorCode, "dependency", nil) // TestCase: cm1 depends on cm0; both are managed by ConfigSync. // Both exist in the repo and in the cluster. // Disable cm0, expected an ExternalDependencyError nt.T.Log("A new test: verify that disabling a dependant from the git repo cause an external dependency error") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding cm1 and cm0: cm1 depends on cm0")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding cm1 and cm0: cm1 depends on cm0")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName), core.Annotation(metadata.ResourceManagementKey, metadata.ResourceManagementDisabled)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Disabling management for cm0 in the git repo")) + nt.Must(rootSyncGitRepo.CommitAndPush("Disabling management for cm0 in the git repo")) nt.WaitForRootSyncSyncError(configsync.RootSyncName, applier.ApplierErrorCode, "external dependency", nil) // TestCase: cm1 depends on cm0; cm0 is disabled. // Neither exists in the cluster. // Expected an ExternalDependencyError - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding cm0 and cm1")) + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding cm0 and cm1")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm0.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Removing cm0 and cm1")) + nt.Must(rootSyncGitRepo.Remove("acme/cm0.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/cm1.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Removing cm0 and cm1")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } nt.T.Log("A new test: verify that disabling a dependant from the git repo cause an external dependency error") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm0.yaml", k8sobjects.ConfigMapObject(core.Name(cm0Name), core.Namespace(namespaceName), core.Annotation(metadata.ResourceManagementKey, metadata.ResourceManagementDisabled)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm0")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding cm1 and cm0: cm1 depends on cm0, cm0 is disabled")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding cm1 and cm0: cm1 depends on cm0, cm0 is disabled")) nt.WaitForRootSyncSyncError(configsync.RootSyncName, applier.ApplierErrorCode, "external dependency", nil) // TestCase: cm1 depends on object that is not in the repo or cluster. // Expected an ExternalDependencyError nt.T.Log("A new test: verify that a dependant not in the repo and not in the cluster cause an external dependency error") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm0.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("cleaning cm0 and adding cm1")) + nt.Must(rootSyncGitRepo.Remove("acme/cm0.yaml")) + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName)))) + nt.Must(rootSyncGitRepo.CommitAndPush("cleaning cm0 and adding cm1")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm-not-exist")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding cm1: cm1 depends on a resource that doesn't exist in either the repo or in cluster")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding cm1: cm1 depends on a resource that doesn't exist in either the repo or in cluster")) nt.WaitForRootSyncSyncError(configsync.RootSyncName, applier.ApplierErrorCode, "external dependency", nil) // TestCase: cm1 depends on an object that is not in the repo, but in the cluster @@ -423,14 +425,14 @@ func TestExternalDependencyError(t *testing.T) { if err := nt.Validate("cm4", namespaceName, &corev1.ConfigMap{}); err != nil { nt.T.Fatal(err) } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/cm1.yaml", + nt.Must(rootSyncGitRepo.Add("acme/cm1.yaml", k8sobjects.ConfigMapObject(core.Name(cm1Name), core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/ConfigMap/cm4")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding cm1: cm1 depends on a resource that only exists in the cluster")) + nt.Must(rootSyncGitRepo.CommitAndPush("Adding cm1: cm1 depends on a resource that only exists in the cluster")) nt.WaitForRootSyncSyncError(configsync.RootSyncName, applier.ApplierErrorCode, "external dependency", nil) nt.T.Log("Cleaning up") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/cm1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("remove cm1")) + nt.Must(rootSyncGitRepo.Remove("acme/cm1.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("remove cm1")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -447,6 +449,7 @@ func TestDependencyWithReconciliation(t *testing.T) { // Increase reconcile timeout to account for slow pod scheduling due to cluster autoscaling. nt := nomostest.New(t, nomostesting.Lifecycle, ntopts.Unstructured, ntopts.WithReconcileTimeout(5*time.Minute)) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) namespaceName := "bookstore" nt.T.Logf("Remove the namespace %q if it already exists", namespaceName) @@ -474,10 +477,10 @@ func TestDependencyWithReconciliation(t *testing.T) { PeriodSeconds: 10, }, } - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/ns.yaml", k8sobjects.NamespaceObject(namespaceName))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/pod1.yaml", + nt.Must(rootSyncGitRepo.Add("acme/ns.yaml", k8sobjects.NamespaceObject(namespaceName))) + nt.Must(rootSyncGitRepo.Add("acme/pod1.yaml", k8sobjects.PodObject(pod1Name, []corev1.Container{container}, core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/pod2.yaml", + nt.Must(rootSyncGitRepo.Add("acme/pod2.yaml", k8sobjects.PodObject(pod2Name, []corev1.Container{container}, core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/Pod/pod1")))) @@ -518,7 +521,7 @@ func TestDependencyWithReconciliation(t *testing.T) { <-pod1SyncCh <-pod2SyncCh - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add pod1 and pod2 (pod2 depends on pod1)")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add pod1 and pod2 (pod2 depends on pod1)")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -536,8 +539,8 @@ func TestDependencyWithReconciliation(t *testing.T) { } nt.T.Logf("Remove Pod1 and Pod2") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/pod1.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/pod2.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/pod1.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/pod2.yaml")) pod1 = &corev1.Pod{} pod2 = &corev1.Pod{} @@ -604,7 +607,7 @@ func TestDependencyWithReconciliation(t *testing.T) { <-pod1SyncCh <-pod2SyncCh - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove pod1 and pod2")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove pod1 and pod2")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -626,12 +629,12 @@ func TestDependencyWithReconciliation(t *testing.T) { nt.T.Log("add pod3 and pod4, pod3's image is not valid, pod4 depends on pod3") invalidImageContainer := container invalidImageContainer.Image = "does-not-exist" - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/pod3.yaml", + nt.Must(rootSyncGitRepo.Add("acme/pod3.yaml", k8sobjects.PodObject("pod3", []corev1.Container{invalidImageContainer}, core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/pod4.yaml", + nt.Must(rootSyncGitRepo.Add("acme/pod4.yaml", k8sobjects.PodObject("pod4", []corev1.Container{container}, core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/Pod/pod3")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add pod3 and pod4 (pod4 depends on pod3 and pod3 won't be reconciled)")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add pod3 and pod4 (pod4 depends on pod3 and pod3 won't be reconciled)")) nt.WaitForRootSyncSyncError(configsync.RootSyncName, applier.ApplierErrorCode, "skipped apply of Pod, bookstore/pod4: dependency apply reconcile timeout: bookstore_pod3__Pod", nil) @@ -647,9 +650,9 @@ func TestDependencyWithReconciliation(t *testing.T) { } nt.T.Log("cleanup") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/pod3.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/pod4.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove pod3 and pod4")) + nt.Must(rootSyncGitRepo.Remove("acme/pod3.yaml")) + nt.Must(rootSyncGitRepo.Remove("acme/pod4.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove pod3 and pod4")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -667,12 +670,12 @@ func TestDependencyWithReconciliation(t *testing.T) { // pod5 shouldn't be pruned in the cluster since pod6 depends on it. nt.T.Log("add pod5 and pod6, pod6 depends on pod5. Delete pod5 from the repo. pruning pod5 should be skipped.") nt.T.Logf("Add Pod5 and Pod6") - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/pod5.yaml", + nt.Must(rootSyncGitRepo.Add("acme/pod5.yaml", k8sobjects.PodObject("pod5", []corev1.Container{container}, core.Namespace(namespaceName)))) - nt.Must(nt.RootRepos[configsync.RootSyncName].Add("acme/pod6.yaml", + nt.Must(rootSyncGitRepo.Add("acme/pod6.yaml", k8sobjects.PodObject("pod6", []corev1.Container{container}, core.Namespace(namespaceName), core.Annotation(dependson.Annotation, "/namespaces/bookstore/Pod/pod5")))) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Add pod5 and pod6")) + nt.Must(rootSyncGitRepo.CommitAndPush("Add pod5 and pod6")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } @@ -687,8 +690,8 @@ func TestDependencyWithReconciliation(t *testing.T) { } nt.T.Logf("Remove pod5 from the repo") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/pod5.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove pod5")) + nt.Must(rootSyncGitRepo.Remove("acme/pod5.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove pod5")) nt.WaitForRootSyncSyncError(configsync.RootSyncName, applier.ApplierErrorCode, "dependency", nil) nt.T.Logf("Verify that pod5 and pod6 were not deleted") @@ -701,8 +704,8 @@ func TestDependencyWithReconciliation(t *testing.T) { } nt.T.Logf("Remove Pod6") - nt.Must(nt.RootRepos[configsync.RootSyncName].Remove("acme/pod6.yaml")) - nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Remove pod6")) + nt.Must(rootSyncGitRepo.Remove("acme/pod6.yaml")) + nt.Must(rootSyncGitRepo.CommitAndPush("Remove pod6")) if err := nt.WatchForAllSyncs(); err != nil { nt.T.Fatal(err) } diff --git a/e2e/testcases/workload_identity_test.go b/e2e/testcases/workload_identity_test.go index 51918ee8dc..20e54b7244 100644 --- a/e2e/testcases/workload_identity_test.go +++ b/e2e/testcases/workload_identity_test.go @@ -350,8 +350,10 @@ func TestWorkloadIdentity(t *testing.T) { nt.T.Logf("Update RootSync and RepoSync to sync from %s", tc.sourceType) switch tc.sourceType { case configsync.GitSource: - rootMeta = updateRSyncWithGitSourceConfig(nt, rootSync, nt.RootRepos[configsync.RootSyncName], tc.rootSrcCfg) - nsMeta = updateRSyncWithGitSourceConfig(nt, repoSync, nt.NonRootRepos[nsRef], tc.nsSrcCfg) + rootSyncGitRepo := nt.SyncSourceGitRepository(nomostest.DefaultRootSyncID) + rootMeta = updateRSyncWithGitSourceConfig(nt, rootSync, rootSyncGitRepo, tc.rootSrcCfg) + repoSyncGitRepo := nt.SyncSourceGitRepository(nomostest.RepoSyncID(nsRef.Name, nsRef.Namespace)) + nsMeta = updateRSyncWithGitSourceConfig(nt, repoSync, repoSyncGitRepo, tc.nsSrcCfg) case configsync.HelmSource: rootChart, err = updateRootSyncWithHelmSourceConfig(nt, rsRef, tc.rootSrcCfg) if err != nil {