Skip to content

Commit

Permalink
Replace DHCP "SSHKey" with "password" field for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTheEvilOne committed Nov 17, 2021
1 parent 6d05d67 commit 2b33f4f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
1 change: 0 additions & 1 deletion example/30-infrastructure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ spec:
version: "20.04"
cores: 1
memory: 1024
sshKey: ssh-rsa invalid
userData: |-
#cloud-config
package_update: true
Expand Down
21 changes: 18 additions & 3 deletions pkg/controller/infrastructure/ensurer/dhcp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ import (
"context"
"encoding/base64"
"errors"
"fmt"
"math"
"math/rand"
"strings"
"time"

"github.com/23technologies/gardener-extension-provider-ionos/pkg/ionos/apis"
ionosapiwrapper "github.com/23technologies/ionos-api-wrapper/pkg"
ionossdk "github.com/ionos-cloud/sdk-go/v5"
)

// Constant ionosPasswordGeneratedLength is the length of the generated random password
const ionosPasswordGeneratedLength = 32
// Constant ionosVolumeType is the volume type
const ionosVolumeType = "SSD"

Expand All @@ -45,12 +49,23 @@ func createDHCPServer(ctx context.Context, client *ionossdk.APIClient, datacente
return "", errors.New("imageID given doesn't belong to a cloud-init enabled image")
}

password := configuration.Password
userDataBase64Encoded := base64.StdEncoding.EncodeToString([]byte(configuration.UserData))
sshKeys := []string{fmt.Sprintf("%s\n", configuration.SSHKey)}
volumeName := "dhcp-server-root-volume"
volumeSize := configuration.VolumeSize
volumeType := ionosVolumeType

if "" == password {
var passwordBuilder strings.Builder
seededRand := rand.New(rand.NewSource(time.Now().Unix()))

for i := 0; i < ionosPasswordGeneratedLength; i++ {
passwordBuilder.WriteString(string(32 + seededRand.Intn(94)))
}

password = passwordBuilder.String()
}

if 0 == volumeSize {
volumeSize = *image.Properties.Size
} else {
Expand All @@ -62,7 +77,7 @@ func createDHCPServer(ctx context.Context, client *ionossdk.APIClient, datacente
Name: &volumeName,
Size: &volumeSize,
Image: &imageID,
SshKeys: &sshKeys,
ImagePassword: &password,
UserData: &userDataBase64Encoded,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/ionos/apis/types_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ type DHCPServerConfiguration struct {
//
Memory uint `json:"memory"`
//
SSHKey string `json:"sshKey"`
//
UserData string `json:"userData"`

//
Password string `json:"password,omitempty"`
// Volume size
VolumeSize float32 `json:"volumeSize,omitempty"`
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ionos/apis/v1alpha1/types_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ type DHCPServerConfiguration struct {
//
Memory uint `json:"memory"`
//
SSHKey string `json:"sshKey"`
//
UserData string `json:"userData"`

//
Password string `json:"password,omitempty"`
// Volume size
VolumeSize float32 `json:"volumeSize,omitempty"`
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ionos/apis/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b33f4f

Please sign in to comment.