mirror of
https://github.com/stakater/Reloader.git
synced 2026-02-14 18:09:50 +00:00
* separate methods * basic refactoring * moved common code to util package to use it in gateway * common check for argo rollouts * made code compilable with latest changes on master * Moved options to separate package and created CommandLineOptions instance that will be in sync with options values. * reverted extra changes * initialize CommandLineOptions with default options in module init * wait for paused at annotation before checking deployment paused * moved things around to fix things * reverted unnecessary changes * reverted rolling_upgrade changes * reverted extra change * additional checks in reloader * refactor: ShouldReloadInternal method. It will be called by Reloader ShouldReload has some additional resource/namespace filter checks which are not needed for Reloader * added test cases * moved config to sharable packae * moved resource selector and label selctor methods * fixed pipeline * removed map.yaml * removed vague comment
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/stakater/Reloader/internal/pkg/metrics"
|
|
"github.com/stakater/Reloader/internal/pkg/options"
|
|
"github.com/stakater/Reloader/internal/pkg/util"
|
|
"github.com/stakater/Reloader/pkg/common"
|
|
v1 "k8s.io/api/core/v1"
|
|
"k8s.io/client-go/tools/record"
|
|
)
|
|
|
|
// ResourceUpdatedHandler contains updated objects
|
|
type ResourceUpdatedHandler struct {
|
|
Resource interface{}
|
|
OldResource interface{}
|
|
Collectors metrics.Collectors
|
|
Recorder record.EventRecorder
|
|
}
|
|
|
|
// Handle processes the updated resource
|
|
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 {
|
|
// Send a webhook if update
|
|
if options.WebhookUrl != "" {
|
|
return sendUpgradeWebhook(config, options.WebhookUrl)
|
|
}
|
|
// process resource based on its type
|
|
return doRollingUpgrade(config, r.Collectors, r.Recorder, invokeReloadStrategy)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetConfig gets configurations containing SHA, annotations, namespace and resource name
|
|
func (r ResourceUpdatedHandler) GetConfig() (common.Config, string) {
|
|
var oldSHAData string
|
|
var config common.Config
|
|
if _, ok := r.Resource.(*v1.ConfigMap); ok {
|
|
oldSHAData = util.GetSHAfromConfigmap(r.OldResource.(*v1.ConfigMap))
|
|
config = common.GetConfigmapConfig(r.Resource.(*v1.ConfigMap))
|
|
} else if _, ok := r.Resource.(*v1.Secret); ok {
|
|
oldSHAData = util.GetSHAfromSecret(r.OldResource.(*v1.Secret).Data)
|
|
config = common.GetSecretConfig(r.Resource.(*v1.Secret))
|
|
} else {
|
|
logrus.Warnf("Invalid resource: Resource should be 'Secret' or 'Configmap' but found, %v", r.Resource)
|
|
}
|
|
return config, oldSHAData
|
|
}
|