Skip to content
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

[DONTMERGE]feat: add vmss and vm etag support for track1 SDK #7698

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mainred
Copy link
Contributor

@mainred mainred commented Nov 28, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

  1. extend VirtualMachineScaleSet and VirtualMachineScaleSetVM with etag. This is to remain the original model untouched for less risk.
type VirtualMachineScaleSet struct {
	compute.VirtualMachineScaleSet `json:",inline"`
	// READ-ONLY; Etag is property returned in Create/Update/Get response of the VMSS, so that customer can supply it in the header
	// to ensure optimistic updates
	Etag *string `json:"etag,omitempty"`
}
type VirtualMachineScaleSetVM struct {
	compute.VirtualMachineScaleSetVM `json:",inline"`
	// READ-ONLY; Etag is property returned in Update/Get response of the VMSS VM, so that customer can supply it in the header
	// to ensure optimistic updates.
	Etag *string `json:"etag,omitempty"`
}
  1. bump vmss and vmssvm api version to 2024-03-01 to have etag support

crp etag support are enabled since 2023-09-01, but we want to use 2024-03-01, on which aks rp is updating.

  1. invalidate vmss cache when update vmss happens

This maybe a bug since we always invalidate vmss vms' cache after updating them when both adding backendpool or deleting backendpool since vmss vms are updated anyway, but we forgot to invalidate vmss cache.

NOTE:
Putting etag header in the put/patch API call can bring extra effort to update a resources since any update to the resource will change the etag version even though it's not related to the resource field we care, like tags to cloud provider azure.

This PR does not touch vm availabilitySet since vm availabilitySet model and API so far does not support etag, while we use vm as to list vm for cache, also AttachDisk and DetachDisk is also not covered in pkg/provider/azure_controller_vmss.go, which lacks e2e test, but we can consider it as a second phase.

Test report

#7698 (comment)

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

feat: add vmss and vm etag support for track1 SDK

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 28, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mainred
Once this PR has been reviewed and has the lgtm label, please assign feiskyer for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 28, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @mainred. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 28, 2024
@MartinForReal
Copy link
Contributor

/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 Nov 28, 2024
@andyzhangx
Copy link
Member

we are going to migrate to track2 sdk for vmss client very soon, why do we want to add etag support for track1?

EtagMismatchErrorTag = "EtagMismatchError"
)

