Skip to content

feat(gateway): Auto-create ServiceNetwork on Gateway creation#904

Open
abdallahmahran10 wants to merge 1 commit intoaws:mainfrom
abdallahmahran10:feat/auto-create-service-network
Open

feat(gateway): Auto-create ServiceNetwork on Gateway creation#904
abdallahmahran10 wants to merge 1 commit intoaws:mainfrom
abdallahmahran10:feat/auto-create-service-network

Conversation

@abdallahmahran10
Copy link
Copy Markdown
Contributor

@abdallahmahran10 abdallahmahran10 commented Mar 6, 2026

Summary

Auto-create a VPC Lattice ServiceNetwork when a Gateway is reconciled, eliminating the need for users to pre-create ServiceNetworks or rely on DEFAULT_SERVICE_NETWORK.

Changes

Auto-create ServiceNetwork (gateway_controller.go)

  • reconcileUpsert calls snManager.CreateOrUpdate() using the Gateway .metadata.name as the SN name
  • CreateOrUpdate is idempotent — finds and reuses an existing SN if one already exists
  • Ownership tracked via ManagedBy tag; externally-created SNs are never deleted by the controller

Sibling Gateway deletion safety (gateway_controller.go)

  • reconcileDelete checks for sibling Gateways (same .Name, different namespace) before deleting the SN
  • If another active Lattice-controlled Gateway shares the SN name, deletion is skipped
  • Gateways with DeletionTimestamp set are excluded from the sibling check, so simultaneous deletion of all siblings still cleans up the SN

Service association delete guard (service_network_manager.go)

  • Delete() checks for active service associations before attempting SN deletion
  • Returns a clear error: "cannot delete ServiceNetwork X: N service association(s) still active, detach all services before deleting the Gateway"

Documentation (docs/api-types/gateway.md)

  • Documents auto-creation behavior and default settings (no auth, no sharing config)
  • Documents external SN reuse for advanced configuration
  • Documents deletion behavior and safety guards

Fixes #888

Testing

Unit tests

  • TestHasSiblingGateway: 4 cases — no sibling, has sibling (same name different ns), sibling being deleted (not counted), different name (not a sibling)
  • Test_Delete_SnOwned_ActiveServiceAssociations: verifies Delete returns error when SN has active service associations
  • All existing tests pass (go test ./...)

E2E integration tests (gateway_service_network_test.go)

  • Sibling Gateway deletion safety: creates two Gateways with the same name in different namespaces, verifies deleting one does not remove the SN, verifies deleting the last one does
  • Service association delete guard: creates a Gateway, manually associates a dummy Lattice service to its SN, verifies Gateway deletion is blocked (finalizer not removed), verifies Gateway deletes after removing the association
  • All 4 specs pass against a live EKS cluster with VPC Lattice

@abdallahmahran10 abdallahmahran10 force-pushed the feat/auto-create-service-network branch from e6f2a31 to dd6327a Compare March 9, 2026 16:52
@abdallahmahran10 abdallahmahran10 added this pull request to the merge queue Mar 15, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 15, 2026
@SinghVikram97 SinghVikram97 added this pull request to the merge queue Mar 17, 2026
github-merge-queue bot pushed a commit that referenced this pull request Mar 17, 2026
- Gateway reconciler auto-creates a VPC Lattice ServiceNetwork using the
  Gateway's .metadata.name when no external SN exists
- CreateOrUpdate is idempotent: reuses existing SN if found
- Sibling Gateway safety: when deleting a Gateway, skip SN deletion if
  another active Gateway with the same name exists in a different namespace
- Service association guard: block SN deletion if it still has active
  service associations, returning a clear error message
- Ownership tracked via ManagedBy tag; externally-created SNs are never deleted
- Documentation updated with auto-creation behavior, default settings,
  and external SN reuse for advanced configuration
- Unit tests for hasSiblingGateway (4 cases) and Delete with active
  service associations
- E2E integration tests for sibling deletion safety and service
  association delete guard
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 17, 2026
@SinghVikram97 SinghVikram97 self-requested a review March 18, 2026 23:37
Copy link
Copy Markdown
Contributor

@SinghVikram97 SinghVikram97 left a comment

Choose a reason for hiding this comment

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

One of the e2e test in failing

Test vpc association policy Update a VpcAssociationPolicy with associateWithVpc to false, expecting deleted ServiceNetworkVpcAssociation [Serial]

There is a CRD: https://www.gateway-api-controller.eks.aws.dev/latest/api-types/vpc-association-policy/ if you set associateWithVpc flag as false it should delete SNVA, but after this change it creates one if it doesn't exist.

Need further consideration on how to handle this case before we merge this.

- Gateway reconciler auto-creates a VPC Lattice ServiceNetwork using the
  Gateway's .metadata.name when no external SN exists
- CreateOrUpdate is idempotent: reuses existing SN if found
- Sibling Gateway safety: when deleting a Gateway, skip SN deletion if
  another active Gateway with the same name exists in a different namespace
- Service association guard: block SN deletion if it still has active
  service associations, returning a clear error message
- Ownership tracked via ManagedBy tag; externally-created SNs are never deleted
- Documentation updated with auto-creation behavior, default settings,
  and external SN reuse for advanced configuration
- Unit tests for hasSiblingGateway (4 cases) and Delete with active
  service associations
- E2E integration tests for sibling deletion safety and service
  association delete guard
@abdallahmahran10 abdallahmahran10 force-pushed the feat/auto-create-service-network branch from dd6327a to 4691eed Compare March 27, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow creation of ServiceNetworks in code

3 participants