Skip to content

Commit

Permalink
Issue 579: Fixing leader election failure after node reboot (#581)
Browse files Browse the repository at this point in the history
* Fixing leader election failure after node reboot

Signed-off-by: anishakj <[email protected]>

* Fixing unit tests

Signed-off-by: anishakj <[email protected]>

* Finding namespace using operator-sdk utility

Signed-off-by: anishakj <[email protected]>

* Added logging

Signed-off-by: anishakj <[email protected]>

* updating go.sum

Signed-off-by: anishakj <[email protected]>
  • Loading branch information
anishakj authored Oct 6, 2021
1 parent b84af47 commit ee566f2
Show file tree
Hide file tree
Showing 5 changed files with 426 additions and 44 deletions.
22 changes: 18 additions & 4 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ import (
"runtime"

"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/leader"
sdkVersion "github.com/operator-framework/operator-sdk/version"
"github.com/pravega/pravega-operator/pkg/apis"
"github.com/pravega/pravega-operator/pkg/apis/pravega/v1beta1"
"github.com/pravega/pravega-operator/pkg/controller"
controllerconfig "github.com/pravega/pravega-operator/pkg/controller/config"
"github.com/pravega/pravega-operator/pkg/util"
"github.com/pravega/pravega-operator/pkg/version"
log "github.com/sirupsen/logrus"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"

"sigs.k8s.io/controller-runtime/pkg/client/config"
logf "sigs.k8s.io/controller-runtime/pkg/log"
logz "sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

Expand All @@ -56,7 +57,10 @@ func printVersion() {

func main() {
flag.Parse()
logf.SetLogger(logf.ZapLogger(false))

// The logger instantiated here can be changed to any logger
// implementing the logr.Logger interface.
logf.SetLogger(logz.New(logz.UseDevMode(false)))

printVersion()

Expand All @@ -79,8 +83,18 @@ func main() {
log.Fatal(err)
}

operatorNs, err := k8sutil.GetOperatorNamespace()
if err != nil {
log.Error(err, "failed to get operator namespace")
os.Exit(1)
}

// Become the leader before proceeding
leader.Become(context.TODO(), "pravega-operator-lock")
err = util.BecomeLeader(context.TODO(), cfg, "pravega-operator-lock", operatorNs)
if err != nil {
log.Error(err, "")
os.Exit(1)
}

// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
Expand Down
25 changes: 16 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ module github.com/pravega/pravega-operator
go 1.13

require (
github.com/alexkohler/nakedret v1.0.0 // indirect
github.com/hashicorp/go-version v1.1.0
github.com/jgautheron/goconst v1.4.0 // indirect
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.13.0
github.com/operator-framework/operator-lib v0.7.0
github.com/operator-framework/operator-sdk v0.17.0
github.com/pravega/bookkeeper-operator v0.1.3
github.com/pravega/zookeeper-operator v0.2.8
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da
github.com/sirupsen/logrus v1.5.0
golang.org/x/tools v0.0.0-20201002184944-ecd9fd270d5d // indirect
k8s.io/api v0.17.5
k8s.io/apimachinery v0.17.5
github.com/sirupsen/logrus v1.7.0
golang.org/x/tools v0.1.5 // indirect
k8s.io/api v0.21.1
k8s.io/apimachinery v0.21.1
k8s.io/client-go v12.0.0+incompatible
k8s.io/utils v0.0.0-20191114200735-6ca3b61696b6
sigs.k8s.io/controller-runtime v0.5.2
sigs.k8s.io/controller-runtime v0.9.0
)

replace (
github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.3.2+incompatible // Required by OLM

github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm

github.com/go-logr/zapr => github.com/go-logr/zapr v0.4.0

github.com/onsi/ginkgo => github.com/onsi/ginkgo v1.12.0

github.com/onsi/gomega => github.com/onsi/gomega v1.9.0

k8s.io/api => k8s.io/api v0.17.5

k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.17.5
Expand Down Expand Up @@ -73,4 +78,6 @@ replace (
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.17.5

k8s.io/sample-controller => k8s.io/sample-controller v0.17.5

sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.5.2
)
Loading

0 comments on commit ee566f2

Please sign in to comment.