Skip to content

fix: respect namespace in structured local-gateways config#2217

Merged
knative-prow[bot] merged 3 commits intoknative:mainfrom
DCchoudhury15:fix/structured-local-gateway-namespace
Jan 29, 2026
Merged

fix: respect namespace in structured local-gateways config#2217
knative-prow[bot] merged 3 commits intoknative:mainfrom
DCchoudhury15:fix/structured-local-gateway-namespace

Conversation

@DCchoudhury15
Copy link
Copy Markdown
Contributor

Changes

  • Fixed a bug where the Operator ignored the namespace field when using the structured local-gateways configuration format.
  • Updated UpdateNamespace logic in ingress_service.go to unmarshal and prioritize the plural local-gateways YAML array.
  • Added unit tests in ingress_service_test.go to verify structured config parsing and ensure it takes precedence over legacy dot-notation config.

/kind bug

Fixes #2201

Release Note

Fixed an issue where the Knative Operator ignored the namespace field in the structured local-gateways configuration, defaulting incorrectly to istio-system.

@knative-prow knative-prow Bot added the kind/bug Categorizes issue or PR as related to a bug. label Jan 9, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jan 9, 2026

Welcome @DCchoudhury15! It looks like this is your first PR to knative/operator 🎉

@knative-prow knative-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 9, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jan 9, 2026

Hi @DCchoudhury15. Thanks for your PR.

I'm waiting for a github.com 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. Regular contributors should join the org to skip this step.

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.

@knative-prow knative-prow Bot requested review from houshengbo and matzew January 9, 2026 13:37
@DCchoudhury15
Copy link
Copy Markdown
Contributor Author

@houshengbo i have created the pr up for review.

@houshengbo
Copy link
Copy Markdown

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 13, 2026
@DCchoudhury15
Copy link
Copy Markdown
Contributor Author

@houshengbo all tests have passed waiting for approval

Comment thread pkg/reconciler/knativeserving/ingress/ingress_service.go Outdated
@@ -76,11 +85,25 @@ func updateIstioService(ks *v1beta1.KnativeServing, u *unstructured.Unstructured

// UpdateNamespace set correct namespace of istio to the service knative-local-gateway
func UpdateNamespace(u *unstructured.Unstructured, data map[string]string, ns string) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This func can be refactored a bit for better logical separation:

var (
	knativeLocalGateway = "knative-local-gateway"
	localGateways = "local-gateways"
)

func UpdateNamespace(u *unstructured.Unstructured, data map[string]string, namespace string) {
	if ns := resolveGatewayNamespace(data, namespace); ns != "" {
		u.SetNamespace(ns)
	}
}

func resolveGatewayNamespace(data map[string]string, ns string) string {
	if ns := fromStructuredGateways(data); ns != "" {
		return ns
	}

	return fromLegacyGateway(data, ns)
}

func fromStructuredGateways(data map[string]string) string {
	raw, ok := data[localGateways]
	if !ok {
		return ""
	}

	var gateways []localGatewayConfig
	if err := yaml.Unmarshal([]byte(raw), &gateways); err != nil {
		return ""
	}

	for _, gw := range gateways {
		if gw.Name == knativeLocalGateway {
			return gw.Namespace
		}
	}

	return ""
}

func fromLegacyGateway(data map[string]string, ns string) string {
	key := fmt.Sprintf("local-gateway.%s.%s", ns, knativeLocalGateway)

	raw, ok := data[key]
	if !ok {
		return ""
	}

	fields := strings.Split(raw, ".")
	if len(fields) < 2 {
		return ""
	}

	return fields[1]
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@DCchoudhury15 Could you refactor this func?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@houshengbo i have done the changes up for review

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 81.48148% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.45%. Comparing base (70d1cc0) to head (a482109).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...conciler/knativeserving/ingress/ingress_service.go 81.48% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2217      +/-   ##
==========================================
+ Coverage   63.31%   63.45%   +0.14%     
==========================================
  Files          49       49              
  Lines        1878     1899      +21     
==========================================
+ Hits         1189     1205      +16     
- Misses        597      600       +3     
- Partials       92       94       +2     

☔ 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.

@knative-prow knative-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 29, 2026
Copy link
Copy Markdown

@houshengbo houshengbo left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow knative-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jan 29, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jan 29, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DCchoudhury15, houshengbo

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 29, 2026
@DCchoudhury15
Copy link
Copy Markdown
Contributor Author

@houshengbo some ci tests were failing so made some changes up for review.

@houshengbo
Copy link
Copy Markdown

@DCchoudhury15 As long as you rebase the main branch, it should be good, since I updated the deps and manifests.

@DCchoudhury15 DCchoudhury15 force-pushed the fix/structured-local-gateway-namespace branch from 48da06b to a482109 Compare January 29, 2026 17:08
@knative-prow knative-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 29, 2026
@DCchoudhury15
Copy link
Copy Markdown
Contributor Author

@DCchoudhury15 As long as you rebase the main branch, it should be good, since I updated the deps and manifests.

i have rebased the main branch.

@houshengbo
Copy link
Copy Markdown

/lgtm

@knative-prow knative-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jan 29, 2026
@knative-prow knative-prow Bot merged commit 78678ff into knative:main Jan 29, 2026
25 checks passed
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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Operator ignores namespace field in structured local-gateways config (service is always created in istio-system)

2 participants