Skip to content

sample-app: Add serviceName to postgresql manifest #6205

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

Merged

Conversation

guzalv
Copy link
Contributor

@guzalv guzalv commented Jan 25, 2025

To fix this error:

error: error validating "db-service/200-create-postgre.yaml": error validating data: ValidationError(StatefulSet.spec): missing required field "serviceName" in io.k8s.api.apps.v1.StatefulSetSpec; if you choose to ignore these errors, turn validation off with --validate=false

Without this, applying the manifest yields:
    error: error validating "db-service/200-create-postgre.yaml": error validating data: ValidationError(StatefulSet.spec): missing required field "serviceName" in io.k8s.api.apps.v1.StatefulSetSpec; if you choose to ignore these errors, turn validation off with --validate=false

Signed-off-by: Guzman <guzman@guzman.fi>
@knative-prow knative-prow bot requested review from csantanapr and skonto January 25, 2025 17:55
@knative-prow knative-prow bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jan 25, 2025
Copy link

netlify bot commented Jan 25, 2025

Deploy Preview for knative ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e9056f6
🔍 Latest deploy log https://app.netlify.com/sites/knative/deploys/679525ae41d75e0008aa3922
😎 Deploy Preview https://deploy-preview-6205--knative.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@dprotaso
Copy link
Member

/assign @Leo6Leo @Cali0707

@Leo6Leo
Copy link
Member

Leo6Leo commented Jan 28, 2025

/cc @Leo6Leo

@knative-prow knative-prow bot requested a review from Leo6Leo January 28, 2025 05:24
@Leo6Leo
Copy link
Member

Leo6Leo commented Feb 3, 2025

@guzalv Thanks for the PR! I have tried the original yaml file to create the StatefulSet in the cluster, it doesn't seem to have the error you have mentioned above. Could you please provide some of your tech spec (e.g your k8s version, minikube/kind, knative version etc...) so that we can figure out the reason why the error happened too you?

@guzalv
Copy link
Contributor Author

guzalv commented Feb 4, 2025

Hi @Leo6Leo, thanks for your comment. Good that you noticed, this was an interesting issue: serviceName is marked as required in the Kubernetes' StatefulSet reference:

  • serviceName (string), required

I went to reproduce it again, and it failed, as I expected. However I noticed I was using a rather old kubectl version (1.22.5). When I upgraded to 1.30.0, to match my Kubernetes cluster, it didn't fail anymore. So even if the docs still state a serviceName is required, that is actually not enforced by recent kubectl versions:

$ kubectl-1.30.0 apply -f ./code-samples/eventing/bookstore-sample-app/solution/db-service/200-create-postgre.yaml
statefulset.apps/postgresql created

$ ./kubectl-1.22.5 apply -f ./code-samples/eventing/bookstore-sample-app/solution/db-service/200-create-postgre.yaml
error: error validating "./code-samples/eventing/bookstore-sample-app/solution/db-service/200-create-postgre.yaml": error validating data: ValidationError(StatefulSet.spec): missing required field "serviceName" in io.k8s.api.apps.v1.StatefulSetSpec; if you choose to ignore these errors, turn validation off with --validate=false

(Could it be that the StatefulSets' limitation of requiring a headless service is being removed?)

I also checked that this PR works fine with the latest kubectl too, but I'm not familiar enough with the project to know whether it's ok/recommended/discouraged to make a change to support an older version of a tool. What do you think?

@dprotaso
Copy link
Member

I just tested this out and it worked without setting the serviceName - it defaults to an empty string

@guzalv what version of k8s are you using?

 % k version
Client Version: v1.32.1
Kustomize Version: v5.5.0
Server Version: v1.32.0

@dprotaso
Copy link
Member

dprotaso commented Feb 10, 2025

This might be a Kubernetes bug in newer versions. I asked in k8s slack and folks were surprised by this behaviour

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Feb 10, 2025
Copy link

knative-prow bot commented Feb 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, guzalv

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 10, 2025
@knative-prow knative-prow bot merged commit 64fc93b into knative:main Feb 10, 2025
19 checks passed
@guzalv
Copy link
Contributor Author

guzalv commented Feb 11, 2025

I just tested this out and it worked without setting the serviceName - it defaults to an empty string

@guzalv what version of k8s are you using?

 % k version
Client Version: v1.32.1
Kustomize Version: v5.5.0
Server Version: v1.32.0

Hi @dprotaso,

$ kubectl version
Client Version: v1.30.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.30.0

In case the Kubernetes folks want to pick this up: the conclusion from my earlier trials was that the issue lies in kubectl: 1.22.5 complains about the missing serviceName, as expected according to the docs, and 1.30.0 doesn't.

Thanks for checking and merging the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants