Skip to content
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

Use standard collector selectors in target allocator config #2466

Merged

Conversation

swiatekm
Copy link
Contributor

@swiatekm swiatekm commented Dec 20, 2023

Description:
Make the label selector for collectors in target allocator configuration use the K8s standard format. We can later explicitly expose this in the TargetAllocator CRD.

One annoying aspect of using the core struct is that it only has tags for json serialization, and the yaml marshaler just lowercases the name. So we end up with matchlabels rather than matchLabels or match_labels. I'm not sure the additional complexity of using a custom struct and then converting is worth it, given that target allocator is almost exclusively used and configured by the operator.

Link to tracking Issue: #2422

Resolves #2422

Testing:
Modified existing tests.

@swiatekm swiatekm force-pushed the feat/targetallocator-selector branch 2 times, most recently from f50e03e to 6c8c7a7 Compare December 20, 2023 20:21
@swiatekm swiatekm marked this pull request as ready for review December 20, 2023 20:30
@swiatekm swiatekm requested review from a team December 20, 2023 20:30
# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: This is a breaking change only for users of standalone target allocator. Operator users are unaffected.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is acceptable IMO

Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two thoughts

KubeConfigFilePath string `yaml:"kube_config_file_path,omitempty"`
ClusterConfig *rest.Config `yaml:"-"`
RootLogger logr.Logger `yaml:"-"`
CollectorSelector metav1.LabelSelector `yaml:"collector_selector,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be reference? or should we remove omitempty? I'm not sure the TA can work without the collector selector.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be, good catch. The semantics of v1.LabelSelector, as per the documentation, are:

A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects.

So the target allocator should in fact work without a selector, it'll behave the same way as if there were no collectors to assign targets to.

Comment on lines 55 to 50
taConfig["label_selector"] = manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, collector.ComponentOpenTelemetryCollector)
taConfig["collector_selector"] = map[string]any{
"matchlabels": manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, collector.ComponentOpenTelemetryCollector),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one issue that may arise with this change is that users cannot use the newer operator with an older TA version. This could be problematic in this scenario:

  • a company runs a mirrored image of the TA due to a security requirement for the image in the collector CRD
  • engineer bumps the operator version which no longer writes the former selector
  • TA can no longer startup until they re-mirror and bump the TA image

I think for now it may make sense to just mark the label_selector as deprecated in the operator and will be removed entirely in v1alpha2. It is totally fine, however, to just remove it entirely from the TA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support running different versions of the operator and targetallocator? I know we don't for the collector, even though things usually work anyway.

How would you mark the label_selector as deprecated? From the operator's perspective, it's just a key in an untyped map.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just mark it in a comment with a TODO linking to an open issue, this could also be a featuregate that starts enabled by default and then we eventually just delete it?

I'm not sure we've discussed what the operators own compat matrix looks like, but the scenario I linked above could break a lot of users because you cannot usually update the TA image and the operator image in the same release. Doing either one without the other would result in a broken state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A problem with this is that target allocator currently unmarshals its configuration in strict mode, so the old version can't deal with the new value either way. The way I see it, there's two possible approaches:

  1. Do an explicit version check and apply the right value.
  2. Merge a change that makes config unmarshalling non-strict, wait till that's released, and then merge this PR.

I think I like 2 better, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh 🤦 I think i like 2 more as well. Lets get that merged in before #2482

@swiatekm swiatekm force-pushed the feat/targetallocator-selector branch 2 times, most recently from c8be097 to a1b0dd9 Compare January 2, 2024 17:37
@swiatekm swiatekm force-pushed the feat/targetallocator-selector branch from a1b0dd9 to 0db3028 Compare January 8, 2024 14:15
@jaronoff97
Copy link
Contributor

jaronoff97 commented Jan 8, 2024

@swiatekm-sumo i think we're good to merge this now that #2488 has been merged right? In the changelog can you call out the potential incompatability?

This is to keep backwards compatibility with older target
allocator versions, which makes upgrades easier.
@swiatekm swiatekm force-pushed the feat/targetallocator-selector branch from 0db3028 to 803b7f2 Compare January 8, 2024 17:29
@swiatekm
Copy link
Contributor Author

swiatekm commented Jan 8, 2024

@swiatekm-sumo i think we're good to merge this now that #2488 has been merged right? In the changelog can you call out the potential incompatability?

I made the backwards compatibility guarantee explicit.

@jaronoff97 jaronoff97 merged commit 87e23fa into open-telemetry:main Jan 8, 2024
27 checks passed
@swiatekm swiatekm deleted the feat/targetallocator-selector branch January 8, 2024 19:28
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
…emetry#2466)

* Use standard collector selectors in target allocator config

* Use both collector selector formats in ta config

This is to keep backwards compatibility with older target
allocator versions, which makes upgrades easier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce TargetAllocator CRD
3 participants