Skip to content

Commit f0cb1fa

Browse files
committed
🐛 fix: CCM crashes when unable to talk to OAPI
1 parent 4dd4253 commit f0cb1fa

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cloud-controller-manager/osc/oapi/oapi.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
osc "github.com/outscale/osc-sdk-go/v2"
1616
"k8s.io/klog/v2"
17+
"k8s.io/utils/ptr"
1718
)
1819

1920
const (
@@ -33,11 +34,11 @@ var (
3334

3435
func (c *OscClient) CheckCredentials(ctx context.Context) error {
3536
logger := klog.FromContext(ctx)
36-
req := osc.ReadVmsRequest{}
37+
req := osc.ReadVmsRequest{DryRun: ptr.To(true)}
3738
logger.V(4).Info("Check credentials", "OAPI", "ReadVms")
3839
_, httpRes, err := c.api.VmApi.ReadVms(c.WithAuth(ctx)).ReadVmsRequest(req).Execute()
3940
switch {
40-
case err == nil || httpRes.StatusCode == http.StatusTooManyRequests:
41+
case err == nil || (httpRes != nil && httpRes.StatusCode == http.StatusTooManyRequests):
4142
return nil
4243
case httpRes == nil:
4344
logger.V(3).Error(err, "OAPI error", "OAPI", "ReadVms")

cloud-controller-manager/osc/oapi/oapi_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ func TestCheckCredentials(t *testing.T) {
2121
err = api.OAPI().CheckCredentials(t.Context())
2222
require.ErrorIs(t, err, oapi.ErrInvalidCredentials)
2323
})
24+
t.Run("CheckCredentials returns an error in case of a network problem", func(t *testing.T) {
25+
t.Setenv("OSC_ACCESS_KEY", "foo")
26+
t.Setenv("OSC_SECRET_KEY", "bar")
27+
api, err := oapi.NewClient("foo")
28+
require.NoError(t, err)
29+
err = api.OAPI().CheckCredentials(t.Context())
30+
require.Error(t, err)
31+
})
2432
}

0 commit comments

Comments
 (0)