Skip to content

Commit 53b650a

Browse files
authored
Provide annotations to exclude reloading resources (#764)
* Provide annotations to exclude reloading resources * update test case * undo commented tests * remove sleep
1 parent 32d5bb8 commit 53b650a

File tree

4 files changed

+360
-96
lines changed

4 files changed

+360
-96
lines changed

internal/pkg/handler/upgrade.go

+36
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,34 @@ func PerformAction(clients kube.Clients, config util.Config, upgradeFuncs callba
199199
searchAnnotationValue, foundSearchAnn := annotations[options.AutoSearchAnnotation]
200200
reloaderEnabledValue, foundAuto := annotations[options.ReloaderAutoAnnotation]
201201
typedAutoAnnotationEnabledValue, foundTypedAuto := annotations[config.TypedAutoAnnotation]
202+
excludeConfigmapAnnotationValue, foundExcludeConfigmap := annotations[options.ConfigmapExcludeReloaderAnnotation]
203+
excludeSecretAnnotationValue, foundExcludeSecret := annotations[options.SecretExcludeReloaderAnnotation]
204+
202205
if !found && !foundAuto && !foundTypedAuto && !foundSearchAnn {
203206
annotations = upgradeFuncs.PodAnnotationsFunc(i)
204207
annotationValue = annotations[config.Annotation]
205208
searchAnnotationValue = annotations[options.AutoSearchAnnotation]
206209
reloaderEnabledValue = annotations[options.ReloaderAutoAnnotation]
207210
typedAutoAnnotationEnabledValue = annotations[config.TypedAutoAnnotation]
208211
}
212+
213+
isResourceExcluded := false
214+
215+
switch config.Type {
216+
case constants.ConfigmapEnvVarPostfix:
217+
if foundExcludeConfigmap {
218+
isResourceExcluded = checkIfResourceIsExcluded(config.ResourceName, excludeConfigmapAnnotationValue)
219+
}
220+
case constants.SecretEnvVarPostfix:
221+
if foundExcludeSecret {
222+
isResourceExcluded = checkIfResourceIsExcluded(config.ResourceName, excludeSecretAnnotationValue)
223+
}
224+
}
225+
226+
if isResourceExcluded {
227+
continue
228+
}
229+
209230
result := constants.NotUpdated
210231
reloaderEnabled, _ := strconv.ParseBool(reloaderEnabledValue)
211232
typedAutoAnnotationEnabled, _ := strconv.ParseBool(typedAutoAnnotationEnabledValue)
@@ -275,6 +296,21 @@ func PerformAction(clients kube.Clients, config util.Config, upgradeFuncs callba
275296
return nil
276297
}
277298

299+
func checkIfResourceIsExcluded(resourceName, excludedResources string) bool {
300+
if excludedResources == "" {
301+
return false
302+
}
303+
304+
excludedResourcesList := strings.Split(excludedResources, ",")
305+
for _, excludedResource := range excludedResourcesList {
306+
if strings.TrimSpace(excludedResource) == resourceName {
307+
return true
308+
}
309+
}
310+
311+
return false
312+
}
313+
278314
func getVolumeMountName(volumes []v1.Volume, mountType string, volumeName string) string {
279315
for i := range volumes {
280316
if mountType == constants.ConfigmapEnvVarPostfix {

0 commit comments

Comments
 (0)