Skip to content

Commit

Permalink
Add external IP when present
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Thakur <[email protected]>
  • Loading branch information
Harsh Thakur authored and RealHarshThakur committed Jul 4, 2023
1 parent 4e0f261 commit f779bae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
CIVO_API_KEY=
CIVO_REGION=STAGING
CIVO_API_URL=https://api-staging.civo.com
CIVO_CLUSTER_ID=
19 changes: 13 additions & 6 deletions cloud-controller-manager/civo/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/civo/civo-cloud-controller-manager/cloud-controller-manager/pkg/utils"
"github.com/civo/civogo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -34,11 +35,19 @@ func (i *instances) NodeAddresses(ctx context.Context, name types.NodeName) ([]v
return nil, err
}

a := v1.NodeAddress{Type: "InternalIP", Address: instance.PrivateIP}

// Return Public and Private Addresses
return []v1.NodeAddress{a}, nil
return getAddressessFromCivoInstance(instance), nil

}

func getAddressessFromCivoInstance(instance civogo.Instance) []v1.NodeAddress {
nodeAdresses := make([]v1.NodeAddress, 0, 2)
nodeAdresses = append(nodeAdresses, v1.NodeAddress{Type: v1.NodeInternalIP, Address: instance.PrivateIP})
if instance.PublicIP != "" {
nodeAdresses = append(nodeAdresses, v1.NodeAddress{Type: v1.NodeExternalIP, Address: instance.PublicIP})
}

return nodeAdresses
}

// NodeAddressesByProviderID returns the addresses of the specified instance.
Expand All @@ -53,10 +62,8 @@ func (i *instances) NodeAddressesByProviderID(ctx context.Context, providerID st
return nil, err
}

a := v1.NodeAddress{Type: "InternalIP", Address: instance.PrivateIP}

// Return Public and Private Addresses
return []v1.NodeAddress{a}, nil
return getAddressessFromCivoInstance(instance), nil
}

// InstanceID returns the cloud provider ID of the node with the specified NodeName.
Expand Down
5 changes: 5 additions & 0 deletions cloud-controller-manager/civo/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestNodeAddressesByProviderID(t *testing.T) {
ID: "acb5cbd0-ef7f-4edd-8a51-005940fdb7a8",
Hostname: "test-node",
PrivateIP: "192.168.11.11",
PublicIP: "127.0.0.101",
},
}
expected :=
Expand All @@ -86,6 +87,10 @@ func TestNodeAddressesByProviderID(t *testing.T) {
Type: corev1.NodeInternalIP,
Address: "192.168.11.11",
},
corev1.NodeAddress{
Type: corev1.NodeExternalIP,
Address: "127.0.0.101",
},
}
clusterStore := []civogo.KubernetesCluster{
{
Expand Down

0 comments on commit f779bae

Please sign in to comment.