Skip to content

Commit

Permalink
update nsg logic for clb + add/refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeedward2000 committed Jan 27, 2025
1 parent 3f0f834 commit 2ff6f2d
Show file tree
Hide file tree
Showing 5 changed files with 962 additions and 112 deletions.
27 changes: 27 additions & 0 deletions internal/testutil/fixture/azure_managedcluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fixture

import (
armcontainerservice "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v6"
"k8s.io/utils/ptr"
)

func (f *AzureFixture) ManagedCluster() *AzureManagedClusterFixture {
return &AzureManagedClusterFixture{
mc: &armcontainerservice.ManagedCluster{
Name: ptr.To("mangaedcluster"),
Properties: &armcontainerservice.ManagedClusterProperties{
NetworkProfile: &armcontainerservice.NetworkProfile{
PodCidr: ptr.To("192.1.0.0/16"),
},
},
},
}
}

type AzureManagedClusterFixture struct {
mc *armcontainerservice.ManagedCluster
}

func (f *AzureManagedClusterFixture) Build() *armcontainerservice.ManagedCluster {
return f.mc
}
36 changes: 36 additions & 0 deletions internal/testutil/fixture/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,42 @@ func (f *KubernetesServiceFixture) WithIngressIPs(ips []string) *KubernetesServi
return f
}

func (f *KubernetesServiceFixture) WithOnlyTCPPorts() *KubernetesServiceFixture {
f.svc.Spec.Ports = []v1.ServicePort{
{
Name: "http",
Protocol: v1.ProtocolTCP,
Port: 80,
NodePort: 50080,
},
{
Name: "dns-tcp",
Protocol: v1.ProtocolTCP,
Port: 53,
NodePort: 50053,
},
{
Name: "https",
Protocol: v1.ProtocolTCP,
Port: 443,
NodePort: 50443,
},
}
return f
}

func (f *KubernetesServiceFixture) WithOnlyUDPPorts() *KubernetesServiceFixture {
f.svc.Spec.Ports = []v1.ServicePort{
{
Name: "dns-udp",
Protocol: v1.ProtocolUDP,
Port: 53,
NodePort: 50053,
},
}
return f
}

func (f *KubernetesServiceFixture) Build() v1.Service {
return f.svc
}
3 changes: 3 additions & 0 deletions pkg/provider/azure_fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/diskclient/mock_diskclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/interfaceclient/mock_interfaceclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/loadbalancerclient/mock_loadbalancerclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/managedclusterclient/mock_managedclusterclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/mock_azclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/privateendpointclient/mock_privateendpointclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/privatelinkserviceclient/mock_privatelinkserviceclient"
Expand Down Expand Up @@ -134,6 +135,8 @@ func GetTestCloud(ctrl *gomock.Controller) (az *Cloud) {
clientFactory.EXPECT().GetVirtualMachineScaleSetClient().Return(virtualMachineScaleSetsClient).AnyTimes()
virtualMachineScaleSetVMsClient := mock_virtualmachinescalesetvmclient.NewMockInterface(ctrl)
clientFactory.EXPECT().GetVirtualMachineScaleSetVMClient().Return(virtualMachineScaleSetVMsClient).AnyTimes()
managedClusterClient := mock_managedclusterclient.NewMockInterface(ctrl)
clientFactory.EXPECT().GetManagedClusterClient().Return(managedClusterClient).AnyTimes()

virtualMachinesClient := mock_virtualmachineclient.NewMockInterface(ctrl)
clientFactory.EXPECT().GetVirtualMachineClient().Return(virtualMachinesClient).AnyTimes()
Expand Down
Loading

0 comments on commit 2ff6f2d

Please sign in to comment.