diff --git a/pkg/cloudprovider/providers/gce/cloud/gen.go b/pkg/cloudprovider/providers/gce/cloud/gen.go index b74559adfe3..c5ccfb0d7b1 100644 --- a/pkg/cloudprovider/providers/gce/cloud/gen.go +++ b/pkg/cloudprovider/providers/gce/cloud/gen.go @@ -8939,6 +8939,7 @@ type BetaInstances interface { Delete(ctx context.Context, key *meta.Key) error AttachDisk(context.Context, *meta.Key, *beta.AttachedDisk) error DetachDisk(context.Context, *meta.Key, string) error + UpdateNetworkInterface(context.Context, *meta.Key, string, *beta.NetworkInterface) error } // NewMockBetaInstances returns a new mock for Instances. @@ -8970,12 +8971,13 @@ type MockBetaInstances struct { // order to add your own logic. Return (true, _, _) to prevent the normal // execution flow of the mock. Return (false, nil, nil) to continue with // normal mock behavior/ after the hook function executes. - GetHook func(m *MockBetaInstances, ctx context.Context, key *meta.Key) (bool, *beta.Instance, error) - ListHook func(m *MockBetaInstances, ctx context.Context, zone string, fl *filter.F) (bool, []*beta.Instance, error) - InsertHook func(m *MockBetaInstances, ctx context.Context, key *meta.Key, obj *beta.Instance) (bool, error) - DeleteHook func(m *MockBetaInstances, ctx context.Context, key *meta.Key) (bool, error) - AttachDiskHook func(*MockBetaInstances, context.Context, *meta.Key, *beta.AttachedDisk) error - DetachDiskHook func(*MockBetaInstances, context.Context, *meta.Key, string) error + GetHook func(m *MockBetaInstances, ctx context.Context, key *meta.Key) (bool, *beta.Instance, error) + ListHook func(m *MockBetaInstances, ctx context.Context, zone string, fl *filter.F) (bool, []*beta.Instance, error) + InsertHook func(m *MockBetaInstances, ctx context.Context, key *meta.Key, obj *beta.Instance) (bool, error) + DeleteHook func(m *MockBetaInstances, ctx context.Context, key *meta.Key) (bool, error) + AttachDiskHook func(*MockBetaInstances, context.Context, *meta.Key, *beta.AttachedDisk) error + DetachDiskHook func(*MockBetaInstances, context.Context, *meta.Key, string) error + UpdateNetworkInterfaceHook func(*MockBetaInstances, context.Context, *meta.Key, string, *beta.NetworkInterface) error // X is extra state that can be used as part of the mock. Generated code // will not use this field. @@ -9141,6 +9143,14 @@ func (m *MockBetaInstances) DetachDisk(ctx context.Context, key *meta.Key, arg0 return nil } +// UpdateNetworkInterface is a mock for the corresponding method. +func (m *MockBetaInstances) UpdateNetworkInterface(ctx context.Context, key *meta.Key, arg0 string, arg1 *beta.NetworkInterface) error { + if m.UpdateNetworkInterfaceHook != nil { + return m.UpdateNetworkInterfaceHook(m, ctx, key, arg0, arg1) + } + return nil +} + // GCEBetaInstances is a simplifying adapter for the GCE Instances. type GCEBetaInstances struct { s *Service @@ -9348,6 +9358,39 @@ func (g *GCEBetaInstances) DetachDisk(ctx context.Context, key *meta.Key, arg0 s return err } +// UpdateNetworkInterface is a method on GCEBetaInstances. +func (g *GCEBetaInstances) UpdateNetworkInterface(ctx context.Context, key *meta.Key, arg0 string, arg1 *beta.NetworkInterface) error { + glog.V(5).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...): called", ctx, key) + + if !key.Valid() { + glog.V(2).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...): key is invalid (%#v)", ctx, key, key) + return fmt.Errorf("invalid GCE key (%+v)", key) + } + projectID := g.s.ProjectRouter.ProjectID(ctx, "beta", "Instances") + rk := &RateLimitKey{ + ProjectID: projectID, + Operation: "UpdateNetworkInterface", + Version: meta.Version("beta"), + Service: "Instances", + } + glog.V(5).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk) + + if err := g.s.RateLimiter.Accept(ctx, rk); err != nil { + glog.V(4).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...): RateLimiter error: %v", ctx, key, err) + return err + } + call := g.s.Beta.Instances.UpdateNetworkInterface(projectID, key.Zone, key.Name, arg0, arg1) + call.Context(ctx) + op, err := call.Do() + if err != nil { + glog.V(4).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...) = %+v", ctx, key, err) + return err + } + err = g.s.WaitForCompletion(ctx, op) + glog.V(4).Infof("GCEBetaInstances.UpdateNetworkInterface(%v, %v, ...) = %+v", ctx, key, err) + return err +} + // AlphaInstances is an interface that allows for mocking of Instances. type AlphaInstances interface { Get(ctx context.Context, key *meta.Key) (*alpha.Instance, error) diff --git a/pkg/cloudprovider/providers/gce/cloud/meta/meta.go b/pkg/cloudprovider/providers/gce/cloud/meta/meta.go index a636b5a1feb..852248beb80 100644 --- a/pkg/cloudprovider/providers/gce/cloud/meta/meta.go +++ b/pkg/cloudprovider/providers/gce/cloud/meta/meta.go @@ -272,6 +272,7 @@ var AllServices = []*ServiceInfo{ additionalMethods: []string{ "AttachDisk", "DetachDisk", + "UpdateNetworkInterface", }, }, { diff --git a/pkg/cloudprovider/providers/gce/gce_instances.go b/pkg/cloudprovider/providers/gce/gce_instances.go index 3a3fc5e6ddd..90506911d81 100644 --- a/pkg/cloudprovider/providers/gce/gce_instances.go +++ b/pkg/cloudprovider/providers/gce/gce_instances.go @@ -27,7 +27,6 @@ import ( "cloud.google.com/go/compute/metadata" "github.com/golang/glog" - computealpha "google.golang.org/api/compute/v0.alpha" computebeta "google.golang.org/api/compute/v0.beta" compute "google.golang.org/api/compute/v1" @@ -373,7 +372,7 @@ func (gce *GCECloud) AddAliasToInstance(nodeName types.NodeName, alias *net.IPNe if err != nil { return err } - instance, err := gce.c.AlphaInstances().Get(context.Background(), meta.ZonalKey(v1instance.Name, lastComponent(v1instance.Zone))) + instance, err := gce.c.BetaInstances().Get(context.Background(), meta.ZonalKey(v1instance.Name, lastComponent(v1instance.Zone))) if err != nil { return err } @@ -388,13 +387,13 @@ func (gce *GCECloud) AddAliasToInstance(nodeName types.NodeName, alias *net.IPNe } iface := instance.NetworkInterfaces[0] - iface.AliasIpRanges = append(iface.AliasIpRanges, &computealpha.AliasIpRange{ + iface.AliasIpRanges = append(iface.AliasIpRanges, &computebeta.AliasIpRange{ IpCidrRange: alias.String(), SubnetworkRangeName: gce.secondaryRangeName, }) mc := newInstancesMetricContext("add_alias", v1instance.Zone) - err = gce.c.AlphaInstances().UpdateNetworkInterface(context.Background(), meta.ZonalKey(instance.Name, lastComponent(instance.Zone)), iface.Name, iface) + err = gce.c.BetaInstances().UpdateNetworkInterface(context.Background(), meta.ZonalKey(instance.Name, lastComponent(instance.Zone)), iface.Name, iface) return mc.Observe(err) }