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

Fix job wait by adding polling options to impersonation client #687

Merged
merged 1 commit into from
Jun 29, 2022
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
5 changes: 3 additions & 2 deletions controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type KustomizationReconciler struct {
EventRecorder kuberecorder.EventRecorder
MetricsRecorder *metrics.Recorder
StatusPoller *polling.StatusPoller
PollingOpts polling.Options
ControllerName string
statusManager string
NoCrossNamespaceRefs bool
Expand Down Expand Up @@ -350,7 +351,7 @@ func (r *KustomizationReconciler) reconcile(
}

// setup the Kubernetes client for impersonation
impersonation := NewKustomizeImpersonation(kustomization, r.Client, r.StatusPoller, r.DefaultServiceAccount, r.KubeConfigOpts)
impersonation := NewKustomizeImpersonation(kustomization, r.Client, r.StatusPoller, r.DefaultServiceAccount, r.KubeConfigOpts, r.PollingOpts)
kubeClient, statusPoller, err := impersonation.GetClient(ctx)
if err != nil {
return kustomizev1.KustomizationNotReady(
Expand Down Expand Up @@ -931,7 +932,7 @@ func (r *KustomizationReconciler) finalize(ctx context.Context, kustomization ku
kustomization.Status.Inventory.Entries != nil {
objects, _ := ListObjectsInInventory(kustomization.Status.Inventory)

impersonation := NewKustomizeImpersonation(kustomization, r.Client, r.StatusPoller, r.DefaultServiceAccount, r.KubeConfigOpts)
impersonation := NewKustomizeImpersonation(kustomization, r.Client, r.StatusPoller, r.DefaultServiceAccount, r.KubeConfigOpts, r.PollingOpts)
if impersonation.CanFinalize(ctx) {
kubeClient, _, err := impersonation.GetClient(ctx)
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions controllers/kustomization_impersonation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type KustomizeImpersonation struct {
kustomization kustomizev1.Kustomization
statusPoller *polling.StatusPoller
defaultServiceAccount string
pollingOpts polling.Options
kubeConfigOpts runtimeClient.KubeConfigOptions
}

Expand All @@ -50,13 +51,15 @@ func NewKustomizeImpersonation(
kubeClient client.Client,
statusPoller *polling.StatusPoller,
defaultServiceAccount string,
kubeConfigOpts runtimeClient.KubeConfigOptions) *KustomizeImpersonation {
kubeConfigOpts runtimeClient.KubeConfigOptions,
pollingOpts polling.Options) *KustomizeImpersonation {
return &KustomizeImpersonation{
defaultServiceAccount: defaultServiceAccount,
kustomization: kustomization,
statusPoller: statusPoller,
Client: kubeClient,
kubeConfigOpts: kubeConfigOpts,
pollingOpts: pollingOpts,
}
}

Expand Down Expand Up @@ -131,7 +134,7 @@ func (ki *KustomizeImpersonation) clientForServiceAccountOrDefault() (client.Cli
return nil, nil, err
}

statusPoller := polling.NewStatusPoller(client, restMapper, polling.Options{})
statusPoller := polling.NewStatusPoller(client, restMapper, ki.pollingOpts)
return client, statusPoller, err

}
Expand Down Expand Up @@ -160,7 +163,7 @@ func (ki *KustomizeImpersonation) clientForKubeConfig(ctx context.Context) (clie
return nil, nil, err
}

statusPoller := polling.NewStatusPoller(client, restMapper, polling.Options{})
statusPoller := polling.NewStatusPoller(client, restMapper, ki.pollingOpts)

return client, statusPoller, err
}
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func main() {
}

jobStatusReader := statusreaders.NewCustomJobStatusReader(mgr.GetRESTMapper())
pollingOpts := polling.Options{
CustomStatusReaders: []engine.StatusReader{jobStatusReader},
}
if err = (&controllers.KustomizationReconciler{
ControllerName: controllerName,
DefaultServiceAccount: defaultServiceAccount,
Expand All @@ -151,9 +154,8 @@ func main() {
NoCrossNamespaceRefs: aclOptions.NoCrossNamespaceRefs,
NoRemoteBases: noRemoteBases,
KubeConfigOpts: kubeConfigOpts,
StatusPoller: polling.NewStatusPoller(mgr.GetClient(), mgr.GetRESTMapper(), polling.Options{
CustomStatusReaders: []engine.StatusReader{jobStatusReader},
}),
PollingOpts: pollingOpts,
StatusPoller: polling.NewStatusPoller(mgr.GetClient(), mgr.GetRESTMapper(), pollingOpts),
}).SetupWithManager(mgr, controllers.KustomizationReconcilerOptions{
MaxConcurrentReconciles: concurrent,
DependencyRequeueInterval: requeueDependency,
Expand Down