Skip to content

Commit 13aa533

Browse files
committed
Correct comments and documentation for the 'retain' field in VPCSubnetCreateOptions to ensure consistency in terminology. Refactor VPC fetching logic in LinodeVPCReconciler to improve code clarity and reduce redundancy by introducing a helper function for VPC retrieval.
1 parent d68d6c2 commit 13aa533

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

api/v1alpha2/linodevpc_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type VPCSubnetCreateOptions struct {
6464
// +optional
6565
SubnetID int `json:"subnetID,omitempty"`
6666
// Retain allows you to keep the Subnet after the LinodeVPC object is deleted.
67-
// This is only applicable when the parent VPC has RetainVPC set to true.
67+
// This is only applicable when the parent VPC has retain set to true.
6868
// +optional
6969
// +kubebuilder:default=false
7070
Retain bool `json:"retain,omitempty"`

config/crd/bases/infrastructure.cluster.x-k8s.io_linodevpcs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ spec:
9494
default: false
9595
description: |-
9696
Retain allows you to keep the Subnet after the LinodeVPC object is deleted.
97-
This is only applicable when the parent VPC has RetainVPC set to true.
97+
This is only applicable when the parent VPC has retain set to true.
9898
type: boolean
9999
subnetID:
100100
description: SubnetID is subnet id for the subnet

docs/src/reference/out.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,6 @@ _Appears in:_
12381238
| `label` _string_ | | | MaxLength: 63 <br />MinLength: 3 <br /> |
12391239
| `ipv4` _string_ | | | |
12401240
| `subnetID` _integer_ | SubnetID is subnet id for the subnet | | |
1241-
| `retain` _boolean_ | Retain allows you to keep the Subnet after the LinodeVPC object is deleted.<br />This is only applicable when the parent VPC has RetainVPC set to true. | false | |
1241+
| `retain` _boolean_ | Retain allows you to keep the Subnet after the LinodeVPC object is deleted.<br />This is only applicable when the parent VPC has retain set to true. | false | |
12421242

12431243

internal/controller/linodevpc_controller.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,8 @@ func (r *LinodeVPCReconciler) handleRetainedVPC(ctx context.Context, logger logr
370370
}
371371

372372
func (r *LinodeVPCReconciler) handleRetainedSubnets(ctx context.Context, logger logr.Logger, vpcScope *scope.VPCScope) error {
373-
if vpcScope.LinodeVPC.Spec.VPCID == nil {
374-
return nil
375-
}
376-
377-
vpc, err := vpcScope.LinodeClient.GetVPC(ctx, *vpcScope.LinodeVPC.Spec.VPCID)
373+
vpc, err := getVPC(ctx, vpcScope)
378374
if err != nil {
379-
if util.IgnoreLinodeAPIError(err, http.StatusNotFound) == nil {
380-
return nil
381-
}
382375
logger.Error(err, "Failed to fetch VPC for subnet deletion")
383376
if vpcScope.LinodeVPC.ObjectMeta.DeletionTimestamp.Add(reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultVPCControllerReconcileTimeout)).After(time.Now()) {
384377
logger.Info("re-queuing VPC deletion due to fetch error for subnet deletion")
@@ -438,16 +431,8 @@ func (r *LinodeVPCReconciler) handleRetainedSubnets(ctx context.Context, logger
438431
}
439432

440433
func (r *LinodeVPCReconciler) deleteVPCResources(ctx context.Context, logger logr.Logger, vpcScope *scope.VPCScope) error {
441-
if vpcScope.LinodeVPC.Spec.VPCID == nil {
442-
logger.Info("VPC ID is missing, nothing to do")
443-
return nil
444-
}
445-
446-
vpc, err := vpcScope.LinodeClient.GetVPC(ctx, *vpcScope.LinodeVPC.Spec.VPCID)
434+
vpc, err := getVPC(ctx, vpcScope)
447435
if err != nil {
448-
if util.IgnoreLinodeAPIError(err, http.StatusNotFound) == nil {
449-
return nil
450-
}
451436
logger.Error(err, "Failed to fetch VPC")
452437
if vpcScope.LinodeVPC.ObjectMeta.DeletionTimestamp.Add(reconciler.DefaultTimeout(r.ReconcileTimeout, reconciler.DefaultVPCControllerReconcileTimeout)).After(time.Now()) {
453438
logger.Info("re-queuing VPC deletion due to fetch error")

internal/controller/linodevpc_controller_helpers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controller
1919
import (
2020
"context"
2121
"errors"
22+
"net/http"
2223

2324
"github.com/go-logr/logr"
2425
"github.com/linode/linodego"
@@ -128,3 +129,22 @@ func linodeVPCSpecToVPCCreateConfig(vpcSpec infrav1alpha2.LinodeVPCSpec) *linode
128129
Subnets: subnets,
129130
}
130131
}
132+
133+
// getVPC fetches a VPC and handles not-found errors.
134+
// It returns the VPC if found.
135+
// It returns nil, nil if the VPC is not found.
136+
// It returns nil and an error for other API errors.
137+
func getVPC(ctx context.Context, vpcScope *scope.VPCScope) (*linodego.VPC, error) {
138+
if vpcScope.LinodeVPC.Spec.VPCID == nil {
139+
return nil, nil
140+
}
141+
142+
vpc, err := vpcScope.LinodeClient.GetVPC(ctx, *vpcScope.LinodeVPC.Spec.VPCID)
143+
if err != nil {
144+
if util.IgnoreLinodeAPIError(err, http.StatusNotFound) == nil {
145+
return nil, nil
146+
}
147+
return nil, err
148+
}
149+
return vpc, nil
150+
}

0 commit comments

Comments
 (0)