Skip to content

Feat/flexible topology config#273

Open
Transcendental-Programmer wants to merge 34 commits intokubeslice:masterfrom
Transcendental-Programmer:feat/flexible-topology-config
Open

Feat/flexible topology config#273
Transcendental-Programmer wants to merge 34 commits intokubeslice:masterfrom
Transcendental-Programmer:feat/flexible-topology-config

Conversation

@Transcendental-Programmer

Description

This PR implements flexible topology configuration for SliceConfig, enabling hub-spoke, custom connectivity patterns, and restricted topologies to replace the hardcoded full-mesh model.

What changed:

  1. API types (apis/controller/v1alpha1/sliceconfig_types.go):

    • Added TopologyConfig with 3 topology types: full-mesh (default), custom, restricted
    • Added ConnectivityMatrix for explicit source→target definitions (custom mode)
    • Added ForbiddenEdges to exclude specific cluster pairs (restricted mode)
    • All fields optional with backward-compatible defaults
  2. Service layer (service/topology_service.go):

    • New TopologyService with dependency injection pattern
    • resolveTopologyPairs() - main entry point returning gateway pairs
    • resolveFullMeshTopology() - creates n*(n-1)/2 bidirectional pairs
    • resolveCustomTopology() - processes connectivity matrix entries
    • resolveRestrictedTopology() - full-mesh minus forbidden edges
    • filterForbiddenPairs() - bidirectional filtering (blocks both A→B and B→A)
    • 100% unit test coverage (67 tests)
  3. Validation (service/slice_config_webhook_validation.go):

    • Inline validation helpers for topology config fields
    • validateTopologyConfig() - orchestrates all topology validation
    • validateCustomTopology() - ensures all clusters in matrix exist in spec.clusters
    • validateRestrictedTopology() - validates forbidden edge clusters
    • validateForbiddenEdges() - checks source/target cluster validity
    • Returns proper field.ErrorList for API server integration
  4. Gateway integration (service/worker_slice_gateway_service.go):

    • Refactored CreateMinimumWorkerSliceGateways() to use topology service
    • Changed from nested loop (O(n²)) to topology-aware pair processing
    • Gateway creation now respects topology configuration
    • Maintains bidirectional VPN tunnel semantics (2 gateway objects per pair)
  5. Integration tests (controllers/controller/sliceconfig_controller_test.go):

    • 7 topology test cases with envtest
    • Full-mesh: verifies 1 pair → 2 gateways (2 clusters), 3 pairs → 6 gateways (3 clusters)
    • Custom: verifies matrix respected (1 pair specified → 2 gateways)
    • Restricted: verifies forbidden edges excluded (3 clusters, forbid 1→3 → 4 gateways remain)
    • Dynamic updates: verifies topology changes trigger gateway reconciliation
    • Default behavior: nil topology config → full-mesh
  6. CRD updates (config/crd/bases/controller.kubeslice.io_sliceconfigs.yaml):

    • Extended OpenAPI schema with topology fields
    • Enum validation for topologyType
    • All topology fields marked optional

Architecture highlights:

  • Bidirectional filtering: Forbidding A→B also blocks B→A due to symmetric gateway naming ({A,B} set creates both slice-A-B and slice-B-A)
  • Gateway pairs: Each directional pair creates 2 gateway objects (server + client) for bidirectional VPN tunnel
  • Stateless topology service: Pure transformation (SliceConfig → []GatewayPair), no side effects
  • Dependency injection: TopologyService wired in main.go and passed to gateway service

Backward compatibility:

SliceConfigs without topologyConfig default to full-mesh (maintains existing behavior). No breaking changes.

Fixes: #253

How Has This Been Tested?

Unit tests:

make test  # All 67 topology tests passing
go test ./service -run "Topology" -coverprofile=coverage.out
go tool cover -html=coverage.out  # 100% coverage for 11 topology functions

Integration tests:

make test  # envtest-based controller tests
# 7 topology integration tests verify gateway creation for all topology types

