Skip to content

Conversation

@linkvt
Copy link
Contributor

@linkvt linkvt commented Dec 5, 2025

Fixes #13053

Proposed Changes

  • Add validation in RevisionTemplateSpec.Validate() to reject unknown networking.knative.dev/* annotations early at Service creation time
  • Reuse existing networking.ValidateAnnotations() from the networking package for consistency with SKS validation
  • Add test cases for invalid and valid networking annotations on RevisionTemplate

Background

When users mistakenly place networking.knative.dev/visibility: cluster-local as an annotation on spec.template.metadata.annotations (instead of as a label on the Service's metadata.labels), the annotation propagates through Revision → PodAutoscaler → ServerlessService, where SKS validation rejects it. This caused services to silently get stuck in "Unknown" state with no clear error message.

With this fix, users now get an immediate validation error:

validation failed: invalid key name "networking.knative.dev/visibility": spec.template.metadata.annotations
Example of broken resource (click to expand)
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: my-service
spec:
  template:
    metadata:
      annotations:
        # WRONG: This causes the service to get stuck!
        # visibility should be a LABEL on the Service metadata, not here
        networking.knative.dev/visibility: cluster-local
    spec:
      containers:
        - image: gcr.io/knative-samples/helloworld-go

Correct usage:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: my-service
  labels:
    networking.knative.dev/visibility: cluster-local  # Correct!
spec:
  template:
    spec:
      containers:
        - image: gcr.io/knative-samples/helloworld-go

Release Note

Services with invalid networking.knative.dev/* annotations on the revision template now fail immediately with a clear error instead of getting stuck.

@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 5, 2025
@knative-prow knative-prow bot requested review from dsimansk and skonto December 5, 2025 15:46
@knative-prow
Copy link

knative-prow bot commented Dec 5, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: linkvt
Once this PR has been reviewed and has the lgtm label, please assign dprotaso for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.10%. Comparing base (5fbd94e) to head (8bf896f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16296   +/-   ##
=======================================
  Coverage   80.10%   80.10%           
=======================================
  Files         215      215           
  Lines       13332    13333    +1     
=======================================
+ Hits        10679    10680    +1     
  Misses       2294     2294           
  Partials      359      359           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add validation to reject unknown networking.knative.dev/* annotations
on the RevisionTemplate early at Service creation time, rather than
failing silently when creating the ServerlessService.
@linkvt linkvt force-pushed the reject-networking-annotations-on-revision-template branch from 627eb81 to 8bf896f Compare December 5, 2025 16:01
@linkvt
Copy link
Contributor Author

linkvt commented Dec 5, 2025

/retest

@skonto
Copy link
Contributor

skonto commented Dec 6, 2025

Hi @linkvt! Some thoughts:

@linkvt
Copy link
Contributor Author

linkvt commented Dec 8, 2025

Hi @skonto , thanks for the review!

  1. I would say we could keep the validation there as
    • we ensure the SKS is always created with valid annotations and avoid bad annotations e.g. even when it is created by other resources - even if unlikely
    • it doesn't do any damage keeping it
    • the LSP of my IDE didn't show me references in the vendor/ directory so I actually didn't see it when looking for references until now 😅
  2. We're actually validating this within the Service validation call, here is the call chain:
    1. Service Validation:
      func (s *Service) Validate(ctx context.Context) (errs *apis.FieldError) {
    2. Call of Service Spec validation:
      errs = errs.Also(s.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec"))
    3. Call of Configuration Spec validation:
      return ss.ConfigurationSpec.Validate(ctx).Also(
    4. Call of Revision Template validation:
      return cs.Template.Validate(ctx).ViaField("template")
    5. Revision Template validation:
      func (rts *RevisionTemplateSpec) Validate(ctx context.Context) *apis.FieldError {
  3. I'm not aware of other annotations but I'm kinda new to the project. Considering that the issue is 3 years old with no recent updates and no upvotes I think it's OK to fix only the problem described here and focus on other bugs afterwards 🙂

Let me know what you think, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Knative Service failing to become ready if label is confused with annotation

2 participants