-
Notifications
You must be signed in to change notification settings - Fork 567
ROSAENG-60642: feat(install): add --operator-pprof-addr flag to enable pprof on the HyperShift Operator #8853
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,10 @@ import ( | |
| "fmt" | ||
| "io" | ||
| "io/fs" | ||
| "net" | ||
| "path/filepath" | ||
| "slices" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
|
|
@@ -559,6 +561,7 @@ type HyperShiftOperatorDeployment struct { | |
| ScaleFromZeroSecretKey string | ||
| ScaleFromZeroProvider string | ||
| HCPEgressBlockCIDRs []string | ||
| PprofAddr string | ||
| } | ||
|
|
||
| func (o HyperShiftOperatorDeployment) Build() *appsv1.Deployment { | ||
|
|
@@ -723,6 +726,12 @@ func (o HyperShiftOperatorDeployment) Build() *appsv1.Deployment { | |
| }, | ||
| } | ||
|
|
||
| if port, ok := o.pprofContainerPort(); ok { | ||
| deployment.Spec.Template.Spec.Containers[0].Ports = append( | ||
| deployment.Spec.Template.Spec.Containers[0].Ports, port, | ||
| ) | ||
| } | ||
|
|
||
| // Azure Workload Identity requires this pod label for the webhook to inject | ||
| // federated tokens (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_FEDERATED_TOKEN_FILE). | ||
| if o.AzurePLSManagedIdentityClientID != "" { | ||
|
|
@@ -794,6 +803,9 @@ func (o HyperShiftOperatorDeployment) buildArgs() []string { | |
| if o.RegistryOverrides != "" { | ||
| args = append(args, fmt.Sprintf("--registry-overrides=%s", o.RegistryOverrides)) | ||
| } | ||
| if _, ok := o.pprofContainerPort(); ok { | ||
| args = append(args, "--pprof-addr="+o.PprofAddr) | ||
| } | ||
| return args | ||
| } | ||
|
|
||
|
|
@@ -950,6 +962,28 @@ func (o HyperShiftOperatorDeployment) addScaleFromZeroResources(args *[]string, | |
| }) | ||
| } | ||
|
|
||
| // pprofContainerPort parses o.PprofAddr and returns the corresponding | ||
| // ContainerPort when the address is non-empty and valid. The installer | ||
| // validates the address before Build is called, so errors here are a safety net. | ||
| func (o HyperShiftOperatorDeployment) pprofContainerPort() (corev1.ContainerPort, bool) { | ||
| if o.PprofAddr == "" { | ||
| return corev1.ContainerPort{}, false | ||
| } | ||
| _, portStr, err := net.SplitHostPort(o.PprofAddr) | ||
| if err != nil { | ||
| return corev1.ContainerPort{}, false | ||
| } | ||
| port, err := strconv.Atoi(portStr) | ||
| if err != nil || port < 1 || port > 65535 { | ||
| return corev1.ContainerPort{}, false | ||
| } | ||
| return corev1.ContainerPort{ | ||
| Name: "pprof", | ||
| ContainerPort: int32(port), | ||
| Protocol: corev1.ProtocolTCP, | ||
| }, true | ||
| } | ||
|
Comment on lines
+965
to
+985
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major Still reject pprof addresses that collide with the metrics listener.
🧰 Tools🪛 ast-grep (0.44.1)[warning] 981-981: Narrowing a non-constant integer to a smaller fixed-width type (int8/int16/int32, uint8/uint16/uint32) can silently overflow or wrap, yielding negative or truncated values that are dangerous in size, length, or index logic. Validate the source value is within the target type's range before converting (e.g. bounds-check, or use a checked helper), and avoid narrowing untrusted or len()/parsed values. (integer-overflow-narrowing-conversion-go) 🤖 Prompt for AI Agents |
||
|
|
||
| func (o HyperShiftOperatorDeployment) resolveImage() string { | ||
| image := o.OperatorImage | ||
| if mapImage, ok := o.Images["hypershift-operator"]; ok { | ||
|
|
||
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.
🩺 Stability & Availability | 🟠 Major
Reject pprof port 9000 in the shared validation helper.
buildArgs()always passes--metrics-addr=:9000at Line [794], butpprofContainerPort()accepts:9000; both deployment generation and argument propagation then configure conflicting listeners, causing operator startup failure when upstream validation is bypassed. Reject the reserved metrics port here and keep the installer validator aligned.Suggested fix
Also applies to: 806-808, 965-986
🤖 Prompt for AI Agents