Skip to content
Commits on Source (1)
  • JonasS's avatar
    chore: int64 ID support (#108) · 3cef7226
    JonasS authored
    - update hcloud-go to v2
    - use int64 for ID flags in driver
    - work around lack of int64 in mcnflag
    3cef7226
......@@ -15,8 +15,8 @@ You can find sources and pre-compiled binaries [here](https://github.com/JonasPr
```bash
# Download the binary (this example downloads the binary for linux amd64)
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/4.1.2/docker-machine-driver-hetzner_4.1.2_linux_amd64.tar.gz
$ tar -xvf docker-machine-driver-hetzner_4.1.2_linux_amd64.tar.gz
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/5.0.0/docker-machine-driver-hetzner_5.0.0_linux_amd64.tar.gz
$ tar -xvf docker-machine-driver-hetzner_5.0.0_linux_amd64.tar.gz
# Make it executable and copy the binary in a directory accessible with your $PATH
$ chmod +x docker-machine-driver-hetzner
......@@ -259,16 +259,27 @@ $ docker-machine create --driver hetzner
### 4.0.0
* **check log output for BREAKING-V5**
* **check log output for BREAKING-V6** (previously *BREAKING-V5*)
* `--hetzner-user-data-from-file` will be fully deprecated and its flag description will only read 'DEPRECATED, legacy'; current fallback behaviour will be retained. `--hetzner-flag-user-data-file` should be used instead.
* `--hetzner-disable-public-4`/`--hetzner-disable-public-6` will be fully deprecated and its flag description will only read 'DEPRECATED, legacy'; current fallback behaviour will be retained. `--hetzner-disable-public-ipv4`/`--hetzner-disable-public-ipv6` should be used instead.
### 5.0.0
* major update due to #108 ([hetznercloud/hcloud-go#263](https://github.com/hetznercloud/hcloud-go/v2/issues/263))
* new `hcloud-go` v2 requiring int64 IDs is used for interaction with Hetzner cloud
* old configs should be forward-compatible
* newly created machines may now use 64-bit integers in all stored and transmitted data, potentially breaking existing tools supporting 32-bit only
- this includes anything interacting with the flags CLI via RPC, as `mcnflags` lacks an int64 flag type, so `StringFlag` and parsing are used now
* previous changes were moved one version (i.e. 5 -> 6, 6 -> 7)
### 6.0.0
* *moved from 5.0.0*
* `--hetzner-user-data-from-file` will be removed entirely, including its fallback behavior
* `--hetzner-disable-public-4`/`--hetzner-disable-public-6` ill be removed entirely, including their fallback behavior
* not specifying `--hetzner-image` will generate a warning stating 'use of default image is DEPRECATED'
### 6.0.0
### 7.0.0
* *moved from 6.0.0*
* specifying `--hetzner-image` will be mandatory, and a default image will no longer be provided
......@@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/docker/machine/libmachine/log"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/pkg/errors"
)
......
......@@ -4,13 +4,14 @@ import (
"context"
"fmt"
"net"
"strconv"
"time"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/state"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/pkg/errors"
)
......@@ -20,19 +21,19 @@ type Driver struct {
AccessToken string
Image string
ImageID int
ImageID int64
ImageArch hcloud.Architecture
cachedImage *hcloud.Image
Type string
cachedType *hcloud.ServerType
Location string
cachedLocation *hcloud.Location
KeyID int
KeyID int64
cachedKey *hcloud.SSHKey
IsExistingKey bool
originalKey string
dangling []func()
ServerID int
ServerID int64
cachedServer *hcloud.Server
userData string
userDataFile string
......@@ -52,7 +53,7 @@ type Driver struct {
cachedPGrp *hcloud.PlacementGroup
AdditionalKeys []string
AdditionalKeyIDs []int
AdditionalKeyIDs []int64
cachedAdditionalKeys []*hcloud.SSHKey
WaitOnError int
......@@ -146,7 +147,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Image to use for server creation",
Value: "",
},
mcnflag.IntFlag{
mcnflag.StringFlag{
EnvVar: "HETZNER_IMAGE_ID",
Name: flagImageID,
Usage: "Image to use for server creation",
......@@ -168,11 +169,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Location to create machine at",
Value: "",
},
mcnflag.IntFlag{
mcnflag.StringFlag{
EnvVar: "HETZNER_EXISTING_KEY_ID",
Name: flagExKeyID,
Usage: "Existing key ID to use for server; requires --hetzner-existing-key-path",
Value: 0,
Value: "0",
},
mcnflag.StringFlag{
EnvVar: "HETZNER_EXISTING_KEY_PATH",
......@@ -319,6 +320,20 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
}
}
func flagI64(opts drivers.DriverOptions, key string) (int64, error) {
raw := opts.String(key)
if raw == "" {
return 0, nil
}
ret, err := strconv.ParseInt(raw, 10, 64)
if err != nil {
return 0, errors.Wrapf(err, "could not parse int64 for %v", key)
}
return ret, nil
}
// SetConfigFromFlags handles additional driver arguments as retrieved by [Driver.GetCreateFlags];
// see [drivers.Driver.SetConfigFromFlags]
func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
......@@ -326,16 +341,24 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
}
func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
var err error
d.AccessToken = opts.String(flagAPIToken)
d.Image = opts.String(flagImage)
d.ImageID = opts.Int(flagImageID)
err := d.setImageArch(opts.String(flagImageArch))
d.ImageID, err = flagI64(opts, flagImageID)
if err != nil {
return err
}
err = d.setImageArch(opts.String(flagImageArch))
if err != nil {
return err
}
d.Location = opts.String(flagLocation)
d.Type = opts.String(flagType)
d.KeyID = opts.Int(flagExKeyID)
d.KeyID, err = flagI64(opts, flagExKeyID)
if err != nil {
return err
}
d.IsExistingKey = d.KeyID != 0
d.originalKey = opts.String(flagExKeyPath)
err = d.setUserDataFlags(opts)
......@@ -390,10 +413,10 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
instrumented(d)
if d.usesDfr {
log.Warn("!!!! BREAKING-V5 !!!!")
log.Warn("!!!! BREAKING-V6 !!!!")
log.Warn("your configuration uses deprecated flags and will stop working as-is from v5 onwards")
log.Warn("check preceding output for 'DEPRECATED' log statements")
log.Warn("!!!! /BREAKING-V5 !!!!")
log.Warn("!!!! /BREAKING-V6 !!!!")
}
return nil
......
......@@ -3,8 +3,9 @@ package driver
import (
"github.com/docker/machine/commands/commandstest"
"github.com/docker/machine/libmachine/drivers"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"os"
"strconv"
"strings"
"testing"
)
......@@ -212,7 +213,7 @@ func TestImageFlagExclusions(t *testing.T) {
// both id and name given
d := NewDriver("test")
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagImageID: 42,
flagImageID: "42",
flagImage: "answer",
}))
assertMutualExclusion(t, err, flagImageID, flagImage)
......@@ -220,7 +221,7 @@ func TestImageFlagExclusions(t *testing.T) {
// both id and arch given
d = NewDriver("test")
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagImageID: 42,
flagImageID: "42",
flagImageArch: string(hcloud.ArchitectureX86),
}))
assertMutualExclusion(t, err, flagImageID, flagImageArch)
......@@ -255,6 +256,32 @@ func TestImageArch(t *testing.T) {
}
}
func TestBogusId(t *testing.T) {
d := NewDriver("test")
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagImageID: "answer",
}))
if err == nil {
t.Fatal("expected error, but invalid arch was accepted")
}
}
func TestLongId(t *testing.T) {
var testId int64 = 79871865169581
d := NewDriver("test")
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
flagImageID: strconv.FormatInt(testId, 10),
}))
if err != nil {
t.Fatalf("unexpected error, %v", err)
}
if d.ImageID != testId {
t.Errorf("expected %v id, but got %v", testId, d.ImageArch)
}
}
func testArchFlag(t *testing.T, arch hcloud.Architecture) {
d := NewDriver("test")
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
......
......@@ -3,7 +3,7 @@ package driver
import (
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/pkg/errors"
"strings"
)
......
......@@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/docker/machine/libmachine/log"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"
"time"
......
......@@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/docker/machine/libmachine/log"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/pkg/errors"
"net"
"time"
......
......@@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/docker/machine/libmachine/log"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
const (
......
......@@ -3,7 +3,7 @@ package driver
import (
"context"
"github.com/docker/machine/libmachine/state"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/pkg/errors"
"os"
"time"
......
......@@ -6,7 +6,7 @@ import (
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnutils"
mcnssh "github.com/docker/machine/libmachine/ssh"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"
"os"
......
......@@ -4,9 +4,9 @@ go 1.18
require (
github.com/docker/machine v0.16.2
github.com/hetznercloud/hcloud-go v1.42.0
github.com/hetznercloud/hcloud-go/v2 v2.1.1
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.8.0
golang.org/x/crypto v0.12.0
)
replace github.com/codegangsta/cli v1.22.12 => github.com/urfave/cli v1.22.12
......@@ -21,14 +21,14 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/prometheus/client_golang v1.15.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)
......@@ -22,8 +22,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/hetznercloud/hcloud-go v1.42.0 h1:Es/CDOForQN3nOOP5Vxh1N/YHjpCg386iYEX5zCgi+A=
github.com/hetznercloud/hcloud-go v1.42.0/go.mod h1:YADL8AbmQYH0Eo+1lkuyoc8LutT0UeMvaKP47nNUb+Y=
github.com/hetznercloud/hcloud-go/v2 v2.1.1 h1:HDe1IBEYut7sfi4uiDyz1ml2+4ZuQZWW6vjSK3PP8DM=
github.com/hetznercloud/hcloud-go/v2 v2.1.1/go.mod h1:4iUG2NG8b61IAwNx6UsMWQ6IfIf/i1RsG0BbsKAyR5Q=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
......@@ -32,14 +32,14 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM=
github.com/prometheus/client_golang v1.15.0/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM=
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
......@@ -48,21 +48,21 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/urfave/cli v1.22.12 h1:igJgVw1JdKH+trcLWLeLwZjU9fEfPesQ+9/e4MQ44S8=
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
......