Skip to content

Commit

Permalink
configuration domain requeue interval (#31)
Browse files Browse the repository at this point in the history
* requeue interval

* re-queue processing when secerets synced

Co-authored-by: Radu Popovici <[email protected]>
  • Loading branch information
oncicaradupopovici and Radu Popovici authored Jul 6, 2022
1 parent a4c011a commit 595ae1a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (
ReadyCondition string = "Ready"
)

var requeueInterval time.Duration = 2 * time.Minute

type ConfigurationDomainController struct {
kubeClientset kubernetes.Interface
csiClientset csiClientset.Interface
Expand Down Expand Up @@ -231,6 +233,7 @@ func (c *ConfigurationDomainController) processNextWorkItem() bool {
// get queued again until another change happens.
c.workqueue.Forget(obj)
klog.Infof("Successfully synced '%s'", key)

return nil
}(obj)

Expand Down Expand Up @@ -307,6 +310,9 @@ func (c *ConfigurationDomainController) syncHandler(key string) error {
c.updateStatus(configDomain, false, "Aggregation failed"+err.Error())
return err
}

//Requeue the processing after the configured interval
c.workqueue.AddAfter(key, requeueInterval)
}

// Finally, we update the status block of the ConfigurationDomain resource to reflect the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,56 @@ func TestConfigurationDomainController_processNextWorkItem(t *testing.T) {
t.Errorf("output SPC %s should be re-generated ", outputSpcName)
}
})

t.Run("should re-queue key when secrets synced", func(t *testing.T) {
// Arrange
platform, namespace, domain := "qa", "qa-t1", "domain1"
platforms := []runtime.Object{
newPlatform(platform, platform),
}
configurationDomains := []runtime.Object{
newConfigurationDomain(domain, namespace, platform, false, true),
}
configMaps := []runtime.Object{}
spcs := []runtime.Object{}
c := runController(platforms, configurationDomains, configMaps, spcs)

var oldGetSecrets = getSecrets
defer func() { getSecrets = oldGetSecrets }()
getSecrets = func(platform, namespace, domain, role string) ([]secretSpec, error) {
return []secretSpec{
{Key: "key1", Path: "path1"},
{Key: "key2", Path: "path2"},
}, nil
}

requeueInterval = 1 * time.Millisecond

// Act
if c.workqueue.Len() != 1 {
t.Error("queue should have only 1 item, but it has", c.workqueue.Len())
}
if result := c.processNextWorkItem(); !result {
t.Error("processing failed")
}

time.Sleep(10 * time.Millisecond)

// Assert
if c.workqueue.Len() != 1 {
t.Error("queue should have 1 item, but it has", c.workqueue.Len())
return
}

obj, _ := c.workqueue.Get()
actualKey, _ := obj.(string)
expectedKey := encodeDomainKey(namespace, domain)

if actualKey != expectedKey {
t.Error("expected key", expectedKey, ", got", actualKey)
}
})

}

func newConfigurationDomain(name, namespace, platform string, aggregateConfigMaps, aggregateSecrets bool) *configurationv1.ConfigurationDomain {
Expand Down

0 comments on commit 595ae1a

Please sign in to comment.