fix syncing of stream CRDs (#2152)

* fix syncing of stream CRDs and improve corresponding unit tests
This commit is contained in:
Felix Kunde
2022-12-30 13:09:15 +01:00
committed by GitHub
parent c1657ec484
commit 4534a4cd9e
2 changed files with 48 additions and 27 deletions
+12 -6
View File
@@ -374,13 +374,16 @@ func (c *Cluster) createOrUpdateStreams() error {
}
for _, appId := range appIds {
streamExists := false
// update stream when it exists and EventStreams array differs
for _, stream := range streams.Items {
if appId == stream.Spec.ApplicationId {
streamExists = true
desiredStreams := c.generateFabricEventStream(appId)
if match, reason := sameStreams(stream.Spec.EventStreams, desiredStreams.Spec.EventStreams); !match {
c.logger.Debugf("updating event streams: %s", reason)
desiredStreams.ObjectMeta.ResourceVersion = stream.ObjectMeta.ResourceVersion
desiredStreams.ObjectMeta = stream.ObjectMeta
err = c.updateStreams(desiredStreams)
if err != nil {
return fmt.Errorf("failed updating event stream %s: %v", stream.Name, err)
@@ -390,12 +393,15 @@ func (c *Cluster) createOrUpdateStreams() error {
continue
}
}
c.logger.Infof("event streams with applicationId %s do not exist, create it", appId)
streamCRD, err := c.createStreams(appId)
if err != nil {
return fmt.Errorf("failed creating event streams with applicationId %s: %v", appId, err)
if !streamExists {
c.logger.Infof("event streams with applicationId %s do not exist, create it", appId)
streamCRD, err := c.createStreams(appId)
if err != nil {
return fmt.Errorf("failed creating event streams with applicationId %s: %v", appId, err)
}
c.logger.Infof("event streams %q have been successfully created", streamCRD.Name)
}
c.logger.Infof("event streams %q have been successfully created", streamCRD.Name)
}
return nil