Skip to content

Commit 4db003b

Browse files
Merge pull request #19 from cloudbase/revert-17-lower-case-fqnd
Revert "Allow forcing lower case runner names"
2 parents 6640e28 + 4993fb8 commit 4db003b

File tree

6 files changed

+22
-92
lines changed

6 files changed

+22
-92
lines changed

config/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ type Incus struct {
118118

119119
// InstanceType allows you to choose between a virtual machine and a container
120120
InstanceType IncusImageType `toml:"instance_type" json:"instance-type"`
121-
122-
// UseLowerCaseHostnames makes the runner name all lowercase before sending it to incus.
123-
UseLowerCaseHostnames bool `toml:"use_lowercase_hostnames" json:"use_lowercase_hostnames"`
124121
}
125122

126123
func (l *Incus) GetInstanceType() IncusImageType {

provider/incus.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package provider
1818
import (
1919
"context"
2020
"fmt"
21-
"strings"
2221
"sync"
2322
"time"
2423

@@ -54,9 +53,6 @@ const (
5453
// architecture a runner is supposed to have. This value is defined in the pool and
5554
// passed into the provider as bootstrap params.
5655
osArchKeyNAme = "user.os-arch"
57-
58-
// runnerInstanceName is the ID of the runner in GRAM.
59-
runnerInstanceKeyName = "user.runner-name"
6056
)
6157

6258
var (
@@ -234,23 +230,17 @@ func (l *Incus) getCreateInstanceArgs(ctx context.Context, bootstrapParams commo
234230
}
235231

236232
configMap := map[string]string{
237-
"user.user-data": cloudCfg,
238-
osTypeKeyName: string(bootstrapParams.OSType),
239-
osArchKeyNAme: string(bootstrapParams.OSArch),
240-
controllerIDKeyName: l.controllerID,
241-
poolIDKey: bootstrapParams.PoolID,
242-
runnerInstanceKeyName: bootstrapParams.Name,
233+
"user.user-data": cloudCfg,
234+
osTypeKeyName: string(bootstrapParams.OSType),
235+
osArchKeyNAme: string(bootstrapParams.OSArch),
236+
controllerIDKeyName: l.controllerID,
237+
poolIDKey: bootstrapParams.PoolID,
243238
}
244239

245240
if instanceType == config.IncusImageVirtualMachine {
246241
configMap["security.secureboot"] = l.secureBootEnabled()
247242
}
248243

249-
instanceName := bootstrapParams.Name
250-
if specs.UseLowerCaseHostnames {
251-
instanceName = strings.ToLower(instanceName)
252-
}
253-
254244
args := api.InstancesPost{
255245
InstancePut: api.InstancePut{
256246
Architecture: arch,
@@ -259,7 +249,7 @@ func (l *Incus) getCreateInstanceArgs(ctx context.Context, bootstrapParams commo
259249
Config: configMap,
260250
},
261251
Source: instanceSource,
262-
Name: instanceName,
252+
Name: bootstrapParams.Name,
263253
Type: api.InstanceType(instanceType),
264254
}
265255
return args, nil
@@ -331,16 +321,6 @@ func (l *Incus) GetInstance(ctx context.Context, instanceName string) (commonPar
331321
return commonParams.ProviderInstance{}, errors.Wrap(err, "fetching client")
332322
}
333323
instance, _, err := cli.GetInstanceFull(instanceName)
334-
if err == nil {
335-
return incusInstanceToAPIInstance(instance), nil
336-
}
337-
338-
if !isNotFoundError(err) {
339-
return commonParams.ProviderInstance{}, errors.Wrap(err, "fetching instance")
340-
}
341-
342-
asLower := strings.ToLower(instanceName)
343-
instance, _, err = cli.GetInstanceFull(asLower)
344324
if err != nil {
345325
if isNotFoundError(err) {
346326
return commonParams.ProviderInstance{}, errors.Wrapf(runnerErrors.ErrNotFound, "fetching instance: %q", err)

provider/incus_test.go

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package provider
1717

1818
import (
1919
"context"
20-
"encoding/json"
2120
"testing"
2221

2322
commonParams "github.com/cloudbase/garm-provider-common/params"
@@ -185,12 +184,11 @@ func TestGetCreateInstanceArgsContainer(t *testing.T) {
185184
Profiles: []string{"default", "container"},
186185
Description: "Github runner provisioned by garm",
187186
Config: map[string]string{
188-
"user.user-data": `#cloud-config`,
189-
osTypeKeyName: "linux",
190-
osArchKeyNAme: "amd64",
191-
controllerIDKeyName: "controller",
192-
poolIDKey: "default",
193-
runnerInstanceKeyName: "test-instance",
187+
"user.user-data": `#cloud-config`,
188+
osTypeKeyName: "linux",
189+
osArchKeyNAme: "amd64",
190+
controllerIDKeyName: "controller",
191+
poolIDKey: "default",
194192
},
195193
},
196194
Source: api.InstanceSource{
@@ -261,6 +259,7 @@ func TestGetCreateInstanceArgsVM(t *testing.T) {
261259
cli.On("GetImageAliasArchitectures", config.IncusImageType("virtual-machine").String(), "windows").Return(aliases, nil)
262260
cli.On("GetImage", aliases["x86_64"].Target).Return(&api.Image{Fingerprint: "123abc"}, "", nil)
263261
cli.On("GetProfileNames").Return([]string{"default", "virtual-machine"}, nil)
262+
specs := extraSpecs{}
264263
tests := []struct {
265264
name string
266265
bootstrapParams commonParams.BootstrapInstance
@@ -276,7 +275,7 @@ func TestGetCreateInstanceArgsVM(t *testing.T) {
276275
{
277276
name: "success vm instance",
278277
bootstrapParams: commonParams.BootstrapInstance{
279-
Name: "test-InStAnCe",
278+
Name: "test-instance",
280279
Tools: tools,
281280
Image: "windows",
282281
Flavor: "virtual-machine",
@@ -285,43 +284,6 @@ func TestGetCreateInstanceArgsVM(t *testing.T) {
285284
OSArch: commonParams.Amd64,
286285
OSType: commonParams.Windows,
287286
},
288-
expected: api.InstancesPost{
289-
Name: "test-InStAnCe",
290-
InstancePut: api.InstancePut{
291-
Architecture: "x86_64",
292-
Profiles: []string{"default", "virtual-machine"},
293-
Description: "Github runner provisioned by garm",
294-
Config: map[string]string{
295-
"user.user-data": "#ps1_sysnative\n" + "#cloud-config",
296-
osTypeKeyName: "windows",
297-
osArchKeyNAme: "amd64",
298-
controllerIDKeyName: "controller",
299-
poolIDKey: "default",
300-
runnerInstanceKeyName: "test-InStAnCe",
301-
"security.secureboot": "false",
302-
},
303-
},
304-
Source: api.InstanceSource{
305-
Type: "image",
306-
Fingerprint: "123abc",
307-
},
308-
Type: "virtual-machine",
309-
},
310-
errString: "",
311-
},
312-
{
313-
name: "success vm instance with lower case name",
314-
bootstrapParams: commonParams.BootstrapInstance{
315-
Name: "test-InStAnCe",
316-
Tools: tools,
317-
Image: "windows",
318-
Flavor: "virtual-machine",
319-
RepoURL: "mock-repo-url",
320-
PoolID: "default",
321-
OSArch: commonParams.Amd64,
322-
OSType: commonParams.Windows,
323-
ExtraSpecs: json.RawMessage(`{"use_lowercase_hostnames": true}`),
324-
},
325287
expected: api.InstancesPost{
326288
Name: "test-instance",
327289
InstancePut: api.InstancePut{
@@ -334,7 +296,6 @@ func TestGetCreateInstanceArgsVM(t *testing.T) {
334296
osArchKeyNAme: "amd64",
335297
controllerIDKeyName: "controller",
336298
poolIDKey: "default",
337-
runnerInstanceKeyName: "test-InStAnCe",
338299
"security.secureboot": "false",
339300
},
340301
},
@@ -350,9 +311,6 @@ func TestGetCreateInstanceArgsVM(t *testing.T) {
350311

351312
for _, tt := range tests {
352313
t.Run(tt.name, func(t *testing.T) {
353-
specs, err := parseExtraSpecsFromBootstrapParams(tt.bootstrapParams)
354-
require.NoError(t, err)
355-
356314
ret, err := l.getCreateInstanceArgs(ctx, tt.bootstrapParams, specs)
357315
if tt.errString != "" {
358316
require.Error(t, err)

provider/specs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ import (
2626
)
2727

2828
type extraSpecs struct {
29-
ExtraPackages []string `json:"extra_packages,omitempty" jsonschema:"description=A list of packages that cloud-init should install on the instance."`
30-
DisableUpdates bool `json:"disable_updates,omitempty" jsonschema:"description=Whether to disable updates when cloud-init comes online."`
31-
EnableBootDebug bool `json:"enable_boot_debug,omitempty" jsonschema:"description=Allows providers to set the -x flag in the runner install script."`
32-
UseLowerCaseHostnames bool `json:"use_lowercase_hostnames,omitempty" jsonschema:"description=Instructs the provider to make the hostname of the runner all lowercase."`
29+
ExtraPackages []string `json:"extra_packages,omitempty" jsonschema:"description=A list of packages that cloud-init should install on the instance."`
30+
DisableUpdates bool `json:"disable_updates,omitempty" jsonschema:"description=Whether to disable updates when cloud-init comes online."`
31+
EnableBootDebug bool `json:"enable_boot_debug,omitempty" jsonschema:"description=Allows providers to set the -x flag in the runner install script."`
3332
cloudconfig.CloudConfigSpec
3433
}
3534

provider/specs_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ var testCases = []struct {
3333
}{
3434
{
3535
name: "full specs",
36-
input: json.RawMessage(`{"use_lowercase_hostnames": false, "disable_updates": true, "extra_packages": ["package1", "package2"], "enable_boot_debug": true, "runner_install_template": "IyEvYmluL2Jhc2gKZWNobyBJbnN0YWxsaW5nIHJ1bm5lci4uLg==", "pre_install_scripts": {"setup.sh": "IyEvYmluL2Jhc2gKZWNobyBTZXR1cCBzY3JpcHQuLi4="}, "extra_context": {"key": "value"}}`),
36+
input: json.RawMessage(`{"disable_updates": true, "extra_packages": ["package1", "package2"], "enable_boot_debug": true, "runner_install_template": "IyEvYmluL2Jhc2gKZWNobyBJbnN0YWxsaW5nIHJ1bm5lci4uLg==", "pre_install_scripts": {"setup.sh": "IyEvYmluL2Jhc2gKZWNobyBTZXR1cCBzY3JpcHQuLi4="}, "extra_context": {"key": "value"}}`),
3737
expectedOutput: extraSpecs{
38-
DisableUpdates: true,
39-
ExtraPackages: []string{"package1", "package2"},
40-
EnableBootDebug: true,
41-
UseLowerCaseHostnames: false,
38+
DisableUpdates: true,
39+
ExtraPackages: []string{"package1", "package2"},
40+
EnableBootDebug: true,
4241
CloudConfigSpec: cloudconfig.CloudConfigSpec{
4342
RunnerInstallTemplate: []byte("#!/bin/bash\necho Installing runner..."),
4443
PreInstallScripts: map[string][]byte{

provider/util.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@ func incusInstanceToAPIInstance(instance *api.InstanceFull) commonParams.Provide
6666
incusOS := instance.ExpandedConfig["image.os"]
6767

6868
osType, _ := util.OSToOSType(incusOS)
69+
6970
if osType == "" {
7071
osTypeFromTag := instance.ExpandedConfig[osTypeKeyName]
7172
osType = commonParams.OSType(osTypeFromTag)
7273
}
7374
osRelease := instance.ExpandedConfig["image.release"]
74-
runnerName := instance.Name
75-
if instance.ExpandedConfig[runnerInstanceKeyName] != "" {
76-
runnerName = instance.ExpandedConfig[runnerInstanceKeyName]
77-
}
7875

7976
state := instance.State
8077
addresses := []commonParams.Address{}
@@ -96,7 +93,7 @@ func incusInstanceToAPIInstance(instance *api.InstanceFull) commonParams.Provide
9693
return commonParams.ProviderInstance{
9794
OSArch: instanceArch,
9895
ProviderID: instance.Name,
99-
Name: runnerName,
96+
Name: instance.Name,
10097
OSType: osType,
10198
OSName: strings.ToLower(incusOS),
10299
OSVersion: osRelease,

0 commit comments

Comments
 (0)