Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Clean up ReconcileTimeout config #777

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 34 additions & 44 deletions e2e/nomostest/config_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,28 +458,6 @@ func noOOMKilledContainer(nt *NT) testpredicates.Predicate {
}
}

func setupRootSync(nt *NT, rsName string, reconcileTimeout *time.Duration) {
// create RootSync to initialize the root reconciler.
rs := RootSyncObjectV1Beta1FromRootRepo(nt, rsName)
if reconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*reconcileTimeout)
}
if err := nt.KubeClient.Apply(rs); err != nil {
nt.T.Fatal(err)
}
}

func setupRepoSync(nt *NT, nn types.NamespacedName, reconcileTimeout *time.Duration) {
// create RepoSync to initialize the Namespace reconciler.
rs := RepoSyncObjectV1Beta1FromNonRootRepo(nt, nn)
if reconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*reconcileTimeout)
}
if err := nt.KubeClient.Create(rs); err != nil {
nt.T.Fatal(err)
}
}

// RepoSyncRoleBinding returns rolebinding that grants service account
// permission to manage resources in the namespace.
func RepoSyncRoleBinding(nn types.NamespacedName) *rbacv1.RoleBinding {
Expand Down Expand Up @@ -623,7 +601,7 @@ func setOtelCollectorPrometheusAnnotations(obj client.Object) error {
return nil
}

func setupDelegatedControl(nt *NT, reconcileTimeout *time.Duration) {
func setupDelegatedControl(nt *NT) {
nt.T.Log("[SETUP] Delegated control")

// Just create one RepoSync ClusterRole, even if there are no Namespace repos.
Expand All @@ -636,7 +614,10 @@ func setupDelegatedControl(nt *NT, reconcileTimeout *time.Duration) {
if rsName == configsync.RootSyncName {
continue
}
setupRootSync(nt, rsName, reconcileTimeout)
rs := RootSyncObjectV1Beta1FromRootRepo(nt, rsName)
if err := nt.KubeClient.Apply(rs); err != nil {
nt.T.Fatal(err)
}
}

for nn := range nt.NonRootRepos {
Expand Down Expand Up @@ -665,7 +646,10 @@ func setupDelegatedControl(nt *NT, reconcileTimeout *time.Duration) {
nt.T.Fatal(err)
}

setupRepoSync(nt, nn, reconcileTimeout)
rs := RepoSyncObjectV1Beta1FromNonRootRepo(nt, nn)
if err := nt.KubeClient.Apply(rs); err != nil {
nt.T.Fatal(err)
}
}
}

Expand Down Expand Up @@ -699,8 +683,10 @@ func RootSyncObjectV1Alpha1FromRootRepo(nt *NT, name string) *v1alpha1.RootSync
repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName)
sourceFormat := repo.Format
rs := RootSyncObjectV1Alpha1(name, repoURL, sourceFormat)
if nt.DefaultReconcileTimeout != 0 {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(nt.DefaultReconcileTimeout)
if nt.DefaultReconcileTimeout != nil {
karlkfi marked this conversation as resolved.
Show resolved Hide resolved
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout)
} else if rs.Spec.Override != nil {
rs.Spec.Override.ReconcileTimeout = nil
sdowell marked this conversation as resolved.
Show resolved Hide resolved
}
return rs
}
Expand Down Expand Up @@ -735,8 +721,10 @@ func RootSyncObjectV1Beta1FromRootRepo(nt *NT, name string) *v1beta1.RootSync {
repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName)
sourceFormat := repo.Format
rs := RootSyncObjectV1Beta1(name, repoURL, sourceFormat)
if nt.DefaultReconcileTimeout != 0 {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(nt.DefaultReconcileTimeout)
if nt.DefaultReconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout)
} else if rs.Spec.Override != nil {
rs.Spec.Override.ReconcileTimeout = nil
}
return rs
}
Expand All @@ -751,8 +739,10 @@ func RootSyncObjectV1Beta1FromOtherRootRepo(nt *NT, syncName, repoName string) *
repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName)
sourceFormat := repo.Format
rs := RootSyncObjectV1Beta1(syncName, repoURL, sourceFormat)
if nt.DefaultReconcileTimeout != 0 {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(nt.DefaultReconcileTimeout)
if nt.DefaultReconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout)
} else if rs.Spec.Override != nil {
rs.Spec.Override.ReconcileTimeout = nil
}
return rs
}
Expand Down Expand Up @@ -792,8 +782,10 @@ func RepoSyncObjectV1Alpha1FromNonRootRepo(nt *NT, nn types.NamespacedName) *v1a
repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName)
// RepoSync is always Unstructured. So ignore repo.Format.
rs := RepoSyncObjectV1Alpha1(nn, repoURL)
if nt.DefaultReconcileTimeout != 0 {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(nt.DefaultReconcileTimeout)
if nt.DefaultReconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout)
} else if rs.Spec.Override != nil {
rs.Spec.Override.ReconcileTimeout = nil
}
// Enable automatic deletion of managed objects by default.
// This helps ensure that test artifacts are cleaned up.
Expand Down Expand Up @@ -836,8 +828,10 @@ func RepoSyncObjectV1Beta1FromNonRootRepo(nt *NT, nn types.NamespacedName) *v1be
repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName)
sourceFormat := repo.Format
rs := RepoSyncObjectV1Beta1(nn, repoURL, sourceFormat)
if nt.DefaultReconcileTimeout != 0 {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(nt.DefaultReconcileTimeout)
if nt.DefaultReconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout)
} else if rs.Spec.Override != nil {
rs.Spec.Override.ReconcileTimeout = nil
}
// Add dependencies to ensure managed objects can be deleted.
if err := SetRepoSyncDependencies(nt, rs); err != nil {
Expand All @@ -856,8 +850,10 @@ func RepoSyncObjectV1Beta1FromOtherRootRepo(nt *NT, nn types.NamespacedName, rep
repoURL := nt.GitProvider.SyncURL(repo.RemoteRepoName)
sourceFormat := repo.Format
rs := RepoSyncObjectV1Beta1(nn, repoURL, sourceFormat)
if nt.DefaultReconcileTimeout != 0 {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(nt.DefaultReconcileTimeout)
if nt.DefaultReconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*nt.DefaultReconcileTimeout)
} else if rs.Spec.Override != nil {
rs.Spec.Override.ReconcileTimeout = nil
}
// Add dependencies to ensure managed objects can be deleted.
if err := SetRepoSyncDependencies(nt, rs); err != nil {
Expand All @@ -868,7 +864,7 @@ func RepoSyncObjectV1Beta1FromOtherRootRepo(nt *NT, nn types.NamespacedName, rep

// setupCentralizedControl is a pure central-control mode.
// A default root repo (root-sync) manages all other root repos and namespace repos.
func setupCentralizedControl(nt *NT, reconcileTimeout *time.Duration) {
func setupCentralizedControl(nt *NT) {
nt.T.Log("[SETUP] Centralized control")

rsCount := 0
Expand All @@ -882,9 +878,6 @@ func setupCentralizedControl(nt *NT, reconcileTimeout *time.Duration) {
continue
}
rs := RootSyncObjectV1Beta1FromRootRepo(nt, rsName)
if reconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*reconcileTimeout)
}
nt.Must(nt.RootRepos[configsync.RootSyncName].Add(fmt.Sprintf("acme/namespaces/%s/%s.yaml", configsync.ControllerNamespace, rsName), rs))
nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rs)
nt.Must(nt.RootRepos[configsync.RootSyncName].CommitAndPush("Adding RootSync: " + rsName))
Expand Down Expand Up @@ -935,9 +928,6 @@ func setupCentralizedControl(nt *NT, reconcileTimeout *time.Duration) {

// Add RepoSync pointing to the Git repo specified in nt.NonRootRepos[rsNN]
rs := RepoSyncObjectV1Beta1FromNonRootRepo(nt, rsNN)
if reconcileTimeout != nil {
rs.Spec.SafeOverride().ReconcileTimeout = toMetav1Duration(*reconcileTimeout)
}
nt.Must(nt.RootRepos[configsync.RootSyncName].Add(StructuredNSPath(ns, rsNN.Name), rs))
nt.MetricsExpectations.AddObjectApply(configsync.RootSyncKind, rootSyncNN, rs)

Expand Down
14 changes: 9 additions & 5 deletions e2e/nomostest/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"kpt.dev/configsync/e2e"
"kpt.dev/configsync/e2e/nomostest/gitproviders"
testmetrics "kpt.dev/configsync/e2e/nomostest/metrics"
Expand Down Expand Up @@ -62,6 +63,9 @@ func newOptStruct(testName, tmpDir string, t nomostesting.NTB, ntOptions ...ntop
MultiRepo: ntopts.MultiRepo{
NamespaceRepos: make(map[types.NamespacedName]ntopts.RepoOpts),
RootRepos: map[string]ntopts.RepoOpts{configsync.RootSyncName: {}},
// Default to 1m to keep tests fast.
// To override, use WithReconcileTimeout.
ReconcileTimeout: pointer.Duration(1 * time.Minute),
},
}
for _, opt := range ntOptions {
Expand Down Expand Up @@ -156,7 +160,7 @@ func SharedTestEnv(t nomostesting.NTB, opts *ntopts.New) *NT {
WatchClient: sharedNt.WatchClient,
IsGKEAutopilot: sharedNt.IsGKEAutopilot,
DefaultWaitTimeout: sharedNt.DefaultWaitTimeout,
DefaultReconcileTimeout: sharedNt.DefaultReconcileTimeout,
DefaultReconcileTimeout: opts.ReconcileTimeout,
kubeconfigPath: sharedNt.kubeconfigPath,
ReconcilerPollingPeriod: sharedNt.ReconcilerPollingPeriod,
HydrationPollingPeriod: sharedNt.HydrationPollingPeriod,
Expand Down Expand Up @@ -239,7 +243,7 @@ func FreshTestEnv(t nomostesting.NTB, opts *ntopts.New) *NT {
TmpDir: opts.TmpDir,
Config: opts.RESTConfig,
repoSyncPermissions: opts.RepoSyncPermissions,
DefaultReconcileTimeout: 1 * time.Minute,
DefaultReconcileTimeout: opts.ReconcileTimeout,
kubeconfigPath: opts.KubeconfigPath,
RootRepos: make(map[string]*gitproviders.Repository),
NonRootRepos: make(map[types.NamespacedName]*gitproviders.Repository),
Expand Down Expand Up @@ -429,14 +433,14 @@ func setupTestCase(nt *NT, opts *ntopts.New) {
nt.Control = opts.Control
switch opts.Control {
case ntopts.DelegatedControl:
setupDelegatedControl(nt, opts.ReconcileTimeout)
setupDelegatedControl(nt)
case ntopts.CentralControl:
setupCentralizedControl(nt, opts.ReconcileTimeout)
setupCentralizedControl(nt)
default:
nt.Control = ntopts.CentralControl
// Most tests don't care about centralized/delegated control, but can
// specify the behavior if that distinction is under test.
setupCentralizedControl(nt, opts.ReconcileTimeout)
setupCentralizedControl(nt)
}

// Wait for all RootSyncs and all RepoSyncs to be reconciled
Expand Down
4 changes: 2 additions & 2 deletions e2e/nomostest/nt.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ type NT struct {
DefaultWaitTimeout time.Duration

// DefaultReconcileTimeout is the default timeout for the applier to wait
// for object reconcilition.
DefaultReconcileTimeout time.Duration
// for object reconciliation.
DefaultReconcileTimeout *time.Duration
sdowell marked this conversation as resolved.
Show resolved Hide resolved

// 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.
Expand Down
8 changes: 7 additions & 1 deletion e2e/nomostest/ntopts/multi_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@ const (
)

// WithReconcileTimeout tells the test case to override the default reconcile
// timeout on all RootSyncs and RepoSyncs.
// timeout on all RootSyncs and RepoSyncs by default.
func WithReconcileTimeout(timeout time.Duration) func(opt *New) {
return func(opt *New) {
timeoutCopy := timeout
opt.ReconcileTimeout = &timeoutCopy
}
}

// WithoutReconcileTimeout tells the test case not to override the default
// reconcile timeout on all RootSyncs and RepoSyncs by default.
func WithoutReconcileTimeout(opt *New) {
opt.ReconcileTimeout = nil
}

// RepoSyncPermissions specifies PolicyRule(s) to grant NS reconcilers
func RepoSyncPermissions(policy ...rbacv1.PolicyRule) Opt {
return func(opt *New) {
Expand Down