Skip to content

Commit

Permalink
Merge pull request #19 from afbjorklund/master
Browse files Browse the repository at this point in the history
Update machine-drivers/machine to docker/machine
  • Loading branch information
afbjorklund authored Jul 21, 2019
2 parents 533ea58 + a555e4f commit 0d8c85d
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 36 deletions.
13 changes: 5 additions & 8 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
[Org]
[Org."Core maintainers"]
people = [
"dgageot",
"jeanlaurent",
"shin-",
]

[Org.Alumni]
people = [
"shin-",
]
[people]

# A reference list of all people associated with the project.
Expand All @@ -24,17 +26,12 @@

# ADD YOURSELF HERE IN ALPHABETICAL ORDER

[people.dgageot]
Name = "David Gageot"
Email = "[email protected]"
GitHub = "dgageot"

[people.jeanlaurent]
Name = "Jean-Laurent de Morlhon"
Email = "[email protected]"
GitHub = "jeanlaurent"

[people.shin-]
Name = "Joffrey F"
Email = "joffrey@docker.com"
Email = "f.joffrey@gmail.com"
GitHub = "shin-"
26 changes: 21 additions & 5 deletions drivers/amazonec2/amazonec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
defaultVolumeType = "gp2"
defaultZone = "a"
defaultSecurityGroup = machineSecurityGroupName
defaultSSHPort = 22
defaultSSHUser = "ubuntu"
defaultSpotPrice = "0.50"
defaultBlockDurationMinutes = 0
Expand Down Expand Up @@ -211,9 +212,15 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "AWS IAM Instance Profile",
EnvVar: "AWS_INSTANCE_PROFILE",
},
mcnflag.IntFlag{
Name: "amazonec2-ssh-port",
Usage: "SSH port",
Value: defaultSSHPort,
EnvVar: "AWS_SSH_PORT",
},
mcnflag.StringFlag{
Name: "amazonec2-ssh-user",
Usage: "Set the name of the ssh user",
Usage: "SSH username",
Value: defaultSSHUser,
EnvVar: "AWS_SSH_USER",
},
Expand Down Expand Up @@ -294,6 +301,7 @@ func NewDriver(hostName, storePath string) *Driver {
SpotPrice: defaultSpotPrice,
BlockDurationMinutes: defaultBlockDurationMinutes,
BaseDriver: &drivers.BaseDriver{
SSHPort: defaultSSHPort,
SSHUser: defaultSSHUser,
MachineName: hostName,
StorePath: storePath,
Expand Down Expand Up @@ -363,7 +371,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.VolumeType = flags.String("amazonec2-volume-type")
d.IamInstanceProfile = flags.String("amazonec2-iam-instance-profile")
d.SSHUser = flags.String("amazonec2-ssh-user")
d.SSHPort = 22
d.SSHPort = flags.Int("amazonec2-ssh-port")
d.PrivateIPOnly = flags.Bool("amazonec2-private-address-only")
d.UsePrivateIP = flags.Bool("amazonec2-use-private-address")
d.Monitoring = flags.Bool("amazonec2-monitoring")
Expand Down Expand Up @@ -837,6 +845,14 @@ func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP()
}

func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = defaultSSHPort
}

return d.SSHPort, nil
}

