From 06345438c5f14514ac33f5241611f638f6e64bc0 Mon Sep 17 00:00:00 2001 From: Neil Wilson Date: Wed, 25 Jan 2023 12:20:44 +0000 Subject: [PATCH] cluster-autoscaler: support Brightbox image pattern cluster-autoscaler/cloudprovider/brightbox Allow scaled workers to be built from an image name pattern as well as an image id. This deals with long running clusters where the official image is updated with security changes over time. --- .../brightbox/brightbox_node_group.go | 28 +- .../brightbox/k8ssdk/brightbox_interface.go | 56 +++ .../brightbox/k8ssdk/cloud_access.go | 3 + .../brightbox/k8ssdk/mocks/CloudAccess.go | 345 ++++++++++++------ 4 files changed, 304 insertions(+), 128 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/brightbox/brightbox_node_group.go b/cluster-autoscaler/cloudprovider/brightbox/brightbox_node_group.go index 6ce89bbbf98f..75d03de79caf 100644 --- a/cluster-autoscaler/cloudprovider/brightbox/brightbox_node_group.go +++ b/cluster-autoscaler/cloudprovider/brightbox/brightbox_node_group.go @@ -359,24 +359,32 @@ func makeNodeGroupFromAPIDetails( if mapData["server_group"] == "" { return nil, cloudprovider.ErrIllegalConfiguration } + ng := brightboxNodeGroup{ + id: mapData["server_group"], + minSize: minSize, + maxSize: maxSize, + Cloud: cloudclient, + } + imageID := mapData["image"] + if !(len(imageID) == 9 && strings.HasPrefix(imageID, "img-")) { + image, err := ng.GetImageByName(imageID) + if err != nil || image == nil { + return nil, cloudprovider.ErrIllegalConfiguration + } + imageID = image.Id + } userData := mapData["user_data"] options := &brightbox.ServerOptions{ - Image: mapData["image"], + Image: imageID, Name: &name, ServerType: mapData["type"], Zone: mapData["zone"], UserData: &userData, ServerGroups: mergeServerGroups(mapData), } - result := brightboxNodeGroup{ - id: mapData["server_group"], - minSize: minSize, - maxSize: maxSize, - serverOptions: options, - Cloud: cloudclient, - } - klog.V(4).Info(result.Debug()) - return &result, nil + ng.serverOptions = options + klog.V(4).Info(ng.Debug()) + return &ng, nil } func mergeServerGroups(data map[string]string) []string { diff --git a/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/brightbox_interface.go b/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/brightbox_interface.go index 5fffa2025143..131e1c5a541b 100644 --- a/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/brightbox_interface.go +++ b/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/brightbox_interface.go @@ -18,6 +18,8 @@ import ( "context" "fmt" "net/http" + "regexp" + "sort" "strings" brightbox "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/brightbox/gobrightbox" @@ -166,6 +168,36 @@ func (c *Cloud) GetServerType(identifier string) (*brightbox.ServerType, error) return client.ServerType(identifier) } +// GetImageByName obtains the most recent available image that matches the supplied pattern +func (c *Cloud) GetImageByName(name string) (*brightbox.Image, error) { + klog.V(4).Infof("GetImageByName %q", name) + client, err := c.CloudClient() + if err != nil { + return nil, err + } + klog.V(6).Info("GetImageByName compiling regexp") + nameRe, err := regexp.Compile(name) + if err != nil { + return nil, err + } + klog.V(6).Info("GetImageByName retrieving images") + images, err := client.Images() + if err != nil { + return nil, err + } + klog.V(6).Info("GetImageByName filtering images") + filteredImages := filter( + images, + func(i brightbox.Image) bool { + return i.Official && + i.Status == status.Available && + nameRe.MatchString(i.Name) + }, + ) + klog.V(6).Infof("GetImageByName images selected (%+v)", filteredImages) + return mostRecent(filteredImages), nil +} + // GetConfigMaps obtains the list of Config Maps on the account func (c *Cloud) GetConfigMaps() ([]brightbox.ConfigMap, error) { klog.V(4).Info("GetConfigMaps") @@ -555,3 +587,27 @@ func ErrorIfAcmeNotComplete(acme *brightbox.LoadBalancerAcme) error { } return nil } + +// Returns the most recent item out of a slice of items with Dates +// or nil if there are no items +func mostRecent(items []brightbox.Image) *brightbox.Image { + if len(items) == 0 { + return nil + } + sortedItems := items + sort.Slice(items, func(i, j int) bool { + return items[i].CreatedAt.Unix() > items[j].CreatedAt.Unix() + }) + return &sortedItems[0] +} + +// filter returns a new slice with all elements from the +// input elements for which the provided predicate function returns true. +func filter[T any](input []T, pred func(T) bool) (output []T) { + for _, v := range input { + if pred(v) { + output = append(output, v) + } + } + return output +} diff --git a/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/cloud_access.go b/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/cloud_access.go index d1ad5d55056b..f544edf39ac6 100644 --- a/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/cloud_access.go +++ b/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/cloud_access.go @@ -92,6 +92,9 @@ type CloudAccess interface { // DestroyCloudIP issues a request to destroy the cloud ip DestroyCloudIP(identifier string) error + // ConfigMaps retrieves a list of all config maps + Images() ([]brightbox.Image, error) + // ConfigMaps retrieves a list of all config maps ConfigMaps() ([]brightbox.ConfigMap, error) diff --git a/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/mocks/CloudAccess.go b/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/mocks/CloudAccess.go index 04e09aeb4f35..271f2e728f5a 100644 --- a/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/mocks/CloudAccess.go +++ b/cluster-autoscaler/cloudprovider/brightbox/k8ssdk/mocks/CloudAccess.go @@ -12,10 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Code generated by mockery v2.20.0. DO NOT EDIT. + package mocks import ( - brightbox "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/brightbox/gobrightbox" + gobrightbox "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/brightbox/gobrightbox" mock "github.com/stretchr/testify/mock" ) @@ -26,19 +28,22 @@ type CloudAccess struct { } // AddServersToServerGroup provides a mock function with given fields: identifier, serverIds -func (_m *CloudAccess) AddServersToServerGroup(identifier string, serverIds []string) (*brightbox.ServerGroup, error) { +func (_m *CloudAccess) AddServersToServerGroup(identifier string, serverIds []string) (*gobrightbox.ServerGroup, error) { ret := _m.Called(identifier, serverIds) - var r0 *brightbox.ServerGroup - if rf, ok := ret.Get(0).(func(string, []string) *brightbox.ServerGroup); ok { + var r0 *gobrightbox.ServerGroup + var r1 error + if rf, ok := ret.Get(0).(func(string, []string) (*gobrightbox.ServerGroup, error)); ok { + return rf(identifier, serverIds) + } + if rf, ok := ret.Get(0).(func(string, []string) *gobrightbox.ServerGroup); ok { r0 = rf(identifier, serverIds) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.ServerGroup) + r0 = ret.Get(0).(*gobrightbox.ServerGroup) } } - var r1 error if rf, ok := ret.Get(1).(func(string, []string) error); ok { r1 = rf(identifier, serverIds) } else { @@ -49,19 +54,22 @@ func (_m *CloudAccess) AddServersToServerGroup(identifier string, serverIds []st } // CloudIP provides a mock function with given fields: identifier -func (_m *CloudAccess) CloudIP(identifier string) (*brightbox.CloudIP, error) { +func (_m *CloudAccess) CloudIP(identifier string) (*gobrightbox.CloudIP, error) { ret := _m.Called(identifier) - var r0 *brightbox.CloudIP - if rf, ok := ret.Get(0).(func(string) *brightbox.CloudIP); ok { + var r0 *gobrightbox.CloudIP + var r1 error + if rf, ok := ret.Get(0).(func(string) (*gobrightbox.CloudIP, error)); ok { + return rf(identifier) + } + if rf, ok := ret.Get(0).(func(string) *gobrightbox.CloudIP); ok { r0 = rf(identifier) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.CloudIP) + r0 = ret.Get(0).(*gobrightbox.CloudIP) } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(identifier) } else { @@ -72,19 +80,22 @@ func (_m *CloudAccess) CloudIP(identifier string) (*brightbox.CloudIP, error) { } // CloudIPs provides a mock function with given fields: -func (_m *CloudAccess) CloudIPs() ([]brightbox.CloudIP, error) { +func (_m *CloudAccess) CloudIPs() ([]gobrightbox.CloudIP, error) { ret := _m.Called() - var r0 []brightbox.CloudIP - if rf, ok := ret.Get(0).(func() []brightbox.CloudIP); ok { + var r0 []gobrightbox.CloudIP + var r1 error + if rf, ok := ret.Get(0).(func() ([]gobrightbox.CloudIP, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []gobrightbox.CloudIP); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]brightbox.CloudIP) + r0 = ret.Get(0).([]gobrightbox.CloudIP) } } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -95,19 +106,22 @@ func (_m *CloudAccess) CloudIPs() ([]brightbox.CloudIP, error) { } // ConfigMap provides a mock function with given fields: identifier -func (_m *CloudAccess) ConfigMap(identifier string) (*brightbox.ConfigMap, error) { +func (_m *CloudAccess) ConfigMap(identifier string) (*gobrightbox.ConfigMap, error) { ret := _m.Called(identifier) - var r0 *brightbox.ConfigMap - if rf, ok := ret.Get(0).(func(string) *brightbox.ConfigMap); ok { + var r0 *gobrightbox.ConfigMap + var r1 error + if rf, ok := ret.Get(0).(func(string) (*gobrightbox.ConfigMap, error)); ok { + return rf(identifier) + } + if rf, ok := ret.Get(0).(func(string) *gobrightbox.ConfigMap); ok { r0 = rf(identifier) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.ConfigMap) + r0 = ret.Get(0).(*gobrightbox.ConfigMap) } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(identifier) } else { @@ -118,19 +132,22 @@ func (_m *CloudAccess) ConfigMap(identifier string) (*brightbox.ConfigMap, error } // ConfigMaps provides a mock function with given fields: -func (_m *CloudAccess) ConfigMaps() ([]brightbox.ConfigMap, error) { +func (_m *CloudAccess) ConfigMaps() ([]gobrightbox.ConfigMap, error) { ret := _m.Called() - var r0 []brightbox.ConfigMap - if rf, ok := ret.Get(0).(func() []brightbox.ConfigMap); ok { + var r0 []gobrightbox.ConfigMap + var r1 error + if rf, ok := ret.Get(0).(func() ([]gobrightbox.ConfigMap, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []gobrightbox.ConfigMap); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]brightbox.ConfigMap) + r0 = ret.Get(0).([]gobrightbox.ConfigMap) } } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -141,20 +158,23 @@ func (_m *CloudAccess) ConfigMaps() ([]brightbox.ConfigMap, error) { } // CreateCloudIP provides a mock function with given fields: newCloudIP -func (_m *CloudAccess) CreateCloudIP(newCloudIP *brightbox.CloudIPOptions) (*brightbox.CloudIP, error) { +func (_m *CloudAccess) CreateCloudIP(newCloudIP *gobrightbox.CloudIPOptions) (*gobrightbox.CloudIP, error) { ret := _m.Called(newCloudIP) - var r0 *brightbox.CloudIP - if rf, ok := ret.Get(0).(func(*brightbox.CloudIPOptions) *brightbox.CloudIP); ok { + var r0 *gobrightbox.CloudIP + var r1 error + if rf, ok := ret.Get(0).(func(*gobrightbox.CloudIPOptions) (*gobrightbox.CloudIP, error)); ok { + return rf(newCloudIP) + } + if rf, ok := ret.Get(0).(func(*gobrightbox.CloudIPOptions) *gobrightbox.CloudIP); ok { r0 = rf(newCloudIP) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.CloudIP) + r0 = ret.Get(0).(*gobrightbox.CloudIP) } } - var r1 error - if rf, ok := ret.Get(1).(func(*brightbox.CloudIPOptions) error); ok { + if rf, ok := ret.Get(1).(func(*gobrightbox.CloudIPOptions) error); ok { r1 = rf(newCloudIP) } else { r1 = ret.Error(1) @@ -164,20 +184,23 @@ func (_m *CloudAccess) CreateCloudIP(newCloudIP *brightbox.CloudIPOptions) (*bri } // CreateFirewallPolicy provides a mock function with given fields: policyOptions -func (_m *CloudAccess) CreateFirewallPolicy(policyOptions *brightbox.FirewallPolicyOptions) (*brightbox.FirewallPolicy, error) { +func (_m *CloudAccess) CreateFirewallPolicy(policyOptions *gobrightbox.FirewallPolicyOptions) (*gobrightbox.FirewallPolicy, error) { ret := _m.Called(policyOptions) - var r0 *brightbox.FirewallPolicy - if rf, ok := ret.Get(0).(func(*brightbox.FirewallPolicyOptions) *brightbox.FirewallPolicy); ok { + var r0 *gobrightbox.FirewallPolicy + var r1 error + if rf, ok := ret.Get(0).(func(*gobrightbox.FirewallPolicyOptions) (*gobrightbox.FirewallPolicy, error)); ok { + return rf(policyOptions) + } + if rf, ok := ret.Get(0).(func(*gobrightbox.FirewallPolicyOptions) *gobrightbox.FirewallPolicy); ok { r0 = rf(policyOptions) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.FirewallPolicy) + r0 = ret.Get(0).(*gobrightbox.FirewallPolicy) } } - var r1 error - if rf, ok := ret.Get(1).(func(*brightbox.FirewallPolicyOptions) error); ok { + if rf, ok := ret.Get(1).(func(*gobrightbox.FirewallPolicyOptions) error); ok { r1 = rf(policyOptions) } else { r1 = ret.Error(1) @@ -187,20 +210,23 @@ func (_m *CloudAccess) CreateFirewallPolicy(policyOptions *brightbox.FirewallPol } // CreateFirewallRule provides a mock function with given fields: ruleOptions -func (_m *CloudAccess) CreateFirewallRule(ruleOptions *brightbox.FirewallRuleOptions) (*brightbox.FirewallRule, error) { +func (_m *CloudAccess) CreateFirewallRule(ruleOptions *gobrightbox.FirewallRuleOptions) (*gobrightbox.FirewallRule, error) { ret := _m.Called(ruleOptions) - var r0 *brightbox.FirewallRule - if rf, ok := ret.Get(0).(func(*brightbox.FirewallRuleOptions) *brightbox.FirewallRule); ok { + var r0 *gobrightbox.FirewallRule + var r1 error + if rf, ok := ret.Get(0).(func(*gobrightbox.FirewallRuleOptions) (*gobrightbox.FirewallRule, error)); ok { + return rf(ruleOptions) + } + if rf, ok := ret.Get(0).(func(*gobrightbox.FirewallRuleOptions) *gobrightbox.FirewallRule); ok { r0 = rf(ruleOptions) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.FirewallRule) + r0 = ret.Get(0).(*gobrightbox.FirewallRule) } } - var r1 error - if rf, ok := ret.Get(1).(func(*brightbox.FirewallRuleOptions) error); ok { + if rf, ok := ret.Get(1).(func(*gobrightbox.FirewallRuleOptions) error); ok { r1 = rf(ruleOptions) } else { r1 = ret.Error(1) @@ -210,20 +236,23 @@ func (_m *CloudAccess) CreateFirewallRule(ruleOptions *brightbox.FirewallRuleOpt } // CreateLoadBalancer provides a mock function with given fields: newDetails -func (_m *CloudAccess) CreateLoadBalancer(newDetails *brightbox.LoadBalancerOptions) (*brightbox.LoadBalancer, error) { +func (_m *CloudAccess) CreateLoadBalancer(newDetails *gobrightbox.LoadBalancerOptions) (*gobrightbox.LoadBalancer, error) { ret := _m.Called(newDetails) - var r0 *brightbox.LoadBalancer - if rf, ok := ret.Get(0).(func(*brightbox.LoadBalancerOptions) *brightbox.LoadBalancer); ok { + var r0 *gobrightbox.LoadBalancer + var r1 error + if rf, ok := ret.Get(0).(func(*gobrightbox.LoadBalancerOptions) (*gobrightbox.LoadBalancer, error)); ok { + return rf(newDetails) + } + if rf, ok := ret.Get(0).(func(*gobrightbox.LoadBalancerOptions) *gobrightbox.LoadBalancer); ok { r0 = rf(newDetails) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.LoadBalancer) + r0 = ret.Get(0).(*gobrightbox.LoadBalancer) } } - var r1 error - if rf, ok := ret.Get(1).(func(*brightbox.LoadBalancerOptions) error); ok { + if rf, ok := ret.Get(1).(func(*gobrightbox.LoadBalancerOptions) error); ok { r1 = rf(newDetails) } else { r1 = ret.Error(1) @@ -233,20 +262,23 @@ func (_m *CloudAccess) CreateLoadBalancer(newDetails *brightbox.LoadBalancerOpti } // CreateServer provides a mock function with given fields: newServer -func (_m *CloudAccess) CreateServer(newServer *brightbox.ServerOptions) (*brightbox.Server, error) { +func (_m *CloudAccess) CreateServer(newServer *gobrightbox.ServerOptions) (*gobrightbox.Server, error) { ret := _m.Called(newServer) - var r0 *brightbox.Server - if rf, ok := ret.Get(0).(func(*brightbox.ServerOptions) *brightbox.Server); ok { + var r0 *gobrightbox.Server + var r1 error + if rf, ok := ret.Get(0).(func(*gobrightbox.ServerOptions) (*gobrightbox.Server, error)); ok { + return rf(newServer) + } + if rf, ok := ret.Get(0).(func(*gobrightbox.ServerOptions) *gobrightbox.Server); ok { r0 = rf(newServer) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.Server) + r0 = ret.Get(0).(*gobrightbox.Server) } } - var r1 error - if rf, ok := ret.Get(1).(func(*brightbox.ServerOptions) error); ok { + if rf, ok := ret.Get(1).(func(*gobrightbox.ServerOptions) error); ok { r1 = rf(newServer) } else { r1 = ret.Error(1) @@ -256,20 +288,23 @@ func (_m *CloudAccess) CreateServer(newServer *brightbox.ServerOptions) (*bright } // CreateServerGroup provides a mock function with given fields: newServerGroup -func (_m *CloudAccess) CreateServerGroup(newServerGroup *brightbox.ServerGroupOptions) (*brightbox.ServerGroup, error) { +func (_m *CloudAccess) CreateServerGroup(newServerGroup *gobrightbox.ServerGroupOptions) (*gobrightbox.ServerGroup, error) { ret := _m.Called(newServerGroup) - var r0 *brightbox.ServerGroup - if rf, ok := ret.Get(0).(func(*brightbox.ServerGroupOptions) *brightbox.ServerGroup); ok { + var r0 *gobrightbox.ServerGroup + var r1 error + if rf, ok := ret.Get(0).(func(*gobrightbox.ServerGroupOptions) (*gobrightbox.ServerGroup, error)); ok { + return rf(newServerGroup) + } + if rf, ok := ret.Get(0).(func(*gobrightbox.ServerGroupOptions) *gobrightbox.ServerGroup); ok { r0 = rf(newServerGroup) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.ServerGroup) + r0 = ret.Get(0).(*gobrightbox.ServerGroup) } } - var r1 error - if rf, ok := ret.Get(1).(func(*brightbox.ServerGroupOptions) error); ok { + if rf, ok := ret.Get(1).(func(*gobrightbox.ServerGroupOptions) error); ok { r1 = rf(newServerGroup) } else { r1 = ret.Error(1) @@ -349,19 +384,48 @@ func (_m *CloudAccess) DestroyServerGroup(identifier string) error { } // FirewallPolicies provides a mock function with given fields: -func (_m *CloudAccess) FirewallPolicies() ([]brightbox.FirewallPolicy, error) { +func (_m *CloudAccess) FirewallPolicies() ([]gobrightbox.FirewallPolicy, error) { ret := _m.Called() - var r0 []brightbox.FirewallPolicy - if rf, ok := ret.Get(0).(func() []brightbox.FirewallPolicy); ok { + var r0 []gobrightbox.FirewallPolicy + var r1 error + if rf, ok := ret.Get(0).(func() ([]gobrightbox.FirewallPolicy, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []gobrightbox.FirewallPolicy); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]brightbox.FirewallPolicy) + r0 = ret.Get(0).([]gobrightbox.FirewallPolicy) } } + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Images provides a mock function with given fields: +func (_m *CloudAccess) Images() ([]gobrightbox.Image, error) { + ret := _m.Called() + + var r0 []gobrightbox.Image var r1 error + if rf, ok := ret.Get(0).(func() ([]gobrightbox.Image, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []gobrightbox.Image); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]gobrightbox.Image) + } + } + if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -372,19 +436,22 @@ func (_m *CloudAccess) FirewallPolicies() ([]brightbox.FirewallPolicy, error) { } // LoadBalancer provides a mock function with given fields: identifier -func (_m *CloudAccess) LoadBalancer(identifier string) (*brightbox.LoadBalancer, error) { +func (_m *CloudAccess) LoadBalancer(identifier string) (*gobrightbox.LoadBalancer, error) { ret := _m.Called(identifier) - var r0 *brightbox.LoadBalancer - if rf, ok := ret.Get(0).(func(string) *brightbox.LoadBalancer); ok { + var r0 *gobrightbox.LoadBalancer + var r1 error + if rf, ok := ret.Get(0).(func(string) (*gobrightbox.LoadBalancer, error)); ok { + return rf(identifier) + } + if rf, ok := ret.Get(0).(func(string) *gobrightbox.LoadBalancer); ok { r0 = rf(identifier) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.LoadBalancer) + r0 = ret.Get(0).(*gobrightbox.LoadBalancer) } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(identifier) } else { @@ -395,19 +462,22 @@ func (_m *CloudAccess) LoadBalancer(identifier string) (*brightbox.LoadBalancer, } // LoadBalancers provides a mock function with given fields: -func (_m *CloudAccess) LoadBalancers() ([]brightbox.LoadBalancer, error) { +func (_m *CloudAccess) LoadBalancers() ([]gobrightbox.LoadBalancer, error) { ret := _m.Called() - var r0 []brightbox.LoadBalancer - if rf, ok := ret.Get(0).(func() []brightbox.LoadBalancer); ok { + var r0 []gobrightbox.LoadBalancer + var r1 error + if rf, ok := ret.Get(0).(func() ([]gobrightbox.LoadBalancer, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []gobrightbox.LoadBalancer); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]brightbox.LoadBalancer) + r0 = ret.Get(0).([]gobrightbox.LoadBalancer) } } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -432,19 +502,22 @@ func (_m *CloudAccess) MapCloudIP(identifier string, destination string) error { } // RemoveServersFromServerGroup provides a mock function with given fields: identifier, serverIds -func (_m *CloudAccess) RemoveServersFromServerGroup(identifier string, serverIds []string) (*brightbox.ServerGroup, error) { +func (_m *CloudAccess) RemoveServersFromServerGroup(identifier string, serverIds []string) (*gobrightbox.ServerGroup, error) { ret := _m.Called(identifier, serverIds) - var r0 *brightbox.ServerGroup - if rf, ok := ret.Get(0).(func(string, []string) *brightbox.ServerGroup); ok { + var r0 *gobrightbox.ServerGroup + var r1 error + if rf, ok := ret.Get(0).(func(string, []string) (*gobrightbox.ServerGroup, error)); ok { + return rf(identifier, serverIds) + } + if rf, ok := ret.Get(0).(func(string, []string) *gobrightbox.ServerGroup); ok { r0 = rf(identifier, serverIds) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.ServerGroup) + r0 = ret.Get(0).(*gobrightbox.ServerGroup) } } - var r1 error if rf, ok := ret.Get(1).(func(string, []string) error); ok { r1 = rf(identifier, serverIds) } else { @@ -455,19 +528,22 @@ func (_m *CloudAccess) RemoveServersFromServerGroup(identifier string, serverIds } // Server provides a mock function with given fields: identifier -func (_m *CloudAccess) Server(identifier string) (*brightbox.Server, error) { +func (_m *CloudAccess) Server(identifier string) (*gobrightbox.Server, error) { ret := _m.Called(identifier) - var r0 *brightbox.Server - if rf, ok := ret.Get(0).(func(string) *brightbox.Server); ok { + var r0 *gobrightbox.Server + var r1 error + if rf, ok := ret.Get(0).(func(string) (*gobrightbox.Server, error)); ok { + return rf(identifier) + } + if rf, ok := ret.Get(0).(func(string) *gobrightbox.Server); ok { r0 = rf(identifier) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.Server) + r0 = ret.Get(0).(*gobrightbox.Server) } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(identifier) } else { @@ -478,19 +554,22 @@ func (_m *CloudAccess) Server(identifier string) (*brightbox.Server, error) { } // ServerGroup provides a mock function with given fields: identifier -func (_m *CloudAccess) ServerGroup(identifier string) (*brightbox.ServerGroup, error) { +func (_m *CloudAccess) ServerGroup(identifier string) (*gobrightbox.ServerGroup, error) { ret := _m.Called(identifier) - var r0 *brightbox.ServerGroup - if rf, ok := ret.Get(0).(func(string) *brightbox.ServerGroup); ok { + var r0 *gobrightbox.ServerGroup + var r1 error + if rf, ok := ret.Get(0).(func(string) (*gobrightbox.ServerGroup, error)); ok { + return rf(identifier) + } + if rf, ok := ret.Get(0).(func(string) *gobrightbox.ServerGroup); ok { r0 = rf(identifier) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.ServerGroup) + r0 = ret.Get(0).(*gobrightbox.ServerGroup) } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(identifier) } else { @@ -501,19 +580,22 @@ func (_m *CloudAccess) ServerGroup(identifier string) (*brightbox.ServerGroup, e } // ServerGroups provides a mock function with given fields: -func (_m *CloudAccess) ServerGroups() ([]brightbox.ServerGroup, error) { +func (_m *CloudAccess) ServerGroups() ([]gobrightbox.ServerGroup, error) { ret := _m.Called() - var r0 []brightbox.ServerGroup - if rf, ok := ret.Get(0).(func() []brightbox.ServerGroup); ok { + var r0 []gobrightbox.ServerGroup + var r1 error + if rf, ok := ret.Get(0).(func() ([]gobrightbox.ServerGroup, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []gobrightbox.ServerGroup); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]brightbox.ServerGroup) + r0 = ret.Get(0).([]gobrightbox.ServerGroup) } } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -524,19 +606,22 @@ func (_m *CloudAccess) ServerGroups() ([]brightbox.ServerGroup, error) { } // ServerType provides a mock function with given fields: identifier -func (_m *CloudAccess) ServerType(identifier string) (*brightbox.ServerType, error) { +func (_m *CloudAccess) ServerType(identifier string) (*gobrightbox.ServerType, error) { ret := _m.Called(identifier) - var r0 *brightbox.ServerType - if rf, ok := ret.Get(0).(func(string) *brightbox.ServerType); ok { + var r0 *gobrightbox.ServerType + var r1 error + if rf, ok := ret.Get(0).(func(string) (*gobrightbox.ServerType, error)); ok { + return rf(identifier) + } + if rf, ok := ret.Get(0).(func(string) *gobrightbox.ServerType); ok { r0 = rf(identifier) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.ServerType) + r0 = ret.Get(0).(*gobrightbox.ServerType) } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(identifier) } else { @@ -547,19 +632,22 @@ func (_m *CloudAccess) ServerType(identifier string) (*brightbox.ServerType, err } // ServerTypes provides a mock function with given fields: -func (_m *CloudAccess) ServerTypes() ([]brightbox.ServerType, error) { +func (_m *CloudAccess) ServerTypes() ([]gobrightbox.ServerType, error) { ret := _m.Called() - var r0 []brightbox.ServerType - if rf, ok := ret.Get(0).(func() []brightbox.ServerType); ok { + var r0 []gobrightbox.ServerType + var r1 error + if rf, ok := ret.Get(0).(func() ([]gobrightbox.ServerType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []gobrightbox.ServerType); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]brightbox.ServerType) + r0 = ret.Get(0).([]gobrightbox.ServerType) } } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -584,20 +672,23 @@ func (_m *CloudAccess) UnMapCloudIP(identifier string) error { } // UpdateFirewallRule provides a mock function with given fields: ruleOptions -func (_m *CloudAccess) UpdateFirewallRule(ruleOptions *brightbox.FirewallRuleOptions) (*brightbox.FirewallRule, error) { +func (_m *CloudAccess) UpdateFirewallRule(ruleOptions *gobrightbox.FirewallRuleOptions) (*gobrightbox.FirewallRule, error) { ret := _m.Called(ruleOptions) - var r0 *brightbox.FirewallRule - if rf, ok := ret.Get(0).(func(*brightbox.FirewallRuleOptions) *brightbox.FirewallRule); ok { + var r0 *gobrightbox.FirewallRule + var r1 error + if rf, ok := ret.Get(0).(func(*gobrightbox.FirewallRuleOptions) (*gobrightbox.FirewallRule, error)); ok { + return rf(ruleOptions) + } + if rf, ok := ret.Get(0).(func(*gobrightbox.FirewallRuleOptions) *gobrightbox.FirewallRule); ok { r0 = rf(ruleOptions) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.FirewallRule) + r0 = ret.Get(0).(*gobrightbox.FirewallRule) } } - var r1 error - if rf, ok := ret.Get(1).(func(*brightbox.FirewallRuleOptions) error); ok { + if rf, ok := ret.Get(1).(func(*gobrightbox.FirewallRuleOptions) error); ok { r1 = rf(ruleOptions) } else { r1 = ret.Error(1) @@ -607,20 +698,23 @@ func (_m *CloudAccess) UpdateFirewallRule(ruleOptions *brightbox.FirewallRuleOpt } // UpdateLoadBalancer provides a mock function with given fields: newDetails -func (_m *CloudAccess) UpdateLoadBalancer(newDetails *brightbox.LoadBalancerOptions) (*brightbox.LoadBalancer, error) { +func (_m *CloudAccess) UpdateLoadBalancer(newDetails *gobrightbox.LoadBalancerOptions) (*gobrightbox.LoadBalancer, error) { ret := _m.Called(newDetails) - var r0 *brightbox.LoadBalancer - if rf, ok := ret.Get(0).(func(*brightbox.LoadBalancerOptions) *brightbox.LoadBalancer); ok { + var r0 *gobrightbox.LoadBalancer + var r1 error + if rf, ok := ret.Get(0).(func(*gobrightbox.LoadBalancerOptions) (*gobrightbox.LoadBalancer, error)); ok { + return rf(newDetails) + } + if rf, ok := ret.Get(0).(func(*gobrightbox.LoadBalancerOptions) *gobrightbox.LoadBalancer); ok { r0 = rf(newDetails) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*brightbox.LoadBalancer) + r0 = ret.Get(0).(*gobrightbox.LoadBalancer) } } - var r1 error - if rf, ok := ret.Get(1).(func(*brightbox.LoadBalancerOptions) error); ok { + if rf, ok := ret.Get(1).(func(*gobrightbox.LoadBalancerOptions) error); ok { r1 = rf(newDetails) } else { r1 = ret.Error(1) @@ -628,3 +722,18 @@ func (_m *CloudAccess) UpdateLoadBalancer(newDetails *brightbox.LoadBalancerOpti return r0, r1 } + +type mockConstructorTestingTNewCloudAccess interface { + mock.TestingT + Cleanup(func()) +} + +// NewCloudAccess creates a new instance of CloudAccess. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewCloudAccess(t mockConstructorTestingTNewCloudAccess) *CloudAccess { + mock := &CloudAccess{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}