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

Use k8s utils/pointer instead of Azure autorest/to #3026

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/v1alpha3/azurecluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error {
// set default control plane outbound lb for private v1alpha3 clusters.
if src.Spec.NetworkSpec.APIServerLB.Type == Internal {
dst.Spec.NetworkSpec.ControlPlaneOutboundLB = &infrav1.LoadBalancerSpec{
FrontendIPsCount: pointer.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
}
// We also need to set the defaults here because "get" won't set defaults, and hence there is no mismatch when a client
// gets a v1alpha3 cluster.
Expand All @@ -55,7 +55,7 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error {

// set default node plane outbound lb for all v1alpha3 clusters.
dst.Spec.NetworkSpec.NodeOutboundLB = &infrav1.LoadBalancerSpec{
FrontendIPsCount: pointer.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
}
// We also need to set the defaults here because "get" won't set defaults, and hence there is no mismatch when a client
// gets a v1alpha3 cluster.
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func overrideOutboundLBFunc(codecs runtimeserializer.CodecFactory) []interface{}
return []interface{}{
func(networkSpec *infrav1.NetworkSpec, c fuzz.Continue) {
networkSpec.ControlPlaneOutboundLB = &infrav1.LoadBalancerSpec{
FrontendIPsCount: pointer.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
}
networkSpec.NodeOutboundLB = &infrav1.LoadBalancerSpec{
FrontendIPsCount: pointer.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
}
},
}
Expand Down
10 changes: 5 additions & 5 deletions api/v1beta1/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (c *AzureCluster) SetNodeOutboundLBDefaults() {
}

if lb.FrontendIPsCount == nil {
lb.FrontendIPsCount = pointer.Int32Ptr(1)
lb.FrontendIPsCount = pointer.Int32(1)
}

c.setOutboundLBFrontendIPs(lb, generateNodeOutboundIPName)
Expand All @@ -255,7 +255,7 @@ func (c *AzureCluster) SetControlPlaneOutboundLBDefaults() {
lb.Name = generateControlPlaneOutboundLBName(c.ObjectMeta.Name)
}
if lb.FrontendIPsCount == nil {
lb.FrontendIPsCount = pointer.Int32Ptr(1)
lb.FrontendIPsCount = pointer.Int32(1)
}
c.setOutboundLBFrontendIPs(lb, generateControlPlaneOutboundIPName)

Expand Down Expand Up @@ -322,7 +322,7 @@ func (lb *LoadBalancerClassSpec) setAPIServerLBDefaults() {
lb.SKU = SKUStandard
}
if lb.IdleTimeoutInMinutes == nil {
lb.IdleTimeoutInMinutes = pointer.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes)
lb.IdleTimeoutInMinutes = pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes)
}
}

Expand All @@ -338,7 +338,7 @@ func (lb *LoadBalancerClassSpec) setOutboundLBDefaults() {
lb.Type = Public
lb.SKU = SKUStandard
if lb.IdleTimeoutInMinutes == nil {
lb.IdleTimeoutInMinutes = pointer.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes)
lb.IdleTimeoutInMinutes = pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes)
}
}

Expand All @@ -357,7 +357,7 @@ func setControlPlaneOutboundLBDefaults(lb *LoadBalancerClassSpec, apiserverLBTyp
lb.SKU = SKUStandard

if lb.IdleTimeoutInMinutes == nil {
lb.IdleTimeoutInMinutes = pointer.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes)
lb.IdleTimeoutInMinutes = pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes)
}
}

Expand Down
64 changes: 32 additions & 32 deletions api/v1beta1/azurecluster_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"reflect"
"testing"

"github.com/Azure/go-autorest/autorest/to"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)

