Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit ab34c89

Browse files
committed
fix when additional tags are ssh fingerprints are not provided
1 parent 60dd553 commit ab34c89

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

plugin/digitalocean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (t *TargetPlugin) scaleOut(ctx context.Context, num int64, template *drople
4141
Image: godo.DropletCreateImage{
4242
ID: template.snapshotID,
4343
},
44-
Tags: append(template.tags, template.nodeClass),
44+
Tags: template.tags,
4545
}
4646

4747
if len(template.sshKeys) != 0 {

plugin/plugin.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ func (t *TargetPlugin) createDropletTemplate(config map[string]string) (*droplet
208208
return nil, fmt.Errorf("invalid value for config param %s", configKeySnapshotID)
209209
}
210210

211-
sshKeyFingerprint, _ := t.getValue(config, configKeySshKeys)
212-
tags, _ := t.getValue(config, configKeyTags)
211+
sshKeyFingerprintAsString, _ := t.getValue(config, configKeySshKeys)
212+
tagsAsString, _ := t.getValue(config, configKeyTags)
213213
userData, _ := t.getValue(config, configKeyUserData)
214214

215215
// We cannot scale droplets without knowing the target node class.
@@ -218,15 +218,25 @@ func (t *TargetPlugin) createDropletTemplate(config map[string]string) (*droplet
218218
return nil, fmt.Errorf("required config param %s not found", sdk.TargetConfigKeyClass)
219219
}
220220

221+
var tags = []string{nodeClass}
222+
if len(tagsAsString) != 0 {
223+
tags = append(tags, strings.Split(tagsAsString, ",")...)
224+
}
225+
226+
var sshKeyFingerprints = []string{}
227+
if len(sshKeyFingerprintAsString) != 0 {
228+
sshKeyFingerprints = append(sshKeyFingerprints, strings.Split(sshKeyFingerprintAsString, ",")...)
229+
}
230+
221231
return &dropletTemplate{
222232
region: region,
223233
size: size,
224234
vpc: vpc,
225235
snapshotID: int(snapshotID),
226236
nodeClass: nodeClass,
227-
sshKeys: strings.Split(sshKeyFingerprint, ","),
237+
sshKeys: sshKeyFingerprints,
228238
userData: userData,
229-
tags: strings.Split(tags, ","),
239+
tags: tags,
230240
}, nil
231241
}
232242

plugin/plugin_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,37 @@ func TestTargetPlugin_calculateDirection(t *testing.T) {
4747
})
4848
}
4949
}
50+
51+
func TestTargetPlugin_createDropletTemplate(t *testing.T) {
52+
input := map[string]string{
53+
"region" : "ny1",
54+
"size" : "s-1vcpu-1gb",
55+
"vpc_uuid" : "b6ac51f4-dc83-11e8-a3da-3cfdfea9f0d8",
56+
"snapshot_id" : "123",
57+
"node_class" : "hashistack",
58+
}
59+
60+
plugin := TargetPlugin{}
61+
dropletTemplate, err := plugin.createDropletTemplate(input)
62+
63+
assert.Nil(t, err)
64+
assert.Equal(t, []string{}, dropletTemplate.sshKeys)
65+
assert.Equal(t, []string{"hashistack"}, dropletTemplate.tags)
66+
}
67+
68+
func TestTargetPlugin_createDropletTemplateWithMultipleTags(t *testing.T) {
69+
input := map[string]string{
70+
"region" : "ny1",
71+
"size" : "s-1vcpu-1gb",
72+
"vpc_uuid" : "b6ac51f4-dc83-11e8-a3da-3cfdfea9f0d8",
73+
"snapshot_id" : "123",
74+
"tags" : "tag1,tag2",
75+
"node_class" : "hashistack",
76+
}
77+
78+
plugin := TargetPlugin{}
79+
dropletTemplate, err := plugin.createDropletTemplate(input)
80+
81+
assert.Nil(t, err)
82+
assert.Equal(t, []string{"hashistack", "tag1", "tag2"}, dropletTemplate.tags)
83+
}

0 commit comments

Comments
 (0)