Skip to content

Commit cabe2ae

Browse files
committed
Make configured disk size applied to server
fix issue that configured disk size was not applied and remove test user from cloud init script
1 parent 7f14d55 commit cabe2ae

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

pkg/options/options.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package options
33
import (
44
"fmt"
55
"os"
6+
"regexp"
7+
"strconv"
68
)
79

810
type Options struct {
@@ -13,7 +15,7 @@ type Options struct {
1315
ProjectID string
1416
AvailabilityZone string
1517
Flavor string
16-
DiskSize string
18+
DiskSize int64
1719
}
1820

1921
type ClientOptions struct {
@@ -51,7 +53,11 @@ func FromEnv(skipMachine bool) (*Options, error) {
5153
if err != nil {
5254
return nil, err
5355
}
54-
retOptions.DiskSize, err = fromEnvOrError("STACKIT_DISK_SIZE")
56+
diskSize, err := fromEnvOrError("STACKIT_DISK_SIZE")
57+
if err != nil {
58+
return nil, err
59+
}
60+
retOptions.DiskSize, err = extractInt64(diskSize)
5561
if err != nil {
5662
return nil, err
5763
}
@@ -79,3 +85,18 @@ func fromEnvOrError(name string) (string, error) {
7985

8086
return val, nil
8187
}
88+
89+
func extractInt64(s string) (int64, error) {
90+
re := regexp.MustCompile(`\d+`)
91+
match := re.FindString(s)
92+
93+
if match == "" {
94+
return 0, fmt.Errorf("couldn't find number in %s", s)
95+
}
96+
97+
result, err := strconv.ParseInt(match, 10, 64)
98+
if err != nil {
99+
return 0, err
100+
}
101+
return result, nil
102+
}

pkg/stackit/cloud-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ users:
1818
shell: /bin/bash
1919
ssh_authorized_keys:
2020
- "{{ .PublicKey }}"
21-
- name: test
22-
lock_passwd: false
23-
passwd: $1$X4rlCkR8$mZuINsPlJmSydnLeIFTl5/
24-
sudo: ALL=(ALL) NOPASSWD:ALL
2521
write_files:
2622
- path: /etc/docker/daemon.json
2723
content: |

pkg/stackit/stackit.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"embed"
77
"encoding/base64"
88
"fmt"
9-
"github.com/loft-sh/log"
109
"text/template"
1110

11+
"github.com/loft-sh/log"
12+
1213
"github.com/stackitcloud/stackit-sdk-go/core/utils"
1314
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
1415

@@ -215,7 +216,7 @@ func (s *Stackit) Create(ctx context.Context, options *options.Options, publicKe
215216
MachineType: &options.Flavor,
216217
BootVolume: &iaas.CreateServerPayloadBootVolume{
217218
DeleteOnTermination: utils.Ptr(true),
218-
Size: utils.Ptr(int64(64)),
219+
Size: utils.Ptr(options.DiskSize),
219220
Source: &iaas.BootVolumeSource{
220221
Id: utils.Ptr(ubuntuImageID),
221222
Type: utils.Ptr("image"),

0 commit comments

Comments
 (0)