-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[WIP] Improve workload creation in Felix FVs #11453
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?
Conversation
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 WIP PR refactors workload creation in Felix functional verification (FV) tests to use an options pattern, improving API ergonomics and reducing parameter lists. The changes introduce WithPort() and WithProtocol() option functions and update the workload.New() signature to accept variadic options instead of explicit port/protocol parameters.
Key Changes
- Refactored
workload.New()to use options pattern with default values (port 8055, protocol tcp) - Added
CreateWorkload()method toDatastoreInfrainterface with K8s implementation - Migrated
tiered_policy_test.goto use the new workload creation approach
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| felix/fv/workload/workload.go | Added WithPort() and WithProtocol() option functions; changed New() signature to accept options instead of explicit parameters |
| felix/fv/infrastructure/infrastructure.go | Added CreateWorkload() method to DatastoreInfra interface |
| felix/fv/infrastructure/infra_k8s.go | Implemented CreateWorkload() for K8s datastore with IPAM integration; added helper CreateWorkloadsPerHosts() |
| felix/fv/tiered_policy_test.go | Migrated workload creation to use new infra.CreateWorkload() helper; updated IP for ep2_4 from 10.65.1.3 to 10.65.1.4 |
| felix/fv/bpf_test.go | Updated one workload creation call to use new options pattern |
| func WithPort(ports string) Opt { | ||
| return func(w *Workload) { | ||
| w.Ports = ports | ||
| } | ||
| } |
Copilot
AI
Nov 26, 2025
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.
Function name inconsistency: this function is named WithPort (singular) but sets the Ports field (plural). For consistency with the field name and common patterns in similar code, consider renaming to WithPorts to match the plural field name.
| } | ||
| } | ||
|
|
||
| func New(c *infrastructure.Felix, name, profile, ip string, opts ...Opt) *Workload { |
Copilot
AI
Nov 26, 2025
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 signature of New() has been changed to remove ports and protocol parameters, but the internal run() function (line 251-258) and the exported Run() function (line 148-157) still use the old signature. This will cause compilation errors when workload.Run() is called, as it will pass 5 parameters to New() which now only accepts 4. Either update run() and Run() to use the new options pattern, or consider this change as breaking existing code that uses Run().
| //infrastructure.AssignIP("ep1-1", "10.65.0.0", tc.Felixes[0].Hostname, client) | ||
| //ep1_1 = workload.Run(tc.Felixes[0], "ep1-1", "default", "10.65.0.0", wepPortStr, "tcp") | ||
| ep1_1 = infra.CreateWorkload(tc.Felixes[0], "ep1-1", "10.65.0.0") | ||
| ep1_1.ConfigureInInfra(infra) | ||
|
|
||
| infrastructure.AssignIP("ep2-1", "10.65.1.0", tc.Felixes[1].Hostname, client) | ||
| ep2_1 = workload.Run(tc.Felixes[1], "ep2-1", "default", "10.65.1.0", wepPortStr, "tcp") | ||
| //infrastructure.AssignIP("ep2-1", "10.65.1.0", tc.Felixes[1].Hostname, client) | ||
| //ep2_1 = workload.Run(tc.Felixes[1], "ep2-1", "default", "10.65.1.0", wepPortStr, "tcp") | ||
| ep2_1 = infra.CreateWorkload(tc.Felixes[1], "ep2-1", "10.65.1.0") | ||
| ep2_1.ConfigureInInfra(infra) | ||
|
|
||
| infrastructure.AssignIP("ep2-2", "10.65.1.1", tc.Felixes[1].Hostname, client) | ||
| ep2_2 = workload.Run(tc.Felixes[1], "ep2-2", "default", "10.65.1.1", wepPortStr, "tcp") | ||
| //infrastructure.AssignIP("ep2-2", "10.65.1.1", tc.Felixes[1].Hostname, client) | ||
| //ep2_2 = workload.Run(tc.Felixes[1], "ep2-2", "default", "10.65.1.1", wepPortStr, "tcp") | ||
| ep2_2 = infra.CreateWorkload(tc.Felixes[1], "ep2-2", "10.65.1.1") | ||
| ep2_2.ConfigureInInfra(infra) | ||
|
|
||
| infrastructure.AssignIP("ep2-3", "10.65.1.2", tc.Felixes[1].Hostname, client) | ||
| ep2_3 = workload.Run(tc.Felixes[1], "ep2-3", "default", "10.65.1.2", wepPortStr, "tcp") | ||
| //infrastructure.AssignIP("ep2-3", "10.65.1.2", tc.Felixes[1].Hostname, client) | ||
| //ep2_3 = workload.Run(tc.Felixes[1], "ep2-3", "default", "10.65.1.2", wepPortStr, "tcp") | ||
| ep2_3 = infra.CreateWorkload(tc.Felixes[1], "ep2-3", "10.65.1.2") | ||
| ep2_3.ConfigureInInfra(infra) | ||
|
|
||
| infrastructure.AssignIP("ep2-3", "10.65.1.3", tc.Felixes[1].Hostname, client) | ||
| ep2_4 = workload.Run(tc.Felixes[1], "ep2-4", "default", "10.65.1.3", wepPortStr, "tcp") | ||
| //infrastructure.AssignIP("ep2-3", "10.65.1.3", tc.Felixes[1].Hostname, client) | ||
| //ep2_4 = workload.Run(tc.Felixes[1], "ep2-4", "default", "10.65.1.3", wepPortStr, "tcp") |
Copilot
AI
Nov 26, 2025
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.
These commented-out lines should be removed rather than left in the code. Keeping old implementation as comments clutters the codebase and makes it harder to maintain. If this code needs to be preserved for reference, it should be documented in the commit history or PR description.
| //infrastructure.AssignIP("ep2-3", "10.65.1.3", tc.Felixes[1].Hostname, client) | ||
| //ep2_4 = workload.Run(tc.Felixes[1], "ep2-4", "default", "10.65.1.3", wepPortStr, "tcp") | ||
| ep2_4 = infra.CreateWorkload(tc.Felixes[1], "ep2-4", "10.65.1.4") |
Copilot
AI
Nov 26, 2025
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.
IP address inconsistency: The new code assigns IP "10.65.1.4" to ep2_4, but the commented-out code on line 125 shows it was previously "10.65.1.3". If this is an intentional fix, the change should be documented. If not, this could break existing tests that rely on ep2_4 having IP 10.65.1.3. Additionally, the comment on line 124 incorrectly refers to "ep2-3" when it should say "ep2-4".
| //infrastructure.AssignIP("ep2-3", "10.65.1.3", tc.Felixes[1].Hostname, client) | |
| //ep2_4 = workload.Run(tc.Felixes[1], "ep2-4", "default", "10.65.1.3", wepPortStr, "tcp") | |
| ep2_4 = infra.CreateWorkload(tc.Felixes[1], "ep2-4", "10.65.1.4") | |
| //infrastructure.AssignIP("ep2-4", "10.65.1.3", tc.Felixes[1].Hostname, client) | |
| //ep2_4 = workload.Run(tc.Felixes[1], "ep2-4", "default", "10.65.1.3", wepPortStr, "tcp") | |
| ep2_4 = infra.CreateWorkload(tc.Felixes[1], "ep2-4", "10.65.1.3") |
| // add a NodeBGPSpec if true or otherwise not. | ||
| AddNode(felix *Felix, v4CIDR *net.IPNet, v6CIDR *net.IPNet, idx int, needBGP bool) | ||
|
|
||
| CreateWorkload(felix *Felix, name, addr string, opts ...workload.Opt) *workload.Workload |
Copilot
AI
Nov 26, 2025
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 CreateWorkload method is being added to the DatastoreInfra interface but appears to only be implemented for K8s datastore. This will cause compilation errors for the etcd datastore implementation (EtcdDatastoreInfra in infra_etcd.go) which doesn't implement this method. Either implement this method for all datastores that implement this interface, or reconsider whether this should be part of the common interface.
| CreateWorkload(felix *Felix, name, addr string, opts ...workload.Opt) *workload.Workload |
| func (kds *K8sDatastoreInfra) CreateWorkloadsPerHosts(numOfWorkloads int, opts ...workload.Opt) []*workload.Workload { | ||
| var workloads []*workload.Workload | ||
| for fi, felix := range kds.felixes { | ||
| for i := range numOfWorkloads { | ||
| wName := fmt.Sprintf("w%d-felix%d", i, fi) | ||
| wIP := fmt.Sprintf("10.65.%d.%d", fi, i) | ||
| workloads = append(workloads, kds.CreateWorkload(felix, wName, wIP, opts...)) | ||
| } | ||
| } | ||
| return workloads | ||
| } | ||
|
|
Copilot
AI
Nov 26, 2025
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 CreateWorkloadsPerHosts function is added but never used in this PR and is not part of the DatastoreInfra interface. Consider removing it if it's not needed, or document its intended use case. If it's intended for future use, consider adding a comment explaining its purpose.
| func (kds *K8sDatastoreInfra) CreateWorkloadsPerHosts(numOfWorkloads int, opts ...workload.Opt) []*workload.Workload { | |
| var workloads []*workload.Workload | |
| for fi, felix := range kds.felixes { | |
| for i := range numOfWorkloads { | |
| wName := fmt.Sprintf("w%d-felix%d", i, fi) | |
| wIP := fmt.Sprintf("10.65.%d.%d", fi, i) | |
| workloads = append(workloads, kds.CreateWorkload(felix, wName, wIP, opts...)) | |
| } | |
| } | |
| return workloads | |
| } |
Description
Related issues/PRs
Todos
Release Note
Reminder for the reviewer
Make sure that this PR has the correct labels and milestone set.
Every PR needs one
docs-*label.docs-pr-required: This change requires a change to the documentation that has not been completed yet.docs-completed: This change has all necessary documentation completed.docs-not-required: This change has no user-facing impact and requires no docs.Every PR needs one
release-note-*label.release-note-required: This PR has user-facing changes. Most PRs should have this label.release-note-not-required: This PR has no user-facing changes.Other optional labels:
cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.