Skip to content

Commit

Permalink
Add IPv6 support for Google Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
booya committed Feb 28, 2023
1 parent 8ccb862 commit 569551d
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 49 deletions.
1 change: 1 addition & 0 deletions cmd/drone-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func setupProvider(c config.Config) (autoscaler.Provider, error) {
google.WithLabels(c.Google.Labels),
google.WithNetwork(c.Google.Network),
google.WithSubnetwork(c.Google.Subnetwork),
google.WithStackType(c.Google.StackType),
google.WithPrivateIP(c.Google.PrivateIP),
google.WithServiceAccountEmail(c.Google.ServiceAccountEmail),
google.WithProject(c.Google.Project),
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ type (
MachineImage string `envconfig:"DRONE_GOOGLE_MACHINE_IMAGE"`
Network string `envconfig:"DRONE_GOOGLE_NETWORK"`
Subnetwork string `envconfig:"DRONE_GOOGLE_SUBNETWORK"`
StackType string `envconfig:"DRONE_GOOGLE_STACK_TYPE"`
Labels map[string]string `envconfig:"DRONE_GOOGLE_LABELS"`
Scopes []string `envconfig:"DRONE_GOOGLE_SCOPES"`
ServiceAccountEmail string `envconfig:"DRONE_GOOGLE_SERVICE_ACCOUNT_EMAIL"`
Expand Down
14 changes: 13 additions & 1 deletion drivers/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (p *provider) Create(ctx context.Context, opts autoscaler.InstanceCreateOpt
logger.Debugln("instance insert")

networkConfig := []*compute.AccessConfig{}

if !p.privateIP {
networkConfig = []*compute.AccessConfig{
{
Expand Down Expand Up @@ -88,6 +87,7 @@ func (p *provider) Create(ctx context.Context, opts autoscaler.InstanceCreateOpt
{
Network: p.network,
Subnetwork: p.subnetwork,
StackType: p.stackType,
AccessConfigs: networkConfig,
},
},
Expand All @@ -106,6 +106,18 @@ func (p *provider) Create(ctx context.Context, opts autoscaler.InstanceCreateOpt
},
}

// Cannot add this in the same way as v4 access configs since the instance creation
// fails if any v6 access configs are specified for an instance with IPV4_ONLY stack type
if p.stackType == "IPV4_IPV6" {
in.NetworkInterfaces[0].Ipv6AccessConfigs = []*compute.AccessConfig{
{
Name: "external-ipv6",
Type: "DIRECT_IPV6",
NetworkTier: "PREMIUM",
},
}
}

op, err := p.service.Instances.Insert(p.project, zone, in).Do()
if err != nil {
logger.WithError(err).
Expand Down
6 changes: 4 additions & 2 deletions drivers/google/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ var insertInstanceMock = &compute.Instance{
CanIpForward: false,
NetworkInterfaces: []*compute.NetworkInterface{
{
Network: "global/networks/default",
Network: "global/networks/default",
StackType: "IPV4_ONLY",
AccessConfigs: []*compute.AccessConfig{
{
Name: "External NAT",
Expand Down Expand Up @@ -216,7 +217,8 @@ var insertInstanceMockB = &compute.Instance{
CanIpForward: false,
NetworkInterfaces: []*compute.NetworkInterface{
{
Network: "global/networks/default",
Network: "global/networks/default",
StackType: "IPV4_ONLY",
AccessConfigs: []*compute.AccessConfig{
{
Name: "External NAT",
Expand Down
7 changes: 7 additions & 0 deletions drivers/google/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ func WithSubnetwork(subnetwork string) Option {
}
}

// WithStackType returns an option to set the stack type for the instance.
func WithStackType(stackType string) Option {
return func(p *provider) {
p.stackType = stackType
}
}

// WithPrivateIP returns an option to set the private IP address.
func WithPrivateIP(private bool) Option {
return func(p *provider) {
Expand Down
4 changes: 4 additions & 0 deletions drivers/google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type provider struct {
labels map[string]string
network string
subnetwork string
stackType string
project string
privateIP bool
scopes []string
Expand Down Expand Up @@ -83,6 +84,9 @@ func New(opts ...Option) (autoscaler.Provider, error) {
if p.network == "" {
p.network = "global/networks/default"
}
if p.stackType == "" {
p.stackType = "IPV4_ONLY"
}
if p.userdata == nil {
p.userdata = userdata.T
}
Expand Down
56 changes: 31 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ replace github.com/docker/docker => github.com/docker/engine v17.12.0-ce-rc1.0.2

require (
github.com/99designs/basicauth-go v0.0.0-20160802081356-2a93ba0f464d
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.4.7 // indirect
github.com/avast/retry-go v3.0.0+incompatible
github.com/aws/aws-sdk-go v1.44.205
github.com/beorn7/perks v1.0.1 // indirect
github.com/bluele/slack v0.0.0-20171128075526-307046097ee9
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9
github.com/digitalocean/godo v1.1.1
Expand All @@ -20,10 +23,14 @@ require (
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4
github.com/go-chi/chi v3.3.2+incompatible
github.com/go-sql-driver/mysql v1.3.0
github.com/golang/mock v1.4.4
github.com/google/go-cmp v0.5.8
github.com/gogo/protobuf v1.1.1 // indirect
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.9
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gophercloud/gophercloud v0.0.0-20181014043407-c8947f7d1c51
github.com/h2non/gock v1.0.7
github.com/gorilla/mux v1.7.4 // indirect
github.com/h2non/gock v1.2.0
github.com/hetznercloud/hcloud-go v1.4.0
github.com/jmoiron/sqlx v0.0.0-20180228184624-cf35089a1979
github.com/joho/godotenv v1.2.0
Expand All @@ -35,50 +42,49 @@ require (
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.3
github.com/sirupsen/logrus v1.6.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65
google.golang.org/api v0.30.0
golang.org/x/oauth2 v0.5.0
golang.org/x/sync v0.1.0
golang.org/x/time v0.1.0
google.golang.org/api v0.110.0
)

require (
cloud.google.com/go v0.65.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.4.7 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/containerd v1.3.4 // indirect
github.com/docker/distribution v0.0.0-20170726174610-edc3ab29cdff // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/gogo/protobuf v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/gorilla/mux v1.7.4 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 // indirect
go.opencensus.io v0.22.4 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
google.golang.org/grpc v1.31.0 // indirect
gotest.tools v2.2.0+incompatible // indirect
)

require (
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230209215440-0dfe4f8abfcc // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools v2.2.0+incompatible // indirect
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
Loading

0 comments on commit 569551d

Please sign in to comment.