Skip to content

Commit

Permalink
Fix #1233: start dev mode also when integration is already running
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Feb 21, 2020
1 parent e20049b commit 6c27346
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions pkg/util/watch/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func HandleIntegrationStateChanges(ctx context.Context, integration *v1.Integrat
if err != nil {
return nil, err
}

watcher, err := dynamicClient.Watch(metav1.ListOptions{
FieldSelector: "metadata.name=" + integration.Name,
ResourceVersion: integration.ObjectMeta.ResourceVersion,
Expand All @@ -63,6 +64,21 @@ func HandleIntegrationStateChanges(ctx context.Context, integration *v1.Integrat

var lastObservedState *v1.IntegrationPhase

var handlerWrapper = func(it *v1.Integration) bool {
if lastObservedState == nil || *lastObservedState != it.Status.Phase {
lastObservedState = &it.Status.Phase
if !handler(it) {
return false
}
}
return true
}

// Check completion before starting the watch
if !handlerWrapper(integration) {
return lastObservedState, nil
}

for {
select {
case <-ctx.Done():
Expand All @@ -85,11 +101,8 @@ func HandleIntegrationStateChanges(ctx context.Context, integration *v1.Integrat
return lastObservedState, nil
}

if lastObservedState == nil || *lastObservedState != copy.Status.Phase {
lastObservedState = &copy.Status.Phase
if !handler(copy) {
return lastObservedState, nil
}
if !handlerWrapper(copy) {
return lastObservedState, nil
}
}
}
Expand Down Expand Up @@ -189,6 +202,21 @@ func HandlePlatformStateChanges(ctx context.Context, platform *v1.IntegrationPla

var lastObservedState *v1.IntegrationPlatformPhase

var handlerWrapper = func(pl *v1.IntegrationPlatform) bool {
if lastObservedState == nil || *lastObservedState != pl.Status.Phase {
lastObservedState = &pl.Status.Phase
if !handler(pl) {
return false
}
}
return true
}

// Check completion before starting the watch
if !handlerWrapper(platform) {
return nil
}

for {
select {
case <-ctx.Done():
Expand All @@ -211,11 +239,8 @@ func HandlePlatformStateChanges(ctx context.Context, platform *v1.IntegrationPla
return nil
}

if lastObservedState == nil || *lastObservedState != copy.Status.Phase {
lastObservedState = &copy.Status.Phase
if !handler(copy) {
return nil
}
if !handlerWrapper(copy) {
return nil
}
}
}
Expand Down

0 comments on commit 6c27346

Please sign in to comment.