From 54a8e0683b0042ae0b71f329a9e7ca7161484727 Mon Sep 17 00:00:00 2001 From: Amund Tenstad Date: Wed, 21 Apr 2021 13:25:08 +0200 Subject: [PATCH 1/2] Propagate PerformRollingUpgrade error to Handle --- internal/pkg/handler/create.go | 2 +- internal/pkg/handler/update.go | 2 +- internal/pkg/handler/upgrade.go | 37 +++++++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/internal/pkg/handler/create.go b/internal/pkg/handler/create.go index 29182169..f6364c5c 100644 --- a/internal/pkg/handler/create.go +++ b/internal/pkg/handler/create.go @@ -20,7 +20,7 @@ func (r ResourceCreatedHandler) Handle() error { } else { config, _ := r.GetConfig() // process resource based on its type - doRollingUpgrade(config, r.Collectors) + return doRollingUpgrade(config, r.Collectors) } return nil } diff --git a/internal/pkg/handler/update.go b/internal/pkg/handler/update.go index 871e46e2..4854151c 100644 --- a/internal/pkg/handler/update.go +++ b/internal/pkg/handler/update.go @@ -22,7 +22,7 @@ func (r ResourceUpdatedHandler) Handle() error { config, oldSHAData := r.GetConfig() if config.SHAValue != oldSHAData { // process resource based on its type - doRollingUpgrade(config, r.Collectors) + return doRollingUpgrade(config, r.Collectors) } } return nil diff --git a/internal/pkg/handler/upgrade.go b/internal/pkg/handler/upgrade.go index 9fba3729..5c80ac2e 100644 --- a/internal/pkg/handler/upgrade.go +++ b/internal/pkg/handler/upgrade.go @@ -85,34 +85,52 @@ func GetArgoRolloutRollingUpgradeFuncs() callbacks.RollingUpgradeFuncs { } } -func doRollingUpgrade(config util.Config, collectors metrics.Collectors) { +func doRollingUpgrade(config util.Config, collectors metrics.Collectors) error { clients := kube.GetClients() - rollingUpgrade(clients, config, GetDeploymentRollingUpgradeFuncs(), collectors) - rollingUpgrade(clients, config, GetDaemonSetRollingUpgradeFuncs(), collectors) - rollingUpgrade(clients, config, GetStatefulSetRollingUpgradeFuncs(), collectors) + err := rollingUpgrade(clients, config, GetDeploymentRollingUpgradeFuncs(), collectors) + if err != nil { + return err + } + err = rollingUpgrade(clients, config, GetDaemonSetRollingUpgradeFuncs(), collectors) + if err != nil { + return err + } + err = rollingUpgrade(clients, config, GetStatefulSetRollingUpgradeFuncs(), collectors) + if err != nil { + return err + } if kube.IsOpenshift { - rollingUpgrade(clients, config, GetDeploymentConfigRollingUpgradeFuncs(), collectors) + err = rollingUpgrade(clients, config, GetDeploymentConfigRollingUpgradeFuncs(), collectors) + if err != nil { + return err + } } if options.IsArgoRollouts == "true" { - rollingUpgrade(clients, config, GetArgoRolloutRollingUpgradeFuncs(), collectors) + err = rollingUpgrade(clients, config, GetArgoRolloutRollingUpgradeFuncs(), collectors) + if err != nil { + return err + } } + + return nil } -func rollingUpgrade(clients kube.Clients, config util.Config, upgradeFuncs callbacks.RollingUpgradeFuncs, collectors metrics.Collectors) { +func rollingUpgrade(clients kube.Clients, config util.Config, upgradeFuncs callbacks.RollingUpgradeFuncs, collectors metrics.Collectors) error { err := PerformRollingUpgrade(clients, config, upgradeFuncs, collectors) if err != nil { logrus.Errorf("Rolling upgrade for '%s' failed with error = %v", config.ResourceName, err) } + return err } // PerformRollingUpgrade upgrades the deployment if there is any change in configmap or secret data func PerformRollingUpgrade(clients kube.Clients, config util.Config, upgradeFuncs callbacks.RollingUpgradeFuncs, collectors metrics.Collectors) error { items := upgradeFuncs.ItemsFunc(clients, config.Namespace) - var err error + for _, i := range items { // find correct annotation and update the resource annotations := upgradeFuncs.AnnotationsFunc(i) @@ -157,6 +175,7 @@ func PerformRollingUpgrade(clients kube.Clients, config util.Config, upgradeFunc if err != nil { logrus.Errorf("Update for '%s' of type '%s' in namespace '%s' failed with error %v", resourceName, upgradeFuncs.ResourceType, config.Namespace, err) collectors.Reloaded.With(prometheus.Labels{"success": "false"}).Inc() + return err } else { logrus.Infof("Changes detected in '%s' of type '%s' in namespace '%s'", config.ResourceName, config.Type, config.Namespace) logrus.Infof("Updated '%s' of type '%s' in namespace '%s'", resourceName, upgradeFuncs.ResourceType, config.Namespace) @@ -164,7 +183,7 @@ func PerformRollingUpgrade(clients kube.Clients, config util.Config, upgradeFunc } } } - return err + return nil } func getVolumeMountName(volumes []v1.Volume, mountType string, volumeName string) string { From 78be58b090a5b936585662083b35b06c191616a8 Mon Sep 17 00:00:00 2001 From: Amund Tenstad Date: Wed, 21 Apr 2021 16:12:53 +0200 Subject: [PATCH 2/2] Do not log content of secrets --- internal/pkg/controller/controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/controller/controller.go b/internal/pkg/controller/controller.go index efed3228..6012ada1 100644 --- a/internal/pkg/controller/controller.go +++ b/internal/pkg/controller/controller.go @@ -145,7 +145,7 @@ func (c *Controller) handleErr(err error, key interface{}) { // This controller retries 5 times if something goes wrong. After that, it stops trying. if c.queue.NumRequeues(key) < 5 { - logrus.Errorf("Error syncing events %v: %v", key, err) + logrus.Errorf("Error syncing events: %v", err) // Re-enqueue the key rate limited. Based on the rate limiter on the // queue and the re-enqueue history, the key will be processed later again.