func TestResourceGroupDefault(t *testing.T) {
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestVnetDefaults(t *testing.T) {
},
},
NodeOutboundLB: &LoadBalancerSpec{
FrontendIPsCount: to.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
},
},
},
Expand Down Expand Up @@ -629,10 +629,10 @@ func TestSubnetDefaults(t *testing.T) {
Description: "allow port 50000",
Protocol: "*",
Priority: 2202,
SourcePorts: to.StringPtr("*"),
DestinationPorts: to.StringPtr("*"),
Source: to.StringPtr("*"),
Destination: to.StringPtr("*"),
SourcePorts: pointer.String("*"),
DestinationPorts: pointer.String("*"),
Source: pointer.String("*"),
Destination: pointer.String("*"),
},
},
},
Expand Down Expand Up @@ -664,10 +664,10 @@ func TestSubnetDefaults(t *testing.T) {
Description: "allow port 50000",
Protocol: "*",
Priority: 2202,
SourcePorts: to.StringPtr("*"),
DestinationPorts: to.StringPtr("*"),
Source: to.StringPtr("*"),
Destination: to.StringPtr("*"),
SourcePorts: pointer.String("*"),
DestinationPorts: pointer.String("*"),
Source: pointer.String("*"),
Destination: pointer.String("*"),
Direction: SecurityRuleDirectionInbound,
},
},
Expand Down Expand Up @@ -868,7 +868,7 @@ func TestAPIServerLBDefaults(t *testing.T) {
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
},
Expand Down Expand Up @@ -912,7 +912,7 @@ func TestAPIServerLBDefaults(t *testing.T) {
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Internal,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
Name: "cluster-test-internal-lb",
},
Expand Down Expand Up @@ -960,7 +960,7 @@ func TestAPIServerLBDefaults(t *testing.T) {
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Internal,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
Name: "cluster-test-internal-lb",
},
Expand Down Expand Up @@ -1143,11 +1143,11 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
BackendPool: BackendPool{
Name: "cluster-test-outboundBackendPool",
},
FrontendIPsCount: to.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
},
Expand Down Expand Up @@ -1324,11 +1324,11 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
BackendPool: BackendPool{
Name: "cluster-test-outboundBackendPool",
},
FrontendIPsCount: to.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
},
Expand Down Expand Up @@ -1433,14 +1433,14 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
Name: "pip-cluster-test-node-outbound",
},
}},
FrontendIPsCount: to.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
BackendPool: BackendPool{
Name: "cluster-test-outboundBackendPool",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
Name: "cluster-test",
},
Expand Down Expand Up @@ -1616,12 +1616,12 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{LoadBalancerClassSpec: LoadBalancerClassSpec{Type: Public}},
NodeOutboundLB: &LoadBalancerSpec{
FrontendIPsCount: to.Int32Ptr(2),
FrontendIPsCount: pointer.Int32(2),
BackendPool: BackendPool{
Name: "custom-backend-pool",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
IdleTimeoutInMinutes: to.Int32Ptr(15),
IdleTimeoutInMinutes: pointer.Int32(15),
},
},
},
Expand Down Expand Up @@ -1656,11 +1656,11 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
BackendPool: BackendPool{
Name: "custom-backend-pool",
},
FrontendIPsCount: to.Int32Ptr(2), // we expect the original value to be respected here
FrontendIPsCount: pointer.Int32(2), // we expect the original value to be respected here
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(15), // we expect the original value to be respected here
IdleTimeoutInMinutes: pointer.Int32(15), // we expect the original value to be respected here
},
Name: "cluster-test",
},
Expand Down Expand Up @@ -1750,11 +1750,11 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
BackendPool: BackendPool{
Name: "user-defined-name-outboundBackendPool",
},
FrontendIPsCount: to.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
ControlPlaneOutboundLB: &LoadBalancerSpec{
Expand Down Expand Up @@ -1850,9 +1850,9 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{LoadBalancerClassSpec: LoadBalancerClassSpec{Type: Internal}},
ControlPlaneOutboundLB: &LoadBalancerSpec{
FrontendIPsCount: to.Int32Ptr(2),
FrontendIPsCount: pointer.Int32(2),
LoadBalancerClassSpec: LoadBalancerClassSpec{
IdleTimeoutInMinutes: to.Int32Ptr(15),
IdleTimeoutInMinutes: pointer.Int32(15),
},
},
},
Expand Down Expand Up @@ -1888,11 +1888,11 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
},
},
},
FrontendIPsCount: to.Int32Ptr(2),
FrontendIPsCount: pointer.Int32(2),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(15),
IdleTimeoutInMinutes: pointer.Int32(15),
},
},
},
Expand All @@ -1913,7 +1913,7 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
Name: "custom-outbound-lb",
},
LoadBalancerClassSpec: LoadBalancerClassSpec{
IdleTimeoutInMinutes: to.Int32Ptr(15),
IdleTimeoutInMinutes: pointer.Int32(15),
},
},
},
Expand Down Expand Up @@ -1943,11 +1943,11 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
},
},
},
FrontendIPsCount: to.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
LoadBalancerClassSpec: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(15),
IdleTimeoutInMinutes: pointer.Int32(15),
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions api/v1beta1/azurecluster_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ func TestValidateNodeOutboundLB(t *testing.T) {
}, {
Name: "some-frontend-ip-2",
}},
FrontendIPsCount: pointer.Int32Ptr(2),
FrontendIPsCount: pointer.Int32(2),
},
old: &LoadBalancerSpec{
FrontendIPs: []FrontendIP{{
Expand All @@ -1088,7 +1088,7 @@ func TestValidateNodeOutboundLB(t *testing.T) {
{
name: "frontend ips count exceeds max value",
lb: &LoadBalancerSpec{
FrontendIPsCount: pointer.Int32Ptr(100),
FrontendIPsCount: pointer.Int32(100),
},
wantErr: true,
expectedErr: field.Error{
Expand Down Expand Up @@ -1164,7 +1164,7 @@ func TestValidateControlPlaneNodeOutboundLB(t *testing.T) {
{
name: "frontend ips count exceeds max value",
lb: &LoadBalancerSpec{
FrontendIPsCount: pointer.Int32Ptr(100),
FrontendIPsCount: pointer.Int32(100),
},
apiServerLB: LoadBalancerSpec{
LoadBalancerClassSpec: LoadBalancerClassSpec{
Expand Down Expand Up @@ -1357,7 +1357,7 @@ func createValidAPIServerLB() LoadBalancerSpec {

func createValidNodeOutboundLB() *LoadBalancerSpec {
return &LoadBalancerSpec{
FrontendIPsCount: pointer.Int32Ptr(1),
FrontendIPsCount: pointer.Int32(1),
}
}

Expand Down
16 changes: 8 additions & 8 deletions api/v1beta1/azureclustertemplate_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"reflect"
"testing"

"github.com/Azure/go-autorest/autorest/to"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)

func TestVnetTemplateDefaults(t *testing.T) {
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestAPIServerLBClassDefaults(t *testing.T) {
APIServerLB: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
},
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestAPIServerLBClassDefaults(t *testing.T) {
APIServerLB: LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Internal,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
},
Expand Down Expand Up @@ -591,7 +591,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) {
NodeOutboundLB: &LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
},
Expand Down Expand Up @@ -728,7 +728,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) {
NodeOutboundLB: &LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
},
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) {
NodeOutboundLB: &LoadBalancerClassSpec{
SKU: SKUStandard,
Type: Public,
IdleTimeoutInMinutes: to.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes),
IdleTimeoutInMinutes: pointer.Int32(DefaultOutboundRuleIdleTimeoutInMinutes),
},
},
},
Expand Down Expand Up @@ -926,7 +926,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) {
NetworkSpec: NetworkTemplateSpec{
APIServerLB: LoadBalancerClassSpec{Type: Internal},
NodeOutboundLB: &LoadBalancerClassSpec{
IdleTimeoutInMinutes: to.Int32Ptr(15),
IdleTimeoutInMinutes: pointer.Int32(15),
},
},
},
Expand All @@ -943,7 +943,7 @@ func TestNodeOutboundLBClassDefaults(t *testing.T) {
NetworkSpec: NetworkTemplateSpec{
APIServerLB: LoadBalancerClassSpec{Type: Internal},
NodeOutboundLB: &LoadBalancerClassSpec{
IdleTimeoutInMinutes: to.Int32Ptr(15),
IdleTimeoutInMinutes: pointer.Int32(15),
SKU: SKUStandard,
Type: Public,
},
Expand Down
Loading