Skip to content

Conversation

harikrishna-patnala
Copy link
Contributor

Description of changes:
This PR related to #448, here we are adding multiple validations, csMachine status updates for the network and IPs, and a template for explaining configuration for multiple nics.

Testing performed:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 7, 2025
Copy link

netlify bot commented Jul 7, 2025

Deploy Preview for kubernetes-sigs-cluster-api-cloudstack ready!

Name Link
🔨 Latest commit 054530e
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-cluster-api-cloudstack/deploys/686cf531a5e7e100089e3622
😎 Deploy Preview https://deploy-preview-453--kubernetes-sigs-cluster-api-cloudstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 7, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @harikrishna-patnala. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 7, 2025
@vishesh92 vishesh92 requested a review from Copilot July 8, 2025 04:38
@vishesh92
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot 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 Jul 8, 2025
Copilot

This comment was marked as outdated.

Comment on lines 315 to 393
func (c *client) isIpAvailableInNetwork(ip, networkID string) (bool, error) {
params := c.cs.Address.NewListPublicIpAddressesParams()
params.SetNetworkid(networkID)
params.SetIpaddress(ip)
params.SetAllocatedonly(false)
params.SetForvirtualnetwork(false)
params.SetListall(true)

resp, err := c.cs.Address.ListPublicIpAddresses(params)
if err != nil {
return false, errors.Wrapf(err, "failed to list public IP addresses for network %q", networkID)
}

for _, addr := range resp.PublicIpAddresses {
if addr.State == "Free" {
return true, nil
}
}

return false, nil
}

func (c *client) hasFreeIPInNetwork(resolvedNet *cloudstack.Network) (bool, error) {
params := c.cs.Address.NewListPublicIpAddressesParams()
params.SetNetworkid(resolvedNet.Id)
params.SetAllocatedonly(false)
params.SetForvirtualnetwork(false)
params.SetListall(true)

resp, err := c.cs.Address.ListPublicIpAddresses(params)
if err != nil {
return false, errors.Wrapf(err, "failed to check free IPs for network %q", resolvedNet.Id)
}

for _, addr := range resp.PublicIpAddresses {
if addr.State == "Free" {
return true, nil
}
}

return false, nil
}

func (c *client) buildStaticIPEntry(ip, networkID string, resolvedNet *cloudstack.Network) (map[string]string, error) {
if err := c.validateIPInCIDR(ip, resolvedNet, networkID); err != nil {
return nil, err
}

if resolvedNet.Type == "Shared" {
isAvailable, err := c.isIpAvailableInNetwork(ip, networkID)
if err != nil {
return nil, err
}
if !isAvailable {
return nil, errors.Errorf("IP %q is already allocated in network %q or out of range", ip, networkID)
}
}

return map[string]string{
"networkid": networkID,
"ip": ip,
}, nil
}

