Skip to content

Commit

Permalink
deprecate ProviderID (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine authored Aug 20, 2024
1 parent 9e2fb06 commit 98b4e79
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 79 deletions.
4 changes: 0 additions & 4 deletions api/v1alpha1/linodemachine_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestLinodeMachineConvertTo(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "test-machine"},
Spec: LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand Down Expand Up @@ -82,7 +81,6 @@ func TestLinodeMachineConvertTo(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "test-machine"},
Spec: infrav1alpha2.LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand Down Expand Up @@ -168,7 +166,6 @@ func TestLinodeMachineConvertFrom(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "test-machine"},
Spec: infrav1alpha2.LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand Down Expand Up @@ -215,7 +212,6 @@ func TestLinodeMachineConvertFrom(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "test-machine"},
Spec: LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand Down
4 changes: 0 additions & 4 deletions api/v1alpha1/linodemachinetemplate_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestLinodeMachineTemplateConvertTo(t *testing.T) {
Template: LinodeMachineTemplateResource{
Spec: LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand Down Expand Up @@ -87,7 +86,6 @@ func TestLinodeMachineTemplateConvertTo(t *testing.T) {
Template: infrav1alpha2.LinodeMachineTemplateResource{
Spec: infrav1alpha2.LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand Down Expand Up @@ -176,7 +174,6 @@ func TestLinodeMachineTemplateConvertFrom(t *testing.T) {
Template: infrav1alpha2.LinodeMachineTemplateResource{
Spec: infrav1alpha2.LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand Down Expand Up @@ -221,7 +218,6 @@ func TestLinodeMachineTemplateConvertFrom(t *testing.T) {
Template: LinodeMachineTemplateResource{
Spec: LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand Down
3 changes: 2 additions & 1 deletion api/v1alpha2/linodemachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type LinodeMachineSpec struct {
ProviderID *string `json:"providerID,omitempty"`
// InstanceID is the Linode instance ID for this machine.
// +optional
// +kubebuilder:deprecatedversion:warning="ProviderID deprecates InstanceID"
InstanceID *int `json:"instanceID,omitempty"`

// +kubebuilder:validation:Required
Expand Down Expand Up @@ -215,7 +216,7 @@ type LinodeMachineStatus struct {
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this LinodeMachine belongs"
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.instanceState",description="Linode instance state"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Machine ready status"
// +kubebuilder:printcolumn:name="InstanceID",type="string",JSONPath=".spec.providerID",description="Linode instance ID"
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="Provider ID"
// +kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this LinodeMachine"

// LinodeMachine is the Schema for the linodemachines API
Expand Down
34 changes: 17 additions & 17 deletions cloud/services/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestAddIPToEdgeDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestAddIPToEdgeDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestRemoveIPFromEdgeDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestRemoveIPFromEdgeDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -398,7 +398,7 @@ func TestAddIPToDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestAddIPToDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -545,7 +545,7 @@ func TestAddIPToDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -613,7 +613,7 @@ func TestAddIPToDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -687,7 +687,7 @@ func TestAddIPToDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -754,7 +754,7 @@ func TestAddIPToDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: nil,
Expand Down Expand Up @@ -811,7 +811,7 @@ func TestAddIPToDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -916,7 +916,7 @@ func TestDeleteIPFromDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -991,7 +991,7 @@ func TestDeleteIPFromDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -1066,7 +1066,7 @@ func TestDeleteIPFromDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
},
Expand Down Expand Up @@ -1113,7 +1113,7 @@ func TestDeleteIPFromDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -1174,7 +1174,7 @@ func TestDeleteIPFromDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down Expand Up @@ -1240,7 +1240,7 @@ func TestDeleteIPFromDNS(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
Status: infrav1alpha2.LinodeMachineStatus{
Addresses: []clusterv1.MachineAddress{
Expand Down
18 changes: 14 additions & 4 deletions cloud/services/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ func AddNodeToNB(
return nil
}

instanceID, err := util.GetInstanceID(machineScope.LinodeMachine.Spec.ProviderID)
if err != nil {
logger.Error(err, "Failed to parse instance ID from provider ID")
return err
}
// Get the private IP that was assigned
addresses, err := machineScope.LinodeClient.GetInstanceIPAddresses(ctx, *machineScope.LinodeMachine.Spec.InstanceID)
addresses, err := machineScope.LinodeClient.GetInstanceIPAddresses(ctx, instanceID)
if err != nil {
logger.Error(err, "Failed get instance IP addresses")

Expand Down Expand Up @@ -200,11 +205,16 @@ func DeleteNodeFromNB(
return nil
}

err := machineScope.LinodeClient.DeleteNodeBalancerNode(
instanceID, err := util.GetInstanceID(machineScope.LinodeMachine.Spec.ProviderID)
if err != nil {
logger.Error(err, "Failed to parse instance ID from provider ID")
return err
}
err = machineScope.LinodeClient.DeleteNodeBalancerNode(
ctx,
*machineScope.LinodeCluster.Spec.Network.NodeBalancerID,
*machineScope.LinodeCluster.Spec.Network.ApiserverNodeBalancerConfigID,
*machineScope.LinodeMachine.Spec.InstanceID,
instanceID,
)
if util.IgnoreLinodeAPIError(err, http.StatusNotFound) != nil {
logger.Error(err, "Failed to update Node Balancer")
Expand All @@ -217,7 +227,7 @@ func DeleteNodeFromNB(
ctx,
*machineScope.LinodeCluster.Spec.Network.NodeBalancerID,
*portConfig.NodeBalancerConfigID,
*machineScope.LinodeMachine.Spec.InstanceID,
instanceID,
)
if util.IgnoreLinodeAPIError(err, http.StatusNotFound) != nil {
logger.Error(err, "Failed to update Node Balancer")
Expand Down
18 changes: 9 additions & 9 deletions cloud/services/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func TestAddNodeToNBConditions(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
},
Expand Down Expand Up @@ -488,7 +488,7 @@ func TestAddNodeToNBConditions(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
},
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestAddNodeToNBConditions(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
},
Expand Down Expand Up @@ -631,7 +631,7 @@ func TestAddNodeToNBFullWorkflow(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
},
Expand Down Expand Up @@ -687,7 +687,7 @@ func TestAddNodeToNBFullWorkflow(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
},
Expand Down Expand Up @@ -782,7 +782,7 @@ func TestDeleteNodeFromNB(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
LinodeCluster: &infrav1alpha2.LinodeCluster{
Expand Down Expand Up @@ -818,7 +818,7 @@ func TestDeleteNodeFromNB(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
LinodeCluster: &infrav1alpha2.LinodeCluster{
Expand Down Expand Up @@ -867,7 +867,7 @@ func TestDeleteNodeFromNB(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
LinodeCluster: &infrav1alpha2.LinodeCluster{
Expand Down Expand Up @@ -910,7 +910,7 @@ func TestDeleteNodeFromNB(t *testing.T) {
UID: "test-uid",
},
Spec: infrav1alpha2.LinodeMachineSpec{
InstanceID: ptr.To(123),
ProviderID: ptr.To("linode://123"),
},
},
LinodeCluster: &infrav1alpha2.LinodeCluster{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ spec:
jsonPath: .status.ready
name: Ready
type: string
- description: Linode instance ID
- description: Provider ID
jsonPath: .spec.providerID
name: InstanceID
name: ProviderID
type: string
- description: Machine object which owns with this LinodeMachine
jsonPath: .metadata.ownerReferences[?(@.kind=="Machine")].name
Expand Down
Loading

0 comments on commit 98b4e79

Please sign in to comment.