Skip to content

Commit 56f697c

Browse files
committed
chore: address review comments
Signed-off-by: Artur Shad Nik <arturshadnik@gmail.com>
1 parent 909e45e commit 56f697c

File tree

3 files changed

+12
-36
lines changed

3 files changed

+12
-36
lines changed

fleetconfig-controller/hack/support-bundle/serve.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ if [[ -n "$local_bundle" ]]; then
141141
# Bundle is exactly the fleetconfig-support-bundle directory
142142
echo "Bundle is already in the expected location"
143143
else
144-
# Bundle is outside fleetconfig-support-bundle-support-bundle, create symlink
144+
# Bundle is outside fleetconfig-support-bundle, create symlink
145145
if [[ -d "fleetconfig-support-bundle" ]]; then
146146
rm -rf fleetconfig-support-bundle
147147
fi

fleetconfig-controller/internal/args/args_test.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"os"
66
"reflect"
7+
"slices"
78
"testing"
89
)
910

@@ -74,21 +75,21 @@ users:
7475
defer cleanup()
7576

7677
if err != nil {
77-
t.Fatalf("PrepareKubeconfig() error = %v", err)
78+
t.Errorf("PrepareKubeconfig() error = %v", err)
7879
}
7980

8081
// Check that kubeconfig flag is added
81-
if !contains(resultArgs, "--kubeconfig") {
82+
if !slices.Contains(resultArgs, "--kubeconfig") {
8283
t.Error("PrepareKubeconfig() should add --kubeconfig flag")
8384
}
8485

8586
// Check that context flag is added
86-
if !contains(resultArgs, "--context") {
87+
if !slices.Contains(resultArgs, "--context") {
8788
t.Error("PrepareKubeconfig() should add --context flag")
8889
}
8990

9091
// Check that the kubeconfig file exists
91-
kubeconfigIndex := indexOf(resultArgs, "--kubeconfig")
92+
kubeconfigIndex := slices.Index(resultArgs, "--kubeconfig")
9293
if kubeconfigIndex == -1 || kubeconfigIndex+1 >= len(resultArgs) {
9394
t.Fatal("PrepareKubeconfig() should add kubeconfig path")
9495
}
@@ -104,15 +105,15 @@ users:
104105
defer cleanup()
105106

106107
if err != nil {
107-
t.Fatalf("PrepareKubeconfig() error = %v", err)
108+
t.Errorf("PrepareKubeconfig() error = %v", err)
108109
}
109110

110111
// Check that kubeconfig flag is added but context is not
111-
if !contains(resultArgs, "--kubeconfig") {
112+
if !slices.Contains(resultArgs, "--kubeconfig") {
112113
t.Error("PrepareKubeconfig() should add --kubeconfig flag")
113114
}
114115

115-
if contains(resultArgs, "--context") {
116+
if slices.Contains(resultArgs, "--context") {
116117
t.Error("PrepareKubeconfig() should not add --context flag when context is empty")
117118
}
118119
})
@@ -217,22 +218,3 @@ func TestMockResourceValues_String(t *testing.T) {
217218
})
218219
}
219220
}
220-
221-
// Helper functions
222-
func contains(slice []string, item string) bool {
223-
for _, s := range slice {
224-
if s == item {
225-
return true
226-
}
227-
}
228-
return false
229-
}
230-
231-
func indexOf(slice []string, item string) int {
232-
for i, s := range slice {
233-
if s == item {
234-
return i
235-
}
236-
}
237-
return -1
238-
}

fleetconfig-controller/internal/controller/v1beta1/spoke_controller.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (r *SpokeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
128128
}
129129

130130
if slices.Contains(spoke.Finalizers, v1beta1.SpokeCleanupFinalizer) {
131-
if err := r.cleanup(ctx, spoke, spokeKubeconfig); err != nil {
131+
if err := r.cleanup(ctx, spoke, spokeKubeconfig, hubMeta); err != nil {
132132
spoke.SetConditions(true, v1beta1.NewCondition(
133133
err.Error(), v1beta1.CleanupFailed, metav1.ConditionTrue, metav1.ConditionFalse,
134134
))
@@ -210,15 +210,9 @@ func setDefaults(ctx context.Context, spoke *v1beta1.Spoke, hubMeta hubMeta) {
210210
}
211211

212212
// cleanup cleans up a Spoke and its associated resources.
213-
func (r *SpokeReconciler) cleanup(ctx context.Context, spoke *v1beta1.Spoke, spokeKubeconfig []byte) error {
213+
func (r *SpokeReconciler) cleanup(ctx context.Context, spoke *v1beta1.Spoke, spokeKubeconfig []byte, hubMeta hubMeta) error {
214214
logger := log.FromContext(ctx)
215215

216-
hubMeta, err := r.getHubMeta(ctx, spoke.Spec.HubRef)
217-
if err != nil {
218-
// TODO
219-
return err
220-
}
221-
222216
clusterC, err := common.ClusterClient(hubMeta.kubeconfig)
223217
if err != nil {
224218
return err
@@ -454,7 +448,7 @@ func (r *SpokeReconciler) joinSpoke(ctx context.Context, spoke *v1beta1.Spoke, h
454448

455449
hub := hubMeta.hub
456450

457-
if hubMeta.hub == nil {
451+
if hub == nil {
458452
return errors.New("hub not found")
459453
}
460454
// dont start join until the hub is ready

0 commit comments

Comments
 (0)