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

[tweak] - Switch linode labels to LinodeMachine Name instead of UID #143

Merged
merged 1 commit into from
Feb 28, 2024
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
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there other usages of renderObjectLabel? or can this function be deleted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my IDE shows no other usages so we should be safe to remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the function. It doesn't affect anything else

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