github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/step/bdd/bdd_clusters.go (about)

     1  package bdd
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  	"sigs.k8s.io/yaml"
     6  
     7  	"io/ioutil"
     8  )
     9  
    10  // CreateClusters contains an array of clusters
    11  type CreateClusters struct {
    12  	Clusters []*CreateCluster `json:"clusters,omitempty"`
    13  }
    14  
    15  // CreateCluster defines how to create a cluster
    16  type CreateCluster struct {
    17  	Name      string   `json:"name,omitempty"`
    18  	Args      []string `json:"args,omitempty"`
    19  	NoLabels  bool     `json:"noLabels,omitempty"`
    20  	Labels    string   `json:"labels,omitempty"`
    21  	Terraform bool     `json:"terraform,omitempty"`
    22  
    23  	Commands []Command `json:"commands,omitempty"`
    24  }
    25  
    26  // Command for running post create cluster commands
    27  type Command struct {
    28  	Command string   `json:"command,omitempty"`
    29  	Args    []string `json:"args,omitempty"`
    30  }
    31  
    32  // LoadBddClusters loads the cluster configuration from the given file
    33  func LoadBddClusters(fileName string) (*CreateClusters, error) {
    34  	data, err := ioutil.ReadFile(fileName)
    35  	if err != nil {
    36  		return nil, errors.Wrapf(err, "failed to load file %s", fileName)
    37  	}
    38  	answer := &CreateClusters{}
    39  	err = yaml.Unmarshal(data, answer)
    40  	if err != nil {
    41  		return nil, errors.Wrapf(err, "failed to unmarshal YAML in file %s", fileName)
    42  	}
    43  	return answer, nil
    44  }