Skip to content

Commit

Permalink
azure: Use k8s.io/utils/set.Set[string]
Browse files Browse the repository at this point in the history
  • Loading branch information
hakman committed Jul 17, 2023
1 parent 704daec commit 5be7a26
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/resources/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/kops/pkg/resources"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/azure"
"k8s.io/utils/set"
)

const (
Expand Down Expand Up @@ -168,15 +169,15 @@ func (g *resourceGetter) toVirtualNetworkResource(vnet *network.VirtualNetwork)
var blocks []string
blocks = append(blocks, toKey(typeResourceGroup, g.resourceGroupName()))

nsgs := map[string]struct{}{}
nsgs := set.New[string]()
if vnet.Subnets != nil {
for _, sn := range *vnet.Subnets {
if sn.NetworkSecurityGroup != nil {
nsgID, err := azure.ParseNetworkSecurityGroupID(*sn.NetworkSecurityGroup.ID)
if err != nil {
return nil, fmt.Errorf("parsing network security group ID: %s", err)
}
nsgs[nsgID.NetworkSecurityGroupName] = struct{}{}
nsgs.Insert(nsgID.NetworkSecurityGroupName)
}
}
}
Expand Down Expand Up @@ -341,24 +342,24 @@ func (g *resourceGetter) toVMScaleSetResource(vmss *compute.VirtualMachineScaleS
var blocks []string
blocks = append(blocks, toKey(typeResourceGroup, g.resourceGroupName()))

vnets := map[string]struct{}{}
subnets := map[string]struct{}{}
lbs := map[string]struct{}{}
vnets := set.New[string]()
subnets := set.New[string]()
lbs := set.New[string]()
for _, iface := range *vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations {
for _, ip := range *iface.IPConfigurations {
subnetID, err := azure.ParseSubnetID(*ip.Subnet.ID)
if err != nil {
return nil, fmt.Errorf("error on parsing subnet ID: %s", err)
}
vnets[subnetID.VirtualNetworkName] = struct{}{}
subnets[subnetID.SubnetName] = struct{}{}
vnets.Insert(subnetID.VirtualNetworkName)
subnets.Insert(subnetID.SubnetName)
if ip.LoadBalancerBackendAddressPools != nil {
for _, lb := range *ip.LoadBalancerBackendAddressPools {
lbID, err := azure.ParseLoadBalancerID(*lb.ID)
if err != nil {
return nil, fmt.Errorf("parsing load balancer ID: %s", err)
}
lbs[lbID.LoadBalancerName] = struct{}{}
lbs.Insert(lbID.LoadBalancerName)
}
}
}
Expand Down Expand Up @@ -496,15 +497,15 @@ func (g *resourceGetter) toLoadBalancerResource(loadBalancer *network.LoadBalanc
var blocks []string
blocks = append(blocks, toKey(typeResourceGroup, g.resourceGroupName()))

pips := map[string]struct{}{}
pips := set.New[string]()
if loadBalancer.FrontendIPConfigurations != nil {
for _, fip := range *loadBalancer.FrontendIPConfigurations {
if fip.PublicIPAddress != nil {
pipID, err := azure.ParsePublicIPAddressID(*fip.PublicIPAddress.ID)
if err != nil {
return nil, fmt.Errorf("parsing public IP address ID: %s", err)
}
pips[pipID.PublicIPAddressName] = struct{}{}
pips.Insert(pipID.PublicIPAddressName)
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions vendor/k8s.io/utils/set/OWNERS

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

53 changes: 53 additions & 0 deletions vendor/k8s.io/utils/set/ordered.go

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

229 changes: 229 additions & 0 deletions vendor/k8s.io/utils/set/set.go

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

1 change: 1 addition & 0 deletions vendor/modules.txt

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

0 comments on commit 5be7a26

Please sign in to comment.