diff --git a/provision/azure_test.go b/provision/azure_test.go index b30ff85..0c4e819 100644 --- a/provision/azure_test.go +++ b/provision/azure_test.go @@ -11,7 +11,7 @@ func Test_Azure_Auth_Contents_Invalid(t *testing.T) { _, err := NewAzureProvisioner("SubscriptionID", "invalid contents") if err == nil { - t.Errorf("want: error, but got: nil") + t.Fatalf("want: error, but got: nil") } } diff --git a/provision/linode.go b/provision/linode.go index dead5fe..e1e5799 100644 --- a/provision/linode.go +++ b/provision/linode.go @@ -3,11 +3,12 @@ package provision import ( "context" "fmt" + "net/http" + "strconv" + "github.com/linode/linodego" "github.com/sethvargo/go-password/password" "golang.org/x/oauth2" - "net/http" - "strconv" ) type LinodeInterface interface { @@ -65,6 +66,10 @@ func NewLinodeProvisioner(apiKey string) (*LinodeProvisioner, error) { // Provision provisions a new Linode instance as an exit node func (p *LinodeProvisioner) Provision(host BasicHost) (*ProvisionedHost, error) { + if len(host.Name) > 32 { + return nil, fmt.Errorf("name cannot be longer than 32 characters for Linode due to label limitations") + } + // Stack script is how linode does the cloud-init when provisioning a VM. // Stack script is the inlets user data containing inlets auth token. // Making stack script public will allow everyone to read the stack script @@ -87,8 +92,13 @@ func (p *LinodeProvisioner) Provision(host BasicHost) (*ProvisionedHost, error) return nil, err } instanceOptions := linodego.InstanceCreateOptions{ - Label: "inlets-" + host.Name, StackScriptID: stackscript.ID, - Image: host.OS, Region: host.Region, Type: host.Plan, RootPass: rootPassword, + Label: host.Name, + StackScriptID: stackscript.ID, + Image: host.OS, + Region: host.Region, + Type: host.Plan, + RootPass: rootPassword, + Tags: []string{"inlets"}, } instance, err := p.client.CreateInstance(instanceOptions) if err != nil { diff --git a/provision/linode_test.go b/provision/linode_test.go index 1f0653a..95702a0 100644 --- a/provision/linode_test.go +++ b/provision/linode_test.go @@ -31,9 +31,15 @@ func Test_Linode_Provision(t *testing.T) { returnedStackscript := &linodego.Stackscript{ID: 10} expectedInstanceOptions := linodego.InstanceCreateOptions{ - Label: "inlets-" + host.Name, StackScriptID: returnedStackscript.ID, - Image: host.OS, Region: host.Region, Type: host.Plan, RootPass: "testpass", + Label: host.Name, + StackScriptID: returnedStackscript.ID, + Image: host.OS, + Region: host.Region, + Type: host.Plan, + RootPass: "testpass", + Tags: []string{"inlets"}, } + returnedInstance := &linodego.Instance{ ID: 42, Status: linodego.InstanceBooting, @@ -43,19 +49,22 @@ func Test_Linode_Provision(t *testing.T) { mockClient.EXPECT().CreateInstance(gomock.Any()).Return(returnedInstance, nil).Times(1). Do(func(instanceOptions linodego.InstanceCreateOptions) { if instanceOptions.Label != expectedInstanceOptions.Label { - t.Fail() + t.Fatalf("Label didn't match") } if instanceOptions.StackScriptID != expectedInstanceOptions.StackScriptID { - t.Fail() + t.Fatalf("StackScriptID didn't match") } if instanceOptions.Image != expectedInstanceOptions.Image { - t.Fail() + t.Fatalf("Image didn't match") } if instanceOptions.Region != expectedInstanceOptions.Region { - t.Fail() + t.Fatalf("Region didn't match") } if instanceOptions.Type != expectedInstanceOptions.Type { - t.Fail() + t.Fatalf("Type didn't match") + } + if len(instanceOptions.Tags) != len(expectedInstanceOptions.Tags) { + t.Fatalf("tags don't match") } }) provisionedHost, _ := provisioner.Provision(host)