From 020513ad3f40ea169830df51a7bb0fbca2b16ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kosch=C3=BCtzki?= Date: Fri, 2 May 2025 11:41:44 +0200 Subject: [PATCH 1/3] feat: allow configuring in which network instances are created --- README.md | 2 +- config/config.toml.template | 3 +++ provider.go | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1622c70..50c0459 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ A [fleeting](https://docs.gitlab.com/runner/fleet_scaling/fleeting/) plugin for ### Caveats -- 🔒 Private networks are not yet supported. - ⬇️ Stopped runner instances are automatically removed and recycled. ## 🏎️ Demo and Ansible Playbook @@ -141,6 +140,7 @@ The following parameters are supported: | `image` | string | Image (slug) of virtual machine, [more information](https://www.cloudscale.ch/en/api/v1#images) | | `volume_size_gb` | number | The size of the root volume in GiB. Must be at least `10`. | | `user_data` | string | Depending on the image choice is either in the format of cloud-init (YAML) or Ignition (JSON). | +| `network` | string | The network to attach to the machines. Defaults to `public` | ### Default connector config diff --git a/config/config.toml.template b/config/config.toml.template index 8757339..902cbd5 100644 --- a/config/config.toml.template +++ b/config/config.toml.template @@ -96,6 +96,9 @@ concurrent = 40 # The root disk size of each instance. volume_size_gb = 25 + # Create the instances in a private network, instead of the default public one. + # network = "90b7d32b-1400-4d78-95ef-5c4aa9aaab7b" + # The cloud-config applied to each instance. Note that GitLab expects these # instances to have a running docker daemon. user_data = """#cloud-config diff --git a/provider.go b/provider.go index 2ee76f6..486b6a3 100644 --- a/provider.go +++ b/provider.go @@ -37,6 +37,7 @@ type InstanceGroup struct { Zone string `json:"zone"` Flavor string `json:"flavor"` Image string `json:"image"` + Network string `json:"network,omitempty"` UserData string `json:"user_data"` VolumeSizeGB int `json:"volume_size_gb,omitempty"` @@ -202,6 +203,10 @@ func (g *InstanceGroup) Init( g.settings.Username = "root" } + if g.Network == "" { + g.Network = "public" + } + // Validate config if err := g.validate(); err != nil { return provider.ProviderInfo{}, fmt.Errorf( @@ -309,6 +314,9 @@ func (g *InstanceGroup) Increase( SSHKeys: []string{string(publicKey)}, VolumeSizeGB: g.VolumeSizeGB, UserData: g.UserData, + Interfaces: &[]cloudscale.InterfaceRequest{ + cloudscale.InterfaceRequest{Network: g.Network}, + }, TaggedResourceRequest: cloudscale.TaggedResourceRequest{ Tags: &tagMap, }, From 7e266d6cc3179f72a126d061ef99aeee11ddaea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kosch=C3=BCtzki?= Date: Fri, 2 May 2025 14:01:29 +0200 Subject: [PATCH 2/3] feat: Allow adding multiple networks to instances --- README.md | 3 ++- config/config.toml.template | 11 +++++++++-- provider.go | 11 +++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 50c0459..6ec813e 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,8 @@ The following parameters are supported: | `image` | string | Image (slug) of virtual machine, [more information](https://www.cloudscale.ch/en/api/v1#images) | | `volume_size_gb` | number | The size of the root volume in GiB. Must be at least `10`. | | `user_data` | string | Depending on the image choice is either in the format of cloud-init (YAML) or Ignition (JSON). | -| `network` | string | The network to attach to the machines. Defaults to `public` | +| `network` | string | The primary network to attach to the machines. Defaults to `public`. You need to ensure the runner controller can reach the machines via this one. | +| `extra_networks` | string | Additional networks to be added to the machines. | ### Default connector config diff --git a/config/config.toml.template b/config/config.toml.template index 902cbd5..d560ef8 100644 --- a/config/config.toml.template +++ b/config/config.toml.template @@ -96,8 +96,15 @@ concurrent = 40 # The root disk size of each instance. volume_size_gb = 25 - # Create the instances in a private network, instead of the default public one. - # network = "90b7d32b-1400-4d78-95ef-5c4aa9aaab7b" + # The primary network. You need to ensure that the runner manager can + # access your instances on this one. + network = "public" + + # Additional networks to connect to the machine. + # extra_networks = [ + # "b10742ba-6949-44fd-9387-74fa7ac65854", + # "618baa7b-3185-470c-b230-32ff34ddfd72" + # ] # The cloud-config applied to each instance. Note that GitLab expects these # instances to have a running docker daemon. diff --git a/provider.go b/provider.go index 486b6a3..e416c38 100644 --- a/provider.go +++ b/provider.go @@ -37,9 +37,11 @@ type InstanceGroup struct { Zone string `json:"zone"` Flavor string `json:"flavor"` Image string `json:"image"` - Network string `json:"network,omitempty"` UserData string `json:"user_data"` + Network string `json:"network,omitempty"` + ExtraNetworks []string `json:"extra_networks,omitempty"` + VolumeSizeGB int `json:"volume_size_gb,omitempty"` log hclog.Logger @@ -203,10 +205,6 @@ func (g *InstanceGroup) Init( g.settings.Username = "root" } - if g.Network == "" { - g.Network = "public" - } - // Validate config if err := g.validate(); err != nil { return provider.ProviderInfo{}, fmt.Errorf( @@ -292,9 +290,6 @@ func (g *InstanceGroup) Increase( ctx context.Context, delta int, ) (succeeded int, err error) { - servers := make([]*cloudscale.Server, 0, delta) - errs := make([]error, 0) - publicKey, err := g.publicKey() if err != nil { return 0, err From c07e143f82aed414f18859ec78afadfc52d39567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kosch=C3=BCtzki?= Date: Wed, 7 May 2025 12:38:14 +0200 Subject: [PATCH 3/3] feat: revamp interface settings --- README.md | 3 +-- config/config.toml.template | 23 +++++++++++++++-------- provider.go | 11 +++++++++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6ec813e..d38b9e9 100644 --- a/README.md +++ b/README.md @@ -140,8 +140,7 @@ The following parameters are supported: | `image` | string | Image (slug) of virtual machine, [more information](https://www.cloudscale.ch/en/api/v1#images) | | `volume_size_gb` | number | The size of the root volume in GiB. Must be at least `10`. | | `user_data` | string | Depending on the image choice is either in the format of cloud-init (YAML) or Ignition (JSON). | -| `network` | string | The primary network to attach to the machines. Defaults to `public`. You need to ensure the runner controller can reach the machines via this one. | -| `extra_networks` | string | Additional networks to be added to the machines. | +| `interfaces` | object | Describes the interfaces to attach to the instances. Check the config template for some examples. | ### Default connector config diff --git a/config/config.toml.template b/config/config.toml.template index d560ef8..4c32544 100644 --- a/config/config.toml.template +++ b/config/config.toml.template @@ -96,14 +96,21 @@ concurrent = 40 # The root disk size of each instance. volume_size_gb = 25 - # The primary network. You need to ensure that the runner manager can - # access your instances on this one. - network = "public" - - # Additional networks to connect to the machine. - # extra_networks = [ - # "b10742ba-6949-44fd-9387-74fa7ac65854", - # "618baa7b-3185-470c-b230-32ff34ddfd72" + # Networking configuration for the instances + # The Network that is listed first will be used for the communication with the runner controller. + # This direcly mirrors the go sdk types (https://github.com/cloudscale-ch/cloudscale-go-sdk/blob/1baae3ab99a83a25221c77a8c6f4c69838979312/servers.go#L116-L124) + # interfaces = [ + # { network = "UUID3"}, + # { network = "UUID3"}, + # ] + # + # Only one interface in the public network. + # This is also the default if nothing is set + interfaces = [{ network = "public" }] + # Two interfaces, one in a private network + # interfaces = [ + # { network = "public" }, + # { network = "uuid of private net"}, # ] # The cloud-config applied to each instance. Note that GitLab expects these diff --git a/provider.go b/provider.go index e416c38..9d104ce 100644 --- a/provider.go +++ b/provider.go @@ -39,8 +39,7 @@ type InstanceGroup struct { Image string `json:"image"` UserData string `json:"user_data"` - Network string `json:"network,omitempty"` - ExtraNetworks []string `json:"extra_networks,omitempty"` + Interfaces []cloudscale.InterfaceRequest `json:"interfaces,omitempty"` VolumeSizeGB int `json:"volume_size_gb,omitempty"` @@ -119,6 +118,14 @@ func (g *InstanceGroup) validate() error { err("plugin_config: zone %s should be rma1 or lpg1", g.Zone) } + if g.Interfaces == nil { + g.Interfaces = []cloudscale.InterfaceRequest{ + cloudscale.InterfaceRequest{ + Network: "public", + }, + } + } + if g.VolumeSizeGB < 10 { err("plugin_config: volume_size_gb must be >= 10") }