Skip to content

fix(k8s): preserve service network fields on redeploy - #4013

Open
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/preserve-service-network-fields
Open

Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/preserve-service-network-fields

Conversation

@Elvand-Lie

@Elvand-Lie Elvand-Lie commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Changes

The raw Kubernetes deployer reconstructs a corev1.Service when redeploying a function. On updates, it previously preserved only the existing Service's ResourceVersion.

Because the generated Service does not contain the network configuration allocated by Kubernetes, redeploying an existing function could submit an empty spec.clusterIP and fail with:

Service "<function-name>" is invalid: spec.clusterIP: Invalid value: "": field is immutable

This change preserves the existing Service's ClusterIP, ClusterIPs, IPFamilies, and IPFamilyPolicy before calling Update, while continuing to generate mutable fields such as ports, selectors, labels, and annotations from the function configuration.

New Service creation is unchanged, so Kubernetes continues to allocate and default its network fields.

The KEDA deployer inherits the fix because it delegates workload deployment to the raw Kubernetes deployer.

Regression tests cover IPv4 single-stack, IPv6 single-stack, dual-stack, preservation of generated mutable fields, and the initial Service creation path.

Testing

  • Tests done and verified locally: unit test suites (make test), linting and repository checks (make check), and test coverage for single-stack IPv4/IPv6 and dual-stack Service network field preservation.
  • Manual redeployment with func deploy --deployer=raw verified against a Kubernetes cluster, confirming existing Service ClusterIP and network configuration are preserved across updates.
  • Fork CI passed the repository's precheck, unit, integration, template, Podman, and runtime E2E suites.

/kind bug

Release Note

Fixed raw and KEDA function redeployments failing when updating an existing Kubernetes Service.

Docs

NONE

@knative-prow knative-prow Bot added the kind/bug Bugs label Aug 18, 2026
@knative-prow knative-prow Bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Aug 18, 2026
@knative-prow

knative-prow Bot commented Aug 18, 2026

Copy link
Copy Markdown

Hi @Elvand-Lie. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Elvand-Lie
Elvand-Lie force-pushed the fix/preserve-service-network-fields branch from aefc46d to 1aec7b1 Compare August 18, 2026 12:53
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Aug 31, 2026
@lkingland

Copy link
Copy Markdown
Member

Thansk for the contribution. Looks good! Just needs a rebase and we can ✅

@Elvand-Lie
Elvand-Lie force-pushed the fix/preserve-service-network-fields branch from 1aec7b1 to ab64888 Compare September 28, 2026 18:26
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Sep 28, 2026
@Elvand-Lie

Copy link
Copy Markdown
Contributor Author

@lkingland Rebased onto the latest main and re-verified. Ready for another look.

@lkingland

Copy link
Copy Markdown
Member

Thanks @Elvand-Lie, and thanks for the rebase.

/ok-to-test
/lgtm
/approve

@knative-prow knative-prow Bot added the ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. label Oct 30, 2026
@knative-prow knative-prow Bot added lgtm 🤖 PR is ready to be merged. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels Oct 30, 2026
@knative-prow

knative-prow Bot commented Oct 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Elvand-Lie, lkingland

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

The pull request process is described here

Details 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 🤖 PR has been approved by an approver from all required OWNERS files. label Oct 30, 2026
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Oct 30, 2026
The raw deployer reconstructs a Service during redeployment and previously
copied only ResourceVersion from the existing Service. This omitted the
Service's allocated ClusterIP configuration, causing Kubernetes to reject
the update with an immutable clusterIP error.

Preserve ClusterIP, ClusterIPs, IPFamilies, and IPFamilyPolicy from the
existing Service while continuing to generate mutable Service fields from
the function configuration.

The KEDA deployer inherits the fix through its embedded raw deployer.
@lkingland
lkingland force-pushed the fix/preserve-service-network-fields branch from ab64888 to 525d79a Compare October 30, 2026 13:24
@knative-prow knative-prow Bot removed the lgtm 🤖 PR is ready to be merged. label Oct 30, 2026
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Oct 30, 2026
@lkingland

Copy link
Copy Markdown
Member

Rebased onto main (conflict was only appended tests in deployer_test.go; both suites kept).

/lgtm

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. kind/bug Bugs lgtm 🤖 PR is ready to be merged. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants