Shutdown on leader election loss

This commit is contained in:
Alex Vest
2022-09-15 12:09:15 +01:00
parent 16079bd1d4
commit 919f75bb62
5 changed files with 37 additions and 43 deletions

View File

@@ -1,8 +1,6 @@
package handler
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/stakater/Reloader/internal/pkg/metrics"
"github.com/stakater/Reloader/internal/pkg/util"
@@ -16,16 +14,12 @@ type ResourceCreatedHandler struct {
}
// Handle processes the newly created resource
func (r ResourceCreatedHandler) Handle(isLeader bool) error {
func (r ResourceCreatedHandler) Handle() error {
if r.Resource == nil {
logrus.Errorf("Resource creation handler received nil resource")
} else {
config, _ := r.GetConfig()
// process resource based on its type
if isLeader {
return doRollingUpgrade(config, r.Collectors)
}
return fmt.Errorf("instance is not leader, will not perform rolling upgrade on %s %s/%s", config.Type, config.ResourceName, config.Namespace)
return doRollingUpgrade(config, r.Collectors)
}
return nil
}

View File

@@ -6,6 +6,6 @@ import (
// ResourceHandler handles the creation and update of resources
type ResourceHandler interface {
Handle(isLeader bool) error
Handle() error
GetConfig() (util.Config, string)
}

View File

@@ -1,8 +1,6 @@
package handler
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/stakater/Reloader/internal/pkg/metrics"
"github.com/stakater/Reloader/internal/pkg/util"
@@ -17,17 +15,13 @@ type ResourceUpdatedHandler struct {
}
// Handle processes the updated resource
func (r ResourceUpdatedHandler) Handle(isLeader bool) error {
func (r ResourceUpdatedHandler) Handle() error {
if r.Resource == nil || r.OldResource == nil {
logrus.Errorf("Resource update handler received nil resource")
} else {
config, oldSHAData := r.GetConfig()
if config.SHAValue != oldSHAData {
// process resource based on its type
if isLeader {
return doRollingUpgrade(config, r.Collectors)
}
return fmt.Errorf("instance is not leader, will not perform rolling upgrade on %s %s/%s", config.Type, config.ResourceName, config.Namespace)
return doRollingUpgrade(config, r.Collectors)
}
}
return nil