-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix optional resource deletion for collector CR #3494
base: main
Are you sure you want to change the base?
Fix optional resource deletion for collector CR #3494
Conversation
gvk, err := apiutil.GVKForObject(l, cl.Scheme()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
list.SetGroupVersionKind(gvk) | ||
err = cl.List(ctx, list, options...) | ||
gvk.Kind = fmt.Sprintf("%sList", gvk.Kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels really stupid, but I couldn't find an idiomatic way to get a xxxList
instance given an xxx
instance.
96d5c1b
to
8bc20d1
Compare
"app.kubernetes.io/managed-by": "opentelemetry-operator", | ||
"app.kubernetes.io/instance": naming.Truncate("%s.%s", 63, params.OtelCol.Namespace, params.OtelCol.Name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use the constants we have for this type of thing
// removeKeptConfigMaps removes old ConfigMaps that we want to keep from the map of owned objects. | ||
// Normally the controller would delete them after determining they're not in the list of desired objects generated | ||
// from the OpenTelemetryCollector CR, but we want to keep them around. | ||
func removeKeptConfigMapVersions(configVersionsToKeep int, ownedObjects map[types.UID]client.Object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name/purpose of this method is a bit confusing... I understand why we do it this way (no need to query k8s twice) but I think we could probably have the method be something like filterObsoleteConfigMaps
? I think the remove kept feels like it's canceling itself to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the best way would be to change the function to return the CMs that should be kept, then it could be named getConfigMapsToKeep
, it would take a slice of configmaps and return one. Then the calling function could build the slice from the map, call the function, and delete the output from the map.
@@ -351,3 +376,5 @@ func (r *OpenTelemetryCollectorReconciler) finalizeCollector(ctx context.Context | |||
} | |||
return nil | |||
} | |||
|
|||
const resourceOwnerKey = ".metadata.owner" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this to the top?
Description:
I've refactored and cleaned up our owned resource tracking:
Link to tracking Issue(s):
Testing: