Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#168 from esierra-stratio/chore/efs…
Browse files Browse the repository at this point in the history
…_descriptor

[EOS-11436] Configurar EFS en el descriptor (para renderizar el keos.yaml)
  • Loading branch information
esierra-stratio authored Jun 21, 2023
2 parents 7f2a165 + 1997e22 commit 03ea579
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
56 changes: 53 additions & 3 deletions pkg/cluster/internal/create/actions/createworker/keosinstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package createworker

import (
"os"
"path/filepath"
"time"

"gopkg.in/yaml.v3"
"sigs.k8s.io/kind/pkg/commons"
Expand Down Expand Up @@ -61,10 +63,22 @@ type KEOSDescriptor struct {
Flavour string `yaml:"flavour"`
K8sInstallation bool `yaml:"k8s_installation"`
Storage struct {
DefaultStorageClass string `yaml:"default_storage_class"`
DefaultStorageClass string `yaml:"default_storage_class,omitempty"`
Providers []string `yaml:"providers"`
Config struct {
CSIAWS struct {
EFS []EFSConfig `yaml:"efs"`
KMSKeyID string `yaml:"kms_key_id,omitempty"`
} `yaml:"csi-aws"`
} `yaml:"config,omitempty"`
} `yaml:"storage"`
} `yaml:"keos"`
}
}

type EFSConfig struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Permissions string `yaml:"permissions"`
}

func createKEOSDescriptor(descriptorFile commons.DescriptorFile, storageClass string) error {
Expand Down Expand Up @@ -125,7 +139,29 @@ func createKEOSDescriptor(descriptorFile commons.DescriptorFile, storageClass st

// Keos - Storage
keosDescriptor.Keos.Storage.DefaultStorageClass = storageClass
keosDescriptor.Keos.Storage.Providers = []string{"custom"}
if descriptorFile.StorageClass.EFS.Name != "" {
keosDescriptor.Keos.Storage.Providers = []string{"csi-aws"}

name := descriptorFile.StorageClass.EFS.Name
id := descriptorFile.StorageClass.EFS.ID
permissions := descriptorFile.StorageClass.EFS.Permissions

if permissions == "" {
permissions = "700"
}
keosDescriptor.Keos.Storage.Config.CSIAWS.EFS = []EFSConfig{
{
Name: name,
ID: id,
Permissions: permissions,
},
}
if descriptorFile.StorageClass.EncryptionKey != "" {
keosDescriptor.Keos.Storage.Config.CSIAWS.KMSKeyID = descriptorFile.StorageClass.EncryptionKey
}
} else {
keosDescriptor.Keos.Storage.Providers = []string{"custom"}
}

// Keos - External dns
if !descriptorFile.Dns.ManageZone {
Expand All @@ -137,6 +173,20 @@ func createKEOSDescriptor(descriptorFile commons.DescriptorFile, storageClass st
return err
}

// Rotate keos.yaml
keosFilename := "keos.yaml"

if _, err := os.Stat(keosFilename); err == nil {
timestamp := time.Now().Format("2006-01-02@15:04:05")
backupKeosFilename := keosFilename + "." + timestamp + "~"
originalKeosFilePath := filepath.Join(".", keosFilename)
backupKeosFilePath := filepath.Join(".", backupKeosFilename)

if err := os.Rename(originalKeosFilePath, backupKeosFilePath); err != nil {
return err
}
}

// Write file to disk
err = os.WriteFile("keos.yaml", []byte(keosYAMLData), 0644)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/commons/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type DescriptorFile struct {
ExtraVolumes []ExtraVolume `yaml:"extra_volumes"`
} `yaml:"control_plane"`

StorageClass StorageClass `yaml:storageclass`
WorkerNodes WorkerNodes `yaml:"worker_nodes" validate:"required,dive"`
}

Expand Down Expand Up @@ -230,6 +231,17 @@ type Secrets struct {
DockerRegistries []DockerRegistryCredentials `yaml:"docker_registries"`
}

type StorageClass struct {
EFS EFS `yaml:"efs"`
EncryptionKey string `yaml:"encryption_key,omitempty"`
}

type EFS struct {
Name string `yaml:"name" validate:"required_with=ID"`
ID string `yaml:"id" validate:"required_with=Name"`
Permissions string `yaml:"permissions,omitempty"`
}

type ProviderParams struct {
Region string
Managed bool
Expand Down

0 comments on commit 03ea579

Please sign in to comment.