Skip to content

Commit 84d7abb

Browse files
Version 3.9.2
- allow specification of existing public IP (closes #88, thanks @ItsReddi) - fix server being assigned a public IP even when explicitly disabled (closes #90, thanks @makmarius) - fix version display (closes #92, thanks @makmarius) - add instrumented builds
1 parent d1bec1a commit 84d7abb

File tree

10 files changed

+108
-71
lines changed

10 files changed

+108
-71
lines changed

.goreleaser.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,14 @@ builds:
66
goarch:
77
- amd64
88
- arm64
9-
env:
9+
env: &default-env
1010
- CGO_ENABLED=0
11+
- id: instrumented
12+
goos:
13+
- linux
14+
- windows
15+
goarch:
16+
- amd64
17+
env: *default-env
18+
tags: instrumented
19+
binary: docker-machine-driver-hetzner_instrumented

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ You can find sources and pre-compiled binaries [here](https://github.com/JonasPr
1515

1616
```bash
1717
# Download the binary (this example downloads the binary for linux amd64)
18-
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.9.0/docker-machine-driver-hetzner_3.9.0_linux_amd64.tar.gz
19-
$ tar -xvf docker-machine-driver-hetzner_3.9.0_linux_amd64.tar.gz
18+
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.9.2/docker-machine-driver-hetzner_3.9.2_linux_amd64.tar.gz
19+
$ tar -xvf docker-machine-driver-hetzner_3.9.2_linux_amd64.tar.gz
2020

2121
# Make it executable and copy the binary in a directory accessible with your $PATH
2222
$ chmod +x docker-machine-driver-hetzner

driver.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
325325
return d.flagFailure("--%v and --%v are mutually exclusive", flagPrimary6, flagDisablePublic6)
326326
}
327327

328+
instrumented(d)
329+
328330
return nil
329331
}
330332

@@ -438,7 +440,7 @@ func (d *Driver) Create() error {
438440
return err
439441
}
440442

441-
srv, _, err := d.getClient().Server.Create(context.Background(), *srvopts)
443+
srv, _, err := d.getClient().Server.Create(context.Background(), instrumented(*srvopts))
442444
if err != nil {
443445
return errors.Wrap(err, "could not create server")
444446
}
@@ -531,7 +533,7 @@ func (d *Driver) makeCreateServerOptions() (*hcloud.ServerCreateOpts, error) {
531533
PlacementGroup: pgrp,
532534
}
533535

534-
err = d.setPublicNetIfRequired(srvopts)
536+
err = d.setPublicNetIfRequired(&srvopts)
535537
if err != nil {
536538
return nil, err
537539
}
@@ -571,7 +573,7 @@ func (d *Driver) makeCreateServerOptions() (*hcloud.ServerCreateOpts, error) {
571573
return &srvopts, nil
572574
}
573575

574-
func (d *Driver) setPublicNetIfRequired(srvopts hcloud.ServerCreateOpts) error {
576+
func (d *Driver) setPublicNetIfRequired(srvopts *hcloud.ServerCreateOpts) error {
575577
pip4, err := d.getPrimaryIPv4()
576578
if err != nil {
577579
return err
@@ -583,8 +585,8 @@ func (d *Driver) setPublicNetIfRequired(srvopts hcloud.ServerCreateOpts) error {
583585

584586
if d.DisablePublic4 || d.DisablePublic6 || pip4 != nil || pip6 != nil {
585587
srvopts.PublicNet = &hcloud.ServerCreatePublicNet{
586-
EnableIPv4: !d.DisablePublic4,
587-
EnableIPv6: !d.DisablePublic6,
588+
EnableIPv4: !d.DisablePublic4 || pip4 != nil,
589+
EnableIPv6: !d.DisablePublic6 || pip6 != nil,
588590
IPv4: pip4,
589591
IPv6: pip6,
590592
}
@@ -604,7 +606,7 @@ func (d *Driver) createNetworks() ([]*hcloud.Network, error) {
604606
}
605607
networks = append(networks, network)
606608
}
607-
return networks, nil
609+
return instrumented(networks), nil
608610
}
609611

610612
func (d *Driver) createFirewalls() ([]*hcloud.ServerCreateFirewall, error) {
@@ -619,7 +621,7 @@ func (d *Driver) createFirewalls() ([]*hcloud.ServerCreateFirewall, error) {
619621
}
620622
firewalls = append(firewalls, &hcloud.ServerCreateFirewall{Firewall: *firewall})
621623
}
622-
return firewalls, nil
624+
return instrumented(firewalls), nil
623625
}
624626

625627
func (d *Driver) createVolumes() ([]*hcloud.Volume, error) {
@@ -634,7 +636,7 @@ func (d *Driver) createVolumes() ([]*hcloud.Volume, error) {
634636
}
635637
volumes = append(volumes, volume)
636638
}
637-
return volumes, nil
639+
return instrumented(volumes), nil
638640
}
639641

640642
func (d *Driver) createRemoteKeys() error {
@@ -711,7 +713,7 @@ func (d *Driver) makeKey(name string, pubkey string, labels map[string]string) (
711713
Labels: labels,
712714
}
713715

714-
key, _, err := d.getClient().SSHKey.Create(context.Background(), keyopts)
716+
key, _, err := d.getClient().SSHKey.Create(context.Background(), instrumented(keyopts))
715717
if err != nil {
716718
return nil, errors.Wrap(err, "could not create ssh key")
717719
} else if key == nil {
@@ -916,7 +918,7 @@ func (d *Driver) Kill() error {
916918
}
917919

918920
func (d *Driver) getClient() *hcloud.Client {
919-
return hcloud.NewClient(hcloud.WithToken(d.AccessToken), hcloud.WithApplication("docker-machine-driver", Version))
921+
return hcloud.NewClient(hcloud.WithToken(d.AccessToken), hcloud.WithApplication("docker-machine-driver", version))
920922
}
921923

922924
func (d *Driver) copySSHKeyPair(src string) error {
@@ -958,7 +960,7 @@ func (d *Driver) getType() (*hcloud.ServerType, error) {
958960
return stype, errors.Wrap(err, "could not get type by name")
959961
}
960962
d.cachedType = stype
961-
return stype, nil
963+
return instrumented(stype), nil
962964
}
963965

964966
func (d *Driver) getImage() (*hcloud.Image, error) {
@@ -982,7 +984,7 @@ func (d *Driver) getImage() (*hcloud.Image, error) {
982984
}
983985

984986
d.cachedImage = image
985-
return image, nil
987+
return instrumented(image), nil
986988
}
987989

988990
func (d *Driver) getKey() (*hcloud.SSHKey, error) {
@@ -995,7 +997,7 @@ func (d *Driver) getKey() (*hcloud.SSHKey, error) {
995997
return stype, errors.Wrap(err, "could not get sshkey by ID")
996998
}
997999
d.cachedKey = stype
998-
return stype, nil
1000+
return instrumented(stype), nil
9991001
}
10001002

10011003
func (d *Driver) getRemoteKeyWithSameFingerprint(publicKeyBytes []byte) (*hcloud.SSHKey, error) {
@@ -1010,7 +1012,7 @@ func (d *Driver) getRemoteKeyWithSameFingerprint(publicKeyBytes []byte) (*hcloud
10101012
if err != nil {
10111013
return remoteKey, errors.Wrap(err, "could not get sshkey by fingerprint")
10121014
}
1013-
return remoteKey, nil
1015+
return instrumented(remoteKey), nil
10141016
}
10151017

10161018
func (d *Driver) getServerHandle() (*hcloud.Server, error) {
@@ -1074,15 +1076,15 @@ func (d *Driver) getAutoPlacementGroup() (*hcloud.PlacementGroup, error) {
10741076
d.labelName(labelAutoCreated): "true",
10751077
})
10761078

1077-
return grp, err
1079+
return instrumented(grp), err
10781080
}
10791081

10801082
func (d *Driver) makePlacementGroup(name string, labels map[string]string) (*hcloud.PlacementGroup, error) {
1081-
grp, _, err := d.getClient().PlacementGroup.Create(context.Background(), hcloud.PlacementGroupCreateOpts{
1083+
grp, _, err := d.getClient().PlacementGroup.Create(context.Background(), instrumented(hcloud.PlacementGroupCreateOpts{
10821084
Name: name,
10831085
Labels: labels,
10841086
Type: "spread",
1085-
})
1087+
}))
10861088

10871089
if grp.PlacementGroup != nil {
10881090
d.dangling = append(d.dangling, func() {
@@ -1097,7 +1099,7 @@ func (d *Driver) makePlacementGroup(name string, labels map[string]string) (*hcl
10971099
return nil, fmt.Errorf("could not create placement group: %w", err)
10981100
}
10991101

1100-
return grp.PlacementGroup, nil
1102+
return instrumented(grp.PlacementGroup), nil
11011103
}
11021104

11031105
func (d *Driver) getPlacementGroup() (*hcloud.PlacementGroup, error) {
@@ -1193,7 +1195,7 @@ func (d *Driver) resolvePrimaryIP(raw string) (*hcloud.PrimaryIP, error) {
11931195
}
11941196

11951197
if ip != nil {
1196-
return ip, nil
1198+
return instrumented(ip), nil
11971199
}
11981200

11991201
return nil, fmt.Errorf("primary IP not found: %v", raw)

flag_failure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !flag_debug
1+
//go:build !flag_debug && !instrumented
22

33
package main
44

flag_failure_debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build flag_debug
1+
//go:build flag_debug || instrumented
22

33
package main
44

go.mod

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ go 1.18
44

55
require (
66
github.com/docker/machine v0.16.2
7-
github.com/hetznercloud/hcloud-go v1.35.1
7+
github.com/hetznercloud/hcloud-go v1.37.0
88
github.com/pkg/errors v0.9.1
9-
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
9+
golang.org/x/crypto v0.3.0
1010
)
1111

1212
require (
1313
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
1414
github.com/beorn7/perks v1.0.1 // indirect
1515
github.com/cespare/xxhash/v2 v2.1.2 // indirect
16-
github.com/docker/docker v20.10.17+incompatible // indirect
16+
github.com/docker/docker v20.10.21+incompatible // indirect
1717
github.com/golang/protobuf v1.5.2 // indirect
18-
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
19-
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
20-
github.com/prometheus/client_golang v1.12.2 // indirect
21-
github.com/prometheus/client_model v0.2.0 // indirect
18+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
19+
github.com/moby/term v0.0.0-20221120202655-abb19827d345 // indirect
20+
github.com/prometheus/client_golang v1.14.0 // indirect
21+
github.com/prometheus/client_model v0.3.0 // indirect
2222
github.com/prometheus/common v0.37.0 // indirect
23-
github.com/prometheus/procfs v0.7.3 // indirect
24-
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
25-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
26-
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
27-
golang.org/x/text v0.3.7 // indirect
28-
google.golang.org/protobuf v1.28.0 // indirect
23+
github.com/prometheus/procfs v0.8.0 // indirect
24+
golang.org/x/net v0.2.0 // indirect
25+
golang.org/x/sys v0.2.0 // indirect
26+
golang.org/x/term v0.2.0 // indirect
27+
golang.org/x/text v0.4.0 // indirect
28+
google.golang.org/protobuf v1.28.1 // indirect
2929
)

0 commit comments

Comments
 (0)