-
Notifications
You must be signed in to change notification settings - Fork 272
/
machine_types.go
44 lines (37 loc) 路 1.4 KB
/
machine_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package v1alpha1
import "fmt"
type OSFamily string
const (
Ubuntu OSFamily = "ubuntu"
Bottlerocket OSFamily = "bottlerocket"
RedHat OSFamily = "redhat"
)
// UserConfiguration defines the configuration of the user to be added to the VM.
type UserConfiguration struct {
Name string `json:"name"`
SshAuthorizedKeys []string `json:"sshAuthorizedKeys"`
}
func defaultMachineConfigUsers(defaultUsername string, users []UserConfiguration) []UserConfiguration {
if len(users) <= 0 {
users = []UserConfiguration{{}}
}
if len(users[0].SshAuthorizedKeys) <= 0 {
users[0].SshAuthorizedKeys = []string{""}
}
if users[0].Name == "" {
users[0].Name = defaultUsername
}
return users
}
func validateMachineConfigUsers(machineConfigName string, machineConfigKind string, users []UserConfiguration) error {
if len(users) == 0 {
return fmt.Errorf("users is not set for %s %s, please provide a user", machineConfigKind, machineConfigName)
}
if users[0].Name == "" {
return fmt.Errorf("users[0].name is not set or is empty for %s %s, please provide a username", machineConfigKind, machineConfigName)
}
if len(users[0].SshAuthorizedKeys) == 0 || users[0].SshAuthorizedKeys[0] == "" {
return fmt.Errorf("users[0].SshAuthorizedKeys is not set or is empty for %s %s, please provide a valid ssh authorized key for user %s", machineConfigKind, machineConfigName, users[0].Name)
}
return nil
}