Adds support for auto-reloading secrets and configmaps by annotation.

This commit is contained in:
Vlad Losev
2020-06-09 19:14:14 -07:00
parent 732cd5b53a
commit fda733ea5a
6 changed files with 224 additions and 53 deletions
+4 -2
View File
@@ -24,9 +24,11 @@ func NewReloaderCommand() *cobra.Command {
}
// options
cmd.PersistentFlags().StringVar(&options.ConfigmapUpdateOnChangeAnnotation, "configmap-annotation", "configmap.reloader.stakater.com/reload", "annotation to detect changes in configmaps")
cmd.PersistentFlags().StringVar(&options.SecretUpdateOnChangeAnnotation, "secret-annotation", "secret.reloader.stakater.com/reload", "annotation to detect changes in secrets")
cmd.PersistentFlags().StringVar(&options.ConfigmapUpdateOnChangeAnnotation, "configmap-annotation", "configmap.reloader.stakater.com/reload", "annotation to detect changes in configmaps, specified by name")
cmd.PersistentFlags().StringVar(&options.SecretUpdateOnChangeAnnotation, "secret-annotation", "secret.reloader.stakater.com/reload", "annotation to detect changes in secrets, specified by name")
cmd.PersistentFlags().StringVar(&options.ReloaderAutoAnnotation, "auto-annotation", "reloader.stakater.com/auto", "annotation to detect changes in secrets")
cmd.PersistentFlags().StringVar(&options.ConfigmapUpdateAutoSearchAnnotation, "configmap-auto-by-annotation", "configmap.reloader.stakater.com/reload-by-annotation", "annotation to detect changes in configmaps, searched by annotation")
cmd.PersistentFlags().StringVar(&options.SecretUpdateAutoSearchAnnotation, "secret-auto-by-annotation", "secret.reloader.stakater.com/reload-by-annotation", "annotation to detect changes in secret, searched by annotations")
cmd.PersistentFlags().StringVar(&options.LogFormat, "log-format", "", "Log format to use (empty string for text, or JSON")
cmd.PersistentFlags().StringSlice("resources-to-ignore", []string{}, "list of resources to ignore (valid options 'configMaps' or 'secrets')")
cmd.PersistentFlags().StringSlice("namespaces-to-ignore", []string{}, "list of namespaces to ignore")
+16 -1
View File
@@ -99,10 +99,12 @@ func PerformRollingUpgrade(clients kube.Clients, config util.Config, upgradeFunc
// find correct annotation and update the resource
annotations := upgradeFuncs.AnnotationsFunc(i)
annotationValue, found := annotations[config.Annotation]
searchAnnotationValue, foundSearchAnn := annotations[config.SearchAnnotation]
reloaderEnabledValue, foundAuto := annotations[options.ReloaderAutoAnnotation]
if !found && !foundAuto {
if !found && !foundAuto && !foundSearchAnn {
annotations = upgradeFuncs.PodAnnotationsFunc(i)
annotationValue = annotations[config.Annotation]
searchAnnotationValue = annotations[config.SearchAnnotation]
reloaderEnabledValue = annotations[options.ReloaderAutoAnnotation]
}
result := constants.NotUpdated
@@ -123,6 +125,19 @@ func PerformRollingUpgrade(clients kube.Clients, config util.Config, upgradeFunc
}
}
if result != constants.Updated && searchAnnotationValue != "" {
keyValue := strings.Split(searchAnnotationValue, "=")
key := keyValue[0]
searchValue := ""
if len(keyValue) > 1 {
searchValue = keyValue[1]
}
value, found := config.ResourceAnnotations[key]
if found && searchValue == "" || value == searchValue {
result = updateContainers(upgradeFuncs, i, config, true)
}
}
if result == constants.Updated {
err = upgradeFuncs.UpdateFunc(clients, config.Namespace, i)
resourceName := util.ToObjectMeta(i).Name
+161 -16
View File
@@ -15,6 +15,7 @@ import (
"github.com/stakater/Reloader/internal/pkg/testutil"
"github.com/stakater/Reloader/internal/pkg/util"
"github.com/stakater/Reloader/pkg/kube"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testclient "k8s.io/client-go/kubernetes/fake"
)
@@ -622,7 +623,6 @@ func TestRollingUpgradeForDeploymentWithConfigmapInProjectedVolume(t *testing.T)
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap in projected volume")
}
@@ -638,6 +638,166 @@ func TestRollingUpgradeForDeploymentWithConfigmapInProjectedVolume(t *testing.T)
}
}
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotation(t *testing.T) {
annotatedConfigmapName := "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
configmapObj := testutil.GetConfigmap(namespace, annotatedConfigmapName, "www.google.com")
configmapObj.Annotations = map[string]string{"test-annotation": "test"}
configmap, err := clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Create(configmapObj)
if err != nil {
t.Errorf("Failed to create config map with annotation.")
}
defer clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Delete(configmap.Name, &v1.DeleteOptions{})
deploymentObj := testutil.GetDeploymentWithEnvVars(namespace, annotatedConfigmapName)
deploymentObj.Annotations = map[string]string{options.ConfigmapUpdateAutoSearchAnnotation: "test-annotation=test"}
deployment, err := clients.KubernetesClient.AppsV1().Deployments(namespace).Create(deploymentObj)
if err != nil {
t.Errorf("Failed to create deployment with search annotation.")
}
defer clients.KubernetesClient.AppsV1().Deployments(namespace).Delete(deployment.Name, &v1.DeleteOptions{})
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, annotatedConfigmapName, "www.stakater.com")
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, annotatedConfigmapName, shaData, "")
config.SearchAnnotation = options.ConfigmapUpdateAutoSearchAnnotation
config.ResourceAnnotations = configmap.Annotations
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
collectors := getCollectors()
err = PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
}
logrus.Infof("Verifying deployment update")
updated := testutil.VerifyResourceUpdate(clients, config, constants.ConfigmapEnvVarPostfix, deploymentFuncs)
if !updated {
t.Errorf("Deployment was not updated")
}
if promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)) != 1 {
t.Errorf("Counter was not increased")
}
}
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNoValue(t *testing.T) {
annotatedConfigmapName := "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
configmapObj := testutil.GetConfigmap(namespace, annotatedConfigmapName, "www.google.com")
configmapObj.Annotations = map[string]string{"test-annotation": "test"}
configmap, err := clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Create(configmapObj)
if err != nil {
t.Errorf("Failed to create config map with annotation.")
}
defer clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Delete(configmap.Name, &v1.DeleteOptions{})
deploymentObj := testutil.GetDeploymentWithEnvVars(namespace, annotatedConfigmapName)
deploymentObj.Annotations = map[string]string{options.ConfigmapUpdateAutoSearchAnnotation: "test-annotation"}
deployment, err := clients.KubernetesClient.AppsV1().Deployments(namespace).Create(deploymentObj)
if err != nil {
t.Errorf("Failed to create deployment with search annotation.")
}
defer clients.KubernetesClient.AppsV1().Deployments(namespace).Delete(deployment.Name, &v1.DeleteOptions{})
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, annotatedConfigmapName, "www.stakater.com")
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, annotatedConfigmapName, shaData, "")
config.SearchAnnotation = options.ConfigmapUpdateAutoSearchAnnotation
config.ResourceAnnotations = configmap.Annotations
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
collectors := getCollectors()
err = PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
}
logrus.Infof("Verifying deployment update")
updated := testutil.VerifyResourceUpdate(clients, config, constants.ConfigmapEnvVarPostfix, deploymentFuncs)
if !updated {
t.Errorf("Deployment was not updated")
}
if promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)) != 1 {
t.Errorf("Counter was not increased")
}
}
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNotFound(t *testing.T) {
annotatedConfigmapName := "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
configmapObj := testutil.GetConfigmap(namespace, annotatedConfigmapName, "www.google.com")
configmapObj.Annotations = map[string]string{"test-annotation": "test"}
configmap, err := clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Create(configmapObj)
if err != nil {
t.Errorf("Failed to create config map with annotation.")
}
defer clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Delete(configmap.Name, &v1.DeleteOptions{})
deploymentObj := testutil.GetDeploymentWithEnvVars(namespace, annotatedConfigmapName)
deploymentObj.Annotations = map[string]string{options.ConfigmapUpdateAutoSearchAnnotation: "test-annotation=not-found"}
deployment, err := clients.KubernetesClient.AppsV1().Deployments(namespace).Create(deploymentObj)
if err != nil {
t.Errorf("Failed to create deployment with search annotation.")
}
defer clients.KubernetesClient.AppsV1().Deployments(namespace).Delete(deployment.Name, &v1.DeleteOptions{})
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, annotatedConfigmapName, "www.stakater.com")
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, annotatedConfigmapName, shaData, "")
config.SearchAnnotation = options.ConfigmapUpdateAutoSearchAnnotation
config.ResourceAnnotations = configmap.Annotations
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
collectors := getCollectors()
err = PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
}
logrus.Infof("Verifying deployment update")
updated := testutil.VerifyResourceUpdate(clients, config, constants.ConfigmapEnvVarPostfix, deploymentFuncs)
if updated {
t.Errorf("Deployment was updated unexpectedly")
}
if promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)) > 0 {
t.Errorf("Counter was increased unexpectedly")
}
}
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNotMapped(t *testing.T) {
annotatedConfigmapName := "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
configmapObj := testutil.GetConfigmap(namespace, annotatedConfigmapName, "www.google.com")
configmapObj.Annotations = map[string]string{"test-annotation": "test"}
configmap, err := clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Create(configmapObj)
if err != nil {
t.Errorf("Failed to create config map with annotation.")
}
defer clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Delete(configmap.Name, &v1.DeleteOptions{})
deploymentObj := testutil.GetDeploymentWithEnvVars(namespace, annotatedConfigmapName+"-different")
deploymentObj.Annotations = map[string]string{options.ConfigmapUpdateAutoSearchAnnotation: "test-annotation=test"}
deployment, err := clients.KubernetesClient.AppsV1().Deployments(namespace).Create(deploymentObj)
if err != nil {
t.Errorf("Failed to create deployment with search annotation.")
}
defer clients.KubernetesClient.AppsV1().Deployments(namespace).Delete(deployment.Name, &v1.DeleteOptions{})
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, annotatedConfigmapName, "www.stakater.com")
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, annotatedConfigmapName, shaData, "")
config.SearchAnnotation = options.ConfigmapUpdateAutoSearchAnnotation
config.ResourceAnnotations = configmap.Annotations
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
collectors := getCollectors()
err = PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
}
logrus.Infof("Verifying deployment update")
updated := testutil.VerifyResourceUpdate(clients, config, constants.ConfigmapEnvVarPostfix, deploymentFuncs)
if updated {
t.Errorf("Deployment was updated unexpectedly")
}
if promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)) > 0 {
t.Errorf("Counter was increased unexpectedly")
}
}
func TestRollingUpgradeForDeploymentWithConfigmapInInitContainer(t *testing.T) {
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, configmapWithInitContainer, "www.stakater.com")
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, configmapWithInitContainer, shaData, options.ConfigmapUpdateOnChangeAnnotation)
@@ -645,7 +805,6 @@ func TestRollingUpgradeForDeploymentWithConfigmapInInitContainer(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
}
@@ -691,7 +850,6 @@ func TestRollingUpgradeForDeploymentWithConfigmapAsEnvVar(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap used as env var")
}
@@ -714,7 +872,6 @@ func TestRollingUpgradeForDeploymentWithConfigmapAsEnvVarInInitContainer(t *test
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap used as env var")
}
@@ -737,7 +894,6 @@ func TestRollingUpgradeForDeploymentWithConfigmapAsEnvVarFrom(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap used as env var")
}
@@ -760,7 +916,6 @@ func TestRollingUpgradeForDeploymentWithSecret(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Secret")
}
@@ -806,7 +961,6 @@ func TestRollingUpgradeForDeploymentWithSecretinInitContainer(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Secret")
}
@@ -852,7 +1006,6 @@ func TestRollingUpgradeForDeploymentWithSecretAsEnvVar(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Secret")
}
@@ -875,7 +1028,6 @@ func TestRollingUpgradeForDeploymentWithSecretAsEnvVarFrom(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Secret")
}
@@ -898,7 +1050,6 @@ func TestRollingUpgradeForDeploymentWithSecretAsEnvVarInInitContainer(t *testing
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Secret")
}
@@ -921,7 +1072,6 @@ func TestRollingUpgradeForDaemonSetWithConfigmap(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, daemonSetFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for DaemonSet with configmap")
}
@@ -967,7 +1117,6 @@ func TestRollingUpgradeForDaemonSetWithConfigmapAsEnvVar(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, daemonSetFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for DaemonSet with configmap used as env var")
}
@@ -990,7 +1139,6 @@ func TestRollingUpgradeForDaemonSetWithSecret(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, daemonSetFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for DaemonSet with secret")
}
@@ -1036,7 +1184,6 @@ func TestRollingUpgradeForStatefulSetWithConfigmap(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, statefulSetFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for StatefulSet with configmap")
}
@@ -1082,7 +1229,6 @@ func TestRollingUpgradeForStatefulSetWithSecret(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, statefulSetFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for StatefulSet with secret")
}
@@ -1128,7 +1274,6 @@ func TestRollingUpgradeForDeploymentWithPodAnnotations(t *testing.T) {
collectors := getCollectors()
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
time.Sleep(5 * time.Second)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with pod annotations")
}
+10 -2
View File
@@ -1,12 +1,20 @@
package options
var (
// ConfigmapUpdateOnChangeAnnotation is an annotation to detect changes in configmaps
// ConfigmapUpdateOnChangeAnnotation is an annotation to detect changes in
// configmaps specified by name
ConfigmapUpdateOnChangeAnnotation = "configmap.reloader.stakater.com/reload"
// SecretUpdateOnChangeAnnotation is an annotation to detect changes in secrets
// SecretUpdateOnChangeAnnotation is an annotation to detect changes in
// secrets specified by name
SecretUpdateOnChangeAnnotation = "secret.reloader.stakater.com/reload"
// ReloaderAutoAnnotation is an annotation to detect changes in secrets
ReloaderAutoAnnotation = "reloader.stakater.com/auto"
// ConfigmapUpdateAutoSearchAnnotation is an annotation to detect changes in
// configmaps searched by annotation
ConfigmapUpdateAutoSearchAnnotation = "configmap.reloader.stakater.com/auto-by-annotation"
// SecretUpdateAutoSearchAnnotation is an annotation to detect changes in
// secrets searched by annotation
SecretUpdateAutoSearchAnnotation = "secret.reloader.stakater.com/auto-by-annotation"
// LogFormat is the log format to use (json, or empty string for default)
LogFormat = ""
)
+12 -17
View File
@@ -598,7 +598,6 @@ func CreateConfigMap(client kubernetes.Interface, namespace string, configmapNam
logrus.Infof("Creating configmap")
configmapClient := client.CoreV1().ConfigMaps(namespace)
_, err := configmapClient.Create(GetConfigmap(namespace, configmapName, data))
time.Sleep(3 * time.Second)
return configmapClient, err
}
@@ -607,7 +606,6 @@ func CreateSecret(client kubernetes.Interface, namespace string, secretName stri
logrus.Infof("Creating secret")
secretClient := client.CoreV1().Secrets(namespace)
_, err := secretClient.Create(GetSecret(namespace, secretName, data))
time.Sleep(3 * time.Second)
return secretClient, err
}
// CreateDeployment creates a deployment in given namespace and returns the Deployment
@@ -621,7 +619,6 @@ func CreateDeployment(client kubernetes.Interface, deploymentName string, namesp
deploymentObj = GetDeploymentWithEnvVars(namespace, deploymentName)
}
deployment, err := deploymentClient.Create(deploymentObj)
time.Sleep(3 * time.Second)
return deployment, err
}
@@ -636,7 +633,6 @@ func CreateDeploymentConfig(client appsclient.Interface, deploymentName string,
deploymentConfigObj = GetDeploymentConfigWithEnvVars(namespace, deploymentName)
}
deploymentConfig, err := deploymentConfigsClient.Create(deploymentConfigObj)
time.Sleep(5 * time.Second)
return deploymentConfig, err
}
@@ -651,7 +647,6 @@ func CreateDeploymentWithInitContainer(client kubernetes.Interface, deploymentNa
deploymentObj = GetDeploymentWithInitContainerAndEnv(namespace, deploymentName)
}
deployment, err := deploymentClient.Create(deploymentObj)
time.Sleep(3 * time.Second)
return deployment, err
}
@@ -661,7 +656,6 @@ func CreateDeploymentWithEnvVarSource(client kubernetes.Interface, deploymentNam
deploymentClient := client.AppsV1().Deployments(namespace)
deploymentObj := GetDeploymentWithEnvVarSources(namespace, deploymentName)
deployment, err := deploymentClient.Create(deploymentObj)
time.Sleep(3 * time.Second)
return deployment, err
}
@@ -671,7 +665,6 @@ func CreateDeploymentWithPodAnnotations(client kubernetes.Interface, deploymentN
deploymentClient := client.AppsV1().Deployments(namespace)
deploymentObj := GetDeploymentWithPodAnnotations(namespace, deploymentName, both)
deployment, err := deploymentClient.Create(deploymentObj)
time.Sleep(3 * time.Second)
return deployment, err
}
@@ -686,7 +679,6 @@ func CreateDaemonSet(client kubernetes.Interface, daemonsetName string, namespac
daemonsetObj = GetDaemonSetWithEnvVars(namespace, daemonsetName)
}
daemonset, err := daemonsetClient.Create(daemonsetObj)
time.Sleep(3 * time.Second)
return daemonset, err
}
@@ -701,7 +693,6 @@ func CreateStatefulSet(client kubernetes.Interface, statefulsetName string, name
statefulsetObj = GetStatefulSetWithEnvVar(namespace, statefulsetName)
}
statefulset, err := statefulsetClient.Create(statefulsetObj)
time.Sleep(3 * time.Second)
return statefulset, err
}
@@ -709,7 +700,6 @@ func CreateStatefulSet(client kubernetes.Interface, statefulsetName string, name
func DeleteDeployment(client kubernetes.Interface, namespace string, deploymentName string) error {
logrus.Infof("Deleting Deployment")
deploymentError := client.AppsV1().Deployments(namespace).Delete(deploymentName, &metav1.DeleteOptions{})
time.Sleep(3 * time.Second)
return deploymentError
}
@@ -717,7 +707,6 @@ func DeleteDeployment(client kubernetes.Interface, namespace string, deploymentN
func DeleteDeploymentConfig(client appsclient.Interface, namespace string, deploymentConfigName string) error {
logrus.Infof("Deleting DeploymentConfig")
deploymentConfigError := client.AppsV1().DeploymentConfigs(namespace).Delete(deploymentConfigName, &metav1.DeleteOptions{})
time.Sleep(3 * time.Second)
return deploymentConfigError
}
@@ -725,7 +714,6 @@ func DeleteDeploymentConfig(client appsclient.Interface, namespace string, deplo
func DeleteDaemonSet(client kubernetes.Interface, namespace string, daemonsetName string) error {
logrus.Infof("Deleting DaemonSet %s", daemonsetName)
daemonsetError := client.AppsV1().DaemonSets(namespace).Delete(daemonsetName, &metav1.DeleteOptions{})
time.Sleep(3 * time.Second)
return daemonsetError
}
@@ -733,7 +721,6 @@ func DeleteDaemonSet(client kubernetes.Interface, namespace string, daemonsetNam
func DeleteStatefulSet(client kubernetes.Interface, namespace string, statefulsetName string) error {
logrus.Infof("Deleting StatefulSet %s", statefulsetName)
statefulsetError := client.AppsV1().StatefulSets(namespace).Delete(statefulsetName, &metav1.DeleteOptions{})
time.Sleep(3 * time.Second)
return statefulsetError
}
@@ -747,7 +734,6 @@ func UpdateConfigMap(configmapClient core_v1.ConfigMapInterface, namespace strin
configmap = GetConfigmap(namespace, configmapName, data)
}
_, updateErr := configmapClient.Update(configmap)
time.Sleep(3 * time.Second)
return updateErr
}
@@ -761,7 +747,6 @@ func UpdateSecret(secretClient core_v1.SecretInterface, namespace string, secret
secret = GetSecret(namespace, secretName, data)
}
_, updateErr := secretClient.Update(secret)
time.Sleep(3 * time.Second)
return updateErr
}
@@ -769,7 +754,6 @@ func UpdateSecret(secretClient core_v1.SecretInterface, namespace string, secret
func DeleteConfigMap(client kubernetes.Interface, namespace string, configmapName string) error {
logrus.Infof("Deleting configmap %q.\n", configmapName)
err := client.CoreV1().ConfigMaps(namespace).Delete(configmapName, &metav1.DeleteOptions{})
time.Sleep(3 * time.Second)
return err
}
@@ -777,7 +761,6 @@ func DeleteConfigMap(client kubernetes.Interface, namespace string, configmapNam
func DeleteSecret(client kubernetes.Interface, namespace string, secretName string) error {
logrus.Infof("Deleting secret %q.\n", secretName)
err := client.CoreV1().Secrets(namespace).Delete(secretName, &metav1.DeleteOptions{})
time.Sleep(3 * time.Second)
return err
}
@@ -798,6 +781,7 @@ func VerifyResourceUpdate(clients kube.Clients, config util.Config, envVarPostfi
containers := upgradeFuncs.ContainersFunc(i)
// match statefulsets with the correct annotation
annotationValue := util.ToObjectMeta(i).Annotations[config.Annotation]
searchAnnotationValue := util.ToObjectMeta(i).Annotations[config.SearchAnnotation]
reloaderEnabledValue := util.ToObjectMeta(i).Annotations[options.ReloaderAutoAnnotation]
reloaderEnabled, err := strconv.ParseBool(reloaderEnabledValue)
matches := false
@@ -811,6 +795,17 @@ func VerifyResourceUpdate(clients kube.Clients, config util.Config, envVarPostfi
break
}
}
} else if searchAnnotationValue != "" {
keyValue := strings.Split(searchAnnotationValue, "=")
key := keyValue[0]
valueToSearch := ""
if len(keyValue) > 1 {
valueToSearch = keyValue[1]
}
value, found := config.ResourceAnnotations[key]
if found && (valueToSearch == "" || value == valueToSearch) {
matches = true
}
}
if matches {
+21 -15
View File
@@ -8,31 +8,37 @@ import (
//Config contains rolling upgrade configuration parameters
type Config struct {
Namespace string
ResourceName string
Annotation string
SHAValue string
Type string
Namespace string
ResourceName string
ResourceAnnotations map[string]string
Annotation string
SearchAnnotation string
SHAValue string
Type string
}
// GetConfigmapConfig provides utility config for configmap
func GetConfigmapConfig(configmap *v1.ConfigMap) Config {
return Config{
Namespace: configmap.Namespace,
ResourceName: configmap.Name,
Annotation: options.ConfigmapUpdateOnChangeAnnotation,
SHAValue: GetSHAfromConfigmap(configmap.Data),
Type: constants.ConfigmapEnvVarPostfix,
Namespace: configmap.Namespace,
ResourceName: configmap.Name,
ResourceAnnotations: configmap.Annotations,
Annotation: options.ConfigmapUpdateOnChangeAnnotation,
SearchAnnotation: options.ConfigmapUpdateAutoSearchAnnotation,
SHAValue: GetSHAfromConfigmap(configmap.Data),
Type: constants.ConfigmapEnvVarPostfix,
}
}
// GetSecretConfig provides utility config for secret
func GetSecretConfig(secret *v1.Secret) Config {
return Config{
Namespace: secret.Namespace,
ResourceName: secret.Name,
Annotation: options.SecretUpdateOnChangeAnnotation,
SHAValue: GetSHAfromSecret(secret.Data),
Type: constants.SecretEnvVarPostfix,
Namespace: secret.Namespace,
ResourceName: secret.Name,
ResourceAnnotations: secret.Annotations,
Annotation: options.SecretUpdateOnChangeAnnotation,
SearchAnnotation: options.SecretUpdateAutoSearchAnnotation,
SHAValue: GetSHAfromSecret(secret.Data),
Type: constants.SecretEnvVarPostfix,
}
}