Skip to content

Commit

Permalink
Changing linode machine and linode vpc labels to names instead of CLi…
Browse files Browse the repository at this point in the history
…-{UID} (#143)

Co-authored-by: Khaja Omer <[email protected]>
  • Loading branch information
komer3 and komer3 authored Feb 28, 2024
1 parent d03b648 commit e019347
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 11 deletions.
3 changes: 1 addition & 2 deletions controller/linodemachine_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/go-logr/logr"
"github.com/google/uuid"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
"github.com/linode/cluster-api-provider-linode/util/reconciler"
"github.com/linode/linodego"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (*LinodeMachineReconciler) newCreateConfig(ctx context.Context, machineScop
createConfig.Tags = append(createConfig.Tags, tags...)

if createConfig.Label == "" {
createConfig.Label = util.RenderObjectLabel(machineScope.LinodeMachine.UID)
createConfig.Label = machineScope.LinodeMachine.Name
}

if createConfig.Image == "" {
Expand Down
2 changes: 1 addition & 1 deletion controller/linodevpc_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (r *LinodeVPCReconciler) reconcileVPC(ctx context.Context, vpcScope *scope.
}

if createConfig.Label == "" {
createConfig.Label = util.RenderObjectLabel(vpcScope.LinodeVPC.UID)
createConfig.Label = vpcScope.LinodeVPC.Name
}

if vpcs, err := vpcScope.LinodeClient.ListVPCs(ctx, linodego.NewListOptions(1, util.CreateLinodeAPIFilter(createConfig.Label, nil))); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ _runThisTest:
getKubeUid:
@kubectl get -o jsonpath='{.metadata.uid}' -n "$$NAMESPACE" "$$OBJ"

getKubeLabel:
@kubectl get -o jsonpath='{.spec.label}' -n "$$NAMESPACE" "$$OBJ"

patchKubeObj:
@kubectl patch --type=merge -p "$$PATCH" -n "$$NAMESPACE" "$$OBJ"

Expand Down
2 changes: 1 addition & 1 deletion e2e/linodevpc-controller/minimal/03-verify-vpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
URI="vpcs" FILTER="{\"label\":\"cli-$(OBJ=linodevpcs/linodevpc-sample make getKubeUid | sed 's/-//g')\"}" make callLinodeApiGet | grep 'results": 0'
URI="vpcs" FILTER="{\"label\":\"$(OBJ=linodevpcs/linodevpc-sample make getKubeLabel)\"}" make callLinodeApiGet | grep 'results": 0'
7 changes: 0 additions & 7 deletions util/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ package util

import (
"encoding/json"
"fmt"
"strings"

"github.com/linode/linodego"
"k8s.io/apimachinery/pkg/types"
)

// Pointer returns the pointer of any type
func Pointer[T any](t T) *T {
return &t
}

// RenderObjectLabel renders a 63 charater long unique label
func RenderObjectLabel(i types.UID) string {
return fmt.Sprintf("cli-%s", strings.ReplaceAll(string(i), "-", ""))
}

// CreateLinodeAPIFilter converts variables to API filter string
func CreateLinodeAPIFilter(label string, tags []string) string {
filter := map[string]string{}
Expand Down

0 comments on commit e019347

Please sign in to comment.