Manual verification in kind cluster:

  • CRD applied with new topology fields
  • Full-mesh topology: 3 clusters → 6 gateways created
  • Custom topology: 1→2 specified → 2 gateways created
  • Restricted topology: 3 clusters, forbid 1→3 → 4 gateways created
  • Backward compatibility: SliceConfig without topology → full-mesh (2 gateways for 2 clusters)

Checklist:

  • The title states what changed and related issue number
  • Documentation: Inline code comments + kubebuilder markers
  • Self-review performed
  • Code commented (validation logic, gateway pair semantics)
  • Unit tests: 67 tests, 100% coverage
  • Integration tests: 7 envtest-based scenarios

Does this PR introduce a breaking change?

No. All topology fields are optional. Existing SliceConfigs continue to work with full-mesh default.

Add flexible topology configuration support to SliceConfig with full-mesh, custom, and restricted modes

Added topology configuration API to SliceConfig CRD to enable hub-spoke, partial-mesh, and custom connectivity patterns, moving away from hardcoded full-mesh topology.

Changes include:
- Extended SliceConfig API with TopologyConfig struct supporting multiple topology types (auto, full-mesh, hub-spoke, partial-mesh, custom)
- Added hub-spoke configuration with allowSpokeToSpoke flag
- Added custom connectivity matrix for explicit cluster-to-cluster routing
- Added cluster VPN role assignment (auto, server, client)
- Added policy nodes for security-aware routing in auto topology mode
- Updated CRD OpenAPI schema with validation rules and defaults
- Added three sample SliceConfig manifests demonstrating topology patterns

API changes are backward compatible - existing SliceConfigs without topologyConfig will default to 'auto' mode.

Signed-off-by: Priyansh Saxena <priyena.programming@gmail.com>
Signed-off-by: “Transcendental-Programmer” <“priyena.programming@gmail.com”>
Signed-off-by: Priyansh Saxena <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
- Add TopologyConfig with 5 topology types (full-mesh, hub-spoke, auto, custom, isolated)
- Implement AutoTopologyOptions with int-based relativeThresholdPercent (1-500 = 0.1%-50.0%)
- Add HubSpokeConfig with SpokeConnectivity for selective spoke-to-spoke connections
- Create TopologyValidator service for comprehensive validation
- Integrate validation into SliceConfig admission webhook
- Generate CRD with topology fields and validation constraints
- Maintain backward compatibility (nil topologyConfig defaults to full-mesh)
Tested:
- ✅ Legacy SliceConfig without topology (backward compatible)
- ✅ Hub-spoke topology with spoke connectivity
- ✅ Auto topology with integer threshold
- ✅ CRD validation rejects out-of-range values (1000 > 500)
Week 1-2 deliverable: API specification and validation logic

Signed-off-by: Priyansh Saxena <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
…tom, and full-mesh support

Signed-off-by: Priyansh Saxena <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
…tility

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
…ustom)

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Replace deprecated PolicyNodes/ClusterRoles API with ForbiddenEdges for
explicit edge blacklisting in topology configuration.

Changes:
- Remove ClusterRole struct (ClusterName, VPNRole fields)
- Add ForbiddenEdge struct (SourceCluster, TargetClusters fields)
- Replace TopologyConfig.ClusterRoles with ForbiddenEdges
- Replace TopologyConfig.PolicyNodes with ForbiddenEdges
- Update CRD OpenAPI schema to reflect new field structure
- Regenerate deepcopy code for ForbiddenEdge type

Rationale:
ForbiddenEdges provides simpler, more predictable topology control
compared to PolicyNodes' implicit isolation behavior.

Part-of: Week 1 API changes
Related-to: #topology-refactor
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Add sample topology configurations for auto-secure, full-mesh,
and custom-matrix topology types.

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Update slice configuration validation and service logic related to
topology implementation.

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Add and update tests for slice configuration webhook validation
related to topology implementation.

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Update worker slice gateway service logic related to
topology implementation.

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Add and update tests for worker slice gateway service
related to topology implementation.

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
This change updates the default topology type from 'auto' to 'full-mesh' in both the Go types and CRD specification. It also removes some unnecessary comments in the slice config service.

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
- Remove AutoOptions struct containing telemetry fields
- Remove telemetry-specific configuration options
- Keep topology type enum with 'auto', 'full-mesh', and 'custom' values
- Update TopologyConfig to only include connectivity-based options

