-
Notifications
You must be signed in to change notification settings - Fork 53
OLS-3799 Add wait-for-rhokp init container to app-server deployment #1921
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
vimalk78
wants to merge
1
commit into
openshift:main
Choose a base branch
from
vimalk78:ols-3799
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.
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
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,92 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "path" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/api/resource" | ||
| ) | ||
|
|
||
| // RHOKPWaitMaxSeconds is the maximum time the wait-for-rhokp init container | ||
| // will poll before giving up. Matches the RHOKP startup-probe budget | ||
| // (20 s initial-delay + 34 failures × 10 s period ≈ 360 s). | ||
| const RHOKPWaitMaxSeconds = 360 | ||
|
|
||
| // GenerateRHOKPWaitInitContainer returns an init container that blocks until the | ||
| // standalone RHOKP/Solr instance is reachable on its HTTPS endpoint. | ||
| // | ||
| // Without this gate the app-server's SolrHybridSearch initializer may exhaust | ||
| // its 120 s retry budget before RHOKP is ready, permanently caching a nil | ||
| // reference for product-docs RAG (OLS-3799). | ||
| // | ||
| // The container uses the app-server image (which ships curl) and polls the | ||
| // Solr admin/ping endpoint. The RHOKP CA certificate volume must already | ||
| // be defined on the pod (AppRHOKPCACertVolumeName). | ||
| func GenerateRHOKPWaitInitContainer(image, namespace string) corev1.Container { | ||
| rhokpURL := RHOKPServiceURL(namespace) + RHOOKPReadinessHTTPPath | ||
|
|
||
| caPath := path.Join(OLSAppCertsMountRoot, AppRHOKPCACertDir, AppRHOKPCACertFile) | ||
|
|
||
| script := fmt.Sprintf(` | ||
| if ! command -v curl >/dev/null 2>&1; then | ||
| echo "wait-for-rhokp: curl not found in image" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| sleep_sec=1 | ||
| max_sleep=30 | ||
| start=$(date +%%s) | ||
| max_elapsed=%d | ||
| url="%s" | ||
| ca="%s" | ||
|
|
||
| backoff() { | ||
| sleep "$sleep_sec" | ||
| sleep_sec=$((sleep_sec * 2)) | ||
| [ "$sleep_sec" -gt "$max_sleep" ] && sleep_sec="$max_sleep" | ||
| } | ||
|
|
||
| while true; do | ||
| now=$(date +%%s) | ||
| elapsed=$((now - start)) | ||
| if [ "$elapsed" -ge "$max_elapsed" ]; then | ||
| echo "wait-for-rhokp: timed out after ${max_elapsed}s" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if curl -sf --cacert "$ca" --max-time 5 "$url" >/dev/null 2>&1; then | ||
| echo "wait-for-rhokp: RHOKP/Solr is reachable" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "wait-for-rhokp: not ready yet (elapsed=${elapsed}s)" >&2 | ||
| backoff | ||
| done | ||
| `, RHOKPWaitMaxSeconds, rhokpURL, caPath) | ||
|
|
||
| return corev1.Container{ | ||
| Name: RHOKPWaitInitContainerName, | ||
| Image: image, | ||
| ImagePullPolicy: corev1.PullIfNotPresent, | ||
| Command: []string{"/bin/sh", "-c", script}, | ||
| VolumeMounts: []corev1.VolumeMount{ | ||
| { | ||
| Name: AppRHOKPCACertVolumeName, | ||
| MountPath: path.Join(OLSAppCertsMountRoot, AppRHOKPCACertDir), | ||
| ReadOnly: true, | ||
| }, | ||
| }, | ||
| SecurityContext: RestrictedContainerSecurityContext(), | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("10m"), | ||
| corev1.ResourceMemory: resource.MustParse("32Mi"), | ||
| }, | ||
| Limits: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("100m"), | ||
| corev1.ResourceMemory: resource.MustParse("64Mi"), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
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,79 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "path" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/api/resource" | ||
| ) | ||
|
|
||
| var _ = Describe("RHOKP wait", func() { | ||
|
|
||
| Describe("GenerateRHOKPWaitInitContainer", func() { | ||
| const testNS = "openshift-lightspeed" | ||
|
|
||
| It("uses the provided image and generates correct container spec", func() { | ||
| c := GenerateRHOKPWaitInitContainer(OLSAppServerImageDefault, testNS) | ||
| Expect(c.Name).To(Equal(RHOKPWaitInitContainerName)) | ||
| Expect(c.Image).To(Equal(OLSAppServerImageDefault)) | ||
| Expect(c.SecurityContext).To(Equal(RestrictedContainerSecurityContext())) | ||
| Expect(c.Resources.Requests).To(HaveKey(corev1.ResourceCPU)) | ||
| Expect(c.Resources.Requests).To(HaveKey(corev1.ResourceMemory)) | ||
| Expect(c.Resources.Requests[corev1.ResourceCPU]).To(Equal(resource.MustParse("10m"))) | ||
| Expect(c.Resources.Requests[corev1.ResourceMemory]).To(Equal(resource.MustParse("32Mi"))) | ||
| Expect(c.Resources.Limits[corev1.ResourceCPU]).To(Equal(resource.MustParse("100m"))) | ||
| Expect(c.Resources.Limits[corev1.ResourceMemory]).To(Equal(resource.MustParse("64Mi"))) | ||
| Expect(c.Command).To(HaveLen(3)) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
|
|
||
| It("mounts the RHOKP CA certificate volume", func() { | ||
| c := GenerateRHOKPWaitInitContainer(OLSAppServerImageDefault, testNS) | ||
| Expect(c.VolumeMounts).To(HaveLen(1)) | ||
| Expect(c.VolumeMounts[0].Name).To(Equal(AppRHOKPCACertVolumeName)) | ||
| Expect(c.VolumeMounts[0].MountPath).To(Equal(path.Join(OLSAppCertsMountRoot, AppRHOKPCACertDir))) | ||
| Expect(c.VolumeMounts[0].ReadOnly).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("contains curl-based readiness check using admin/ping endpoint", func() { | ||
| c := GenerateRHOKPWaitInitContainer(OLSAppServerImageDefault, testNS) | ||
| script := c.Command[2] | ||
|
|
||
| By("using curl for connectivity check") | ||
| Expect(script).To(ContainSubstring("curl")) | ||
| Expect(script).To(ContainSubstring("--cacert")) | ||
|
|
||
| By("targeting the RHOKP admin/ping endpoint") | ||
| expectedURL := RHOKPServiceURL(testNS) + RHOOKPReadinessHTTPPath | ||
| Expect(script).To(ContainSubstring(expectedURL)) | ||
| }) | ||
|
|
||
| It("guards against missing curl binary", func() { | ||
| c := GenerateRHOKPWaitInitContainer(OLSAppServerImageDefault, testNS) | ||
| script := c.Command[2] | ||
| Expect(script).To(ContainSubstring("command -v curl")) | ||
| Expect(script).To(ContainSubstring("curl not found in image")) | ||
| }) | ||
|
|
||
| It("has timeout and backoff logic", func() { | ||
| c := GenerateRHOKPWaitInitContainer(OLSAppServerImageDefault, testNS) | ||
| script := c.Command[2] | ||
|
|
||
| Expect(script).To(ContainSubstring(fmt.Sprintf("max_elapsed=%d", RHOKPWaitMaxSeconds))) | ||
| Expect(script).To(ContainSubstring("backoff")) | ||
| Expect(script).To(ContainSubstring("timed out")) | ||
| Expect(script).To(ContainSubstring("not ready yet")) | ||
| Expect(script).To(ContainSubstring("RHOKP/Solr is reachable")) | ||
| }) | ||
|
|
||
| It("uses the correct namespace in the service URL", func() { | ||
| customNS := "my-custom-namespace" | ||
| c := GenerateRHOKPWaitInitContainer(OLSAppServerImageDefault, customNS) | ||
| script := c.Command[2] | ||
| Expect(script).To(ContainSubstring(fmt.Sprintf("%s.%s.svc", RHOKPServiceName, customNS))) | ||
| }) | ||
| }) | ||
| }) | ||
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.
Missing
command -v curlguardpostgres_wait.govalidates its tool exists before entering the poll loop:This script has no equivalent check for
curl. If curl is ever removed from the app-server image, the init container will loop for 360 seconds (the curl invocation suppresses all output via>/dev/null 2>&1) before timing out — a confusing silent failure instead of a fast one.Suggestion: add
command -v curlcheck before thewhile trueloop, matching the postgres pattern.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.
Added
command -v curlguard before the poll loop, matching the postgres pattern. Fails fast with a clear message instead of silently looping for 360s.