diff --git a/README.md b/README.md index 93ceec1f..85caa1c8 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,8 @@ spec: ### NOTES - Reloader also supports [sealed-secrets](https://github.com/bitnami-labs/sealed-secrets). [Here](docs/Reloader-with-Sealed-Secrets.md) are the steps to use sealed-secrets with reloader. -- `reloader.stakater.com/auto: "true"` will always override when use with either `secret.reloader.stakater.com/reload` or `configmap.reloader.stakater.com/reload` annotation. +- `reloader.stakater.com/auto: "true"` will only reload the pod, if the configmap or secret is used (as a volume mount or as an env) in `Deployment/Daemonsets/Statefulsets` +- `secret.reloader.stakater.com/reload` or `configmap.reloader.stakater.com/reload` annotation will reload the pod upon changes in specified configmap or secret, irrespective of the usage of configmap or secret. - you may override the auto annotation with the `--auto-annotation` flag - you may override the configmap annotation with the `--configmap-annotation` flag - you may override the secret annotation with the `--secret-annotation` flag diff --git a/internal/pkg/handler/upgrade.go b/internal/pkg/handler/upgrade.go index f2f640e4..653f10b6 100644 --- a/internal/pkg/handler/upgrade.go +++ b/internal/pkg/handler/upgrade.go @@ -79,18 +79,21 @@ func PerformRollingUpgrade(client kubernetes.Interface, config util.Config, upgr result := constants.NotUpdated reloaderEnabled, err := strconv.ParseBool(reloaderEnabledValue) if err == nil && reloaderEnabled { - result = updateContainers(upgradeFuncs, i, config) - } else if annotationValue != "" { + result = updateContainers(upgradeFuncs, i, config, true) + } + + if result != constants.Updated && annotationValue != "" { values := strings.Split(annotationValue, ",") for _, value := range values { if value == config.ResourceName { - result = updateContainers(upgradeFuncs, i, config) + result = updateContainers(upgradeFuncs, i, config, false) if result == constants.Updated { break } } } } + if result == constants.Updated { err = upgradeFuncs.UpdateFunc(client, config.Namespace, i) resourceName := util.ToObjectMeta(i).Name @@ -155,7 +158,7 @@ func getContainerWithEnvReference(containers []v1.Container, resourceName string return nil } -func getContainerToUpdate(upgradeFuncs callbacks.RollingUpgradeFuncs, item interface{}, config util.Config) *v1.Container { +func getContainerToUpdate(upgradeFuncs callbacks.RollingUpgradeFuncs, item interface{}, config util.Config, autoReload bool) *v1.Container { volumes := upgradeFuncs.VolumesFunc(item) containers := upgradeFuncs.ContainersFunc(item) initContainers := upgradeFuncs.InitContainersFunc(item) @@ -185,13 +188,19 @@ func getContainerToUpdate(upgradeFuncs callbacks.RollingUpgradeFuncs, item inter return &containers[0] } } + + // Get the first container if the annotation is related to specified configmap or secret i.e. configmap.reloader.stakater.com/reload + if container == nil && !autoReload { + return &containers[0] + } + return container } -func updateContainers(upgradeFuncs callbacks.RollingUpgradeFuncs, item interface{}, config util.Config) constants.Result { +func updateContainers(upgradeFuncs callbacks.RollingUpgradeFuncs, item interface{}, config util.Config, autoReload bool) constants.Result { var result constants.Result envar := constants.EnvVarPrefix + util.ConvertToEnvVarName(config.ResourceName) + "_" + config.Type - container := getContainerToUpdate(upgradeFuncs, item, config) + container := getContainerToUpdate(upgradeFuncs, item, config, autoReload) if container == nil { return constants.NoContainerFound