Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ aliases:
- jamand
- breuerfelix
- aniruddha2000

machine-controller-manager-provider-stackit-approvers:
- dergeberl
- JuliusSte
Expand Down
21 changes: 0 additions & 21 deletions cmd/machine-controller/main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
/*
Copyright 2014 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

This file was copied and modified from the kubernetes/kubernetes project
https://github.com/kubernetes/kubernetes/release-1.8/cmd/kube-controller-manager/controller_manager.go

Modifications Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved.
*/

package main

import (
Expand Down
4 changes: 0 additions & 4 deletions hack/rename-project
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/bin/bash -eu
#
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

project_name=$1
provider_name=$2
Expand Down
57 changes: 57 additions & 0 deletions pkg/client/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package client

// ptr returns a pointer to the given value
// This helper is needed because the STACKIT SDK uses pointers for optional fields
func ptr[T any](v T) *T {
return &v
}

// convertLabelsToSDK converts map[string]string to *map[string]interface{} for SDK
//
//nolint:gocritic // SDK requires *map
func convertLabelsToSDK(labels map[string]string) *map[string]interface{} {
if labels == nil {
return nil
}

result := make(map[string]interface{}, len(labels))
for k, v := range labels {
result[k] = v
}
return &result
}

// convertLabelsFromSDK converts *map[string]interface{} from SDK to map[string]string
//
//nolint:gocritic // SDK requires *map
func convertLabelsFromSDK(labels *map[string]interface{}) map[string]string {
if labels == nil {
return nil
}

result := make(map[string]string, len(*labels))
for k, v := range *labels {
if strVal, ok := v.(string); ok {
result[k] = strVal
}
}
return result
}

// convertStringSliceToSDK converts []string to *[]string for SDK
func convertStringSliceToSDK(slice []string) *[]string {
if slice == nil {
return nil
}
return &slice
}

// convertMetadataToSDK converts map[string]interface{} to *map[string]interface{} for SDK
//
//nolint:gocritic // SDK requires *map
func convertMetadataToSDK(metadata map[string]interface{}) *map[string]interface{} {
if metadata == nil {
return nil
}
return &metadata
}
77 changes: 77 additions & 0 deletions pkg/client/mock/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package mock

import (
"context"
"encoding/json"

"github.com/stackitcloud/machine-controller-manager-provider-stackit/pkg/client"
api "github.com/stackitcloud/machine-controller-manager-provider-stackit/pkg/provider/apis"
)

// StackitClient is a mock implementation of StackitClient for testing
// Note: Single-tenant design - each client is bound to one set of credentials
type StackitClient struct {
CreateServerFunc func(ctx context.Context, projectID, region string, req *client.CreateServerRequest) (*client.Server, error)
GetServerFunc func(ctx context.Context, projectID, region, serverID string) (*client.Server, error)
DeleteServerFunc func(ctx context.Context, projectID, region, serverID string) error
ListServersFunc func(ctx context.Context, projectID, region string, labelSelector map[string]string) ([]*client.Server, error)
GetNICsFunc func(ctx context.Context, projectID, region, serverID string) ([]*client.NIC, error)
UpdateNICFunc func(ctx context.Context, projectID, region, networkID, nicID string, allowedAddresses []string) (*client.NIC, error)
}

func (m *StackitClient) CreateServer(ctx context.Context, projectID, region string, req *client.CreateServerRequest) (*client.Server, error) {
if m.CreateServerFunc != nil {
return m.CreateServerFunc(ctx, projectID, region, req)
}
return &client.Server{
ID: "550e8400-e29b-41d4-a716-446655440000",
Name: req.Name,
Status: "CREATING",
}, nil
}

func (m *StackitClient) GetServer(ctx context.Context, projectID, region, serverID string) (*client.Server, error) {
if m.GetServerFunc != nil {
return m.GetServerFunc(ctx, projectID, region, serverID)
}
return &client.Server{
ID: serverID,
Name: "test-machine",
Status: "ACTIVE",
}, nil
}

func (m *StackitClient) DeleteServer(ctx context.Context, projectID, region, serverID string) error {
if m.DeleteServerFunc != nil {
return m.DeleteServerFunc(ctx, projectID, region, serverID)
}
return nil
}

func (m *StackitClient) ListServers(ctx context.Context, projectID, region string, labelSelector map[string]string) ([]*client.Server, error) {
if m.ListServersFunc != nil {
return m.ListServersFunc(ctx, projectID, region, labelSelector)
}
return []*client.Server{}, nil
}

func (m *StackitClient) GetNICsForServer(ctx context.Context, projectID, region, serverID string) ([]*client.NIC, error) {
if m.GetNICsFunc != nil {
return m.GetNICsFunc(ctx, projectID, region, serverID)
}
return []*client.NIC{}, nil
}

func (m *StackitClient) UpdateNIC(ctx context.Context, projectID, region, networkID, nicID string, allowedAddresses []string) (*client.NIC, error) {
if m.UpdateNICFunc != nil {
return m.UpdateNICFunc(ctx, projectID, region, networkID, nicID, allowedAddresses)
}
return &client.NIC{}, nil
}

// UpdateNIC updates a network interface

// encodeProviderSpec is a helper function to encode ProviderSpec for tests
func EncodeProviderSpec(spec *api.ProviderSpec) ([]byte, error) {
return json.Marshal(spec)
}
6 changes: 1 addition & 5 deletions pkg/provider/sdk_client.go → pkg/client/sdk.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package provider
package client

import (
"context"
Expand Down
6 changes: 1 addition & 5 deletions pkg/provider/sdk_client_test.go → pkg/client/sdk_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package provider
package client

import (
"errors"
Expand Down
7 changes: 1 addition & 6 deletions pkg/provider/stackit_client.go → pkg/client/stackit.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package provider
package client

import (
"context"
Expand All @@ -18,7 +14,6 @@ import (
//
// Note: region parameter is required by STACKIT SDK v1.0.0+
// It must be extracted from the Secret (e.g., "eu01-1", "eu01-2")
// nolint:dupl // the duplicates are mock functions
type StackitClient interface {
// CreateServer creates a new server in STACKIT
CreateServer(ctx context.Context, projectID, region string, req *CreateServerRequest) (*Server, error)
Expand Down
4 changes: 0 additions & 4 deletions pkg/provider/apis/provider_spec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package api

// ProviderSpec is the spec to be used while parsing the calls.
Expand Down
5 changes: 0 additions & 5 deletions pkg/provider/apis/validation/validation.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

// Package validation - validation is used to validate cloud specific ProviderSpec
package validation

import (
Expand Down
4 changes: 0 additions & 4 deletions pkg/provider/apis/validation/validation_core_labels_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package validation_test

import (
Expand Down
4 changes: 0 additions & 4 deletions pkg/provider/apis/validation/validation_fields_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package validation_test

import (
Expand Down
4 changes: 0 additions & 4 deletions pkg/provider/apis/validation/validation_networking_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package validation_test

import (
Expand Down
4 changes: 0 additions & 4 deletions pkg/provider/apis/validation/validation_secgroup_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package validation_test

import (
Expand Down
4 changes: 0 additions & 4 deletions pkg/provider/apis/validation/validation_secret_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package validation_test

import (
Expand Down
4 changes: 0 additions & 4 deletions pkg/provider/apis/validation/validation_volumes_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package validation_test

import (
Expand Down
Loading