Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/golang.org/x/oauth2-0.…
Browse files Browse the repository at this point in the history
…18.0
  • Loading branch information
eljohnson92 authored Mar 12, 2024
2 parents dea2d97 + bfb5cf1 commit 3ca5483
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 34 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build_test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ jobs:
allowed-endpoints: >
api.github.com:443
github.com:443
golang.org:443
proxy.golang.org:443
sum.golang.org:443
objects.githubusercontent.com:443
storage.googleapis.com:443
cli.codecov.io:443
api.codecov.io:443
- uses: actions/checkout@v4

Expand All @@ -54,6 +57,16 @@ jobs:
- name: Test
run: make test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.out
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
slug: linode/cluster-api-provider-linode


go-analyse:
needs: go-build-test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -103,6 +116,7 @@ jobs:
e2e-test:
needs: [go-build-test, docker-build]
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ IMAGE_NAME ?= cluster-api-provider-linode
CONTROLLER_IMAGE ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= dev
ENVTEST_K8S_VERSION := 1.28.0
VERSION ?= $(shell git describe --always --tag --dirty=-dev)
BUILD_ARGS := --build-arg VERSION=$(VERSION)
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
CONTAINER_TOOL ?= docker
MDBOOK_DEV_HOST = 0.0.0.0
MDBOOK_DEV_PORT = 3000
VERSION ?= $(shell git describe --always --tag --dirty=-dev)

