From 8f77948f6eb0d3ef0d66e52f433574e4d3f93080 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 29 Dec 2025 11:46:34 +0100 Subject: [PATCH 1/2] registry_pod: Avoid grace period delay The shell script does not propagate the SIGTERM signal that is sent to the pod when it is terminated; to avoid this, we run the last command to substitute the shell process, so that the pod stop immediately instead of waiting the 30 default seconds of the grace period when an user uninstall the operator by using 'operator-sdk cleanup ...' command. Signed-off-by: Alejandro Visiedo --- internal/olm/operator/registry/index/registry_pod.go | 2 +- internal/olm/operator/registry/index/registry_pod_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/olm/operator/registry/index/registry_pod.go b/internal/olm/operator/registry/index/registry_pod.go index ccbf9bf3166..7f1849b6242 100644 --- a/internal/olm/operator/registry/index/registry_pod.go +++ b/internal/olm/operator/registry/index/registry_pod.go @@ -377,7 +377,7 @@ const cmdTemplate = `[[ -f {{ .DBPath }} ]] && cp {{ .DBPath }} /tmp/tmp.db; \ {{- range $i, $item := .BundleItems }} opm registry add -d /tmp/tmp.db -b {{ $item.ImageTag }} --mode={{ $item.AddMode }}{{ if $.CASecretName }} --ca-file=/certs/cert.pem{{ end }} --skip-tls-verify={{ $.SkipTLSVerify }} --use-http={{ $.UseHTTP }} && \ {{- end }} -opm registry serve -d /tmp/tmp.db -p {{ .GRPCPort }} +exec opm registry serve -d /tmp/tmp.db -p {{ .GRPCPort }} ` // getContainerCmd uses templating to construct the container command diff --git a/internal/olm/operator/registry/index/registry_pod_test.go b/internal/olm/operator/registry/index/registry_pod_test.go index 40cd21baf40..f7a9a997765 100644 --- a/internal/olm/operator/registry/index/registry_pod_test.go +++ b/internal/olm/operator/registry/index/registry_pod_test.go @@ -291,5 +291,5 @@ func containerCommandFor(dbPath string, items []BundleItem, hasCA, skipTLSVerify additions.WriteString(fmt.Sprintf("opm registry add -d /tmp/tmp.db -b %s --mode=%s%s --skip-tls-verify=%v --use-http=%v && \\\n", item.ImageTag, item.AddMode, caFlag, skipTLSVerify, useHTTP)) } - return fmt.Sprintf("[[ -f %s ]] && cp %s /tmp/tmp.db; \\\n%sopm registry serve -d /tmp/tmp.db -p 50051\n", dbPath, dbPath, additions.String()) + return fmt.Sprintf("[[ -f %s ]] && cp %s /tmp/tmp.db; \\\n%sexec opm registry serve -d /tmp/tmp.db -p 50051\n", dbPath, dbPath, additions.String()) } From 09cb38a5cbc84d02f24e3fd8edd1f583628f66f8 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 29 Dec 2025 13:05:18 +0100 Subject: [PATCH 2/2] registry-server: save grace period when terminating Make registry-server run with pid 1, after initialization so when the container is stopped, the process is gracefully terminated. Signed-off-by: Alejandro Visiedo --- internal/olm/operator/registry/configmap/deployment.go | 2 +- internal/olm/operator/registry/configmap/deployment_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/olm/operator/registry/configmap/deployment.go b/internal/olm/operator/registry/configmap/deployment.go index 566fdc6da99..75d4f705f53 100644 --- a/internal/olm/operator/registry/configmap/deployment.go +++ b/internal/olm/operator/registry/configmap/deployment.go @@ -106,7 +106,7 @@ func withContainerVolumeMounts(volName string, paths ...string) func(*appsv1.Dep func getDBContainerCmd(dbPath, logPath string) string { initCmd := fmt.Sprintf("/bin/initializer -o %s -m %s", dbPath, containerManifestsDir) srvCmd := fmt.Sprintf("/bin/registry-server -d %s -t %s", dbPath, logPath) - return fmt.Sprintf("%s && %s", initCmd, srvCmd) + return fmt.Sprintf("%s && exec %s", initCmd, srvCmd) } // withRegistryGRPCContainer returns a function that appends a container diff --git a/internal/olm/operator/registry/configmap/deployment_test.go b/internal/olm/operator/registry/configmap/deployment_test.go index 31dade87135..e9a56938133 100644 --- a/internal/olm/operator/registry/configmap/deployment_test.go +++ b/internal/olm/operator/registry/configmap/deployment_test.go @@ -160,7 +160,7 @@ var _ = Describe("Deployment", func() { initCmd := "/bin/initializer -o /path/to/database.db -m /registry/manifests" srvCmd := "/bin/registry-server -d /path/to/database.db -t /var/log/temp.log" - Expect(getDBContainerCmd("/path/to/database.db", "/var/log/temp.log")).Should(Equal(fmt.Sprintf("%s && %s", initCmd, srvCmd))) + Expect(getDBContainerCmd("/path/to/database.db", "/var/log/temp.log")).Should(Equal(fmt.Sprintf("%s && exec %s", initCmd, srvCmd))) }) })