Skip to content

Commit

Permalink
fix: watch loop issues (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dara Hayes authored Jun 26, 2018
1 parent 9a99e0c commit a0be10d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ func main() {

operator := configOperator.NewConfigOperator(pushClientProvider, annotationHelper, kubeHelper)

// This is blocking. Any code after this will not be called
operator.StartService()
}
26 changes: 17 additions & 9 deletions pkg/configOperator/configOperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ import (

"log"

"github.com/satori/go.uuid"
"k8s.io/apimachinery/pkg/runtime"
"fmt"
"strings"
"time"

"k8s.io/client-go/pkg/api/v1"
"github.com/satori/go.uuid"
"k8s.io/apimachinery/pkg/runtime"

"github.com/aerogear/ups-config-operator/pkg/constants"
"k8s.io/client-go/pkg/api/v1"
)

var letters = []rune("abcdefghijklmnopqrstuvwxyz0123456789")

type ConfigOperator struct {
pushClientProvider UpsClientProvider
annotationHelper AnnotationHelper
kubeHelper KubeHelper
pushClientProvider UpsClientProvider
annotationHelper AnnotationHelper
kubeHelper KubeHelper
}

func NewConfigOperator(pushClientProvider UpsClientProvider, annotationHelper AnnotationHelper, kubeHelper KubeHelper) *ConfigOperator {
Expand All @@ -38,8 +39,15 @@ func NewConfigOperator(pushClientProvider UpsClientProvider, annotationHelper An
func (op ConfigOperator) StartService() {
log.Print("Entering watch loop")

// poll UPS in a separate thread
go op.startPollingUPS()
op.startKubeWatchLoop()

// call startKubeWatchLoop inside an endless loop
// this is blocking so any code called after it will not be run
// the reason for this is because the k8s watcher dies if an error/timeout occurs
for {
op.startKubeWatchLoop()
}
}

// startPollingUPS() is a loop that calls compareUPSVariantsWithClientConfigs() in intervals
Expand Down Expand Up @@ -106,15 +114,15 @@ func (op ConfigOperator) handleDeleteSecret(obj runtime.Object) {
// If a client config is found that references a variant not found in UPS then we clean up the client config by deleting the associated servicebinding.
func (op ConfigOperator) compareUPSVariantsWithClientConfigs() {
pushClient := op.pushClientProvider.getPushClient()
if pushClient == nil{
if pushClient == nil {
log.Printf("Cannot compare UPS variants with client configs since the push client cannot be built")
return
}

// get the UPS related secrets
selector := fmt.Sprintf("serviceName=ups,pushApplicationId=%s", pushClient.getApplicationId())
secretsList, err := op.kubeHelper.listSecrets(selector)
secrets:= secretsList.Items
secrets := secretsList.Items

if err != nil {
log.Printf("Error searching for ups secrets: %v", err.Error())
Expand Down

0 comments on commit a0be10d

Please sign in to comment.