diff --git a/cloud/linode/cilium_loadbalancers.go b/cloud/linode/cilium_loadbalancers.go index f086f6c6..01ae40b6 100644 --- a/cloud/linode/cilium_loadbalancers.go +++ b/cloud/linode/cilium_loadbalancers.go @@ -13,7 +13,7 @@ import ( ciliumclient "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1" slimv1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1" "github.com/google/uuid" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -218,7 +218,7 @@ func (l *loadbalancers) createSharedIP(ctx context.Context, nodes []*v1.Node, ip return "", err } - newSharedIP, err := l.client.AddInstanceIPAddress(ctx, ipHolder.ID, true) + newSharedIP, err := l.client.AddInstanceIPAddress(ctx, ipHolder.ID, linodego.InstanceIPAddOptions{Public: true}) if err != nil { return "", err } diff --git a/cloud/linode/cilium_loadbalancers_test.go b/cloud/linode/cilium_loadbalancers_test.go index 54c6d396..a85a91a3 100644 --- a/cloud/linode/cilium_loadbalancers_test.go +++ b/cloud/linode/cilium_loadbalancers_test.go @@ -9,7 +9,7 @@ import ( ciliumfake "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/fake" fakev2alpha1 "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1/fake" "github.com/golang/mock/gomock" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -84,7 +84,7 @@ var ( Label: fmt.Sprintf("%s-%s", ipHolderLabelPrefix, zone), Type: "g6-standard-1", Region: "us-west", - IPv4: []*net.IP{&publicIPv4}, + IPv4: []net.IP{publicIPv4}, } newIpHolderInstance = linodego.Instance{} ) @@ -208,7 +208,7 @@ func createNewIpHolderInstance() linodego.Instance { Label: generateClusterScopedIPHolderLinodeName(zone, options.Options.IpHolderSuffix), Type: "g6-standard-1", Region: "us-west", - IPv4: []*net.IP{&publicIPv4}, + IPv4: []net.IP{publicIPv4}, } } @@ -246,10 +246,10 @@ func testNoBGPNodeLabel(t *testing.T, mc *mocks.MockClient) { mc.EXPECT().CreateInstance(gomock.Any(), gomock.Any()).Times(1).Return(&newIpHolderInstance, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), newIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ IPs: []string{dummySharedIP}, LinodeID: 11111, @@ -325,10 +325,10 @@ func testCreateWithExistingIPHolderWithOldIpHolderNamingConvention(t *testing.T, } mc.EXPECT().ListInstances(gomock.Any(), linodego.NewListOptions(1, string(rawFilter))).Times(1).Return([]linodego.Instance{oldIpHolderInstance}, nil) dummySharedIP := dummyIP - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), oldIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), oldIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), oldIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ @@ -371,10 +371,10 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConvention(t *testing.T, } mc.EXPECT().ListInstances(gomock.Any(), linodego.NewListOptions(1, string(rawFilter))).Times(1).Return([]linodego.Instance{oldIpHolderInstance}, nil) dummySharedIP := dummyIP - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), oldIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), oldIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), oldIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ @@ -417,10 +417,10 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffi } mc.EXPECT().ListInstances(gomock.Any(), linodego.NewListOptions(1, string(rawFilter))).Times(1).Return([]linodego.Instance{oldIpHolderInstance}, nil) dummySharedIP := dummyIP - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), oldIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), oldIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), oldIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ @@ -472,10 +472,10 @@ func testCreateWithNoExistingIPHolderUsingNoSuffix(t *testing.T, mc *mocks.MockC mc.EXPECT().CreateInstance(gomock.Any(), gomock.Any()).Times(1).Return(&newIpHolderInstance, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), newIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ IPs: []string{dummySharedIP}, LinodeID: 11111, @@ -525,10 +525,10 @@ func testCreateWithNoExistingIPHolderUsingShortSuffix(t *testing.T, mc *mocks.Mo mc.EXPECT().CreateInstance(gomock.Any(), gomock.Any()).Times(1).Return(&newIpHolderInstance, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), newIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ IPs: []string{dummySharedIP}, LinodeID: 11111, @@ -578,10 +578,10 @@ func testCreateWithNoExistingIPHolderUsingLongSuffix(t *testing.T, mc *mocks.Moc mc.EXPECT().CreateInstance(gomock.Any(), gomock.Any()).Times(1).Return(&newIpHolderInstance, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), newIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ IPs: []string{dummySharedIP}, LinodeID: 11111, @@ -692,10 +692,10 @@ func testCiliumUpdateLoadBalancerAddNodeWithOldIpHolderNamingConvention(t *testi } mc.EXPECT().ListInstances(gomock.Any(), linodego.NewListOptions(1, string(rawFilter))).Times(1).Return([]linodego.Instance{oldIpHolderInstance}, nil) dummySharedIP := dummyIP - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), oldIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), oldIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), oldIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ @@ -719,7 +719,7 @@ func testCiliumUpdateLoadBalancerAddNodeWithOldIpHolderNamingConvention(t *testi mc.EXPECT().ListInstances(gomock.Any(), linodego.NewListOptions(1, string(rawFilter))).Times(1).Return([]linodego.Instance{oldIpHolderInstance}, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), oldIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ @@ -762,10 +762,10 @@ func testCiliumUpdateLoadBalancerAddNodeWithNewIpHolderNamingConvention(t *testi } mc.EXPECT().ListInstances(gomock.Any(), linodego.NewListOptions(1, string(rawFilter))).Times(1).Return([]linodego.Instance{newIpHolderInstance}, nil) dummySharedIP := dummyIP - mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, linodego.InstanceIPAddOptions{Public: true}).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), newIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ @@ -801,7 +801,7 @@ func testCiliumUpdateLoadBalancerAddNodeWithNewIpHolderNamingConvention(t *testi mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), newIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ IPv4: &linodego.InstanceIPv4Response{ - Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, + Public: []linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, }, }, nil) mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ diff --git a/cloud/linode/client/client.go b/cloud/linode/client/client.go index 70f98122..64b52d19 100644 --- a/cloud/linode/client/client.go +++ b/cloud/linode/client/client.go @@ -11,7 +11,7 @@ import ( "os" "time" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "k8s.io/klog/v2" _ "github.com/hexdigest/gowrap" @@ -33,7 +33,7 @@ type Client interface { ListInstanceConfigs(ctx context.Context, linodeID int, opts *linodego.ListOptions) ([]linodego.InstanceConfig, error) GetInstanceIPAddresses(context.Context, int) (*linodego.InstanceIPAddressResponse, error) - AddInstanceIPAddress(ctx context.Context, linodeID int, public bool) (*linodego.InstanceIP, error) + AddInstanceIPAddress(ctx context.Context, linodeID int, options linodego.InstanceIPAddOptions) (*linodego.InstanceIP, error) DeleteInstanceIPAddress(ctx context.Context, linodeID int, ipAddress string) error ShareIPAddresses(ctx context.Context, opts linodego.IPAddressesShareOptions) error @@ -67,7 +67,7 @@ type Client interface { CreateFirewall(ctx context.Context, opts linodego.FirewallCreateOptions) (*linodego.Firewall, error) DeleteFirewall(ctx context.Context, fwid int) error GetFirewall(context.Context, int) (*linodego.Firewall, error) - UpdateFirewallRules(context.Context, int, linodego.FirewallRuleSet) (*linodego.FirewallRuleSet, error) + UpdateFirewallRules(context.Context, int, linodego.FirewallRulesUpdateOptions) (*linodego.FirewallRules, error) ReserveIPAddress(ctx context.Context, opts linodego.ReserveIPOptions) (*linodego.InstanceIP, error) DeleteReservedIPAddress(ctx context.Context, ipAddress string) error @@ -97,6 +97,7 @@ func (t *tokenTransport) RoundTrip(req *http.Request) (*http.Response, error) { // New creates a new linode client with a given token and default timeout. func New(timeout time.Duration, tokenProvider TokenProvider) (*linodego.Client, error) { + var client *linodego.Client userAgent := fmt.Sprintf("linode-cloud-controller-manager %s", linodego.DefaultUserAgent) apiURL := os.Getenv("LINODE_URL") if apiURL == "" { @@ -108,8 +109,11 @@ func New(timeout time.Duration, tokenProvider TokenProvider) (*linodego.Client, tokenProvider: tokenProvider, } - linodeClient := linodego.NewClient(httpClient) - client, err := linodeClient.UseURL(apiURL) + linodeClient, err := linodego.NewClient(httpClient) + if err != nil { + return nil, err + } + client, err = linodeClient.UseURL(apiURL) if err != nil { return nil, err } diff --git a/cloud/linode/client/client_with_metrics.go b/cloud/linode/client/client_with_metrics.go index 80faf1fc..03fbdcc1 100644 --- a/cloud/linode/client/client_with_metrics.go +++ b/cloud/linode/client/client_with_metrics.go @@ -8,7 +8,7 @@ import ( "context" _ "github.com/hexdigest/gowrap" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" ) @@ -34,7 +34,7 @@ func NewClientWithPrometheus(base Client) ClientWithPrometheus { } // AddInstanceIPAddress implements Client -func (_d ClientWithPrometheus) AddInstanceIPAddress(ctx context.Context, linodeID int, public bool) (ip1 *linodego.InstanceIP, err error) { +func (_d ClientWithPrometheus) AddInstanceIPAddress(ctx context.Context, linodeID int, options linodego.InstanceIPAddOptions) (ip1 *linodego.InstanceIP, err error) { defer func() { result := "ok" if err != nil { @@ -43,7 +43,7 @@ func (_d ClientWithPrometheus) AddInstanceIPAddress(ctx context.Context, linodeI ClientMethodCounterVec.WithLabelValues("AddInstanceIPAddress", result).Inc() }() - return _d.base.AddInstanceIPAddress(ctx, linodeID, public) + return _d.base.AddInstanceIPAddress(ctx, linodeID, options) } // CreateFirewall implements Client @@ -476,7 +476,7 @@ func (_d ClientWithPrometheus) ShareIPAddresses(ctx context.Context, opts linode } // UpdateFirewallRules implements Client -func (_d ClientWithPrometheus) UpdateFirewallRules(ctx context.Context, i1 int, f1 linodego.FirewallRuleSet) (fp1 *linodego.FirewallRuleSet, err error) { +func (_d ClientWithPrometheus) UpdateFirewallRules(ctx context.Context, i1 int, f1 linodego.FirewallRulesUpdateOptions) (fp1 *linodego.FirewallRules, err error) { defer func() { result := "ok" if err != nil { diff --git a/cloud/linode/client/mocks/mock_client.go b/cloud/linode/client/mocks/mock_client.go index 374049a9..ba8b7cb4 100644 --- a/cloud/linode/client/mocks/mock_client.go +++ b/cloud/linode/client/mocks/mock_client.go @@ -9,7 +9,7 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - linodego "github.com/linode/linodego" + linodego "github.com/linode/linodego/v2" ) // MockClient is a mock of Client interface. @@ -36,7 +36,7 @@ func (m *MockClient) EXPECT() *MockClientMockRecorder { } // AddInstanceIPAddress mocks base method. -func (m *MockClient) AddInstanceIPAddress(arg0 context.Context, arg1 int, arg2 bool) (*linodego.InstanceIP, error) { +func (m *MockClient) AddInstanceIPAddress(arg0 context.Context, arg1 int, arg2 linodego.InstanceIPAddOptions) (*linodego.InstanceIP, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddInstanceIPAddress", arg0, arg1, arg2) ret0, _ := ret[0].(*linodego.InstanceIP) @@ -539,10 +539,10 @@ func (mr *MockClientMockRecorder) ShareIPAddresses(arg0, arg1 interface{}) *gomo } // UpdateFirewallRules mocks base method. -func (m *MockClient) UpdateFirewallRules(arg0 context.Context, arg1 int, arg2 linodego.FirewallRuleSet) (*linodego.FirewallRuleSet, error) { +func (m *MockClient) UpdateFirewallRules(arg0 context.Context, arg1 int, arg2 linodego.FirewallRulesUpdateOptions) (*linodego.FirewallRules, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateFirewallRules", arg0, arg1, arg2) - ret0, _ := ret[0].(*linodego.FirewallRuleSet) + ret0, _ := ret[0].(*linodego.FirewallRules) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/cloud/linode/fake_linode_test.go b/cloud/linode/fake_linode_test.go index 322da9ea..588b5f30 100644 --- a/cloud/linode/fake_linode_test.go +++ b/cloud/linode/fake_linode_test.go @@ -13,7 +13,7 @@ import ( "strings" "testing" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) const apiVersion = "v4" @@ -531,9 +531,15 @@ func (f *fakeAPI) setupRoutes() { } firewall := linodego.Firewall{ - ID: rand.Intn(9999), - Label: fco.Label, - Rules: fco.Rules, + ID: rand.Intn(9999), + Label: fco.Label, + Rules: linodego.FirewallRules{ + Inbound: fco.Rules.Inbound, + InboundPolicy: fco.Rules.InboundPolicy, + Outbound: fco.Rules.Outbound, + OutboundPolicy: fco.Rules.OutboundPolicy, + Version: 1, + }, Tags: fco.Tags, Status: "enabled", } @@ -735,7 +741,7 @@ func (f *fakeAPI) setupRoutes() { }) f.mux.HandleFunc("PUT /v4/networking/firewalls/{firewallID}/rules", func(w http.ResponseWriter, r *http.Request) { - fwrs := new(linodego.FirewallRuleSet) + fwrs := new(linodego.FirewallRulesUpdateOptions) if err := json.NewDecoder(r.Body).Decode(fwrs); err != nil { f.t.Fatal(err) } @@ -785,7 +791,7 @@ func (f *fakeAPI) setupRoutes() { nb.Label = nbuo.Label } if nbuo.Tags != nil { - nb.Tags = *nbuo.Tags + nb.Tags = nbuo.Tags } f.nb[strconv.Itoa(nb.ID)] = nb diff --git a/cloud/linode/health_check_test.go b/cloud/linode/health_check_test.go index b7e71972..c5f06da0 100644 --- a/cloud/linode/health_check_test.go +++ b/cloud/linode/health_check_test.go @@ -5,7 +5,7 @@ import ( "time" "github.com/golang/mock/gomock" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks" ) diff --git a/cloud/linode/loadbalancers.go b/cloud/linode/loadbalancers.go index 2750441b..99586f50 100644 --- a/cloud/linode/loadbalancers.go +++ b/cloud/linode/loadbalancers.go @@ -16,7 +16,7 @@ import ( "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1" ciliumclient "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -423,7 +423,7 @@ func (l *loadbalancers) updateNodeBalancer( tags := l.GetLoadBalancerTags(ctx, clusterName, service) if !reflect.DeepEqual(nb.Tags, tags) { update := nb.GetUpdateOptions() - update.Tags = &tags + update.Tags = tags nb, err = l.client.UpdateNodeBalancer(ctx, nb.ID, update) if err != nil { sentry.CaptureError(ctx, err) @@ -712,8 +712,7 @@ func (l *loadbalancers) getNodeBalancerByIP(ctx context.Context, service *v1.Ser frontendSubnetID := service.GetAnnotations()[annotations.NodeBalancerFrontendSubnetID] if frontendSubnetID != "" { for _, lb := range lbs { - if lb.FrontendAddressType != nil && *lb.FrontendAddressType == "vpc" && - lb.FrontendVPCSubnetID != nil && strconv.Itoa(*lb.FrontendVPCSubnetID) == frontendSubnetID { + if lb.FrontendAddressType == "vpc" && lb.FrontendVPCSubnetID != nil && strconv.Itoa(*lb.FrontendVPCSubnetID) == frontendSubnetID { return &lb, nil } } @@ -781,7 +780,7 @@ func (l *loadbalancers) GetLinodeNBType(service *v1.Service) linodego.NodeBalanc // 3. NodeBalancerBackendIPv4SubnetID/NodeBalancerBackendIPv4SubnetName flag // 4. NodeBalancerBackendIPv4Subnet flag // 5. Default to using the subnet ID of the service's VPC -func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Service) ([]linodego.NodeBalancerVPCOptions, error) { +func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Service) ([]linodego.NodeBalancerBackendVPCOptions, error) { // Evaluate subnetID based on annotations or flags subnetID, err := l.getSubnetIDForSVC(ctx, service) if err != nil { @@ -797,7 +796,7 @@ func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Ser // If the user has specified a NodeBalancerBackendIPv4Range, use that // for the NodeBalancer backend ipv4 range if backendIPv4Range != "" { - vpcCreateOpts := []linodego.NodeBalancerVPCOptions{ + vpcCreateOpts := []linodego.NodeBalancerBackendVPCOptions{ { SubnetID: subnetID, IPv4Range: backendIPv4Range, @@ -813,7 +812,7 @@ func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Ser _, vpcInAnnotation := service.GetAnnotations()[annotations.NodeBalancerBackendVPCName] _, subnetInAnnotation := service.GetAnnotations()[annotations.NodeBalancerBackendSubnetName] if vpcInAnnotation || subnetInAnnotation { - vpcCreateOpts := []linodego.NodeBalancerVPCOptions{ + vpcCreateOpts := []linodego.NodeBalancerBackendVPCOptions{ { SubnetID: subnetID, }, @@ -824,7 +823,7 @@ func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Ser // Precedence 3: If the user has specified a NodeBalancerBackendIPv4SubnetID, use that // and auto-allocate subnets from it for the NodeBalancer if options.Options.NodeBalancerBackendIPv4SubnetID != 0 { - vpcCreateOpts := []linodego.NodeBalancerVPCOptions{ + vpcCreateOpts := []linodego.NodeBalancerBackendVPCOptions{ { SubnetID: options.Options.NodeBalancerBackendIPv4SubnetID, }, @@ -835,7 +834,7 @@ func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Ser // Precedence 4: If the user has specified a NodeBalancerBackendIPv4Subnet, use that // and auto-allocate subnets from it for the NodeBalancer if options.Options.NodeBalancerBackendIPv4Subnet != "" { - vpcCreateOpts := []linodego.NodeBalancerVPCOptions{ + vpcCreateOpts := []linodego.NodeBalancerBackendVPCOptions{ { SubnetID: subnetID, IPv4Range: options.Options.NodeBalancerBackendIPv4Subnet, @@ -846,7 +845,7 @@ func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Ser } // Default to using the subnet ID of the service's VPC - vpcCreateOpts := []linodego.NodeBalancerVPCOptions{ + vpcCreateOpts := []linodego.NodeBalancerBackendVPCOptions{ { SubnetID: subnetID, }, @@ -859,7 +858,7 @@ func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Ser // 1. Frontend Subnet ID Annotation - Direct subnet ID // 2. Frontend VPC/Subnet Name Annotations - Resolve by name // 3. Frontend IPv4/IPv6 Range Annotations - Optional CIDR ranges -func (l *loadbalancers) getFrontendVPCCreateOptions(ctx context.Context, service *v1.Service) ([]linodego.NodeBalancerVPCOptions, error) { +func (l *loadbalancers) getFrontendVPCCreateOptions(ctx context.Context, service *v1.Service) ([]linodego.NodeBalancerFrontendVPCOptions, error) { frontendIPv4Range, hasIPv4Range := service.GetAnnotations()[annotations.NodeBalancerFrontendIPv4Range] frontendIPv6Range, hasIPv6Range := service.GetAnnotations()[annotations.NodeBalancerFrontendIPv6Range] vpcName, hasVPCName := service.GetAnnotations()[annotations.NodeBalancerFrontendVPCName] @@ -897,7 +896,7 @@ func (l *loadbalancers) getFrontendVPCCreateOptions(ctx context.Context, service return nil, fmt.Errorf("frontend VPC configuration requires either subnet-id or both vpc-name and subnet-name annotations") } - vpcCreateOpts := []linodego.NodeBalancerVPCOptions{ + vpcCreateOpts := []linodego.NodeBalancerFrontendVPCOptions{ { SubnetID: subnetID, IPv4Range: frontendIPv4Range, @@ -922,7 +921,7 @@ func (l *loadbalancers) getSubnetIDByVPCAndSubnetNames(ctx context.Context, vpcN return services.GetSubnetID(ctx, l.client, vpcID, subnetName) } -func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName string, service *v1.Service, configs []*linodego.NodeBalancerConfigCreateOptions) (lb *linodego.NodeBalancer, err error) { +func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName string, service *v1.Service, configs []linodego.NodeBalancerConfigCreateOptions) (lb *linodego.NodeBalancer, err error) { connThrottle := getConnectionThrottle(service) useIPv6Backends := resolveIPv6NodeBalancerBackendState(service) @@ -939,7 +938,7 @@ func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName stri } if !useIPv6Backends && len(options.Options.VPCNames) > 0 && !options.Options.DisableNodeBalancerVPCBackends { - createOpts.VPCs, err = l.getVPCCreateOptions(ctx, service) + createOpts.BackendVPCs, err = l.getVPCCreateOptions(ctx, service) if err != nil { return nil, err } @@ -1136,7 +1135,7 @@ func (l *loadbalancers) buildLoadBalancerRequest(ctx context.Context, clusterNam return nil, fmt.Errorf("%w: cluster %s, service %s", errNoNodesAvailable, clusterName, getServiceNn(service)) } ports := service.Spec.Ports - configs := make([]*linodego.NodeBalancerConfigCreateOptions, 0, len(ports)) + configs := make([]linodego.NodeBalancerConfigCreateOptions, 0, len(ports)) useIPv6Backends := resolveIPv6NodeBalancerBackendState(service) subnetID, err := l.getBackendSubnetID(ctx, service, useIPv6Backends) @@ -1160,7 +1159,7 @@ func (l *loadbalancers) buildLoadBalancerRequest(ctx context.Context, clusterNam createOpt.Nodes = append(createOpt.Nodes, newNodeOpts.NodeBalancerNodeCreateOptions) } - configs = append(configs, &createOpt) + configs = append(configs, createOpt) } return l.createNodeBalancer(ctx, clusterName, service, configs) } @@ -1489,7 +1488,7 @@ func makeLoadBalancerStatus(service *v1.Service, nb *linodego.NodeBalancer) *v1. } } - if nb.FrontendAddressType != nil && *nb.FrontendAddressType == "vpc" { + if nb.FrontendAddressType == "vpc" { klog.V(4).Infof("NodeBalancer (%d) is using frontend VPC address type", nb.ID) } diff --git a/cloud/linode/loadbalancers_helpers.go b/cloud/linode/loadbalancers_helpers.go index 72977240..46aea19b 100644 --- a/cloud/linode/loadbalancers_helpers.go +++ b/cloud/linode/loadbalancers_helpers.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" "github.com/linode/linode-cloud-controller-manager/cloud/annotations" diff --git a/cloud/linode/loadbalancers_test.go b/cloud/linode/loadbalancers_test.go index ffef68f0..571bcf88 100644 --- a/cloud/linode/loadbalancers_test.go +++ b/cloud/linode/loadbalancers_test.go @@ -20,7 +20,7 @@ import ( ciliumclient "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1" "github.com/golang/mock/gomock" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -327,7 +327,10 @@ func TestCCMLoadBalancers(t *testing.T) { fake := newFake(t) ts := httptest.NewServer(fake) - linodeClient := linodego.NewClient(http.DefaultClient) + linodeClient, err := linodego.NewClient(http.DefaultClient) + if err != nil { + t.Fatalf("error creating fake linode client: %v", err) + } linodeClient.SetBaseURL(ts.URL) t.Run(tc.name, func(t *testing.T) { @@ -1995,16 +1998,21 @@ func testUpdateLoadBalancerAddNewFirewall(t *testing.T, client *linodego.Client, fwClient := services.LinodeClient{Client: client} fw, err := fwClient.CreateFirewall(t.Context(), linodego.FirewallCreateOptions{ Label: "test", - Rules: linodego.FirewallRuleSet{Inbound: []linodego.FirewallRule{{ - Action: "ACCEPT", - Label: "inbound-rule123", - Description: "inbound rule123", - Ports: "4321", - Protocol: linodego.TCP, - Addresses: linodego.NetworkAddresses{ - IPv4: &[]string{"0.0.0.0/0"}, - }, - }}, Outbound: []linodego.FirewallRule{}, InboundPolicy: "ACCEPT", OutboundPolicy: "ACCEPT"}, + Rules: linodego.FirewallRulesCreateOptions{ + Inbound: []linodego.FirewallRuleInbound{{ + Action: "ACCEPT", + Label: "inbound-rule123", + Description: "inbound rule123", + Ports: "4321", + Protocol: linodego.TCP, + Addresses: linodego.NetworkAddresses{ + IPv4: []string{"0.0.0.0/0"}, + }, + }}, + Outbound: []linodego.FirewallRuleOutbound{}, + InboundPolicy: "ACCEPT", + OutboundPolicy: "ACCEPT", + }, }) if err != nil { t.Errorf("CreatingFirewall returned an error: %s", err) @@ -2364,16 +2372,21 @@ func testUpdateLoadBalancerUpdateFirewallRemoveACLaddID(t *testing.T, client *li fwClient := services.LinodeClient{Client: client} fw, err := fwClient.CreateFirewall(t.Context(), linodego.FirewallCreateOptions{ Label: "test", - Rules: linodego.FirewallRuleSet{Inbound: []linodego.FirewallRule{{ - Action: "ACCEPT", - Label: "inbound-rule123", - Description: "inbound rule123", - Ports: "4321", - Protocol: linodego.TCP, - Addresses: linodego.NetworkAddresses{ - IPv4: &[]string{"0.0.0.0/0"}, - }, - }}, Outbound: []linodego.FirewallRule{}, InboundPolicy: "ACCEPT", OutboundPolicy: "ACCEPT"}, + Rules: linodego.FirewallRulesCreateOptions{ + Inbound: []linodego.FirewallRuleInbound{{ + Action: "ACCEPT", + Label: "inbound-rule123", + Description: "inbound rule123", + Ports: "4321", + Protocol: linodego.TCP, + Addresses: linodego.NetworkAddresses{ + IPv4: []string{"0.0.0.0/0"}, + }, + }}, + Outbound: []linodego.FirewallRuleOutbound{}, + InboundPolicy: "ACCEPT", + OutboundPolicy: "ACCEPT", + }, }) if err != nil { t.Errorf("Error creating firewall %s", err) @@ -2462,16 +2475,21 @@ func testUpdateLoadBalancerUpdateFirewallRemoveIDaddACL(t *testing.T, client *li fwClient := services.LinodeClient{Client: client} fw, err := fwClient.CreateFirewall(t.Context(), linodego.FirewallCreateOptions{ Label: "test", - Rules: linodego.FirewallRuleSet{Inbound: []linodego.FirewallRule{{ - Action: "ACCEPT", - Label: "inbound-rule123", - Description: "inbound rule123", - Ports: "4321", - Protocol: linodego.TCP, - Addresses: linodego.NetworkAddresses{ - IPv4: &[]string{"0.0.0.0/0"}, - }, - }}, Outbound: []linodego.FirewallRule{}, InboundPolicy: "ACCEPT", OutboundPolicy: "ACCEPT"}, + Rules: linodego.FirewallRulesCreateOptions{ + Inbound: []linodego.FirewallRuleInbound{{ + Action: "ACCEPT", + Label: "inbound-rule123", + Description: "inbound rule123", + Ports: "4321", + Protocol: linodego.TCP, + Addresses: linodego.NetworkAddresses{ + IPv4: []string{"0.0.0.0/0"}, + }, + }}, + Outbound: []linodego.FirewallRuleOutbound{}, + InboundPolicy: "ACCEPT", + OutboundPolicy: "ACCEPT", + }, }) if err != nil { t.Errorf("Error creating firewall %s", err) @@ -2678,7 +2696,7 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie t.Errorf("expected non nil IPv4, got %v", fwIPs) } - if len(*fwIPs) != 2 { + if len(fwIPs) != 2 { t.Errorf("expected two IPv4 ips, got %v", fwIPs) } @@ -2686,7 +2704,7 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie t.Errorf("expected non nil IPv6, got %v", firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) } - if len(*firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) != 2 { + if len(firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) != 2 { t.Errorf("expected two IPv6 ips, got %v", firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) } @@ -2724,7 +2742,7 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie t.Errorf("expected non nil IPv4, got %v", fwIPs) } - if len(*fwIPs) != 2 { + if len(fwIPs) != 2 { t.Errorf("expected two IPv4 ips, got %v", fwIPs) } @@ -2732,7 +2750,7 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie t.Errorf("expected non nil IPv6, got %v", firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) } - if len(*firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) != 2 { + if len(firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) != 2 { t.Errorf("expected two IPv6 ips, got %v", firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) } @@ -2770,7 +2788,7 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie t.Errorf("expected non nil IPv4, got %v", fwIPs) } - if len(*fwIPs) != 1 { + if len(fwIPs) != 1 { t.Errorf("expected one IPv4, got %v", fwIPs) } @@ -2778,7 +2796,7 @@ func testUpdateLoadBalancerUpdateFirewallACL(t *testing.T, client *linodego.Clie t.Errorf("expected non nil IPv6, got %v", firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) } - if len(*firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) != 1 { + if len(firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) != 1 { t.Errorf("expected one IPv6, got %v", firewallsNew[0].Rules.Inbound[0].Addresses.IPv6) } @@ -2794,16 +2812,21 @@ func testUpdateLoadBalancerUpdateFirewall(t *testing.T, client *linodego.Client, firewallCreateOpts := linodego.FirewallCreateOptions{ Label: "test", - Rules: linodego.FirewallRuleSet{Inbound: []linodego.FirewallRule{{ - Action: "ACCEPT", - Label: "inbound-rule123", - Description: "inbound rule123", - Ports: "4321", - Protocol: linodego.TCP, - Addresses: linodego.NetworkAddresses{ - IPv4: &[]string{"0.0.0.0/0"}, - }, - }}, Outbound: []linodego.FirewallRule{}, InboundPolicy: "ACCEPT", OutboundPolicy: "ACCEPT"}, + Rules: linodego.FirewallRulesCreateOptions{ + Inbound: []linodego.FirewallRuleInbound{{ + Action: "ACCEPT", + Label: "inbound-rule123", + Description: "inbound rule123", + Ports: "4321", + Protocol: linodego.TCP, + Addresses: linodego.NetworkAddresses{ + IPv4: []string{"0.0.0.0/0"}, + }, + }}, + Outbound: []linodego.FirewallRuleOutbound{}, + InboundPolicy: "ACCEPT", + OutboundPolicy: "ACCEPT", + }, } svc := &v1.Service{ @@ -2932,16 +2955,21 @@ func testUpdateLoadBalancerDeleteFirewallRemoveID(t *testing.T, client *linodego firewallCreateOpts := linodego.FirewallCreateOptions{ Label: "test", - Rules: linodego.FirewallRuleSet{Inbound: []linodego.FirewallRule{{ - Action: "ACCEPT", - Label: "inbound-rule123", - Description: "inbound rule123", - Ports: "4321", - Protocol: linodego.TCP, - Addresses: linodego.NetworkAddresses{ - IPv4: &[]string{"0.0.0.0/0"}, - }, - }}, Outbound: []linodego.FirewallRule{}, InboundPolicy: "ACCEPT", OutboundPolicy: "ACCEPT"}, + Rules: linodego.FirewallRulesCreateOptions{ + Inbound: []linodego.FirewallRuleInbound{{ + Action: "ACCEPT", + Label: "inbound-rule123", + Description: "inbound rule123", + Ports: "4321", + Protocol: linodego.TCP, + Addresses: linodego.NetworkAddresses{ + IPv4: []string{"0.0.0.0/0"}, + }, + }}, + Outbound: []linodego.FirewallRuleOutbound{}, + InboundPolicy: "ACCEPT", + OutboundPolicy: "ACCEPT", + }, } svc := &v1.Service{ @@ -4326,7 +4354,10 @@ func Test_buildLoadBalancerRequestOmitsVPCConfigForIPv6Backends(t *testing.T) { ts := httptest.NewServer(fake) defer ts.Close() - client := linodego.NewClient(http.DefaultClient) + client, err := linodego.NewClient(http.DefaultClient) + if err != nil { + t.Fatal(err) + } client.SetBaseURL(ts.URL) lb, ok := newLoadbalancers(&client, "us-west").(*loadbalancers) if !ok { @@ -4384,7 +4415,7 @@ func Test_buildLoadBalancerRequestOmitsVPCConfigForIPv6Backends(t *testing.T) { }, } - _, err := lb.buildLoadBalancerRequest(t.Context(), "linodelb", svc, nodes) + _, err = lb.buildLoadBalancerRequest(t.Context(), "linodelb", svc, nodes) if err != nil { t.Fatal(err) } @@ -4404,8 +4435,8 @@ func Test_buildLoadBalancerRequestOmitsVPCConfigForIPv6Backends(t *testing.T) { if err := json.Unmarshal([]byte(req.Body), &createOpts); err != nil { t.Fatalf("unable to unmarshal create request body %#v, error: %#v", req.Body, err) } - if len(createOpts.VPCs) != 0 { - t.Fatalf("expected nodebalancer create request to omit VPC config for IPv6 backends, got %#v", createOpts.VPCs) + if len(createOpts.BackendVPCs) != 0 { + t.Fatalf("expected nodebalancer create request to omit VPC config for IPv6 backends, got %#v", createOpts.BackendVPCs) } if len(createOpts.Configs) != 1 || len(createOpts.Configs[0].Nodes) != 1 { t.Fatalf("expected a single nodebalancer config with one backend node, got %#v", createOpts.Configs) @@ -4611,7 +4642,7 @@ func testEnsureLoadBalancerPreserveAnnotation(t *testing.T, client *linodego.Cli Spec: testServiceSpec, } - nb, err := lb.createNodeBalancer(t.Context(), "linodelb", svc, []*linodego.NodeBalancerConfigCreateOptions{}) + nb, err := lb.createNodeBalancer(t.Context(), "linodelb", svc, []linodego.NodeBalancerConfigCreateOptions{}) if err != nil { t.Fatal(err) } @@ -4697,7 +4728,7 @@ func testEnsureLoadBalancerDeleted(t *testing.T, client *linodego.Client, fake * if !assertion { t.Error("type assertion failed") } - configs := []*linodego.NodeBalancerConfigCreateOptions{} + configs := []linodego.NodeBalancerConfigCreateOptions{} _, err := lb.createNodeBalancer(t.Context(), "linodelb", svc, configs) if err != nil { t.Fatal(err) @@ -4753,7 +4784,7 @@ func testEnsureExistingLoadBalancer(t *testing.T, client *linodego.Client, _ *fa lb.kubeClient = fake.NewClientset() addTLSSecret(t, lb.kubeClient) - configs := []*linodego.NodeBalancerConfigCreateOptions{} + configs := []linodego.NodeBalancerConfigCreateOptions{} nb, err := lb.createNodeBalancer(t.Context(), "linodelb", svc, configs) if err != nil { t.Fatal(err) @@ -5172,7 +5203,7 @@ func testGetNodeBalancerByStatus(t *testing.T, client *linodego.Client, _ *fakeA }, } { t.Run(test.name, func(t *testing.T) { - expectedNB, err := lb.createNodeBalancer(t.Context(), "linodelb", test.service, []*linodego.NodeBalancerConfigCreateOptions{}) + expectedNB, err := lb.createNodeBalancer(t.Context(), "linodelb", test.service, []linodego.NodeBalancerConfigCreateOptions{}) if err != nil { t.Fatal(err) } @@ -5421,7 +5452,7 @@ func testGetLoadBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) { }, } - configs := []*linodego.NodeBalancerConfigCreateOptions{} + configs := []linodego.NodeBalancerConfigCreateOptions{} nb, err := lb.createNodeBalancer(t.Context(), "linodelb", svc, configs) if err != nil { t.Fatal(err) @@ -5919,7 +5950,7 @@ func Test_makeLoadBalancerStatus_FrontendVPC(t *testing.T) { Hostname: &[]string{"nb-123.example.com"}[0], IPv4: &[]string{"10.100.5.10"}[0], IPv6: nil, - FrontendAddressType: &[]string{"vpc"}[0], + FrontendAddressType: linodego.NodeBalancerVPCFrontendAddressTypeVPC, }, }, want: &v1.LoadBalancerStatus{ @@ -5946,7 +5977,7 @@ func Test_makeLoadBalancerStatus_FrontendVPC(t *testing.T) { Hostname: &[]string{"nb-123.example.com"}[0], IPv4: &[]string{"10.100.5.10"}[0], IPv6: &[]string{"2001:db80:1005::10"}[0], - FrontendAddressType: &[]string{"vpc"}[0], + FrontendAddressType: linodego.NodeBalancerVPCFrontendAddressTypeVPC, }, }, want: &v1.LoadBalancerStatus{ @@ -5981,7 +6012,7 @@ func Test_getFrontendVPCCreateOptions(t *testing.T) { tests := []struct { name string args args - want []linodego.NodeBalancerVPCOptions + want []linodego.NodeBalancerFrontendVPCOptions wantErr bool prepareMock func(*mocks.MockClient) }{ @@ -6008,7 +6039,7 @@ func Test_getFrontendVPCCreateOptions(t *testing.T) { }, }, }, - want: []linodego.NodeBalancerVPCOptions{ + want: []linodego.NodeBalancerFrontendVPCOptions{ { SubnetID: 123, }, @@ -6027,7 +6058,7 @@ func Test_getFrontendVPCCreateOptions(t *testing.T) { }, }, }, - want: []linodego.NodeBalancerVPCOptions{ + want: []linodego.NodeBalancerFrontendVPCOptions{ { SubnetID: 123, IPv4Range: "10.100.5.0/24", @@ -6047,7 +6078,7 @@ func Test_getFrontendVPCCreateOptions(t *testing.T) { }, }, }, - want: []linodego.NodeBalancerVPCOptions{ + want: []linodego.NodeBalancerFrontendVPCOptions{ { SubnetID: 123, IPv6Range: "2001:db80:1005::/48", @@ -6123,7 +6154,7 @@ func Test_getFrontendVPCCreateOptions(t *testing.T) { }, }, }, - want: []linodego.NodeBalancerVPCOptions{ + want: []linodego.NodeBalancerFrontendVPCOptions{ { SubnetID: 456, }, @@ -6147,7 +6178,7 @@ func Test_getFrontendVPCCreateOptions(t *testing.T) { }, }, }, - want: []linodego.NodeBalancerVPCOptions{ + want: []linodego.NodeBalancerFrontendVPCOptions{ { SubnetID: 123, }, diff --git a/cloud/linode/node_controller.go b/cloud/linode/node_controller.go index 4a5326f7..845c2fb4 100644 --- a/cloud/linode/node_controller.go +++ b/cloud/linode/node_controller.go @@ -10,7 +10,7 @@ import ( "time" "github.com/appscode/go/wait" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1informers "k8s.io/client-go/informers/core/v1" diff --git a/cloud/linode/node_controller_test.go b/cloud/linode/node_controller_test.go index 0932d9df..fa8e8494 100644 --- a/cloud/linode/node_controller_test.go +++ b/cloud/linode/node_controller_test.go @@ -8,7 +8,7 @@ import ( "time" "github.com/golang/mock/gomock" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" @@ -117,7 +117,7 @@ func TestNodeController_processNext(t *testing.T) { publicIP := net.ParseIP("172.234.31.123") privateIP := net.ParseIP("192.168.159.135") client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{ - {ID: 111, Label: "test", IPv4: []*net.IP{&publicIP, &privateIP}, HostUUID: "111"}, + {ID: 111, Label: "test", IPv4: []net.IP{publicIP, privateIP}, HostUUID: "111"}, }, nil) result := controller.processNext() assert.True(t, result, "processNext should return true") @@ -145,7 +145,7 @@ func TestNodeController_processNext(t *testing.T) { publicIP := net.ParseIP("172.234.31.123") privateIP := net.ParseIP("192.168.159.135") client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{ - {ID: 112, Label: "test-node2", IPv4: []*net.IP{&publicIP, &privateIP}, HostUUID: "112"}, + {ID: 112, Label: "test-node2", IPv4: []net.IP{publicIP, privateIP}, HostUUID: "112"}, }, nil) result := controller.processNext() assert.True(t, result, "processNext should return true") @@ -230,7 +230,7 @@ func TestNodeController_handleNode(t *testing.T) { privateIP := net.ParseIP("192.168.159.135") publicIPv6SLAAC := "2001:db::f03c:91ff:fe2b:1a2b" client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{ - {ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"}, + {ID: 123, Label: "test-node", IPv4: []net.IP{publicIP, privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"}, }, nil) err = nodeCtrl.handleNode(t.Context(), node) require.NoError(t, err, "expected no error during handleNode") @@ -261,7 +261,7 @@ func TestNodeController_handleNode(t *testing.T) { nodeCtrl.instances = services.NewInstances(client) nodeCtrl.metadataLastUpdate["test-node"] = time.Now().Add(-2 * nodeCtrl.ttl) client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{ - {ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"}, + {ID: 123, Label: "test-node", IPv4: []net.IP{publicIP, privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"}, }, nil) err = nodeCtrl.handleNode(t.Context(), node) assert.NoError(t, err, "expected no error during handleNode") diff --git a/cloud/linode/route_controller.go b/cloud/linode/route_controller.go index 8d577868..a4d25e2b 100644 --- a/cloud/linode/route_controller.go +++ b/cloud/linode/route_controller.go @@ -10,7 +10,7 @@ import ( "sync" "time" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -246,7 +246,7 @@ func (r *routes) handleInterfaces(ctx context.Context, intfRoutes []string, lino if instance.InterfaceGeneration == linodego.GenerationLinode { interfaceUpdateOptions := linodego.LinodeInterfaceUpdateOptions{ VPC: &linodego.VPCInterfaceUpdateOptions{ - IPv4: &linodego.VPCInterfaceIPv4CreateOptions{Ranges: &linodeInterfaceRoutes}, + IPv4: &linodego.VPCInterfaceIPv4CreateOptions{Ranges: linodeInterfaceRoutes}, }, } resp, err := r.client.UpdateInterface(ctx, instance.ID, intfVPCIP.InterfaceID, interfaceUpdateOptions) @@ -261,7 +261,7 @@ func (r *routes) handleInterfaces(ctx context.Context, intfRoutes []string, lino klog.V(4).Infof("Updated routes for node %s. Current routes: %v", route.TargetNode, resp.VPC.IPv4.Ranges) } else { interfaceUpdateOptions := linodego.InstanceConfigInterfaceUpdateOptions{ - IPRanges: &intfRoutes, + IPRanges: intfRoutes, } resp, err := r.client.UpdateInstanceConfigInterface(ctx, instance.ID, intfVPCIP.ConfigID, intfVPCIP.InterfaceID, interfaceUpdateOptions) if err != nil { diff --git a/cloud/linode/route_controller_test.go b/cloud/linode/route_controller_test.go index bf2bf894..6824db2a 100644 --- a/cloud/linode/route_controller_test.go +++ b/cloud/linode/route_controller_test.go @@ -6,8 +6,7 @@ import ( "testing" "github.com/golang/mock/gomock" - linodeClient "github.com/linode/linode-cloud-controller-manager/cloud/linode/client" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" @@ -16,6 +15,7 @@ import ( cloudprovider "k8s.io/cloud-provider" "k8s.io/utils/ptr" + linodeClient "github.com/linode/linode-cloud-controller-manager/cloud/linode/client" "github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks" "github.com/linode/linode-cloud-controller-manager/cloud/linode/options" "github.com/linode/linode-cloud-controller-manager/cloud/linode/services" @@ -67,7 +67,7 @@ func TestListRoutes(t *testing.T) { Label: name, Type: linodeType, Region: region, - IPv4: []*net.IP{&publicIPv4, &privateIPv4}, + IPv4: []net.IP{publicIPv4, privateIPv4}, } t.Run("should return no routes if instance exists but is not connected to VPC", func(t *testing.T) { @@ -242,14 +242,14 @@ func TestListRoutes(t *testing.T) { Label: instance2Label, Type: linodeType, Region: region, - IPv4: []*net.IP{&publicIPv4, &privateIPv4}, + IPv4: []net.IP{publicIPv4, privateIPv4}, } validInstance3 := linodego.Instance{ ID: instance3ID, Label: instance3Label, Type: linodeType, Region: region, - IPv4: []*net.IP{&publicIPv4, &privateIPv4}, + IPv4: []net.IP{publicIPv4, privateIPv4}, } routesInVPC2 := []linodego.VPCIP{ @@ -347,7 +347,7 @@ func TestCreateRoute(t *testing.T) { Label: name, Type: linodeType, Region: region, - IPv4: []*net.IP{&publicIPv4, &privateIPv4}, + IPv4: []net.IP{publicIPv4, privateIPv4}, } vpcIP := "10.0.0.2" @@ -527,7 +527,7 @@ func TestDeleteRoute(t *testing.T) { Label: name, Type: linodeType, Region: region, - IPv4: []*net.IP{&publicIPv4, &privateIPv4}, + IPv4: []net.IP{publicIPv4, privateIPv4}, } vpcIP := "10.0.0.2" diff --git a/cloud/linode/service_controller.go b/cloud/linode/service_controller.go index ef909428..76bd1f9f 100644 --- a/cloud/linode/service_controller.go +++ b/cloud/linode/service_controller.go @@ -8,7 +8,7 @@ import ( "time" "github.com/appscode/go/wait" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" v1informers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/tools/cache" diff --git a/cloud/linode/services/firewalls.go b/cloud/linode/services/firewalls.go index 0ca36a9a..a15f556f 100644 --- a/cloud/linode/services/firewalls.go +++ b/cloud/linode/services/firewalls.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "golang.org/x/exp/slices" v1 "k8s.io/api/core/v1" "k8s.io/klog/v2" @@ -85,7 +85,7 @@ func (l *LinodeClient) DeleteNodeBalancerFirewall( return nil } -func ipsChanged(ips *linodego.NetworkAddresses, rules []linodego.FirewallRule) bool { +func ipsChanged(ips *linodego.NetworkAddresses, rules []linodego.FirewallRuleInbound) bool { if ips == nil { return false } @@ -95,10 +95,10 @@ func ipsChanged(ips *linodego.NetworkAddresses, rules []linodego.FirewallRule) b for _, rule := range rules { if rule.Addresses.IPv4 != nil { - ruleIPv4s = append(ruleIPv4s, *rule.Addresses.IPv4...) + ruleIPv4s = append(ruleIPv4s, rule.Addresses.IPv4...) } if rule.Addresses.IPv6 != nil { - ruleIPv6s = append(ruleIPv6s, *rule.Addresses.IPv6...) + ruleIPv6s = append(ruleIPv6s, rule.Addresses.IPv6...) } } @@ -111,10 +111,10 @@ func ipsChanged(ips *linodego.NetworkAddresses, rules []linodego.FirewallRule) b } if ips.IPv4 != nil { - if len(*ips.IPv4) != len(ruleIPv4s) { + if len(ips.IPv4) != len(ruleIPv4s) { return true } - for _, ipv4 := range *ips.IPv4 { + for _, ipv4 := range ips.IPv4 { if !slices.Contains(ruleIPv4s, ipv4) { return true } @@ -122,10 +122,10 @@ func ipsChanged(ips *linodego.NetworkAddresses, rules []linodego.FirewallRule) b } if ips.IPv6 != nil { - if len(*ips.IPv6) != len(ruleIPv6s) { + if len(ips.IPv6) != len(ruleIPv6s) { return true } - for _, ipv6 := range *ips.IPv6 { + for _, ipv6 := range ips.IPv6 { if !slices.Contains(ruleIPv6s, ipv6) { return true } @@ -170,7 +170,7 @@ func parsePorts(ports string) ([]int32, error) { return result, nil } -func isPortsChanged(rules []linodego.FirewallRule, service *v1.Service) bool { +func isPortsChanged(rules []linodego.FirewallRuleInbound, service *v1.Service) bool { // Service has at least one port, so we can check if there are any rules in firewall // We only care about the first rule, as all rules should have same ports if len(rules) == 0 { @@ -216,7 +216,7 @@ func isPortsChanged(rules []linodego.FirewallRule, service *v1.Service) bool { // ruleChanged takes an old FirewallRuleSet and new aclConfig and returns if // the IPs of the FirewallRuleSet would be changed with the new ACL Config -func ruleChanged(old linodego.FirewallRuleSet, newACL aclConfig, service *v1.Service) bool { +func ruleChanged(old linodego.FirewallRules, newACL aclConfig, service *v1.Service) bool { var ips *linodego.NetworkAddresses if newACL.AllowList != nil { // this is a allowList, this means that the rules should have `DROP` as inboundpolicy @@ -292,10 +292,10 @@ func processACL(fwcreateOpts *linodego.FirewallCreateOptions, aclType, label, sv // Linode has a limitation of firewall rules with a max of 255 IPs per rule var ipv4s, ipv6s []string // doing this to avoid dereferencing a nil pointer if ips.IPv6 != nil { - ipv6s = *ips.IPv6 + ipv6s = ips.IPv6 } if ips.IPv4 != nil { - ipv4s = *ips.IPv4 + ipv4s = ips.IPv4 } if len(ipv4s)+len(ipv6s) > maxIPsPerFirewall { @@ -303,13 +303,13 @@ func processACL(fwcreateOpts *linodego.FirewallCreateOptions, aclType, label, sv for i, chunk := range ipv4chunks { v4chunk := chunk desc := fmt.Sprintf("Rule %d, Created by linode-ccm: %s, for %s", i, label, svcName) - fwcreateOpts.Rules.Inbound = append(fwcreateOpts.Rules.Inbound, linodego.FirewallRule{ + fwcreateOpts.Rules.Inbound = append(fwcreateOpts.Rules.Inbound, linodego.FirewallRuleInbound{ Action: aclType, Label: ruleLabel, Description: truncateFWRuleDesc(desc), Protocol: linodego.TCP, // Nodebalancers support only TCP. Ports: ports, - Addresses: linodego.NetworkAddresses{IPv4: &v4chunk}, + Addresses: linodego.NetworkAddresses{IPv4: v4chunk}, }) } @@ -317,18 +317,18 @@ func processACL(fwcreateOpts *linodego.FirewallCreateOptions, aclType, label, sv for i, chunk := range ipv6chunks { v6chunk := chunk desc := fmt.Sprintf("Rule %d, Created by linode-ccm: %s, for %s", i, label, svcName) - fwcreateOpts.Rules.Inbound = append(fwcreateOpts.Rules.Inbound, linodego.FirewallRule{ + fwcreateOpts.Rules.Inbound = append(fwcreateOpts.Rules.Inbound, linodego.FirewallRuleInbound{ Action: aclType, Label: ruleLabel, Description: truncateFWRuleDesc(desc), Protocol: linodego.TCP, // Nodebalancers support only TCP. Ports: ports, - Addresses: linodego.NetworkAddresses{IPv6: &v6chunk}, + Addresses: linodego.NetworkAddresses{IPv6: v6chunk}, }) } } else { desc := fmt.Sprintf("Created by linode-ccm: %s, for %s", label, svcName) - fwcreateOpts.Rules.Inbound = append(fwcreateOpts.Rules.Inbound, linodego.FirewallRule{ + fwcreateOpts.Rules.Inbound = append(fwcreateOpts.Rules.Inbound, linodego.FirewallRuleInbound{ Action: aclType, Label: ruleLabel, Description: truncateFWRuleDesc(desc), @@ -557,7 +557,12 @@ func (l *LinodeClient) updateNodeBalancerFirewallWithACL( if err != nil { return err } - if _, err = l.Client.UpdateFirewallRules(ctx, firewalls[0].ID, fwCreateOpts.Rules); err != nil { + if _, err = l.Client.UpdateFirewallRules(ctx, firewalls[0].ID, linodego.FirewallRulesUpdateOptions{ + Inbound: fwCreateOpts.Rules.Inbound, + InboundPolicy: fwCreateOpts.Rules.InboundPolicy, + Outbound: fwCreateOpts.Rules.Outbound, + OutboundPolicy: fwCreateOpts.Rules.OutboundPolicy, + }); err != nil { return err } } diff --git a/cloud/linode/services/firewalls_test.go b/cloud/linode/services/firewalls_test.go index ce3acc90..44c39b1e 100644 --- a/cloud/linode/services/firewalls_test.go +++ b/cloud/linode/services/firewalls_test.go @@ -4,21 +4,21 @@ import ( "reflect" "testing" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" ) // makeOldRuleSet constructs a FirewallRuleSet with the given IPs, ports string, and policy. -func makeOldRuleSet(ipList []string, ports string, policy string) linodego.FirewallRuleSet { - ips := linodego.NetworkAddresses{IPv4: &ipList} - rule := linodego.FirewallRule{ +func makeOldRuleSet(ipList []string, ports string, policy string) linodego.FirewallRules { + ips := linodego.NetworkAddresses{IPv4: ipList} + rule := linodego.FirewallRuleInbound{ Protocol: "TCP", Ports: ports, Addresses: ips, } - return linodego.FirewallRuleSet{ + return linodego.FirewallRules{ InboundPolicy: policy, - Inbound: []linodego.FirewallRule{rule}, + Inbound: []linodego.FirewallRuleInbound{rule}, } } @@ -37,7 +37,7 @@ func TestRuleChanged(t *testing.T) { oldIPs: []string{"1.2.3.4/32"}, oldPorts: "80,8080", policy: drop, - newACL: aclConfig{AllowList: &linodego.NetworkAddresses{IPv4: &[]string{"1.2.3.4/32"}}}, + newACL: aclConfig{AllowList: &linodego.NetworkAddresses{IPv4: []string{"1.2.3.4/32"}}}, svcPorts: []int32{80, 8080}, wantChange: false, }, @@ -46,7 +46,7 @@ func TestRuleChanged(t *testing.T) { oldIPs: []string{"1.2.3.4/32"}, oldPorts: "80", policy: drop, - newACL: aclConfig{AllowList: &linodego.NetworkAddresses{IPv4: &[]string{"5.6.7.8/32"}}}, + newACL: aclConfig{AllowList: &linodego.NetworkAddresses{IPv4: []string{"5.6.7.8/32"}}}, svcPorts: []int32{80}, wantChange: true, }, @@ -55,7 +55,7 @@ func TestRuleChanged(t *testing.T) { oldIPs: []string{"1.2.3.4/32"}, oldPorts: "80", policy: drop, - newACL: aclConfig{AllowList: &linodego.NetworkAddresses{IPv4: &[]string{"1.2.3.4/32"}}}, + newACL: aclConfig{AllowList: &linodego.NetworkAddresses{IPv4: []string{"1.2.3.4/32"}}}, svcPorts: []int32{80, 8080}, wantChange: true, }, diff --git a/cloud/linode/services/instances.go b/cloud/linode/services/instances.go index 8fe135ec..ae36816a 100644 --- a/cloud/linode/services/instances.go +++ b/cloud/linode/services/instances.go @@ -11,7 +11,7 @@ import ( "sync" "time" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" cloudprovider "k8s.io/cloud-provider" diff --git a/cloud/linode/services/instances_test.go b/cloud/linode/services/instances_test.go index 814fa424..48c26fcd 100644 --- a/cloud/linode/services/instances_test.go +++ b/cloud/linode/services/instances_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" @@ -98,8 +98,8 @@ func TestMetadataRetrieval(t *testing.T) { instances := NewInstances(client) publicIP := net.ParseIP("172.234.31.123") privateIP := net.ParseIP("192.168.159.135") - expectedInstance := linodego.Instance{Label: "expected-instance", ID: 12345, IPv4: []*net.IP{&publicIP, &privateIP}} - client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{{Label: "wrong-instance", ID: 3456, IPv4: []*net.IP{&publicIP, &privateIP}}, expectedInstance}, nil) + expectedInstance := linodego.Instance{Label: "expected-instance", ID: 12345, IPv4: []net.IP{publicIP, privateIP}} + client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{{Label: "wrong-instance", ID: 3456, IPv4: []net.IP{publicIP, privateIP}}, expectedInstance}, nil) name := "expected-instance" node := nodeWithName(name) @@ -129,7 +129,7 @@ func TestMetadataRetrieval(t *testing.T) { linodeType := typeG6 region := usEast client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{ - {ID: id, Label: instanceName, Type: linodeType, Region: region, IPv4: []*net.IP{&publicIPv4, &privateIPv4}}, + {ID: id, Label: instanceName, Type: linodeType, Region: region, IPv4: []net.IP{publicIPv4, privateIPv4}}, }, nil) meta, err := instances.InstanceMetadata(ctx, node) @@ -172,7 +172,7 @@ func TestMetadataRetrieval(t *testing.T) { Label: instanceName, Type: linodeType, Region: usEast, - IPv4: []*net.IP{&publicIPv4, &privateIPv4}, + IPv4: []net.IP{publicIPv4, privateIPv4}, IPv6: ipv6Addr, } vpcIP := "10.0.0.2" @@ -351,13 +351,13 @@ func TestMetadataRetrieval(t *testing.T) { if test.existingAddresses != nil { node.Status.Addresses = append(node.Status.Addresses, test.existingAddresses...) } - ips := make([]*net.IP, 0, len(test.inputIPv4s)) + ips := make([]net.IP, 0, len(test.inputIPv4s)) for _, ip := range test.inputIPv4s { parsed := net.ParseIP(ip) if parsed == nil { t.Fatalf("cannot parse %v as an ipv4", ip) } - ips = append(ips, &parsed) + ips = append(ips, parsed) } linodeType := typeG6 @@ -426,12 +426,12 @@ func TestMetadataRetrieval(t *testing.T) { publicIP := net.ParseIP("172.234.31.123") privateIP := net.ParseIP("192.168.159.135") wrongIP := net.ParseIP("1.2.3.4") - expectedInstance := linodego.Instance{Label: "expected-instance", ID: 12345, IPv4: []*net.IP{&publicIP, &privateIP}} + expectedInstance := linodego.Instance{Label: "expected-instance", ID: 12345, IPv4: []net.IP{publicIP, privateIP}} for _, test := range getByIPTests { t.Run(fmt.Sprintf("gets linode by IP - %s", test.name), func(t *testing.T) { instances := NewInstances(client) - client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{{ID: 3456, IPv4: []*net.IP{&wrongIP}}, expectedInstance}, nil) + client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{{ID: 3456, IPv4: []net.IP{wrongIP}}, expectedInstance}, nil) node := v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "test-node-1"}, Status: v1.NodeStatus{Addresses: test.nodeAddresses}} meta, err := instances.InstanceMetadata(ctx, &node) if test.expectedErr != nil { diff --git a/cloud/linode/services/vpc.go b/cloud/linode/services/vpc.go index cf74d31a..a93081e8 100644 --- a/cloud/linode/services/vpc.go +++ b/cloud/linode/services/vpc.go @@ -9,7 +9,7 @@ import ( "strings" "sync" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "k8s.io/klog/v2" "github.com/linode/linode-cloud-controller-manager/cloud/linode/client" diff --git a/cloud/linode/services/vpc_test.go b/cloud/linode/services/vpc_test.go index 88f9dc62..73f9fb82 100644 --- a/cloud/linode/services/vpc_test.go +++ b/cloud/linode/services/vpc_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/cloud/linode/utils/common.go b/cloud/linode/utils/common.go index f4db8962..bb8f97b0 100644 --- a/cloud/linode/utils/common.go +++ b/cloud/linode/utils/common.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) const ( @@ -47,10 +47,10 @@ func IgnoreLinodeAPIError(err error, code int) error { return err } -func IsPrivate(ip *net.IP, linodeExternalNetwork *net.IPNet) bool { +func IsPrivate(ip net.IP, linodeExternalNetwork *net.IPNet) bool { if linodeExternalNetwork == nil { return ip.IsPrivate() } - return ip.IsPrivate() && !linodeExternalNetwork.Contains(*ip) + return ip.IsPrivate() && !linodeExternalNetwork.Contains(ip) } diff --git a/cloud/linode/utils/common_test.go b/cloud/linode/utils/common_test.go index 16827de8..edfa54ff 100644 --- a/cloud/linode/utils/common_test.go +++ b/cloud/linode/utils/common_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" ) func TestParseProviderID(t *testing.T) { diff --git a/cloud/nodeipam/ipam/cloud_allocator.go b/cloud/nodeipam/ipam/cloud_allocator.go index 682d35cb..15138806 100644 --- a/cloud/nodeipam/ipam/cloud_allocator.go +++ b/cloud/nodeipam/ipam/cloud_allocator.go @@ -24,7 +24,7 @@ import ( "strings" "time" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" diff --git a/cloud/nodeipam/ipam/cloud_allocator_test.go b/cloud/nodeipam/ipam/cloud_allocator_test.go index 39a4de19..485be40d 100644 --- a/cloud/nodeipam/ipam/cloud_allocator_test.go +++ b/cloud/nodeipam/ipam/cloud_allocator_test.go @@ -26,7 +26,7 @@ import ( "github.com/appscode/go/wait" "github.com/golang/mock/gomock" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" diff --git a/go.mod b/go.mod index 443f8cd3..30a4aa4d 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/golang/mock v1.6.0 github.com/google/uuid v1.6.0 github.com/hexdigest/gowrap v1.4.3 - github.com/linode/linodego v1.58.0 + github.com/linode/linodego/v2 v2.3.0 github.com/prometheus/client_golang v1.23.2 github.com/spf13/pflag v1.0.10 github.com/stretchr/testify v1.11.1 @@ -63,7 +63,6 @@ require ( github.com/go-openapi/strfmt v0.23.0 // indirect github.com/go-openapi/swag v0.23.1 // indirect github.com/go-openapi/validate v0.24.0 // indirect - github.com/go-resty/resty/v2 v2.17.1 // indirect github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect @@ -72,7 +71,7 @@ require ( github.com/google/cel-go v0.26.0 // indirect github.com/google/gnostic-models v0.7.0 // indirect github.com/google/go-cmp v0.7.0 // indirect - github.com/google/go-querystring v1.1.0 // indirect + github.com/google/go-querystring v1.2.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 // indirect github.com/huandu/xstrings v1.3.2 // indirect @@ -140,7 +139,7 @@ require ( golang.org/x/crypto v0.52.0 // indirect golang.org/x/mod v0.36.0 // indirect golang.org/x/net v0.55.0 // indirect - golang.org/x/oauth2 v0.34.0 // indirect + golang.org/x/oauth2 v0.36.0 // indirect golang.org/x/sync v0.20.0 // indirect golang.org/x/sys v0.45.0 // indirect golang.org/x/term v0.43.0 // indirect @@ -153,7 +152,7 @@ require ( google.golang.org/protobuf v1.36.10 // indirect gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/ini.v1 v1.67.2 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.35.2 // indirect @@ -170,7 +169,7 @@ require ( ) replace ( - github.com/linode/linodego => github.com/linode/linodego v1.64.1-0.20260110062643-8a0a88cf96c9 + github.com/linode/linodego/v2 => github.com/linode/linodego/v2 v2.0.0-20260601073839-52f201e73a60 k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.35.4 k8s.io/cri-api => k8s.io/cri-api v0.35.4 k8s.io/cri-client => k8s.io/cri-client v0.35.4 diff --git a/go.sum b/go.sum index edf0330d..70e82e09 100644 --- a/go.sum +++ b/go.sum @@ -110,8 +110,6 @@ github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3Bum github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ= github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6 h1:teYtXy9B7y5lHTp8V9KPxpYRAVA7dozigQcMiBust1s= github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6/go.mod h1:p4lGIVX+8Wa6ZPNDvqcxq36XpUDLh42FLetFU7odllI= -github.com/go-resty/resty/v2 v2.17.1 h1:x3aMpHK1YM9e4va/TMDRlusDDoZiQ+ViDu/WpA6xTM4= -github.com/go-resty/resty/v2 v2.17.1/go.mod h1:kCKZ3wWmwJaNc7S29BRtUhJwy7iqmn+2mLtQrOyQlVA= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= @@ -137,12 +135,12 @@ github.com/google/cel-go v0.26.0 h1:DPGjXackMpJWH680oGY4lZhYjIameYmR+/6RBdDGmaI= github.com/google/cel-go v0.26.0/go.mod h1:A9O8OU9rdvrK5MQyrqfIxo1a0u4g3sF8KB6PUIaryMM= github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo= github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= -github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0= +github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8= github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= @@ -194,8 +192,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= -github.com/linode/linodego v1.64.1-0.20260110062643-8a0a88cf96c9 h1:Ts0FMJueIIazA3dYfRU9ZeeXCklWLDMIzT282dlx2Kg= -github.com/linode/linodego v1.64.1-0.20260110062643-8a0a88cf96c9/go.mod h1:GoiwLVuLdBQcAebxAVKVL3mMYUgJZR/puOUSla04xBE= +github.com/linode/linodego/v2 v2.0.0-20260601073839-52f201e73a60 h1:hbIDlx3J40WXF1vB/36USHFEQcIoA/bZ6d3Q1qfMcTk= +github.com/linode/linodego/v2 v2.0.0-20260601073839-52f201e73a60/go.mod h1:rsITrtsKFKBi+pEnznDbbF9ZGBou9S8UccCm1yHLbpI= github.com/mackerelio/go-osstat v0.2.6 h1:gs4U8BZeS1tjrL08tt5VUliVvSWP26Ai2Ob8Lr7f2i0= github.com/mackerelio/go-osstat v0.2.6/go.mod h1:lRy8V9ZuHpuRVZh+vyTkODeDPl3/d5MgXHtLSaqG8bA= github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4= @@ -304,6 +302,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= @@ -395,8 +394,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= -golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw= -golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= +golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs= +golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -453,8 +452,8 @@ gopkg.in/evanphx/json-patch.v4 v4.13.0 h1:czT3CmqEaQ1aanPc5SdlgQrrEIb8w/wwCvWWnf gopkg.in/evanphx/json-patch.v4 v4.13.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.67.2 h1:JtOSMb9OuaCZKr7h5D/h6iii14sK0hLbplTc6frx4Ss= +gopkg.in/ini.v1 v1.67.2/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index bf550314..950c8ffa 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ import ( "net" "os" - "github.com/linode/linodego" + "github.com/linode/linodego/v2" "github.com/spf13/pflag" cloudprovider "k8s.io/cloud-provider" "k8s.io/cloud-provider/app"