This removes all telemetry-based autotopology functionality while maintaining the same API interface

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
- Remove AutoOptions struct containing telemetry fields
- Remove telemetry-specific configuration options
- Keep topology type enum with 'auto', 'full-mesh', and 'custom' values
- Update TopologyConfig to only include connectivity-based options

This removes all telemetry-based autotopology functionality while maintaining the same API interface

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
- Move GatewayPair struct from slice_config_service.go to util/common.go
- Update all service files to use util.GatewayPair
- Regenerate mocks with updated interface signature
- Fix test compilation by using util.GatewayPair in tests
- This resolves circular dependency issue in mocks package

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
…ling tests

- Rename TestResolveTopologyPairs_AutoTopology to TestResolveTopologyPairs_RestrictedTopology
- Rename TestResolveTopologyPairs_AutoTopologyNoForbidden to TestResolveTopologyPairs_RestrictedTopologyNoForbidden
- Rename TestResolveAutoTopology to TestResolveRestrictedTopology
- Remove PartitionedTopology and FourClustersWithBridge subtests that relied on removed partition healing logic

These renames align test names with the TopologyRestricted type and remove tests that
validated the partition healing feature which was intentionally removed to simplify the topology resolution logic.

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
…ster detection

Changes:
- Remove Bidirectional field from util.GatewayPair struct
- Update resolveFullMeshTopology to create all directional pairs (n*(n-1) pairs for n clusters)
- Update resolveCustomTopology to remove Bidirectional initialization
- Update buildForbiddenSet and filterForbiddenPairs to use directional keys
- Implement validateRestrictedTopology with O(n²) BFS connectivity check
- Detect isolated clusters and reject topologies with unreachable clusters
- Add buildForbiddenSetStatic helper for webhook validation (O(n) complexity)
- Add tests for isolated cluster validation scenarios
- Update all service tests to expect directional pairs instead of bidirectional

Gateway pairs now explicitly represent directional connections. For full-mesh with
3 clusters, creates 6 pairs (c1->c2, c1->c3, c2->c1, c2->c3, c3->c1, c3->c2)
instead of 3 bidirectional pairs.

Webhook validation ensures forbidden edges do not partition the cluster graph by
performing reachability analysis using BFS algorithm on the complement graph.

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

This commit includes:

- Added comprehensive integration tests for topology features

- Fixed bidirectional filtering in restricted topology

- Updated unit tests for topology validation and service logic

- Removed obsolete auto topology tests

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
…solete auto tests

Changes:
- Restore 7 topology integration test cases in sliceconfig_controller_test.go
  * Full-mesh topology tests
  * Custom topology tests
  * Restricted topology tests
  * Multiple topology types validation
- Add NetworkPresent and ClusterHealth status fields to clusters in integration tests
- Remove obsolete TestValidateTopologyConfig_AutoWithOptions and TestValidateTopologyConfig_AutoInvalidThreshold
- These Auto tests were redundant with Restricted topology tests since topology type was renamed

Integration tests verify:
- Full-mesh topology creates correct gateway pairs
- Custom connectivity matrix is respected
- Restricted topology with forbidden edges works correctly
- Topology changes during slice lifecycle

Signed-off-by: $(git config user.name) <$(git config user.email)>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
- Add TopologyConfig field to WorkerSliceConfigSpec to propagate topology info to workers
- Regenerate deepcopy methods and CRDs
- This enables the hub to send topology type to worker clusters

Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
Signed-off-by: Transcendental-Programmer <priyena.programming@gmail.com>
Signed-off-by: Priyansh Saxena <130545865+Transcendental-Programmer@users.noreply.github.com>
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.

Feature: Implement Custom Topology Definition for a Slice

1 participant