Skip to content

OCPBUGS-83863: Strip debug symbols from Go binaries#1525

Open
sdodson wants to merge 1 commit into
openshift:mainfrom
sdodson:strip-go-binaries
Open

OCPBUGS-83863: Strip debug symbols from Go binaries#1525
sdodson wants to merge 1 commit into
openshift:mainfrom
sdodson:strip-go-binaries

Conversation

@sdodson
Copy link
Copy Markdown
Member

@sdodson sdodson commented May 25, 2026

Summary

  • Add -s -w to ldflags in GO_BUILD_RECIPE to strip DWARF debug info and symbol tables from the main operator binary
  • Fix build-gather-sysinfo and build-performance-profile-creator targets which intended to strip but had a make-vs-shell variable expansion bug ($(LDFLAGS) is expanded by make before the shell runs, so the shell variable set on the previous line was never used)

Impact

The cluster-node-tuning-operator image (617 MB) contains three unstripped Go binaries totaling 195 MB:

  • cluster-node-tuning-operator (96.8 MB)
  • gather-sysinfo (63.8 MB)
  • performance-profile-creator (34.6 MB)

Stripping typically reduces Go binary size by 20-30%, reducing container image pull time during node scale-up.

Test plan

  • Verify image builds successfully
  • Verify binaries are stripped (file /usr/bin/cluster-node-tuning-operator should show "stripped")
  • Verify operator functions correctly

Summary by CodeRabbit

  • Chores
    • Updated build configuration to optimize binary sizes and streamline the compilation process across multiple build targets.

Add -s -w to ldflags to strip DWARF debug info and symbol tables.
This typically reduces binary size by 20-30%, which reduces container
image pull time during node scale-up.

Also fix build-gather-sysinfo and build-performance-profile-creator
targets which intended to strip but had a make-vs-shell variable
expansion bug: they set a shell variable LDFLAGS then referenced
$(LDFLAGS) which make expands (to empty) before the shell runs.

rh-pre-commit.version: 2.4.0
rh-pre-commit.check-secrets: ENABLED
@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels May 25, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@sdodson: This pull request references Jira Issue OCPBUGS-83863, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • Add -s -w to ldflags in GO_BUILD_RECIPE to strip DWARF debug info and symbol tables from the main operator binary
  • Fix build-gather-sysinfo and build-performance-profile-creator targets which intended to strip but had a make-vs-shell variable expansion bug ($(LDFLAGS) is expanded by make before the shell runs, so the shell variable set on the previous line was never used)

Impact

The cluster-node-tuning-operator image (617 MB) contains three unstripped Go binaries totaling 195 MB:

  • cluster-node-tuning-operator (96.8 MB)
  • gather-sysinfo (63.8 MB)
  • performance-profile-creator (34.6 MB)

Stripping typically reduces Go binary size by 20-30%, reducing container image pull time during node scale-up.

Test plan

  • Verify image builds successfully
  • Verify binaries are stripped (file /usr/bin/cluster-node-tuning-operator should show "stripped")
  • Verify operator functions correctly

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci Bot requested review from ffromani and swatisehgal May 25, 2026 15:02
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 25, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sdodson
Once this PR has been reviewed and has the lgtm label, please assign jmencak for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f6542d48-6bf1-4505-aecf-331978457e5c

📥 Commits

Reviewing files that changed from the base of the PR and between 30ad005 and 18d9b3b.

📒 Files selected for processing (1)
  • Makefile

Walkthrough

The Makefile adds Go linker stripping flags (-s -w) to build recipes. The main GO_BUILD_RECIPE variable and two specialized build targets (build-performance-profile-creator and build-gather-sysinfo) are updated to pass -ldflags "-s -w" inline alongside version injection, reducing binary size.

Changes

Binary size optimization via Go linker flags

Layer / File(s) Summary
Go linker stripping flags in build recipes
Makefile
GO_BUILD_RECIPE, build-performance-profile-creator, and build-gather-sysinfo targets are updated to include -s -w linker flags. The main recipe adds flags to the existing -X version injection. The two specialized targets switch from shell variable-based LDFLAGS to inline -ldflags flags containing both stripping and version options.

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 10 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Microshift Test Compatibility ⚠️ Warning New Ginkgo tests use unavailable OpenShift APIs (ClusterOperator, MachineConfig) without MicroShift protection markers or guards. Add [Skipped:MicroShift] labels or [apigroup:...] tags to protect tests using unavailable OpenShift APIs from running on MicroShift.
Single Node Openshift (Sno) Test Compatibility ⚠️ Warning New e2e tests in test/e2e/basic/ assume multiple worker nodes without SNO guards and will fail on single-node clusters when calling GetNodesByRole. Add [Skipped:SingleReplicaTopology] label to tests or guard with exutil.IsSingleNode() checks. Affected: default_node_sysctl.go, modules.go, custom_node_labels.go, etc.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding Go linker stripping flags (-s -w) to remove debug symbols from binaries in the Makefile.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed PR only modifies Makefile (Go linker stripping flags). No Ginkgo test files or test names were added, modified, or removed, so the stable test names check is not applicable.
Test Structure And Quality ✅ Passed PR only modifies Makefile to add binary stripping flags; contains no Ginkgo test code changes. The test files shown are new files being created, not modifications to existing test code.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only Makefile linker flags (-s -w); no scheduling constraints, pod affinity, or topology changes.
Ote Binary Stdout Contract ✅ Passed PR only modifies Makefile to add -s -w linker flags for binary stripping. No Go source code changed. These flags strip debug symbols at compile time, not affecting runtime stdout behavior.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR only modifies Makefile to add binary stripping flags. No new Ginkgo e2e tests are added, so the check is not applicable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 25, 2026

@sdodson: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-pao-updating-profile 18d9b3b link true /test e2e-gcp-pao-updating-profile
ci/prow/e2e-aws-ovn-techpreview 18d9b3b link true /test e2e-aws-ovn-techpreview

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@jmencak
Copy link
Copy Markdown
Contributor

jmencak commented May 25, 2026

Thank you for the PR, Scott. Do we want to do the same thing for cluster-node-tuning-operator-test-ext? It will grow large soon as we add more tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants