Skip to content

fix: wait for app user secret before starting initdb#8663

Merged
leonardoce merged 4 commits intomainfrom
dev/6069
Oct 2, 2025
Merged

fix: wait for app user secret before starting initdb#8663
leonardoce merged 4 commits intomainfrom
dev/6069

Conversation

@armru
Copy link
Member

@armru armru commented Sep 25, 2025

The scope of this PR is to address #6069 with minimally invasive changes

Closes #6069

@armru armru requested a review from a team as a code owner September 25, 2025 09:52
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.26 release-1.27 labels Sep 25, 2025
@github-actions
Copy link
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Sep 25, 2025
@dosubot dosubot bot added the bug 🐛 Something isn't working label Sep 25, 2025
@armru armru changed the title fix: wait for secrets before starting initdb fix: wait for AppSecret before starting initdb Sep 25, 2025
@armru
Copy link
Member Author

armru commented Sep 25, 2025

/test limit=local

@github-actions
Copy link
Contributor

@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/18003840131

@armru
Copy link
Member Author

armru commented Sep 25, 2025

/test limit=local

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Sep 25, 2025
@github-actions
Copy link
Contributor

@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/18012162947

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Sep 25, 2025
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Sep 27, 2025
@armru armru force-pushed the dev/6069 branch 3 times, most recently from b416c6d to 5d37c09 Compare September 27, 2025 09:44
@armru
Copy link
Member Author

armru commented Sep 27, 2025

/test limit=local

@github-actions
Copy link
Contributor

@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/18058199848

Comment on lines +393 to +404
job.Spec.Template.Spec.Containers[0].Env = append(job.Spec.Template.Spec.Containers[0].Env, corev1.EnvVar{
Name: "APP_USERNAME",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: cluster.GetApplicationSecretName()},
Key: "username",
Optional: ptr.To(false),
},
},
})
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially we could use the container envfrom field to mount the whole secret, but I felt like for what we want to achieve this minimalistic approach that exposes only the username to the job is the best

@armru
Copy link
Member Author

armru commented Sep 29, 2025

/test limit=local

@github-actions
Copy link
Contributor

@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/18099907008

@dominik-niebuhr
Copy link

do we have any ETA for a release once this is merged? :) this would help us remove a very ugly workaround

armru added 4 commits October 2, 2025 10:49
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@leonardoce leonardoce changed the title fix: wait for AppSecret before starting initdb fix: wait for app user secret before starting initdb Oct 2, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 2, 2025
@leonardoce leonardoce merged commit 9d4ec08 into main Oct 2, 2025
37 checks passed
@leonardoce leonardoce deleted the dev/6069 branch October 2, 2025 09:01
cnpg-bot pushed a commit that referenced this pull request Oct 2, 2025
This patch ensures that the operator waits for the application user secret
to be available before running `initdb`.

The change is implemented with minimal impact by adding a reference to the
secret in the Pod created by the `initdb` Job. The username is exposed as an
environment variable, which is not currently used, but guarantees that the Job
cannot start until the secret exists.

Closes: #6069

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 9d4ec08)
cnpg-bot pushed a commit that referenced this pull request Oct 2, 2025
This patch ensures that the operator waits for the application user secret
to be available before running `initdb`.

The change is implemented with minimal impact by adding a reference to the
secret in the Pod created by the `initdb` Job. The username is exposed as an
environment variable, which is not currently used, but guarantees that the Job
cannot start until the secret exists.

Closes: #6069

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 9d4ec08)
cnpg-bot pushed a commit that referenced this pull request Oct 2, 2025
This patch ensures that the operator waits for the application user secret
to be available before running `initdb`.

The change is implemented with minimal impact by adding a reference to the
secret in the Pod created by the `initdb` Job. The username is exposed as an
environment variable, which is not currently used, but guarantees that the Job
cannot start until the secret exists.

Closes: #6069

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 9d4ec08)
rossigee pushed a commit to rossigee/cloudnative-pg that referenced this pull request Oct 2, 2025
…tive-pg#8663)

This patch ensures that the operator waits for the application user secret
to be available before running `initdb`.

The change is implemented with minimal impact by adding a reference to the
secret in the Pod created by the `initdb` Job. The username is exposed as an
environment variable, which is not currently used, but guarantees that the Job
cannot start until the secret exists.

Closes: cloudnative-pg#6069

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@dominik-niebuhr
Copy link

@armru Will this fix also work for secrets of managed roles? If not should I open a new issue or do we keep the existing issue open for that?

THE-BRAHMA pushed a commit to THE-BRAHMA/cloudnative-pg that referenced this pull request Oct 30, 2025
…tive-pg#8663)

This patch ensures that the operator waits for the application user secret
to be available before running `initdb`.

The change is implemented with minimal impact by adding a reference to the
secret in the Pod created by the `initdb` Job. The username is exposed as an
environment variable, which is not currently used, but guarantees that the Job
cannot start until the secret exists.

Closes: cloudnative-pg#6069

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: theBrahma <office.utpal.brahma@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases bug 🐛 Something isn't working lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged release-1.25 release-1.26 release-1.27 size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: initdb doesn't wait for secret

5 participants