Skip to content

Commit 291190a

Browse files
committed
allow retrieval of instance fqdn using instanceID
1 parent 909bf68 commit 291190a

File tree

7 files changed

+56
-1
lines changed

7 files changed

+56
-1
lines changed

pkg/cloudprovider/providers/oci/instances.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func (cp *CloudProvider) NodeAddresses(ctx context.Context, name types.NodeName)
9292
// nodeaddresses are being queried. i.e. local metadata services cannot be used
9393
// in this method to obtain nodeaddresses.
9494
func (cp *CloudProvider) NodeAddressesByProviderID(ctx context.Context, providerID string) ([]api.NodeAddress, error) {
95+
addresses := []api.NodeAddress{}
9596
cp.logger.With("instanceID", providerID).Debug("Getting node addresses by provider id")
9697
instanceID, err := MapProviderIDToInstanceID(providerID)
9798
if err != nil {
@@ -101,7 +102,28 @@ func (cp *CloudProvider) NodeAddressesByProviderID(ctx context.Context, provider
101102
if err != nil {
102103
return nil, errors.Wrap(err, "GetPrimaryVNICForInstance")
103104
}
104-
return extractNodeAddressesFromVNIC(vnic)
105+
vnicAddresses, err := extractNodeAddressesFromVNIC(vnic)
106+
if err != nil {
107+
return nil, err
108+
}
109+
addresses = append(addresses, vnicAddresses...)
110+
hostname := vnic.HostnameLabel
111+
if *hostname == "" {
112+
cp.logger.With("instanceID", providerID).Debug("hostname not set, instance won't be resolvable using using the Internet and VCN Resolver")
113+
return addresses, nil
114+
}
115+
subnet, err := cp.client.Networking().GetSubnet(ctx, *vnic.SubnetId)
116+
if err != nil {
117+
return nil, errors.Wrap(err, "GetSubnetForInstance")
118+
}
119+
vcn, err := cp.client.Networking().GetVcn(ctx, *subnet.VcnId)
120+
if err != nil {
121+
return nil, errors.Wrap(err, "GetVcnForInstance")
122+
}
123+
fqdn := strings.Join([]string{*hostname, *subnet.DnsLabel, *vcn.DnsLabel, "oraclevcn.com"}, ".")
124+
addresses = append(addresses, api.NodeAddress{Type: api.NodeHostName, Address: fqdn})
125+
addresses = append(addresses, api.NodeAddress{Type: api.NodeInternalDNS, Address: fqdn})
126+
return addresses, nil
105127
}
106128

107129
// InstanceID returns the cloud provider ID of the node with the specified NodeName.

pkg/oci/client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type computeClient interface {
6666
type virtualNetworkClient interface {
6767
GetVnic(ctx context.Context, request core.GetVnicRequest) (response core.GetVnicResponse, err error)
6868
GetSubnet(ctx context.Context, request core.GetSubnetRequest) (response core.GetSubnetResponse, err error)
69+
GetVcn(ctx context.Context, request core.GetVcnRequest) (response core.GetVcnResponse, err error)
6970
GetSecurityList(ctx context.Context, request core.GetSecurityListRequest) (response core.GetSecurityListResponse, err error)
7071
UpdateSecurityList(ctx context.Context, request core.UpdateSecurityListRequest) (response core.UpdateSecurityListResponse, err error)
7172

pkg/oci/client/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ func (c *mockVirtualNetworkClient) GetSubnet(ctx context.Context, request core.G
187187
return core.GetSubnetResponse{}, nil
188188
}
189189

190+
func (c *mockVirtualNetworkClient) GetVcn(ctx context.Context, request core.GetVcnRequest) (response core.GetVcnResponse, err error) {
191+
return core.GetVcnResponse{} , nil
192+
}
193+
190194
func (c *mockVirtualNetworkClient) GetSecurityList(ctx context.Context, request core.GetSecurityListRequest) (response core.GetSecurityListResponse, err error) {
191195
return core.GetSecurityListResponse{}, nil
192196
}

pkg/oci/client/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
vnicAttachmentResource resource = "vnic_attachment"
3939
vnicResource resource = "vnic"
4040
subnetResource resource = "subnet"
41+
vcnResource resource = "vcn"
4142
loadBalancerResource resource = "load_balancer"
4243
backendSetResource resource = "load_balancer_backend_set"
4344
listenerResource resource = "load_balancer_listener"

pkg/oci/client/networking.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type NetworkingInterface interface {
2828
GetSubnet(ctx context.Context, id string) (*core.Subnet, error)
2929
GetSubnetFromCacheByIP(ip string) (*core.Subnet, error)
3030

31+
GetVcn(ctx context.Context, id string) (*core.Vcn, error)
32+
3133
GetSecurityList(ctx context.Context, id string) (core.GetSecurityListResponse, error)
3234
UpdateSecurityList(ctx context.Context, request core.UpdateSecurityListRequest) (core.UpdateSecurityListResponse, error)
3335

@@ -97,6 +99,23 @@ func (c *client) GetSubnetFromCacheByIP(ip string) (*core.Subnet, error) {
9799
return nil, nil
98100
}
99101

102+
func (c *client) GetVcn(ctx context.Context, id string) (*core.Vcn, error) {
103+
if !c.rateLimiter.Reader.TryAccept() {
104+
return nil, RateLimitError(false, "GetVcn")
105+
}
106+
resp, err := c.network.GetVcn(ctx, core.GetVcnRequest{
107+
VcnId: &id,
108+
})
109+
incRequestCounter(err, getVerb, vcnResource)
110+
111+
if err != nil {
112+
return nil, errors.WithStack(err)
113+
}
114+
115+
vcn := &resp.Vcn
116+
return vcn, nil
117+
}
118+
100119
func (c *client) GetSecurityList(ctx context.Context, id string) (core.GetSecurityListResponse, error) {
101120
if !c.rateLimiter.Reader.TryAccept() {
102121
return core.GetSecurityListResponse{}, RateLimitError(false, "GetSecurityList")

pkg/volume/provisioner/block/block_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ func (c *MockVirtualNetworkClient) GetSubnet(ctx context.Context, id string) (*c
206206
return nil, nil
207207
}
208208

209+
func (c *MockVirtualNetworkClient) GetVcn(ctx context.Context, id string) (*core.Vcn, error) {
210+
return &core.Vcn{}, nil
211+
}
212+
209213
func (c *MockVirtualNetworkClient) GetSubnetFromCacheByIP(ip string) (*core.Subnet, error) {
210214
return nil, nil
211215
}

pkg/volume/provisioner/fss/fss_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ func (c *MockVirtualNetworkClient) GetSubnetFromCacheByIP(ip string) (*core.Subn
209209
return nil, nil
210210
}
211211

212+
func (c *MockVirtualNetworkClient) GetVcn(ctx context.Context, id string) (*core.Vcn, error) {
213+
return &core.Vcn{}, nil
214+
}
215+
212216
func (c *MockVirtualNetworkClient) GetSecurityList(ctx context.Context, id string) (core.GetSecurityListResponse, error) {
213217
return core.GetSecurityListResponse{}, nil
214218
}

0 commit comments

Comments
 (0)