Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Requeue during machine preflight #242

Merged
merged 8 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cloud/scope/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"github.com/linode/cluster-api-provider-linode/version"
)

func CreateLinodeClient(apiKey string) (*linodego.Client, error) {
type clientOption func(*linodego.Client)

func CreateLinodeClient(apiKey string, opts ...clientOption) (*linodego.Client, error) {
bcm820 marked this conversation as resolved.
Show resolved Hide resolved
if apiKey == "" {
return nil, errors.New("missing Linode API key")
}
Expand All @@ -28,6 +30,10 @@ func CreateLinodeClient(apiKey string) (*linodego.Client, error) {
}
linodeClient := linodego.NewClient(oauth2Client)

for _, opt := range opts {
opt(&linodeClient)
}

linodeClient.SetUserAgent(fmt.Sprintf("CAPL/%s", version.GetVersion()))

return &linodeClient, nil
Expand Down
12 changes: 7 additions & 5 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"

"github.com/linode/linodego"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand All @@ -23,8 +24,7 @@ type MachineScopeParams struct {
}

type MachineScope struct {
client k8sClient

Client k8sClient
PatchHelper *patch.Helper
Cluster *clusterv1.Cluster
Machine *clusterv1.Machine
Expand Down Expand Up @@ -82,7 +82,9 @@ func NewMachineScope(ctx context.Context, apiKey string, params MachineScopePara
}
apiKey = string(data)
}
linodeClient, err := CreateLinodeClient(apiKey)
linodeClient, err := CreateLinodeClient(apiKey, func(linodeClient *linodego.Client) {
linodeClient.SetRetryCount(0)
})
if err != nil {
return nil, fmt.Errorf("failed to create linode client: %w", err)
}
Expand All @@ -93,7 +95,7 @@ func NewMachineScope(ctx context.Context, apiKey string, params MachineScopePara
}

return &MachineScope{
client: params.Client,
Client: params.Client,
PatchHelper: helper,
Cluster: params.Cluster,
Machine: params.Machine,
Expand Down Expand Up @@ -135,7 +137,7 @@ func (m *MachineScope) GetBootstrapData(ctx context.Context) ([]byte, error) {

secret := &corev1.Secret{}
key := types.NamespacedName{Namespace: m.LinodeMachine.Namespace, Name: *m.Machine.Spec.Bootstrap.DataSecretName}
if err := m.client.Get(ctx, key, secret); err != nil {
if err := m.Client.Get(ctx, key, secret); err != nil {
return []byte{}, fmt.Errorf(
"failed to retrieve bootstrap data secret for LinodeMachine %s/%s",
m.LinodeMachine.Namespace,
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func TestMachineScopeGetBootstrapData(t *testing.T) {
testcase.expects(mockK8sClient)

mScope := &MachineScope{
client: mockK8sClient,
Client: mockK8sClient,
PatchHelper: &patch.Helper{}, // empty patch helper
Cluster: testcase.fields.Cluster,
Machine: testcase.fields.Machine,
Expand Down
Loading
Loading