Skip to content

Commit

Permalink
Ensure secondary caches are synced
Browse files Browse the repository at this point in the history
  • Loading branch information
ironcladlou committed Dec 14, 2018
1 parent fbde0e7 commit 00070c6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ clean:
verify:
hack/verify-gofmt.sh
hack/verify-generated-bindata.sh

.PHONY: uninstall
uninstall:
hack/uninstall.sh
6 changes: 3 additions & 3 deletions hack/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -uo pipefail

OPERAND_ONLY="${OPERAND_ONLY:-}"
WHAT="${WHAT:-all}"

# Disable the CVO
oc scale --replicas 0 -n openshift-cluster-version deployments/cluster-version-operator
Expand All @@ -12,12 +12,12 @@ oc patch -n openshift-ingress-operator clusteringresses/default --patch '{"metad
oc delete clusteroperator.config.openshift.io/openshift-ingress-operator
oc delete --force --grace-period=0 -n openshift-ingress-operator clusteringresses/default

if [ "$OPERAND_ONLY" != "true" ]; then
if [ "$WHAT" == "all" ]; then
oc delete namespaces/openshift-ingress-operator
fi
oc delete namespaces/openshift-ingress

if [ "$OPERAND_ONLY" != "true" ]; then
if [ "$WHAT" == "all" ]; then
oc delete clusterroles/openshift-ingress-operator
oc delete clusterroles/openshift-ingress-router
oc delete clusterrolebindings/openshift-ingress-operator
Expand Down
2 changes: 0 additions & 2 deletions manifests/02-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OPERATOR_NAME
value: ingress-operator
- name: IMAGE
value: openshift/origin-haproxy-router:v4.0
21 changes: 18 additions & 3 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Operator struct {
client client.Client

manager manager.Manager
caches []cache.Cache
}

// New creates (but does not start) a new operator from configuration.
Expand Down Expand Up @@ -99,9 +100,7 @@ func New(config operatorconfig.Config, installConfig *util.InstallConfig, dnsMan
if err != nil {
return nil, fmt.Errorf("failed to create openshift-ingress cache: %v", err)
}
operatorManager.Add(manager.RunnableFunc(func(s <-chan struct{}) error {
return ingressCache.Start(s)
}))

for _, obj := range []runtime.Object{
&appsv1.Deployment{},
&corev1.Service{},
Expand All @@ -115,6 +114,7 @@ func New(config operatorconfig.Config, installConfig *util.InstallConfig, dnsMan

return &Operator{
manager: operatorManager,
caches: []cache.Cache{ingressCache},

// TODO: These are only needed for the default cluster ingress stuff, which
// should be refactored away.
Expand All @@ -133,6 +133,21 @@ func (o *Operator) Start(stop <-chan struct{}) error {
return fmt.Errorf("failed to ensure default cluster ingress: %v", err)
}

// Start secondary caches.
for _, cache := range o.caches {
go func() {
if err := cache.Start(stop); err != nil {
// TODO: propagate to stop channel?
logrus.Infof("cache stopped with error: %v", err)
}
}()
logrus.Infof("waiting for cache to sync")
if !cache.WaitForCacheSync(stop) {
return fmt.Errorf("failed to sync cache")
}
logrus.Infof("cache synced")
}

// Start the primary manager.
return o.manager.Start(stop)
}
Expand Down

0 comments on commit 00070c6

Please sign in to comment.