@@ -21,6 +21,7 @@ import (
21
21
"context"
22
22
"errors"
23
23
"net"
24
+ "net/http"
24
25
"time"
25
26
26
27
"github.com/go-logr/logr"
@@ -811,9 +812,10 @@ var _ = Describe("machine-lifecycle", Ordered, Label("machine", "machine-lifecyc
811
812
linodeMachine := & infrav1alpha2.LinodeMachine {
812
813
ObjectMeta : metadata ,
813
814
Spec : infrav1alpha2.LinodeMachineSpec {
814
- InstanceID : ptr .To (0 ),
815
- Type : "g6-nanode-1" ,
816
- Image : rutil .DefaultMachineControllerLinodeImage ,
815
+ InstanceID : ptr .To (0 ),
816
+ Type : "g6-nanode-1" ,
817
+ Image : rutil .DefaultMachineControllerLinodeImage ,
818
+ Configuration : & infrav1alpha2.InstanceConfiguration {Kernel : "test" },
817
819
},
818
820
}
819
821
machineKey := client .ObjectKeyFromObject (linodeMachine )
@@ -930,8 +932,113 @@ var _ = Describe("machine-lifecycle", Ordered, Label("machine", "machine-lifecyc
930
932
})),
931
933
),
932
934
),
935
+ Path (
936
+ Call ("machine is not created because there were too many requests" , func (ctx context.Context , mck Mock ) {
937
+ listInst := mck .LinodeClient .EXPECT ().
938
+ ListInstances (ctx , gomock .Any ()).
939
+ Return ([]linodego.Instance {}, nil )
940
+ mck .LinodeClient .EXPECT ().
941
+ GetRegion (ctx , gomock .Any ()).
942
+ After (listInst ).
943
+ Return (& linodego.Region {Capabilities : []string {"Metadata" }}, nil )
944
+ }),
945
+ OneOf (
946
+ Path (Result ("create requeues when failing to create instance config" , func (ctx context.Context , mck Mock ) {
947
+ mck .LinodeClient .EXPECT ().
948
+ GetImage (ctx , gomock .Any ()).
949
+ Return (nil , & linodego.Error {Code : http .StatusTooManyRequests })
950
+ res , err := reconciler .reconcile (ctx , mck .Logger (), mScope )
951
+ Expect (err ).NotTo (HaveOccurred ())
952
+ Expect (res .RequeueAfter ).To (Equal (rutil .DefaultLinodeTooManyRequestsErrorRetryDelay ))
953
+ Expect (mck .Logs ()).To (ContainSubstring ("Failed to create Linode machine InstanceCreateOptions" ))
954
+ })),
955
+ Path (Result ("create requeues when failing to create instance" , func (ctx context.Context , mck Mock ) {
956
+ getImage := mck .LinodeClient .EXPECT ().
957
+ GetImage (ctx , gomock .Any ()).
958
+ Return (& linodego.Image {Capabilities : []string {"cloud-init" }}, nil )
959
+ mck .LinodeClient .EXPECT ().CreateInstance (gomock .Any (), gomock .Any ()).
960
+ After (getImage ).
961
+ Return (nil , & linodego.Error {Code : http .StatusTooManyRequests })
962
+ res , err := reconciler .reconcile (ctx , mck .Logger (), mScope )
963
+ Expect (err ).NotTo (HaveOccurred ())
964
+ Expect (res .RequeueAfter ).To (Equal (rutil .DefaultLinodeTooManyRequestsErrorRetryDelay ))
965
+ Expect (mck .Logs ()).To (ContainSubstring ("Failed to create Linode instance due to API error" ))
966
+ })),
967
+ Path (Result ("create requeues when failing to update instance config" , func (ctx context.Context , mck Mock ) {
968
+ getImage := mck .LinodeClient .EXPECT ().
969
+ GetImage (ctx , gomock .Any ()).
970
+ Return (& linodego.Image {Capabilities : []string {"cloud-init" }}, nil )
971
+ createInst := mck .LinodeClient .EXPECT ().
972
+ CreateInstance (ctx , gomock .Any ()).
973
+ After (getImage ).
974
+ Return (& linodego.Instance {
975
+ ID : 123 ,
976
+ IPv4 : []* net.IP {ptr .To (net .IPv4 (192 , 168 , 0 , 2 ))},
977
+ IPv6 : "fd00::" ,
978
+ Status : linodego .InstanceOffline ,
979
+ }, nil )
980
+ listInstConfigs := mck .LinodeClient .EXPECT ().
981
+ ListInstanceConfigs (ctx , 123 , gomock .Any ()).
982
+ After (createInst ).
983
+ Return ([]linodego.InstanceConfig {{
984
+ Devices : & linodego.InstanceConfigDeviceMap {
985
+ SDA : & linodego.InstanceConfigDevice {DiskID : 100 },
986
+ },
987
+ }}, nil )
988
+ mck .LinodeClient .EXPECT ().
989
+ UpdateInstanceConfig (ctx , 123 , 0 , gomock .Any ()).
990
+ After (listInstConfigs ).
991
+ Return (nil , & linodego.Error {Code : http .StatusTooManyRequests })
992
+ res , err := reconciler .reconcile (ctx , mck .Logger (), mScope )
993
+ Expect (err ).NotTo (HaveOccurred ())
994
+ Expect (res .RequeueAfter ).To (Equal (rutil .DefaultLinodeTooManyRequestsErrorRetryDelay ))
995
+ Expect (mck .Logs ()).To (ContainSubstring ("Failed to update default instance configuration" ))
996
+ })),
997
+ Path (Result ("create requeues when failing to get instance config" , func (ctx context.Context , mck Mock ) {
998
+ getImage := mck .LinodeClient .EXPECT ().
999
+ GetImage (ctx , gomock .Any ()).
1000
+ Return (& linodego.Image {Capabilities : []string {"cloud-init" }}, nil )
1001
+ createInst := mck .LinodeClient .EXPECT ().
1002
+ CreateInstance (ctx , gomock .Any ()).
1003
+ After (getImage ).
1004
+ Return (& linodego.Instance {
1005
+ ID : 123 ,
1006
+ IPv4 : []* net.IP {ptr .To (net .IPv4 (192 , 168 , 0 , 2 ))},
1007
+ IPv6 : "fd00::" ,
1008
+ Status : linodego .InstanceOffline ,
1009
+ }, nil )
1010
+ updateInstConfig := mck .LinodeClient .EXPECT ().
1011
+ UpdateInstanceConfig (ctx , 123 , 0 , gomock .Any ()).
1012
+ After (createInst ).
1013
+ Return (nil , nil ).AnyTimes ()
1014
+ getAddrs := mck .LinodeClient .EXPECT ().
1015
+ GetInstanceIPAddresses (ctx , 123 ).
1016
+ After (updateInstConfig ).
1017
+ Return (& linodego.InstanceIPAddressResponse {
1018
+ IPv4 : & linodego.InstanceIPv4Response {
1019
+ Private : []* linodego.InstanceIP {{Address : "192.168.0.2" }},
1020
+ Public : []* linodego.InstanceIP {{Address : "172.0.0.2" }},
1021
+ },
1022
+ IPv6 : & linodego.InstanceIPv6Response {
1023
+ SLAAC : & linodego.InstanceIP {
1024
+ Address : "fd00::" ,
1025
+ },
1026
+ },
1027
+ }, nil ).AnyTimes ()
1028
+ mck .LinodeClient .EXPECT ().
1029
+ ListInstanceConfigs (ctx , 123 , gomock .Any ()).
1030
+ After (getAddrs ).
1031
+ Return (nil , & linodego.Error {Code : http .StatusTooManyRequests })
1032
+ res , err := reconciler .reconcile (ctx , mck .Logger (), mScope )
1033
+ Expect (err ).NotTo (HaveOccurred ())
1034
+ Expect (res .RequeueAfter ).To (Equal (rutil .DefaultLinodeTooManyRequestsErrorRetryDelay ))
1035
+ Expect (mck .Logs ()).To (ContainSubstring ("Failed to get default instance configuration" ))
1036
+ })),
1037
+ ),
1038
+ ),
933
1039
Path (
934
1040
Call ("machine is created" , func (ctx context.Context , mck Mock ) {
1041
+ linodeMachine .Spec .Configuration = nil
935
1042
}),
936
1043
OneOf (
937
1044
Path (Result ("creates a worker machine without disks" , func (ctx context.Context , mck Mock ) {
0 commit comments