Add annotation to collect objects that have an owner reference
In case of objects created by operators, might still want to collect some
objects that are only created by the operator once
@@ -29,7 +29,9 @@ import (
const (
// Annotation to use when the resource shouldn't be collected
- skipResourceAnnotation = "stork.libopenstorage.org/skipresource"
+ skipResourceAnnotationDeprecated = "stork.libopenstorage.org/skipresource"
+ skipResourceAnnotation = "stork.libopenstorage.org/skip-resource"
+ skipOwnerRefCheckAnnotation = "stork.libopenstorage.org/skip-owner-ref-check"
deletedMaxRetries = 12
deletedRetryInterval = 10 * time.Second
)
@@ -210,6 +212,24 @@ func SkipResource(annotations map[string]string) bool {
if skip, err := strconv.ParseBool(value); err == nil && skip {
return true
}
+ return false
+ }
+ if value, present := annotations[skipResourceAnnotationDeprecated]; present {
+ if skip, err := strconv.ParseBool(value); err == nil && skip {
+ return true
+ }
+ return false
+ }
+ return false
+}
+
+// skipOwnerRefCheck returns whether the object should be collected even if it
+// has an owner reference
+func skipOwnerRefCheck(annotations map[string]string) bool {
+ if value, present := annotations[skipOwnerRefCheckAnnotation]; present {
+ if skip, err := strconv.ParseBool(value); err == nil && skip {
+ return true
+ }
}
return false
}
@@ -296,8 +316,9 @@ func (r *ResourceCollector) pruneOwnedResources(
if objectType.GetKind() != "PersistentVolumeClaim" {
owners := metadata.GetOwnerReferences()
if len(owners) != 0 {
+ if !skipOwnerRefCheck(metadata.GetAnnotations()) {
for _, owner := range owners {
- // We don't collect pods, there might be come leader
+ // We don't collect pods, there might be some leader
// election objects that could have pods as the owner, so
// don't collect those objects
if owner.Kind == "Pod" {
@@ -311,6 +332,7 @@ func (r *ResourceCollector) pruneOwnedResources(
break
}
}
+ }
// If the owner isn't being collected delete the owner reference
metadata.SetOwnerReferences(nil)
}