# ENVTEST_K8S_VERSION
# - refers to the version of kubebuilder assets to be downloaded by envtest binary.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<!-- goreportcard badge -->
<a href="https://goreportcard.com/report/github.com/linode/cluster-api-provider-linode">
<img src="https://goreportcard.com/badge/github.com/linode/cluster-api-provider-linode"></a>
<!-- codecov badge -->
<a href="https://codecov.io/github/linode/cluster-api-provider-linode" >
<img src="https://codecov.io/github/linode/cluster-api-provider-linode/graph/badge.svg?token=YQFKF86KJ6"/>
</a>
<!-- join kubernetes slack channel for linode -->
<a href="https://kubernetes.slack.com/messages/CD4B15LUR">
<img src="https://img.shields.io/badge/join%20slack-%23linode-brightgreen"></a>
Expand Down
17 changes: 17 additions & 0 deletions cloud/scope/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ package scope
import (
"context"

"github.com/linode/linodego"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// LinodeObjectStorageClient defines functions suitable for provisioning object storage buckets and keys.
type LinodeObjectStorageClient interface {
GetObjectStorageBucket(ctx context.Context, cluster, label string) (*linodego.ObjectStorageBucket, error)
CreateObjectStorageBucket(ctx context.Context, opts linodego.ObjectStorageBucketCreateOptions) (*linodego.ObjectStorageBucket, error)
CreateObjectStorageKey(ctx context.Context, opts linodego.ObjectStorageKeyCreateOptions) (*linodego.ObjectStorageKey, error)
DeleteObjectStorageKey(ctx context.Context, keyID int) error
}

// LinodeObjectStorageClientBuilder is a function that returns a LinodeObjectStorageClient.
type LinodeObjectStorageClientBuilder func(apiKey string) (LinodeObjectStorageClient, error)

// CreateLinodeObjectStorageClient is the main implementation of LinodeObjectStorageClientBuilder.
func CreateLinodeObjectStorageClient(apiKey string) (LinodeObjectStorageClient, error) {
return CreateLinodeClient(apiKey)
}

type k8sClient interface {
client.Client
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewClusterScope(ctx context.Context, apiKey string, params ClusterScopePara
}
apiKey = string(data)
}
linodeClient, err := createLinodeClient(apiKey)
linodeClient, err := CreateLinodeClient(apiKey)
if err != nil {
return nil, fmt.Errorf("failed to create linode client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestClusterScopeMethods(t *testing.T) {
mockPatchHelper := mock.NewMockPatchHelper(ctrl)
mockK8sClient := mock.NewMockk8sClient(ctrl)

lClient, err := createLinodeClient("test-key")
lClient, err := CreateLinodeClient("test-key")
if err != nil {
t.Errorf("createLinodeClient() error = %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

type patchNewHelper func(obj client.Object, crClient client.Client) (*patch.Helper, error)

func createLinodeClient(apiKey string) (*linodego.Client, error) {
func CreateLinodeClient(apiKey string) (*linodego.Client, error) {
if apiKey == "" {
return nil, errors.New("missing Linode API key")
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestCreateLinodeClient(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

got, err := createLinodeClient(testCase.apiKey)
got, err := CreateLinodeClient(testCase.apiKey)

if testCase.expectedErr != nil {
assert.EqualError(t, err, testCase.expectedErr.Error())
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewMachineScope(ctx context.Context, apiKey string, params MachineScopePara
}
apiKey = string(data)
}
linodeClient, err := createLinodeClient(apiKey)
linodeClient, err := CreateLinodeClient(apiKey)
if err != nil {
return nil, fmt.Errorf("failed to create linode client: %w", err)
}
Expand Down
14 changes: 9 additions & 5 deletions cloud/scope/object_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ import (
)

type ObjectStorageBucketScopeParams struct {
Client client.Client
Bucket *infrav1alpha1.LinodeObjectStorageBucket
Logger *logr.Logger
Client client.Client
LinodeClientBuilder LinodeObjectStorageClientBuilder
Bucket *infrav1alpha1.LinodeObjectStorageBucket
Logger *logr.Logger
}

type ObjectStorageBucketScope struct {
client client.Client
Bucket *infrav1alpha1.LinodeObjectStorageBucket
Logger logr.Logger
LinodeClient *linodego.Client
LinodeClient LinodeObjectStorageClient
BucketPatchHelper *patch.Helper
}

Expand All @@ -41,6 +42,9 @@ func validateObjectStorageBucketScopeParams(params ObjectStorageBucketScopeParam
if params.Logger == nil {
return errors.New("logger is required when creating an ObjectStorageBucketScope")
}
if params.LinodeClientBuilder == nil {
return errors.New("LinodeClientBuilder is required when creating an ObjectStorageBucketScope")
}

return nil
}
Expand All @@ -58,7 +62,7 @@ func NewObjectStorageBucketScope(ctx context.Context, apiKey string, params Obje
}
apiKey = string(data)
}
linodeClient, err := createLinodeClient(apiKey)
linodeClient, err := params.LinodeClientBuilder(apiKey)
if err != nil {
return nil, fmt.Errorf("failed to create linode client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewVPCScope(ctx context.Context, apiKey string, params VPCScopeParams) (*VP
}
apiKey = string(data)
}
linodeClient, err := createLinodeClient(apiKey)
linodeClient, err := CreateLinodeClient(apiKey)
if err != nil {
return nil, fmt.Errorf("failed to create linode client: %w", err)
}
Expand Down
14 changes: 8 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

infrastructurev1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
controller2 "github.com/linode/cluster-api-provider-linode/controller"
"github.com/linode/cluster-api-provider-linode/version"

Expand Down Expand Up @@ -140,12 +141,13 @@ func main() {
os.Exit(1)
}
if err = (&controller2.LinodeObjectStorageBucketReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Logger: ctrl.Log.WithName("LinodeObjectStorageBucketReconciler"),
Recorder: mgr.GetEventRecorderFor("LinodeObjectStorageBucketReconciler"),
WatchFilterValue: objectStorageBucketWatchFilter,
LinodeApiKey: linodeToken,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Logger: ctrl.Log.WithName("LinodeObjectStorageBucketReconciler"),
Recorder: mgr.GetEventRecorderFor("LinodeObjectStorageBucketReconciler"),
WatchFilterValue: objectStorageBucketWatchFilter,
LinodeApiKey: linodeToken,
LinodeClientBuilder: scope.CreateLinodeObjectStorageClient,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "LinodeObjectStorageBucket")
os.Exit(1)
Expand Down
26 changes: 15 additions & 11 deletions controller/linodeobjectstoragebucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ import (
// LinodeObjectStorageBucketReconciler reconciles a LinodeObjectStorageBucket object
type LinodeObjectStorageBucketReconciler struct {
client.Client
Scheme *runtime.Scheme
Logger logr.Logger
Recorder record.EventRecorder
LinodeApiKey string
WatchFilterValue string
ReconcileTimeout time.Duration
Scheme *runtime.Scheme
Logger logr.Logger
Recorder record.EventRecorder
LinodeApiKey string
LinodeClientBuilder scope.LinodeObjectStorageClientBuilder
WatchFilterValue string
ReconcileTimeout time.Duration
}

// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -89,9 +90,10 @@ func (r *LinodeObjectStorageBucketReconciler) Reconcile(ctx context.Context, req
ctx,
r.LinodeApiKey,
scope.ObjectStorageBucketScopeParams{
Client: r.Client,
Bucket: objectStorageBucket,
Logger: &logger,
Client: r.Client,
LinodeClientBuilder: r.LinodeClientBuilder,
Bucket: objectStorageBucket,
Logger: &logger,
},
)
if err != nil {
Expand Down Expand Up @@ -175,7 +177,7 @@ func (r *LinodeObjectStorageBucketReconciler) reconcileApply(ctx context.Context
bScope.Bucket.Status.LastKeyGeneration = bScope.Bucket.Spec.KeyGeneration
}

r.Recorder.Event(bScope.Bucket, corev1.EventTypeNormal, "Ready", "Object storage bucket configuration applied")
r.Recorder.Event(bScope.Bucket, corev1.EventTypeNormal, "Ready", "Object storage bucket applied")

bScope.Bucket.Status.Ready = true
conditions.MarkTrue(bScope.Bucket, clusterv1.ReadyCondition)
Expand All @@ -195,7 +197,7 @@ func (r *LinodeObjectStorageBucketReconciler) reconcileDelete(ctx context.Contex
}

if err := services.RevokeObjectStorageKeys(ctx, bScope, secret); err != nil {
bScope.Logger.Error(err, "failed to revoke access keys; keys must be manually revoked")
bScope.Logger.Error(err, "Failed to revoke access keys; keys must be manually revoked")
r.setFailure(bScope, err)

return err
Expand Down Expand Up @@ -223,6 +225,8 @@ func (r *LinodeObjectStorageBucketReconciler) reconcileDelete(ctx context.Contex
return err
}

r.Recorder.Event(bScope.Bucket, clusterv1.DeletedReason, "Ready", "Object storage bucket deleted")

return nil
}

Expand Down
Loading

0 comments on commit 3ca5483

Please sign in to comment.