Skip to content

Commit

Permalink
Merge pull request #75 from iamjanr/EOS_10931
Browse files Browse the repository at this point in the history
[EOS-1931] Formato de k8s en el cluster descriptor
  • Loading branch information
iamjanr authored Mar 24, 2023
2 parents 3ee35da + 7cbea27 commit 417200a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/cluster/internal/create/actions/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ import (
//go:embed templates/*
var ctel embed.FS

type K8sObject struct {
APIVersion string `yaml:"apiVersion" validate:"required"`
Kind string `yaml:"kind" validate:"required"`
Spec DescriptorFile `yaml:"spec" validate:"required,dive"`
}

// DescriptorFile represents the YAML structure in the descriptor file
type DescriptorFile struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
ClusterID string `yaml:"cluster_id" validate:"required,min=3,max=100"`
DeployAutoscaler bool `yaml:"deploy_autoscaler" validate:"boolean"`

Expand Down Expand Up @@ -224,20 +228,27 @@ func (d DescriptorFile) Init() DescriptorFile {

// Read descriptor file
func GetClusterDescriptor(descriptorPath string) (*DescriptorFile, error) {

var k8sStruct K8sObject

descriptorRAW, err := os.ReadFile(descriptorPath)
if err != nil {
return nil, err
}
descriptorFile := new(DescriptorFile).Init()
err = yaml.Unmarshal(descriptorRAW, &descriptorFile)

k8sStruct.Spec = new(DescriptorFile).Init()
err = yaml.Unmarshal(descriptorRAW, &k8sStruct)
if err != nil {
return nil, err
}
descriptorFile := k8sStruct.Spec

validate := validator.New()
err = validate.Struct(descriptorFile)
err = validate.Struct(k8sStruct)
if err != nil {
return nil, err
}

return &descriptorFile, nil
}

Expand Down

0 comments on commit 417200a

Please sign in to comment.