func (d *Driver) GetSSHUsername() string {
if d.SSHUser == "" {
d.SSHUser = defaultSSHUser
Expand Down Expand Up @@ -1161,11 +1177,11 @@ func (d *Driver) configureSecurityGroupPermissions(group *ec2.SecurityGroup) ([]

perms := []*ec2.IpPermission{}

if !hasPorts["22/tcp"] {
if !hasPorts[fmt.Sprintf("%d/tcp", d.BaseDriver.SSHPort)] {
perms = append(perms, &ec2.IpPermission{
IpProtocol: aws.String("tcp"),
FromPort: aws.Int64(22),
ToPort: aws.Int64(22),
FromPort: aws.Int64(int64(d.BaseDriver.SSHPort)),
ToPort: aws.Int64(int64(d.BaseDriver.SSHPort)),
IpRanges: []*ec2.IpRange{{CidrIp: aws.String(ipRange)}},
})
}
Expand Down
1 change: 1 addition & 0 deletions drivers/amazonec2/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var regionDetails map[string]*region = map[string]*region{
"ca-central-1": {"ami-8d9e19e9"},
"cn-north-1": {"ami-cc4499a1"}, // Note: this is 20180126
"cn-northwest-1": {"ami-fd0e1a9f"}, // Note: this is 20180126
"eu-north-1": {"ami-017ff17f"},
"eu-central-1": {"ami-bc4925d3"},
"eu-west-1": {"ami-0b541372"},
"eu-west-2": {"ami-ff46a298"},
Expand Down
2 changes: 1 addition & 1 deletion drivers/google/compute_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (c *ComputeUtil) createInstance(d *Driver) error {
},
ServiceAccounts: []*raw.ServiceAccount{
{
Email: "default",
Email: d.ServiceAccount,
Scopes: strings.Split(d.Scopes, ","),
},
},
Expand Down
44 changes: 27 additions & 17 deletions drivers/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Driver struct {
Preemptible bool
UseInternalIP bool
UseInternalIPOnly bool
ServiceAccount string
Scopes string
DiskSize int
Project string
Expand All @@ -35,15 +36,16 @@ type Driver struct {
}

const (
defaultZone = "us-central1-a"
defaultUser = "docker-user"
defaultMachineType = "n1-standard-1"
defaultImageName = "ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20170721"
defaultScopes = "https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write"
defaultDiskType = "pd-standard"
defaultDiskSize = 10
defaultNetwork = "default"
defaultSubnetwork = ""
defaultZone = "us-central1-a"
defaultUser = "docker-user"
defaultMachineType = "n1-standard-1"
defaultImageName = "ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20170721"
defaultServiceAccount = "default"
defaultScopes = "https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write"
defaultDiskType = "pd-standard"
defaultDiskSize = 10
defaultNetwork = "default"
defaultSubnetwork = ""
)

// GetCreateFlags registers the flags this driver adds to
Expand Down Expand Up @@ -79,6 +81,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "GCE Project",
EnvVar: "GOOGLE_PROJECT",
},
mcnflag.StringFlag{
Name: "google-service-account",
Usage: "GCE Service Account for the VM (email address)",
Value: defaultServiceAccount,
EnvVar: "GOOGLE_SERVICE_ACCOUNT",
},
mcnflag.StringFlag{
Name: "google-scopes",
Usage: "GCE Scopes (comma-separated if multiple scopes)",
Expand Down Expand Up @@ -150,14 +158,15 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
// NewDriver creates a Driver with the specified storePath.
func NewDriver(machineName string, storePath string) *Driver {
return &Driver{
Zone: defaultZone,
DiskType: defaultDiskType,
DiskSize: defaultDiskSize,
MachineType: defaultMachineType,
MachineImage: defaultImageName,
Network: defaultNetwork,
Subnetwork: defaultSubnetwork,
Scopes: defaultScopes,
Zone: defaultZone,
DiskType: defaultDiskType,
DiskSize: defaultDiskSize,
MachineType: defaultMachineType,
MachineImage: defaultImageName,
Network: defaultNetwork,
Subnetwork: defaultSubnetwork,
ServiceAccount: defaultServiceAccount,
Scopes: defaultScopes,
BaseDriver: &drivers.BaseDriver{
SSHUser: defaultUser,
MachineName: machineName,
Expand Down Expand Up @@ -205,6 +214,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.Preemptible = flags.Bool("google-preemptible")
d.UseInternalIP = flags.Bool("google-use-internal-ip") || flags.Bool("google-use-internal-ip-only")
d.UseInternalIPOnly = flags.Bool("google-use-internal-ip-only")
d.ServiceAccount = flags.String("google-service-account")
d.Scopes = flags.String("google-scopes")
d.Tags = flags.String("google-tags")
d.OpenPorts = flags.StringSlice("google-open-port")
Expand Down
1 change: 1 addition & 0 deletions drivers/openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (c *GenericClient) CreateInstance(d *Driver) (string, error) {
SecurityGroups: d.SecurityGroups,
AvailabilityZone: d.AvailabilityZone,
ConfigDrive: d.ConfigDrive,
Metadata: d.GetMetadata(),
}
if d.NetworkId != "" {
serverOpts.Networks = []servers.Network{
Expand Down
24 changes: 24 additions & 0 deletions drivers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Driver struct {
FloatingIpPoolId string
IpVersion int
ConfigDrive bool
metadata string
client Client
// ExistingKey keeps track of whether the key was created by us or we used an existing one. If an existing one was used, we shouldn't delete it when the machine is deleted.
ExistingKey bool
Expand Down Expand Up @@ -233,6 +234,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Name: "openstack-config-drive",
Usage: "Enables the OpenStack config drive for the instance",
},
mcnflag.StringFlag{
EnvVar: "OS_METADATA",
Name: "openstack-metadata",
Usage: "OpenStack Instance Metadata (e.g. key1,value1,key2,value2)",
Value: "",
},
}
}

Expand Down Expand Up @@ -286,6 +293,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.ImageName = flags.String("openstack-image-name")
d.NetworkId = flags.String("openstack-net-id")
d.NetworkName = flags.String("openstack-net-name")
d.metadata = flags.String("openstack-metadata")
if flags.String("openstack-sec-groups") != "" {
d.SecurityGroups = strings.Split(flags.String("openstack-sec-groups"), ",")
}
Expand Down Expand Up @@ -487,6 +495,22 @@ func (d *Driver) Remove() error {
return nil
}

func (d *Driver) GetMetadata() map[string]string {
metadata := make(map[string]string)

if d.metadata != "" {
items := strings.Split(d.metadata, ",")
if len(items) > 0 && len(items)%2 != 0 {
log.Warnf("Metadata are not key value in pairs. %d elements found", len(items))
}
for i := 0; i < len(items)-1; i += 2 {
metadata[items[i]] = items[i+1]
}
}

return metadata
}

const (
errorMandatoryEnvOrOption string = "%s must be specified either using the environment variable %s or the CLI option %s"
errorMandatoryOption string = "%s must be specified using the CLI option %s"
Expand Down
1 change: 0 additions & 1 deletion drivers/softlayer/softlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func (c *Client) newRequest(method, uri string, body interface{}) ([]byte, error
}

req.SetBasicAuth(c.User, c.ApiKey)
req.Method = method

resp, err := client.Do(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion drivers/vmwarefusion/fusion_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (d *Driver) Start() error {
return err
} else if !os.IsNotExist(err) {
// create mountpoint and mount shared folder
command := "([ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; sudo mount --bind /mnt/hgfs/" + shareDir + " " + shareDir + ") || ([ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + ") || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/" + shareName + " " + shareDir
command := "([ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; sudo mount --bind /mnt/hgfs/" + shareDir + " " + shareDir + ") || ([ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o nonempty -o allow_other .host:/" + shareName + " " + shareDir + ") || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/" + shareName + " " + shareDir
vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", command)
}
}
Expand Down
2 changes: 1 addition & 1 deletion libmachine/provision/arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (provisioner *ArchProvisioner) Provision(swarmOptions swarm.Options, authOp
provisioner.EngineOptions = engineOptions
swarmOptions.Env = engineOptions.Env

storageDriver, err := decideStorageDriver(provisioner, "overlay", engineOptions.StorageDriver)
storageDriver, err := decideStorageDriver(provisioner, "overlay2", engineOptions.StorageDriver)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions libmachine/provision/arch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestArchDefaultStorageDriver(t *testing.T) {
p := NewArchProvisioner(&fakedriver.Driver{}).(*ArchProvisioner)
p.SSHCommander = provisiontest.NewFakeSSHCommander(provisiontest.FakeSSHCommanderOptions{})
p.Provision(swarm.Options{}, auth.Options{}, engine.Options{})
if p.EngineOptions.StorageDriver != "overlay" {
t.Fatal("Default storage driver should be overlay")
if p.EngineOptions.StorageDriver != "overlay2" {
t.Fatal("Default storage driver should be overlay2")
}
}

0 comments on commit 0d8c85d

Please sign in to comment.