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

fix(operator): truncate sidecar pod injected label to 63 chars #2250

Merged
merged 2 commits into from
Nov 8, 2023

Conversation

RoVernekar
Copy link
Contributor

@RoVernekar RoVernekar commented Oct 19, 2023

Description:

Truncate sidecar.opentelemetry.io/injected sidecar pod label to 63 characters since Kubernetes labels must be 63 characters or less.

Link to tracking Issue:

resolves #1031

Testing:

Tested with a unit test in pod_test.go.

Documentation:

@RoVernekar RoVernekar requested a review from a team October 19, 2023 15:56
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 19, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: RoVernekar / name: Rohan Vernekar (f2f3bd1)
  • ✅ login: jaronoff97 / name: Jacob Aronoff (6025971)

@@ -53,7 +53,7 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCo
if pod.Labels == nil {
pod.Labels = map[string]string{}
}
pod.Labels[label] = fmt.Sprintf("%s.%s", otelcol.Namespace, otelcol.Name)
pod.Labels[label] = naming.Truncate("%s.%s", 63, otelcol.Namespace, otelcol.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: instead of truncating here, could make a method called naming.SidecarLabel in the naming package?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also rename the label variable which IMO is a very nondescript name 😓

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about naming.PodInstanceLabel? The same logic is used in a few other places so I figured we could reuse this function but couldn't think of a great name.

Also I renamed label to injectedLabel. How's that?

Copy link
Contributor

Choose a reason for hiding this comment

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

perfect :)

@jaronoff97
Copy link
Contributor

@RoVernekar youll need to fill out the CLA before we can merge

@RoVernekar RoVernekar force-pushed the truncate-pod-label branch 2 times, most recently from c573d51 to 74211ad Compare October 20, 2023 20:29
@RoVernekar
Copy link
Contributor Author

@RoVernekar youll need to fill out the CLA before we can merge

Sorry for the delay, should be good now.

@RoVernekar RoVernekar requested a review from jaronoff97 October 23, 2023 14:04
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.

LGTM! Thank you for your contribution!

@jaronoff97 jaronoff97 requested a review from swiatekm October 23, 2023 15:13
@@ -124,3 +124,8 @@ func ServiceMonitor(otelcol string) string {
func TargetAllocatorServiceAccount(otelcol string) string {
return DNSName(Truncate("%s-targetallocator", 63, otelcol))
}

// PodInstanceLabel returns a label value containing the namespace and instance name.
func PodInstanceLabel(namespace string, otelcol string) string {
Copy link
Member

Choose a reason for hiding this comment

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

is Pod the right prefix we want to use? Shouldn't this be just InstanceLabel ?

Copy link
Member

Choose a reason for hiding this comment

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

I would revert other changes in this PR . The naming/main.go is used for k8s object names.

Or expose this function in the labels.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I went back to the original changes. Let me know if you would prefer I expose this in labels.go instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pavolloffay can you take another look at this when you get a chance?

@@ -53,7 +53,7 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCo
if pod.Labels == nil {
pod.Labels = map[string]string{}
}
pod.Labels[label] = fmt.Sprintf("%s.%s", otelcol.Namespace, otelcol.Name)
pod.Labels[injectedLabel] = naming.PodInstanceLabel(otelcol.Namespace, otelcol.Name)
Copy link
Member

Choose a reason for hiding this comment

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

review note: this is the fix of the issue

@jaronoff97 jaronoff97 merged commit f60a945 into open-telemetry:main Nov 8, 2023
26 checks passed
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
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.

Label "sidecar.opentelemetry.io/injected" value sometimes longer than 63 characters
5 participants