Skip to content

Commit

Permalink
Fix reconcile interval incase of an error when updating the agent in …
Browse files Browse the repository at this point in the history
…the provsioner (#3429) (#3442)
  • Loading branch information
luhi-DT committed Jul 11, 2024
1 parent f0e2d01 commit 0190b98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions pkg/controllers/csi/provisioner/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ func (provisioner *OneAgentProvisioner) Reconcile(ctx context.Context, request r
return reconcile.Result{RequeueAfter: dtcsi.ShortRequeueDuration}, err
}

err = provisioner.provisionCodeModules(ctx, dk, tenantConfig)
requeue, err := provisioner.provisionCodeModules(ctx, dk, tenantConfig)
if err != nil {
if requeue {
return reconcile.Result{RequeueAfter: dtcsi.ShortRequeueDuration}, err
}

return reconcile.Result{}, err
}

Expand Down Expand Up @@ -226,25 +230,25 @@ func (provisioner *OneAgentProvisioner) collectGarbage(ctx context.Context, requ
return result, nil
}

func (provisioner *OneAgentProvisioner) provisionCodeModules(ctx context.Context, dk *dynatracev1beta2.DynaKube, tenantConfig *metadata.TenantConfig) error {
func (provisioner *OneAgentProvisioner) provisionCodeModules(ctx context.Context, dk *dynatracev1beta2.DynaKube, tenantConfig *metadata.TenantConfig) (requeue bool, err error) {
// creates a dt client and checks tokens exist for the given dynakube
dtc, err := buildDtc(provisioner, ctx, dk)
if err != nil {
return err
return true, err
}

requeue, err := provisioner.updateAgentInstallation(ctx, dtc, tenantConfig, dk)
if requeue || err != nil {
return err
requeue, err = provisioner.updateAgentInstallation(ctx, dtc, tenantConfig, dk)
if err != nil {
return requeue, err
}

// Set/Update the `LatestVersion` field in the database entry
err = provisioner.db.UpdateTenantConfig(tenantConfig)
if err != nil {
return err
return true, err
}

return nil
return false, nil
}

func (provisioner *OneAgentProvisioner) updateAgentInstallation(
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/csi/provisioner/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestOneAgentProvisioner_Reconcile(t *testing.T) {

require.EqualError(t, err, `secrets "`+dkName+`" not found`)
require.NotNil(t, result)
require.Equal(t, reconcile.Result{}, result)
require.Equal(t, reconcile.Result{RequeueAfter: dtcsi.ShortRequeueDuration}, result)
})
t.Run("error when creating dynatrace client", func(t *testing.T) {
gc := reconcilermock.NewReconciler(t)
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestOneAgentProvisioner_Reconcile(t *testing.T) {

require.EqualError(t, err, "failed to create Dynatrace client: "+errorMsg)
require.NotNil(t, result)
require.Equal(t, reconcile.Result{}, result)
require.Equal(t, reconcile.Result{RequeueAfter: dtcsi.ShortRequeueDuration}, result)
})
t.Run("error creating directories", func(t *testing.T) {
gc := reconcilermock.NewReconciler(t)
Expand Down

0 comments on commit 0190b98

Please sign in to comment.