-
Notifications
You must be signed in to change notification settings - Fork 353
Chore/11294 build resources using builder functions #15376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Chore/11294 build resources using builder functions #15376
Conversation
…lders Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
…ice e2e tests Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
…ilder Signed-off-by: NawafSwe <[email protected]>
…al.go Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
Signed-off-by: NawafSwe <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR replaces hardcoded YAML strings with builder pattern functions in e2e tests to improve maintainability, type safety, and readability. The changes systematically convert static YAML resource definitions to the fluent builder API that is already used in unit tests.
Changes:
- Migrated static YAML definitions to builder pattern for
Mesh,MeshMultiZoneService,MeshService, andHostnameGeneratorresources - Added new builder methods to
MeshBuilderfor networking and routing configuration - Replaced
YamlUniversal()withResourceUniversal()where appropriate - Removed redundant helper functions that are now superseded by builders
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
test/e2e_env/multizone/zoneegress/internal_services.go |
Converted Mesh YAML to builder pattern with mTLS and zone egress settings |
test/e2e_env/multizone/meshtrafficpermission/meshtrafficpermission.go |
Replaced inline Mesh YAML helper with builder pattern |
test/e2e_env/multizone/meshtimeout/meshtimeout.go |
Converted MeshMultiZoneService YAML to builder pattern |
test/e2e_env/multizone/meshservice/sync.go |
Migrated MeshMultiZoneService and MeshService YAML definitions to builders |
test/e2e_env/multizone/meshservice/connectivity.go |
Converted HostnameGenerator YAML to builder pattern with helper function |
test/e2e_env/multizone/meshmultizoneservice/connectivity.go |
Replaced MeshMultiZoneService YAML with builder pattern |
test/e2e_env/multizone/meshhttproute/meshservice.go |
Converted MeshMultiZoneService YAML to builder pattern |
test/e2e_env/multizone/localityawarelb/meshmultizoneservice.go |
Migrated MeshMultiZoneService YAML to inline builder pattern |
test/e2e_env/multizone/localityawarelb/meshloadbalancingstrategy.go |
Updated function call to use builder return type instead of YAML |
test/e2e_env/multizone/localityawarelb/locality_multizone_hybrid.go |
Converted Mesh helper function from YAML template to builder pattern |
test/e2e_env/multizone/gateway/cross-mesh.go |
Removed redundant MTLSMeshUniversalEgress helper function |
test/e2e_env/multizone/externalservices/externalservices_multizone_universal.go |
Converted Mesh YAML template to builder pattern with method chaining |
test/e2e/zoneegress/externalservices/zoneegress_externalservices_hybrid.go |
Converted Mesh YAML template to builder function with parameters |
pkg/test/resources/builders/mesh_builder.go |
Added new builder methods for networking passthrough, zone egress, locality-aware load balancing, and mesh external service access |
| `'{{ .DisplayName }}.{{ .Namespace }}.svc.{{ .Zone }}.not-my-mesh-specific.mesh.local'`, | ||
| map[string]string{ | ||
| "kuma.io/env": "kubernetes", | ||
| "kuma.io/mesh": meshName, |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mesh label should be "non-existent-mesh" to match the original YAML behavior for kube-not-my-mesh-specific-msconnectivity, not meshName.
| "kuma.io/mesh": meshName, | |
| "kuma.io/mesh": "non-existent-mesh", |
| ` | ||
|
|
||
| meshMTLOnFn := func(name string, enableNetworkOutBound, enableZoneIngress bool) *core_mesh.MeshResource { | ||
| return builders.Mesh().WithName(nonDefaultMesh).WithBuiltinMTLSBackend("ca-1"). |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function parameter name is unused; the builder always uses nonDefaultMesh instead. Either remove the parameter or use it in WithName(name).
| return builders.Mesh().WithName(nonDefaultMesh).WithBuiltinMTLSBackend("ca-1"). | |
| return builders.Mesh().WithName(name).WithBuiltinMTLSBackend("ca-1"). |
|
|
||
| meshMTLOnFn := func(name string, enableNetworkOutBound, enableZoneIngress bool) *core_mesh.MeshResource { | ||
| return builders.Mesh().WithName(nonDefaultMesh).WithBuiltinMTLSBackend("ca-1"). | ||
| WithEgressRoutingEnabled(). |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method WithEgressRoutingEnabled() does not exist in the MeshBuilder API. This will cause a compilation error. Remove this line or verify the correct method name.
| WithEgressRoutingEnabled(). |
| NewClusterSetup(). | ||
| Install(NamespaceWithSidecarInjection(namespace)). | ||
| Install(YamlK8s(veryLongNamedService)). | ||
| Install(ResourceUniversal(veryLongNamedService)). |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function should use YamlK8s() instead of ResourceUniversal() for Kubernetes resources. The original code used YamlK8s(veryLongNamedService) which is appropriate for KubeZone2.
| Install(ResourceUniversal(veryLongNamedService)). | |
| Install(YamlK8s(veryLongNamedService)). |
| m.res.Spec.Networking = &mesh_proto.Networking{ | ||
| Outbound: &mesh_proto.Networking_Outbound{ | ||
| Passthrough: &wrapperspb.BoolValue{Value: b}, | ||
| }, | ||
| } | ||
| } |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method only sets the passthrough value when Networking is nil. If Networking already exists, the method silently does nothing, leading to incorrect behavior. The method should always update the passthrough value.
| m.res.Spec.Networking = &mesh_proto.Networking{ | |
| Outbound: &mesh_proto.Networking_Outbound{ | |
| Passthrough: &wrapperspb.BoolValue{Value: b}, | |
| }, | |
| } | |
| } | |
| m.res.Spec.Networking = &mesh_proto.Networking{} | |
| } | |
| if m.res.Spec.Networking.Outbound == nil { | |
| m.res.Spec.Networking.Outbound = &mesh_proto.Networking_Outbound{} | |
| } | |
| m.res.Spec.Networking.Outbound.Passthrough = &wrapperspb.BoolValue{Value: b} |
Reviewer Checklist🔍 Each of these sections need to be checked by the reviewer of the PR 🔍:
|
|
@slonka appreicate your review, |
|
Hey @bartsmykla , @lukidzi appreicate your review 🙏 |
Motivation
Currently, many e2e tests use hardcoded YAML strings and
fmt.Sprintf-based helper functions to create test resources. This approach has several drawbacks:Function name bloat: As noted in #11279, this leads to unwieldy function names like
MTLSMeshWithMeshServicesAndMetricsKuberneteswhen we need to support various field combinations.Maintainability: Static YAML strings scattered throughout test files are harder to maintain and refactor when resource schemas change.
Type safety: String-based YAML generation lacks compile-time validation and IDE support.
This PR addresses these issues by replacing static YAML strings with the existing builder pattern that's already used in unit tests, following the approach suggested in the issue comments.
Changes
This PR replaces hardcoded YAML strings with builder functions in e2e tests:
test/e2e_env/multizone/localityawarelb/meshmultizoneservice.go: Replaced staticMeshMultiZoneServiceYAML withbuilders.MeshMultiZoneService()builder pattern using method chaining.test/e2e_env/multizone/externalservices/externalservices_multizone_universal.go: Fixed incorrect usage ofResourceUniversal()to properly use the builder pattern.Benefits
Future work
This PR focuses on
MeshMultiZoneServiceas a starting point. Additional resources (such asMeshLoadBalancingStrategy) still use static YAML and can be migrated in follow-up PRs as builders become available.Related issues
Addresses #11294 and the concerns raised in #11279.