Repository navigation
Add configurable OVN controller probes #690
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
Open
mtomaska
wants to merge
1
commit into
openstack-k8s-operators:main
Choose a base branch
from
mtomaska:osprh-33460
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+858
−49
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| Copyright 2026 Red Hat Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v1beta1 | ||
|
|
||
| import ( | ||
| "github.com/openstack-k8s-operators/lib-common/modules/common/probes" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/util/validation/field" | ||
| ) | ||
|
|
||
| // GetProbeSet builds the effective ovn-controller probes. Startup is opt-in. | ||
| // Keeping defaults and validation in the API also lets parent operators | ||
| // validate partial overrides against the same defaults used by reconciliation. | ||
| func (spec *OVNControllerSpecCore) GetProbeSet() (*probes.ProbeSet, error) { | ||
| set, errors := spec.buildProbes(field.NewPath("spec", "override", "probes")) | ||
| return set, errors.ToAggregate() | ||
| } | ||
|
|
||
| // ValidateProbes validates overrides and their effective configurations. | ||
| // basePath points to the probes object in either the child or parent CR. | ||
| func (spec *OVNControllerSpecCore) ValidateProbes(basePath *field.Path) field.ErrorList { | ||
| _, errors := spec.buildProbes(basePath) | ||
| return errors | ||
| } | ||
|
|
||
| func (spec *OVNControllerSpecCore) buildProbes(basePath *field.Path) (*probes.ProbeSet, field.ErrorList) { | ||
| set := &probes.ProbeSet{} | ||
| errors := field.ErrorList{} | ||
| for _, probe := range []struct { | ||
| name string | ||
| override *probes.ProbeConf | ||
| script string | ||
| target **corev1.Probe | ||
| }{ | ||
| {"livenessProbes", spec.Override.Probes.LivenessProbes, "ovn_controller_liveness.sh", &set.Liveness}, | ||
| {"readinessProbes", spec.Override.Probes.ReadinessProbes, "ovn_controller_readiness.sh", &set.Readiness}, | ||
| {"startupProbes", spec.Override.Probes.StartupProbes, "ovn_controller_liveness.sh", &set.Startup}, | ||
| } { | ||
| if probe.name == "startupProbes" && probe.override == nil { | ||
| continue | ||
| } | ||
| config := probes.ProbeConf{ | ||
| Type: probes.ProbeHandlerExec, | ||
| Command: []string{"/usr/local/bin/container-scripts/" + probe.script}, | ||
| InitialDelaySeconds: 30, | ||
| TimeoutSeconds: 5, | ||
| PeriodSeconds: 5, | ||
| FailureThreshold: 3, | ||
| } | ||
| path := basePath.Child(probe.name) | ||
| if probe.override != nil { | ||
| // Validate before merging: Merge ignores non-positive timing values. | ||
| // An explicitly selected Exec handler may inherit the default command. | ||
| supplied := *probe.override | ||
| if supplied.Type == probes.ProbeHandlerExec && len(supplied.Command) == 0 { | ||
| supplied.Command = config.Command | ||
| } | ||
| if errs := probes.ValidateProbeConf(path, &supplied); len(errs) > 0 { | ||
| errors = append(errors, errs...) | ||
| continue | ||
| } | ||
| config.Merge(*probe.override) | ||
| } | ||
| if errs := probes.ValidateProbeConf(path, &config); len(errs) > 0 { | ||
| errors = append(errors, errs...) | ||
| continue | ||
| } | ||
| if config.Type == probes.ProbeHandlerHTTP && config.Scheme != nil && | ||
| *config.Scheme != "" && *config.Scheme != corev1.URISchemeHTTP && *config.Scheme != corev1.URISchemeHTTPS { | ||
| errors = append(errors, field.NotSupported(path.Child("scheme"), *config.Scheme, []corev1.URIScheme{corev1.URISchemeHTTP, corev1.URISchemeHTTPS})) | ||
| continue | ||
| } | ||
| built, err := probes.SetProbeConfV2(config) | ||
| if err != nil { | ||
| errors = append(errors, field.Invalid(path, nil, err.Error())) | ||
| continue | ||
| } | ||
| *probe.target = built | ||
| } | ||
| return set, errors | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
config.Merge assigns Command by reference (lib-common ProbeConf.Merge: p.Command = overrides.Command), and it flows straight into the final corev1.Probe.Exec.Command. Since probe.override here is spec.Override.Probes.*.Command from the CR spec, a custom command ends up aliasing the cached CR's backing array instead of being copied. The existing test only covers the default-command path, not this one.
Suggest copying the slice before merging (supplied.Command = append([]string(nil), supplied.Command...)), or add a test proving the built probe's Command isn't the same slice as the CR spec's.