Skip to content

Commit

Permalink
add backendpool client
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinForReal committed Dec 9, 2024
1 parent d53fb4a commit 6b8f836
Show file tree
Hide file tree
Showing 13 changed files with 1,997 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/azclient/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ generatecode: build ## Generate client
$(TYPESCAFFOLD) --package github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 --package-alias armnetwork --resource VirtualNetwork --client-name VirtualNetworksClient --verbs get,createorupdate,delete,list --expand
$(TYPESCAFFOLD) --package github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 --package-alias armnetwork --resource Interface --client-name InterfacesClient --verbs get,createorupdate,delete,list --expand --ratelimitkey interfaceRateLimit
$(TYPESCAFFOLD) --package github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 --package-alias armnetwork --resource LoadBalancer --client-name LoadBalancersClient --verbs get,createorupdate,delete,list --expand --ratelimitkey loadBalancerRateLimit
$(TYPESCAFFOLD) --package github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 --package-alias armnetwork --resource LoadBalancer --subresource BackendAddressPool --client-name LoadBalancerBackendAddressPoolsClient --verbs get,createorupdate,delete,list --ratelimitkey loadBalancerRateLimit
$(TYPESCAFFOLD) --package github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 --package-alias armnetwork --resource PrivateEndpoint --client-name PrivateEndpointsClient --verbs get,createorupdate --expand --ratelimitkey privateEndpointRateLimit
$(TYPESCAFFOLD) --package github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 --package-alias armnetwork --resource PrivateEndpoint --subresource PrivateDNSZoneGroup --client-name PrivateDNSZoneGroupsClient --verbs get,createorupdate,delete
$(TYPESCAFFOLD) --package github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 --package-alias armnetwork --resource PublicIPAddress --client-name PublicIPAddressesClient --verbs get,createorupdate,delete,list --expand --ratelimitkey publicIPAddressRateLimit
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions pkg/azclient/backendaddresspoolclient/backendaddresspoolclient_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions pkg/azclient/backendaddresspoolclient/custom_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// /*
// Copyright The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// */

package backendaddresspoolclient

import (
"context"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
armnetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
"github.com/onsi/gomega"
)

var (
networkClientFactory *armnetwork.ClientFactory
loadbalancerClient *armnetwork.LoadBalancersClient
loadBalancer *armnetwork.LoadBalancer
publicIPClient *armnetwork.PublicIPAddressesClient
publicip *armnetwork.PublicIPAddress
publicIPName = "publicip"
)

func init() {
additionalTestCases = func() {
}

beforeAllFunc = func(ctx context.Context) {
networkClientFactory, err = armnetwork.NewClientFactory(subscriptionID, recorder.TokenCredential(), &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Transport: recorder.HTTPClient(),
},
})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
publicIPClient = networkClientFactory.NewPublicIPAddressesClient()
publicip, err = createPublicIP(ctx)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

loadbalancerClient = networkClientFactory.NewLoadBalancersClient()
loadBalancer, err = createLoadbalancer(ctx)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

newResource = &armnetwork.BackendAddressPool{
Name: to.Ptr(resourceName),
Properties: &armnetwork.BackendAddressPoolPropertiesFormat{},
}

}
afterAllFunc = func(ctx context.Context) {
pollerResp, err := loadbalancerClient.BeginDelete(ctx, resourceGroupName, loadbalancerName, nil)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
_, err = pollerResp.PollUntilDone(ctx, nil)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
pippollerResp, err := publicIPClient.BeginDelete(ctx, resourceGroupName, publicIPName, nil)
_, err = pippollerResp.PollUntilDone(ctx, nil)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}

func createLoadbalancer(ctx context.Context) (*armnetwork.LoadBalancer, error) {
pollerResp, err := loadbalancerClient.BeginCreateOrUpdate(
ctx,
resourceGroupName,
loadbalancerName,
armnetwork.LoadBalancer{
Location: to.Ptr(location),
SKU: &armnetwork.LoadBalancerSKU{
Name: to.Ptr(armnetwork.LoadBalancerSKUNameStandard),
Tier: to.Ptr(armnetwork.LoadBalancerSKUTierRegional),
},
Properties: &armnetwork.LoadBalancerPropertiesFormat{
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
{
Name: to.Ptr("frontendIPConfiguration"),
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
PublicIPAddress: &armnetwork.PublicIPAddress{
ID: to.Ptr("/subscriptions/" + subscriptionID + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/publicIPAddresses/" + publicIPName),
},
},
},
},
},
},
nil)
if err != nil {
return nil, err
}

resp, err := pollerResp.PollUntilDone(ctx, nil)
if err != nil {
return nil, err
}
return &resp.LoadBalancer, nil
}

func createPublicIP(ctx context.Context) (*armnetwork.PublicIPAddress, error) {
pollerResp, err := publicIPClient.BeginCreateOrUpdate(
ctx,
resourceGroupName,
publicIPName,
armnetwork.PublicIPAddress{
Location: to.Ptr(location),
SKU: &armnetwork.PublicIPAddressSKU{
Name: to.Ptr(armnetwork.PublicIPAddressSKUNameStandard),
Tier: to.Ptr(armnetwork.PublicIPAddressSKUTierRegional),
},
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodStatic),
PublicIPAddressVersion: to.Ptr(armnetwork.IPVersionIPv4),
},
},
nil)

if err != nil {
return nil, err
}

resp, err := pollerResp.PollUntilDone(ctx, nil)
if err != nil {
return nil, err
}
return &resp.PublicIPAddress, nil
}
32 changes: 32 additions & 0 deletions pkg/azclient/backendaddresspoolclient/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// +azure:enableclientgen:=true
package backendaddresspoolclient

import (
armnetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"

"sigs.k8s.io/cloud-provider-azure/pkg/azclient/utils"
)

// +azure:client:verbs=get;createorupdate;delete;list,resource=LoadBalancer,subResource=BackendAddressPool,packageName=github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6,packageAlias=armnetwork,clientName=LoadBalancerBackendAddressPoolsClient,rateLimitKey=loadBalancerRateLimit
type Interface interface {
utils.SubResourceGetFunc[armnetwork.BackendAddressPool]
utils.SubResourceCreateOrUpdateFunc[armnetwork.BackendAddressPool]
utils.SubResourceDeleteFunc[armnetwork.BackendAddressPool]
utils.SubResourceListFunc[armnetwork.BackendAddressPool]
}
Loading

0 comments on commit 6b8f836

Please sign in to comment.