func (c *client) buildDynamicIPEntry(resolvedNet *cloudstack.Network) (map[string]string, error) {
if resolvedNet.Type == "Shared" {
freeIPExists, err := c.hasFreeIPInNetwork(resolvedNet)
if err != nil {
return nil, err
}
if !freeIPExists {
return nil, errors.Errorf("no free IPs available in network %q", resolvedNet.Id)
}
}

return map[string]string{
"networkid": resolvedNet.Id,
}, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we can merge these 4 methods.

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we have covered each and every type of network possible with cloudstack here. So, this might require more checks as well.

@vishesh92 vishesh92 requested a review from Copilot July 8, 2025 05:38
Copilot

This comment was marked as outdated.

@vishesh92 vishesh92 requested a review from Copilot July 8, 2025 07:20
Copilot

This comment was marked as outdated.

@codecov-commenter
Copy link

codecov-commenter commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 3.80952% with 101 lines in your changes missing coverage. Please review.

Project coverage is 25.21%. Comparing base (d597e80) to head (054530e).
Report is 110 commits behind head on main.

Files with missing lines Patch % Lines
pkg/cloud/instance.go 3.80% 98 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #453      +/-   ##
==========================================
- Coverage   25.66%   25.21%   -0.46%     
==========================================
  Files          59       72      +13     
  Lines        5563     6941    +1378     
==========================================
+ Hits         1428     1750     +322     
- Misses       3996     5022    +1026     
- Partials      139      169      +30     

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

@blueorangutan
Copy link

Setting up environment failed

1 similar comment
@blueorangutan
Copy link

Setting up environment failed

@vishesh92 vishesh92 requested a review from Copilot July 8, 2025 10:17
Copy link

@Copilot Copilot AI left a 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 enhances multi-network support by adding validation logic, status updates, and configuration templates for assigning multiple NICs and IPs in CloudStack.

  • Iterate over all NICs to populate csMachine.Status.Addresses
  • Introduce helper methods for network resolution, IP-in-CIDR validation, and free-IP checks
  • Update deployment logic and documentation to support multiple networks

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/cloud/instance.go Populate multiple NIC addresses; add network/IP helper methods and integrate into VM deploy
docs/book/src/clustercloudstack/configuration.md Add “Option for Multiple Networks” section with template example
Comments suppressed due to low confidence (1)

pkg/cloud/instance.go:339

  • New functions like buildIPEntry, validateIPInCIDR, isFreeIPAvailable, and configureNetworkParams introduce nontrivial logic but lack unit tests. Adding tests for valid/invalid IPs, network mismatches, and no-free-IP scenarios will improve reliability.
func (c *client) buildIPEntry(resolvedNet *cloudstack.Network, ip string) (map[string]string, error) {

@blueorangutan
Copy link

Setting up environment failed

1 similar comment
@blueorangutan
Copy link

Setting up environment failed

@blueorangutan
Copy link

Test Results : (tid-883)
Environment: kvm Rocky8(x3), Advanced Networking with Management Server Rocky8
Kubernetes Version: v1.32.3
Kubernetes Version upgrade from: v1.31.7
Kubernetes Version upgrade to: v1.32.3
CloudStack Version: 4.20
Template: ubuntu-2404-kube
E2E Test Run Logs: https://github.com/blueorangutan/capc-prs/releases/download/capc-pr-ci-cd/capc-e2e-artifacts-pr453-sl-883.zip



Summarizing 6 Failures:
 [FAIL] When testing multiple CPs in a shared network with kubevip [It] Should successfully create a cluster with multiple CPs in a shared network
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [FAIL] When testing machine remediation [It] Should replace a machine when it is destroyed
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:116
 [FAIL] When testing Kubernetes version upgrades [It] Should successfully upgrade kubernetes versions when there is a change in relevant fields
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/node_helpers.go:56
 [FAIL] When testing horizontal scale out/in [TC17][TC18][TC20][TC21] [It] Should successfully scale machine replicas up and down horizontally
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:451
 [FAIL] When testing subdomain [It] Should create a cluster in a subdomain
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/cluster_helpers.go:147
 [TIMEDOUT] When testing resource cleanup [It] Should create a new network when the specified network does not exist
 /jenkins/workspace/capc-e2e-new/test/e2e/resource_cleanup.go:65

Ran 27 of 34 Specs in 10573.990 seconds
FAIL! - Suite Timeout Elapsed -- 21 Passed | 6 Failed | 0 Pending | 7 Skipped
--- FAIL: TestE2E (10574.01s)
FAIL

@blueorangutan
Copy link

Test Results : (tid-881)
Environment: kvm Rocky8(x3), Advanced Networking with Management Server Rocky8
Kubernetes Version: v1.32.3
Kubernetes Version upgrade from: v1.31.7
Kubernetes Version upgrade to: v1.32.3
CloudStack Version: 4.20
Template: ubuntu-2404-kube
E2E Test Run Logs: https://github.com/blueorangutan/capc-prs/releases/download/capc-pr-ci-cd/capc-e2e-artifacts-pr453-sl-881.zip



Summarizing 9 Failures:
 [FAIL] When testing with disk offering [It] Should successfully create a cluster with disk offering
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [FAIL] When testing multiple CPs in a shared network with kubevip [It] Should successfully create a cluster with multiple CPs in a shared network
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [FAIL] When testing resource cleanup [It] Should create a new network when the specified network does not exist
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [FAIL] When testing machine remediation [It] Should replace a machine when it is destroyed
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [FAIL] When testing Kubernetes version upgrades [It] Should successfully upgrade kubernetes versions when there is a change in relevant fields
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [FAIL] When testing MachineDeployment rolling upgrades [It] Should successfully upgrade Machines upon changes in relevant MachineDeployment fields
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [FAIL] When testing horizontal scale out/in [TC17][TC18][TC20][TC21] [It] Should successfully scale machine replicas up and down horizontally
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [FAIL] When testing clusters in a VPC network [It] Should successfully create a cluster in a VPC network with default offering
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:153
 [TIMEDOUT] When testing clusters in a VPC network [It] Should successfully create a cluster in a VPC network with a custom offering
 /jenkins/workspace/capc-e2e-new/test/e2e/vpc_network.go:67

Ran 9 of 34 Specs in 10616.855 seconds
FAIL! - Suite Timeout Elapsed -- 0 Passed | 9 Failed | 0 Pending | 25 Skipped
--- FAIL: TestE2E (10616.86s)
FAIL

@blueorangutan
Copy link

Test Results : (tid-885)
Environment: kvm Rocky8(x3), Advanced Networking with Management Server Rocky8
Kubernetes Version: v1.32.3
Kubernetes Version upgrade from: v1.31.7
Kubernetes Version upgrade to: v1.32.3
CloudStack Version: 4.20
Template: ubuntu-2404-kube
Jobs filtered by: When testing multiple CPs in a shared network with kubevip | When testing machine remediation | When testing Kubernetes version upgrades | When testing horizontal scale out/in | When testing subdomain | When testing resource cleanup
E2E Test Run Logs: https://github.com/blueorangutan/capc-prs/releases/download/capc-pr-ci-cd/capc-e2e-artifacts-pr453-sl-885.zip



Summarizing 3 Failures:
 [FAIL] When testing machine remediation [It] Should replace a machine when it is destroyed
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/controlplane_helpers.go:116
 [FAIL] When testing multiple CPs in a shared network with kubevip [It] Should successfully create a cluster with multiple CPs in a shared network
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/cluster_helpers.go:147
 [FAIL] When testing Kubernetes version upgrades [It] Should successfully upgrade kubernetes versions when there is a change in relevant fields
 /root/go/pkg/mod/sigs.k8s.io/cluster-api/[email protected]/framework/clusterctl/clusterctl_helpers.go:431

Ran 6 of 34 Specs in 3993.098 seconds
FAIL! -- 3 Passed | 3 Failed | 0 Pending | 28 Skipped
--- FAIL: TestE2E (3993.10s)
FAIL

@vishesh92
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 9, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: harikrishna-patnala, vishesh92

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 9, 2025
@k8s-ci-robot k8s-ci-robot merged commit ee61587 into kubernetes-sigs:main Jul 9, 2025
10 checks passed
@vishesh92 vishesh92 deleted the multinic-validations-template branch July 9, 2025 06:30
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", 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.

5 participants