Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: watch loop issues #43

Merged
merged 2 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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