type EtagMismatchError struct {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this error? e.g. for LB, we are checking the http status code // Invalidate the cache because ETAG precondition mismatch.
if rerr.HTTPStatusCode == http.StatusPreconditionFailed {
klog.V(3).Infof("LoadBalancer cache for %s is cleanup because of http.StatusPreconditionFailed", ptr.Deref(lb.Name, ""))
_ = az.lbCache.Delete(*lb.Name)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not required anymore.
I originally introduced this error because the error of the erros of UpdateVMs are aggregated, it's a bit different to tell if etagmismatch error happend. but if we etagmismatch and use errors.As, which internally will iterate the errors wrapped by retry error, we can easily find a etagmismatch in the aggregated error. And that's why I updated the rawerror of retry error here as

	// RawError indicates the raw error from API.
	// It's beneficial to errors.Is() or errors.As() to check the real error type.
	RawError error

We can remove mismatch if we decide to invalidate the cache anyway without checking the exact error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. can redirect all StatusPreconditionFailed status code to a etagmismatch error?
  2. that's how we decide a retry error by if errors.As(err, &re)

BTW because our retry error is not api.RetryError, so even if we have retryafter durtion, all errors including retry errors goes to ratelimited retry, we may need to fix this to honor RetryAfter?

@k8s-ci-robot
Copy link
Contributor

Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository.
Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found 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.

@mainred
Copy link
Contributor Author

mainred commented Dec 2, 2024

Test Scenarios

Two allow etagmismatch happens stable, we hack the code to add sleep before updating the vmss and vm, and use PUT the vmss or vm through the API.

create lb-type service

update vmss with etagmismatch

  • create a lb type service to trigger cache
  • update network configuration to add another ipconfiguration with name ipconfig1 to vmss
curl -i -X PUT  -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0\?api-version\=2024-03-01 --data '{"location":"eastus2","properties":{"virtualMachineProfile":{"networkProfile":{"networkInterfaceConfigurations":[{"name":"etag-k8s-mp-0-nic-0","properties":{"primary":true,"enableAcceleratedNetworking":true,"disableTcpStateTracking":false,"dnsSettings":{"dnsServers":[]},"enableIPForwarding":true,"ipConfigurations":[{"name":"ipConfig0","properties":{"primary":true,"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4"}},{"name":"ipConfig1","properties":{"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4"}}]}}]}}}}'
  • check if a successful retry will happen after etagmismatch error

  • check if the ipconfig1 still exists and service is working fine

curl -i -X GET -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0\?api-version\=2024-03-01

update vm with etagmismatch

  • create a lb type service to trigger cache
  • update network configuration to add another ipconfiguration with name ipconfig1 to vm
curl -i -X PUT  -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0/virtualMachines/0\?api-version\=2024-03-01 --data '{"location":"eastus2","properties":{"networkProfileConfiguration":{"networkInterfaceConfigurations":[{"name":"etag-k8s-mp-0-nic-0","properties":{"primary":true,"enableAcceleratedNetworking":true,"disableTcpStateTracking":false,"dnsSettings":{"dnsServers":[]},"enableIPForwarding":true,"ipConfigurations":[{"name":"ipConfig0","properties":{"primary":true,"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4"}},{"name":"ipConfig1","properties":{"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4"}},]}}]},"hardwareProfile":{"vmSize":"Standard_D2s_v3"}}}'
  • check if the ipconfig1 still exists and service is working fine
curl -i -X GET -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0\?api-version\=2024-03-01
curl -i -X GET -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0/virtualMachines/0\?api-version\=2024-03-01
  • check if the ipconfig1 still exists and service is working fine
curl -i -X GET -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0\?api-version\=2024-03-01
curl -i -X GET -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0/virtualMachines/0\?api-version\=2024-03-01

delete lb-type service

update vmss with etagmismatch

  • create a lb type service to trigger cache
  • update network configuration to add another ipconfiguration with name ipconfig1 vmss to update Etag
curl -i -X PUT  -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0\?api-version\=2024-03-01 --data '{"location":"eastus2","properties":{"virtualMachineProfile":{"networkProfile":{"networkInterfaceConfigurations":[{"name":"etag-k8s-mp-0-nic-0","properties":{"primary":true,"enableAcceleratedNetworking":true,"disableTcpStateTracking":false,"dnsSettings":{"dnsServers":[]},"enableIPForwarding":true,"ipConfigurations":[{"name":"ipConfig0","properties":{"primary":true,"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4","loadBalancerBackendAddressPools":[{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/loadBalancers/etag-k8s/backendAddressPools/etag-k8s"}]}},{"name":"ipConfig1","properties":{"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4"}}]}}]}}}}}'
  • delete lb type service
  • check if the ipconfig1 still exists and service is gone
curl -i -X GET -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0\?api-version\=2024-03-01

update vm with etagmismatch

  • create a lb type service to trigger cache
  • update network configuration to add another ipconfiguration with name ipconfig1 to vm to update Etag
curl -i -X PUT  -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0/virtualMachines/0\?api-version\=2024-03-01 --data '{"location":"eastus2","properties":{"networkProfileConfiguration":{"networkInterfaceConfigurations":[{"name":"etag-k8s-mp-0-nic-0","properties":{"primary":true,"enableAcceleratedNetworking":true,"disableTcpStateTracking":false,"dnsSettings":{"dnsServers":[]},"enableIPForwarding":true,"ipConfigurations":[{"name":"ipConfig0","properties":{"primary":true,"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4","loadBalancerBackendAddressPools":[{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/loadBalancers/etag-k8s/backendAddressPools/etag-k8s"}]}},{"name":"ipConfig1","properties":{"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4"}},]}}]},"hardwareProfile":{"vmSize":"Standard_D2s_v3"}}}'
  • delete lb type service
  • check if the ipconfig1 still exists and service is gone
curl -i -X GET -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0/virtualMachines/0\?api-version\=2024-03-01

reset vmss and vm

reset vmss and vm in case updating vmss or vm but no change will not update etag

token=$(az account get-access-token | jq -r .accessToken)    
curl -i -X PUT  -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0\?api-version\=2024-03-01 --data '{"location":"eastus2","properties":{"virtualMachineProfile":{"networkProfile":{"networkInterfaceConfigurations":[{"name":"etag-k8s-mp-0-nic-0","properties":{"primary":true,"enableAcceleratedNetworking":true,"disableTcpStateTracking":false,"dnsSettings":{"dnsServers":[]},"enableIPForwarding":true,"ipConfigurations":[{"name":"ipConfig0","properties":{"primary":true,"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4"}}]}}]}}}}'
curl -i -X PUT -H "Authorization: Bearer $token" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Compute/virtualMachineScaleSets/etag-k8s-mp-0/virtualMachines/0\?api-version\=2024-03-01  --data '{"location":"eastus2","properties":{"modelDefinitionApplied":"VirtualMachine","networkProfileConfiguration":{"networkInterfaceConfigurations":[{"name":"etag-k8s-mp-0-nic-0","properties":{"primary":true,"enableAcceleratedNetworking":true,"disableTcpStateTracking":false,"dnsSettings":{"dnsServers":[]},"enableIPForwarding":true,"ipConfigurations":[{"name":"ipConfig0","properties":{"primary":true,"subnet":{"id":"/subscriptions/f6e2f77f-9959-42ad-87f0-c30a6abc0133/resourceGroups/etag/providers/Microsoft.Network/virtualNetworks/etag-k8s-vnet/subnets/node-subnet"},"privateIPAddressVersion":"IPv4"}}]}}]},"hardwareProfile":{"vmSize":"Standard_D2s_v3"}}}'

References

Quick Start - The Cluster API Book

@mainred mainred changed the title feat: add vmss and vm etag support for track1 SDK [DONTMERGE]feat: add vmss and vm etag support for track1 SDK Dec 2, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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
Copy link
Contributor

@mainred: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cloud-provider-azure-check 6a67125 link true /test pull-cloud-provider-azure-check
pull-cloud-provider-azure-unit 6a67125 link true /test pull-cloud-provider-azure-unit
pull-cloud-provider-azure-e2e-ccm-vmss-capz 6a67125 link true /test pull-cloud-provider-azure-e2e-ccm-vmss-capz
pull-cloud-provider-azure-e2e-ccm-vmss-shared-probe-capz 6a67125 link true /test pull-cloud-provider-azure-e2e-ccm-vmss-shared-probe-capz
pull-cloud-provider-azure-e2e-ccm-vmss-ip-lb-capz 6a67125 link true /test pull-cloud-provider-azure-e2e-ccm-vmss-ip-lb-capz
pull-cloud-provider-azure-e2e-ccm-capz 6a67125 link true /test pull-cloud-provider-azure-e2e-ccm-capz
pull-cloud-provider-azure-e2e-ccm-vmss-multi-slb-capz 6a67125 link true /test pull-cloud-provider-azure-e2e-ccm-vmss-multi-slb-capz
pull-cloud-provider-azure-e2e-ccm-vmssflex-capz 6a67125 link true /test pull-cloud-provider-azure-e2e-ccm-vmssflex-capz
pull-cloud-provider-azure-e2e-capz 6a67125 link true /test pull-cloud-provider-azure-e2e-capz

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/contains-merge-commits kind/feature Categorizes issue or PR as related to a new feature. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants