mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #59361 from jingax10/aliaes_version_branch
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Use beta instead of alpha GCE Compute API to add an alias range to an instance. … instance. **What this PR does / why we need it**: We use beta instead of alpha GCE Compute API to add an alias range to an instance. Without this change, such an API is reserved for GCP projects which has whitelisted for this feature. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # N/A **Special notes for your reviewer**: **Release note**: ```release-note "NONE". ```
This commit is contained in:
commit
c471b6f946
@ -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)
|
||||
|
@ -272,6 +272,7 @@ var AllServices = []*ServiceInfo{
|
||||
additionalMethods: []string{
|
||||
"AttachDisk",
|
||||
"DetachDisk",
|
||||
"UpdateNetworkInterface",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user