Skip to content

Commit

Permalink
Use private IP for internal communication by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlamillan committed Apr 9, 2020
1 parent cb7e8fc commit 449e641
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
29 changes: 16 additions & 13 deletions pkg/drivers/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Driver struct {
Fingerprint string
Image string
NodeCompartmentID string
PrivateIPAddress string
PrivateKeyContents string
PrivateKeyPassphrase string
PrivateKeyPath string
Expand Down Expand Up @@ -219,24 +220,24 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
func (d *Driver) GetIP() (string, error) {
log.Debug("oci.GetIP()")

if d.IPAddress == "" {
if d.IPAddress == "" || d.PrivateIPAddress == "" {
oci, err := d.initOCIClient()
if err != nil {
return "", err
}
if d.UsePrivateIP {
ip, err := oci.GetPrivateIP(d.InstanceID, d.NodeCompartmentID)
if err != nil {
return "", err
}
d.IPAddress = ip
} else {
ip, err := oci.GetIPAddress(d.InstanceID, d.NodeCompartmentID)
if err != nil {
return "", err
}
d.IPAddress = ip
ip, err := oci.GetIPAddress(d.InstanceID, d.NodeCompartmentID)
if err != nil {
return "", err
}
privateIP, err := oci.GetPrivateIP(d.InstanceID, d.NodeCompartmentID)
if err != nil {
return "", err
}
d.IPAddress = ip
d.PrivateIPAddress = privateIP
}
if d.UsePrivateIP {
return d.PrivateIPAddress, nil
}

return d.IPAddress, nil
Expand Down Expand Up @@ -347,12 +348,14 @@ func (d *Driver) PreCreateCheck() error {
// Remove a host
func (d *Driver) Remove() error {
log.Debug("oci.Remove()")
log.Info("NOTICE: Please check Oracle Cloud Console or CLI to ensure there are no leftover resources.")

oci, err := d.initOCIClient()
if err != nil {
return err
}

log.Infof("terminating instance ID %s", d.InstanceID)
return oci.TerminateInstance(d.InstanceID)
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/drivers/oci/oci_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func (c *Client) CreateInstance(displayName, availabilityDomain, compartmentID,
},
}

log.Debugf("Launching instance with cloud-init: %s", string(createCloudInitScript()))

createResp, err := c.computeClient.LaunchInstance(context.Background(), request)
if err != nil {
return "", err
Expand Down Expand Up @@ -324,7 +326,7 @@ func (c *Client) getImageID(compartmentID, nodeImageName string) (*string, error
for _, image := range r.Items {
if strings.HasPrefix(*image.DisplayName, nodeImageName) {
if !strings.Contains(*image.DisplayName, "GPU") {
log.Debugf("Using node image %s", *image.DisplayName)
log.Infof("Provisioning node using image %s", *image.DisplayName)
return image.Id, nil
}
}
Expand Down

0 comments on commit 449e641

Please sign in to comment.