From 20fa44eda233ad070db6f43a1f54940d01c60b4a Mon Sep 17 00:00:00 2001 From: Guillermo Gaston Date: Wed, 13 Sep 2023 08:17:29 +0000 Subject: [PATCH] Delete yaml parsing code from api package This code was mostly unused and redudant given the parsing tools in the cluster package, which is a better place for it. --- cmd/eks-a-tool/cmd/vsphereautofill.go | 6 +- pkg/api/v1alpha1/cloudstackmachineconfig.go | 38 --- .../v1alpha1/cloudstackmachineconfig_test.go | 239 ------------------ pkg/api/v1alpha1/cluster.go | 10 - pkg/api/v1alpha1/nutanixmachineconfig.go | 45 ---- pkg/api/v1alpha1/nutanixmachineconfig_test.go | 171 ++++--------- .../v1alpha1/nutanixmachineconfig_types.go | 3 + ..._different_machine_configs_cloudstack.yaml | 85 ------- .../testdata/not_parseable_gitopsconfig.yaml | 2 +- .../testdata/not_parseable_oidcconfig.yaml | 2 +- .../testdata/nutanix/invalid-cluster.yaml | 2 +- .../testdata/nutanix/invalid-kind.yaml | 2 +- ...achineconfig-addtional-categories-key.yaml | 2 +- ...hineconfig-addtional-categories-value.yaml | 2 +- .../machineconfig-with-no-osfamily.yaml | 2 +- .../machineconfig-with-no-ssh-key.yaml | 2 +- .../machineconfig-with-no-user-name.yaml | 2 +- .../nutanix/machineconfig-with-no-users.yaml | 2 +- .../valid-cluster-extra-delimiter.yaml | 2 +- .../testdata/nutanix/valid-cluster.yaml | 2 +- ...r_with_duplicate_mchine_config_fields.yaml | 45 ---- pkg/api/v1alpha1/tinkerbellmachineconfig.go | 40 --- .../v1alpha1/tinkerbellmachineconfig_test.go | 66 ----- pkg/api/v1alpha1/vspheremachineconfig.go | 38 --- pkg/api/v1alpha1/vspheremachineconfig_test.go | 225 ----------------- pkg/dependencies/factory.go | 10 +- pkg/providers/cloudstack/cloudstack_test.go | 17 +- pkg/providers/cloudstack/validator_test.go | 7 +- pkg/providers/tinkerbell/tinkerbell_test.go | 5 +- pkg/providers/vsphere/vsphere_test.go | 16 +- .../preflightvalidations_test.go | 5 +- test/framework/flux.go | 36 +-- 32 files changed, 125 insertions(+), 1006 deletions(-) delete mode 100644 pkg/api/v1alpha1/testdata/cluster_different_machine_configs_cloudstack.yaml delete mode 100644 pkg/api/v1alpha1/testdata/tinkerbell_cluster_with_duplicate_mchine_config_fields.yaml delete mode 100644 pkg/api/v1alpha1/tinkerbellmachineconfig_test.go diff --git a/cmd/eks-a-tool/cmd/vsphereautofill.go b/cmd/eks-a-tool/cmd/vsphereautofill.go index 6ddced43dac65..cc91db6fde7d6 100644 --- a/cmd/eks-a-tool/cmd/vsphereautofill.go +++ b/cmd/eks-a-tool/cmd/vsphereautofill.go @@ -15,6 +15,7 @@ import ( "sigs.k8s.io/yaml" "github.com/aws/eks-anywhere/pkg/api/v1alpha1" + "github.com/aws/eks-anywhere/pkg/cluster" "github.com/aws/eks-anywhere/pkg/filewriter" "github.com/aws/eks-anywhere/pkg/validations" ) @@ -65,10 +66,11 @@ func autofill(ctx context.Context) error { if err != nil { return fmt.Errorf("unable to get datacenter config from file: %v", err) } - machineConfig, err := v1alpha1.GetVSphereMachineConfigs(clusterConfigFileName) + config, err := cluster.ParseConfigFromFile(clusterConfigFileName) if err != nil { - return fmt.Errorf("unable to get machine config from file: %v", err) + return err } + machineConfig := config.VSphereMachineConfigs controlPlaneMachineConfig := machineConfig[clusterConfig.Spec.ControlPlaneConfiguration.MachineGroupRef.Name] workerMachineConfig := machineConfig[clusterConfig.Spec.WorkerNodeGroupConfigurations[0].MachineGroupRef.Name] var updatedFields []string diff --git a/pkg/api/v1alpha1/cloudstackmachineconfig.go b/pkg/api/v1alpha1/cloudstackmachineconfig.go index 95ff596d1488f..7c610ec2b2741 100644 --- a/pkg/api/v1alpha1/cloudstackmachineconfig.go +++ b/pkg/api/v1alpha1/cloudstackmachineconfig.go @@ -4,10 +4,6 @@ import ( "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/yaml" - - "github.com/aws/eks-anywhere/pkg/utils/file" - yamlutil "github.com/aws/eks-anywhere/pkg/utils/yaml" ) // DefaultCloudStackUser is the default CloudStackMachingConfig username. @@ -65,40 +61,6 @@ func (c *CloudStackMachineConfigGenerate) Name() string { return c.ObjectMeta.Name } -func GetCloudStackMachineConfigs(fileName string) (map[string]*CloudStackMachineConfig, error) { - configs := make(map[string]*CloudStackMachineConfig) - - r, err := file.ReadFile(fileName) - if err != nil { - return nil, err - } - - resources, err := yamlutil.SplitDocuments(r) - if err != nil { - return nil, err - } - - for _, d := range resources { - var config CloudStackMachineConfig - if err = yaml.UnmarshalStrict(d, &config); err == nil { - if config.Kind == CloudStackMachineConfigKind { - configs[config.Name] = &config - continue - } - } - - _ = yaml.Unmarshal(d, &config) // this is to check if there is a bad spec in the file - if config.Kind == CloudStackMachineConfigKind { - return nil, fmt.Errorf("unable to unmarshall content from file due to: %v", err) - } - } - - if len(configs) == 0 { - return nil, fmt.Errorf("unable to find kind %v in file", CloudStackMachineConfigKind) - } - return configs, nil -} - func validateCloudStackMachineConfig(machineConfig *CloudStackMachineConfig) error { if len(machineConfig.Spec.ComputeOffering.Id) == 0 && len(machineConfig.Spec.ComputeOffering.Name) == 0 { return fmt.Errorf("computeOffering is not set for CloudStackMachineConfig %s. Default computeOffering is not supported in CloudStack, please provide a computeOffering name or ID", machineConfig.Name) diff --git a/pkg/api/v1alpha1/cloudstackmachineconfig_test.go b/pkg/api/v1alpha1/cloudstackmachineconfig_test.go index dc4bcb1c28f36..454c8da0061ad 100644 --- a/pkg/api/v1alpha1/cloudstackmachineconfig_test.go +++ b/pkg/api/v1alpha1/cloudstackmachineconfig_test.go @@ -1,8 +1,6 @@ package v1alpha1 import ( - "fmt" - "reflect" "testing" . "github.com/onsi/gomega" @@ -40,243 +38,6 @@ var cloudStackMachineConfigSpec1 = &CloudStackMachineConfigSpec{ AffinityGroupIds: []string{"affinityGroupId1"}, } -func TestGetCloudStackMachineConfigs(t *testing.T) { - tests := []struct { - testName string - fileName string - wantCloudStackMachineConfigs map[string]*CloudStackMachineConfig - wantErr bool - }{ - { - testName: "file doesn't exist", - fileName: "testdata/fake_file.yaml", - wantCloudStackMachineConfigs: nil, - wantErr: true, - }, - { - testName: "not parseable file", - fileName: "testdata/not_parseable_cluster.yaml", - wantCloudStackMachineConfigs: nil, - wantErr: true, - }, - { - testName: "non-splitable manifest", - fileName: "testdata/invalid_manifest.yaml", - wantCloudStackMachineConfigs: nil, - wantErr: true, - }, - { - testName: "valid 1.19", - fileName: "testdata/cluster_1_19_cloudstack.yaml", - wantCloudStackMachineConfigs: map[string]*CloudStackMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: CloudStackMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: CloudStackMachineConfigSpec{ - Template: CloudStackResourceIdentifier{ - Name: "centos7-k8s-119", - }, - ComputeOffering: CloudStackResourceIdentifier{ - Name: "m4-large", - }, - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - }, - }, - }, - wantErr: false, - }, - { - testName: "valid 1.21", - fileName: "testdata/cluster_1_21_cloudstack.yaml", - wantCloudStackMachineConfigs: map[string]*CloudStackMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: CloudStackMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: CloudStackMachineConfigSpec{ - Template: CloudStackResourceIdentifier{ - Id: "centos7-k8s-121-id", - }, - ComputeOffering: CloudStackResourceIdentifier{ - Id: "m4-large-id", - }, - DiskOffering: &CloudStackResourceDiskOffering{ - CloudStackResourceIdentifier: CloudStackResourceIdentifier{ - Name: "Small", - }, - MountPath: "/data-small", - Device: "/dev/vdb", - Filesystem: "ext4", - Label: "data_disk", - }, - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - }, - }, - }, - wantErr: false, - }, - { - testName: "valid with extra delimiters", - fileName: "testdata/cluster_extra_delimiters_cloudstack.yaml", - wantCloudStackMachineConfigs: map[string]*CloudStackMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: CloudStackMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: CloudStackMachineConfigSpec{ - Template: CloudStackResourceIdentifier{ - Name: "centos7-k8s-118", - }, - ComputeOffering: CloudStackResourceIdentifier{ - Name: "m4-large", - }, - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - }, - }, - }, - wantErr: false, - }, - { - testName: "valid 1.20", - fileName: "testdata/cluster_1_20_cloudstack.yaml", - wantCloudStackMachineConfigs: map[string]*CloudStackMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: CloudStackMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: CloudStackMachineConfigSpec{ - Template: CloudStackResourceIdentifier{ - Name: "centos7-k8s-120", - }, - ComputeOffering: CloudStackResourceIdentifier{ - Name: "m4-large", - }, - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - }, - }, - }, - wantErr: false, - }, - { - testName: "valid different machine configs", - fileName: "testdata/cluster_different_machine_configs_cloudstack.yaml", - wantCloudStackMachineConfigs: map[string]*CloudStackMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: CloudStackMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: CloudStackMachineConfigSpec{ - Template: CloudStackResourceIdentifier{ - Name: "centos7-k8s-118", - }, - ComputeOffering: CloudStackResourceIdentifier{ - Name: "m4-large", - }, - DiskOffering: &CloudStackResourceDiskOffering{ - CloudStackResourceIdentifier: CloudStackResourceIdentifier{ - Name: "Small", - }, - MountPath: "/data-small", - Device: "/dev/vdb", - Filesystem: "ext4", - Label: "data_disk", - }, - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - }, - }, - "eksa-unit-test-2": { - TypeMeta: metav1.TypeMeta{ - Kind: CloudStackMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test-2", - }, - Spec: CloudStackMachineConfigSpec{ - Template: CloudStackResourceIdentifier{ - Name: "centos7-k8s-118", - }, - ComputeOffering: CloudStackResourceIdentifier{ - Name: "m5-xlarge", - }, - DiskOffering: &CloudStackResourceDiskOffering{ - CloudStackResourceIdentifier: CloudStackResourceIdentifier{ - Name: "Medium", - }, - MountPath: "/data-medium", - Device: "/dev/vdb", - Filesystem: "ext4", - Label: "data_disk", - }, - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - }, - }, - }, - wantErr: false, - }, - { - testName: "invalid kind", - fileName: "testdata/cluster_invalid_kinds.yaml", - wantCloudStackMachineConfigs: nil, - wantErr: true, - }, - } - for i, tt := range tests { - if i != 2 { - continue - } - t.Run(tt.testName, func(t *testing.T) { - got, err := GetCloudStackMachineConfigs(tt.fileName) - fmt.Println(err) - if (err != nil) != tt.wantErr { - t.Fatalf("GetCloudStackMachineConfigs() error = %v, wantErr %v", err, tt.wantErr) - } - if !reflect.DeepEqual(got, tt.wantCloudStackMachineConfigs) { - t.Fatalf("GetCloudStackMachineConfigs() = %#v, want %#v", got, tt.wantCloudStackMachineConfigs) - } - }) - } -} - func TestCloudStackMachineConfigValidate(t *testing.T) { tests := []struct { name string diff --git a/pkg/api/v1alpha1/cluster.go b/pkg/api/v1alpha1/cluster.go index 7cb7a5d2f3fe9..8b8d503eabfbb 100644 --- a/pkg/api/v1alpha1/cluster.go +++ b/pkg/api/v1alpha1/cluster.go @@ -204,16 +204,6 @@ func GetClusterConfig(fileName string) (*Cluster, error) { return clusterConfig, nil } -// GetClusterConfigFromContent parses a Cluster object from a multiobject yaml content. -func GetClusterConfigFromContent(content []byte) (*Cluster, error) { - clusterConfig := &Cluster{} - err := ParseClusterConfigFromContent(content, clusterConfig) - if err != nil { - return clusterConfig, err - } - return clusterConfig, nil -} - // GetClusterConfig parses a Cluster object from a multiobject yaml file in disk // sets defaults if necessary and validates the Cluster. func GetAndValidateClusterConfig(fileName string) (*Cluster, error) { diff --git a/pkg/api/v1alpha1/nutanixmachineconfig.go b/pkg/api/v1alpha1/nutanixmachineconfig.go index dce3f4f7ccce0..34e9c40dfad14 100644 --- a/pkg/api/v1alpha1/nutanixmachineconfig.go +++ b/pkg/api/v1alpha1/nutanixmachineconfig.go @@ -5,10 +5,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/yaml" - - "github.com/aws/eks-anywhere/pkg/utils/file" - yamlutil "github.com/aws/eks-anywhere/pkg/utils/yaml" ) // NutanixIdentifierType is an enumeration of different resource identifier types. @@ -121,47 +117,6 @@ func (c *NutanixMachineConfigGenerate) Name() string { return c.ObjectMeta.Name } -func GetNutanixMachineConfigs(fileName string) (map[string]*NutanixMachineConfig, error) { - configs := make(map[string]*NutanixMachineConfig) - - r, err := file.ReadFile(fileName) - if err != nil { - return nil, err - } - - resources, err := yamlutil.SplitDocuments(r) - if err != nil { - return nil, err - } - - for _, d := range resources { - config := NutanixMachineConfig{ - TypeMeta: metav1.TypeMeta{}, - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{}, - }, - } - - if err = yaml.UnmarshalStrict(d, &config); err == nil { - if config.Kind == NutanixMachineConfigKind { - configs[config.Name] = &config - continue - } - } - - _ = yaml.Unmarshal(d, &config) // this is to check if there is a bad spec in the file - if config.Kind == NutanixMachineConfigKind { - return nil, fmt.Errorf("unable to unmarshall content from file due to: %v", err) - } - - } - - if len(configs) == 0 { - return nil, fmt.Errorf("unable to find kind %v in file", NutanixMachineConfigKind) - } - return configs, nil -} - func setNutanixMachineConfigDefaults(machineConfig *NutanixMachineConfig) { initUser := UserConfiguration{ Name: DefaultNutanixMachineConfigUser, diff --git a/pkg/api/v1alpha1/nutanixmachineconfig_test.go b/pkg/api/v1alpha1/nutanixmachineconfig_test.go index bfaf14f1b403c..caa45960c75f5 100644 --- a/pkg/api/v1alpha1/nutanixmachineconfig_test.go +++ b/pkg/api/v1alpha1/nutanixmachineconfig_test.go @@ -1,8 +1,7 @@ -package v1alpha1 +package v1alpha1_test import ( "fmt" - "reflect" "testing" "github.com/aws/smithy-go/ptr" @@ -11,76 +10,40 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/yaml" -) -func TestGetNutanixMachineConfigsInvalidConfig(t *testing.T) { - tests := []struct { - name string - fileName string - expectedErr string - }{ - { - name: "non-existent-file", - fileName: "testdata/nutanix/non-existent-file.yaml", - expectedErr: "open testdata/nutanix/non-existent-file.yaml: no such file or directory", - }, - { - name: "invalid-file", - fileName: "testdata/invalid_format.yaml", - expectedErr: "unable to find kind NutanixMachineConfig in file", - }, - { - name: "invalid-cluster-extraneuous-field", - fileName: "testdata/nutanix/invalid-cluster.yaml", - expectedErr: "unknown field \"idont\"", - }, - { - name: "invalid kind", - fileName: "testdata/nutanix/invalid-kind.yaml", - expectedErr: "unable to find kind NutanixMachineConfig in file", - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - conf, err := GetNutanixMachineConfigs(test.fileName) - assert.Error(t, err) - assert.Nil(t, conf) - assert.Contains(t, err.Error(), test.expectedErr, "expected error", test.expectedErr, "got error", err) - }) - } -} + "github.com/aws/eks-anywhere/pkg/api/v1alpha1" + "github.com/aws/eks-anywhere/pkg/cluster" +) func TestGetNutanixMachineConfigsValidConfig(t *testing.T) { - expectedMachineConfig := &NutanixMachineConfig{ + expectedMachineConfig := &v1alpha1.NutanixMachineConfig{ TypeMeta: metav1.TypeMeta{ - Kind: NutanixMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), + Kind: v1alpha1.NutanixMachineConfigKind, + APIVersion: v1alpha1.SchemeBuilder.GroupVersion.String(), }, ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - Annotations: map[string]string{}, - Namespace: defaultEksaNamespace, + Name: "eksa-unit-test", + Namespace: "default", }, - Spec: NutanixMachineConfigSpec{ + Spec: v1alpha1.NutanixMachineConfigSpec{ SystemDiskSize: resource.MustParse("40Gi"), MemorySize: resource.MustParse("8Gi"), VCPUSockets: 4, VCPUsPerSocket: 1, - OSFamily: Ubuntu, - Image: NutanixResourceIdentifier{ - Type: NutanixIdentifierName, + OSFamily: v1alpha1.Ubuntu, + Image: v1alpha1.NutanixResourceIdentifier{ + Type: v1alpha1.NutanixIdentifierName, Name: ptr.String("prism-image"), }, - Cluster: NutanixResourceIdentifier{ - Type: NutanixIdentifierName, + Cluster: v1alpha1.NutanixResourceIdentifier{ + Type: v1alpha1.NutanixIdentifierName, Name: ptr.String("prism-element"), }, - Subnet: NutanixResourceIdentifier{ - Type: NutanixIdentifierName, + Subnet: v1alpha1.NutanixResourceIdentifier{ + Type: v1alpha1.NutanixIdentifierName, Name: ptr.String("prism-subnet"), }, - Users: []UserConfiguration{{ + Users: []v1alpha1.UserConfiguration{{ Name: "mySshUsername", SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, }}, @@ -91,32 +54,16 @@ func TestGetNutanixMachineConfigsValidConfig(t *testing.T) { tests := []struct { name string fileName string - machineConf map[string]*NutanixMachineConfig - assertions func(t *testing.T, machineConf *NutanixMachineConfig) + machineConf map[string]*v1alpha1.NutanixMachineConfig + assertions func(t *testing.T, machineConf *v1alpha1.NutanixMachineConfig) }{ - { - name: "valid-cluster", - fileName: "testdata/nutanix/valid-cluster.yaml", - machineConf: map[string]*NutanixMachineConfig{ - machineConfName: expectedMachineConfig, - }, - assertions: func(t *testing.T, machineConf *NutanixMachineConfig) {}, - }, - { - name: "valid-cluster-extra-delimiter", - fileName: "testdata/nutanix/valid-cluster-extra-delimiter.yaml", - machineConf: map[string]*NutanixMachineConfig{ - machineConfName: expectedMachineConfig, - }, - assertions: func(t *testing.T, machineConf *NutanixMachineConfig) {}, - }, { name: "valid-cluster-setters-getters", fileName: "testdata/nutanix/valid-cluster.yaml", - machineConf: map[string]*NutanixMachineConfig{ + machineConf: map[string]*v1alpha1.NutanixMachineConfig{ machineConfName: expectedMachineConfig, }, - assertions: func(t *testing.T, machineConf *NutanixMachineConfig) { + assertions: func(t *testing.T, machineConf *v1alpha1.NutanixMachineConfig) { assert.False(t, machineConf.IsReconcilePaused()) machineConf.PauseReconcile() assert.True(t, machineConf.IsReconcilePaused()) @@ -134,30 +81,18 @@ func TestGetNutanixMachineConfigsValidConfig(t *testing.T) { machineConf.SetControlPlane() assert.True(t, machineConf.IsControlPlane()) - assert.Equal(t, Ubuntu, machineConf.OSFamily()) - assert.Equal(t, defaultEksaNamespace, machineConf.GetNamespace()) + assert.Equal(t, v1alpha1.Ubuntu, machineConf.OSFamily()) + assert.Equal(t, "default", machineConf.GetNamespace()) assert.Equal(t, machineConfName, machineConf.GetName()) }, }, { name: "valid-cluster-marshal", fileName: "testdata/nutanix/valid-cluster.yaml", - machineConf: map[string]*NutanixMachineConfig{ + machineConf: map[string]*v1alpha1.NutanixMachineConfig{ machineConfName: expectedMachineConfig, }, - assertions: func(t *testing.T, machineConf *NutanixMachineConfig) { - m := machineConf.Marshallable() - require.NotNil(t, m) - y, err := yaml.Marshal(m) - assert.NoError(t, err) - assert.NotNil(t, y) - }, - }, - { - name: "invalid-manifest", - fileName: "testdata/invalid_manifest.yaml", - machineConf: nil, - assertions: func(t *testing.T, machineConf *NutanixMachineConfig) { + assertions: func(t *testing.T, machineConf *v1alpha1.NutanixMachineConfig) { m := machineConf.Marshallable() require.NotNil(t, m) y, err := yaml.Marshal(m) @@ -169,12 +104,17 @@ func TestGetNutanixMachineConfigsValidConfig(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - conf, err := GetNutanixMachineConfigs(test.fileName) + config, err := cluster.ParseConfigFromFile(test.fileName) + if err != nil { + t.Fatal(err) + } + machineConfigs := config.NutanixMachineConfigs + if test.machineConf != nil { require.NoError(t, err) - require.NotNil(t, conf) - assert.True(t, reflect.DeepEqual(test.machineConf, conf)) - test.assertions(t, conf[machineConfName]) + require.NotNil(t, machineConfigs) + assert.Equal(t, test.machineConf, machineConfigs) + test.assertions(t, machineConfigs[machineConfName]) } else { assert.Error(t, err) } @@ -183,13 +123,13 @@ func TestGetNutanixMachineConfigsValidConfig(t *testing.T) { } func TestNewNutanixMachineConfigGenerate(t *testing.T) { - machineConf := NewNutanixMachineConfigGenerate("eksa-unit-test", func(config *NutanixMachineConfigGenerate) { + machineConf := v1alpha1.NewNutanixMachineConfigGenerate("eksa-unit-test", func(config *v1alpha1.NutanixMachineConfigGenerate) { config.Spec.MemorySize = resource.MustParse("16Gi") }) require.NotNil(t, machineConf) assert.Equal(t, "eksa-unit-test", machineConf.Name()) - assert.Equal(t, NutanixMachineConfigKind, machineConf.Kind()) - assert.Equal(t, SchemeBuilder.GroupVersion.String(), machineConf.APIVersion()) + assert.Equal(t, v1alpha1.NutanixMachineConfigKind, machineConf.Kind()) + assert.Equal(t, v1alpha1.SchemeBuilder.GroupVersion.String(), machineConf.APIVersion()) assert.Equal(t, resource.MustParse("16Gi"), machineConf.Spec.MemorySize) } @@ -197,12 +137,12 @@ func TestNutanixMachineConfigDefaults(t *testing.T) { tests := []struct { name string fileName string - validate func(t *testing.T, nutanixMachineConfig *NutanixMachineConfig) error + validate func(t *testing.T, nutanixMachineConfig *v1alpha1.NutanixMachineConfig) error }{ { name: "machineconfig-with-no-users", fileName: "testdata/nutanix/machineconfig-with-no-users.yaml", - validate: func(t *testing.T, nutanixMachineConfig *NutanixMachineConfig) error { + validate: func(t *testing.T, nutanixMachineConfig *v1alpha1.NutanixMachineConfig) error { if len(nutanixMachineConfig.Spec.Users) <= 0 { return fmt.Errorf("default user was not added") } @@ -212,7 +152,7 @@ func TestNutanixMachineConfigDefaults(t *testing.T) { { name: "machineconfig-with-no-user-name", fileName: "testdata/nutanix/machineconfig-with-no-user-name.yaml", - validate: func(t *testing.T, nutanixMachineConfig *NutanixMachineConfig) error { + validate: func(t *testing.T, nutanixMachineConfig *v1alpha1.NutanixMachineConfig) error { if len(nutanixMachineConfig.Spec.Users[0].Name) <= 0 { return fmt.Errorf("default user name was not added") } @@ -222,9 +162,9 @@ func TestNutanixMachineConfigDefaults(t *testing.T) { { name: "machineconfig-with-no-osfamily", fileName: "testdata/nutanix/machineconfig-with-no-osfamily.yaml", - validate: func(t *testing.T, nutanixMachineConfig *NutanixMachineConfig) error { - if nutanixMachineConfig.Spec.OSFamily != defaultNutanixOSFamily { - return fmt.Errorf("ubuntu OS family was not set") + validate: func(t *testing.T, nutanixMachineConfig *v1alpha1.NutanixMachineConfig) error { + if nutanixMachineConfig.Spec.OSFamily != v1alpha1.DefaultOSFamily { + return fmt.Errorf("v1alpha1.Ubuntu OS family was not set") } return nil }, @@ -232,7 +172,7 @@ func TestNutanixMachineConfigDefaults(t *testing.T) { { name: "machineconfig-with-no-ssh-key", fileName: "testdata/nutanix/machineconfig-with-no-ssh-key.yaml", - validate: func(t *testing.T, nutanixMachineConfig *NutanixMachineConfig) error { + validate: func(t *testing.T, nutanixMachineConfig *v1alpha1.NutanixMachineConfig) error { if len(nutanixMachineConfig.Spec.Users[0].SshAuthorizedKeys) <= 0 { return fmt.Errorf("default ssh key was not added") } @@ -246,15 +186,12 @@ func TestNutanixMachineConfigDefaults(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - conf, err := GetNutanixMachineConfigs(test.fileName) + config, err := cluster.ParseConfigFromFile(test.fileName) if err != nil { - t.Fatalf("GetNutanixMachineConfigs returned error") - } - if conf == nil { - t.Fatalf("GetNutanixMachineConfigs returned conf without defaults") + t.Fatal(err) } - - nutanixMachineConfig := conf["eksa-unit-test"] + machineConfigs := config.NutanixMachineConfigs + nutanixMachineConfig := machineConfigs["eksa-unit-test"] if nutanixMachineConfig == nil { t.Fatalf("Invalid yaml found") } @@ -287,15 +224,13 @@ func TestValidateNutanixMachineConfig(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - conf, err := GetNutanixMachineConfigs(test.fileName) + config, err := cluster.ParseConfigFromFile(test.fileName) if err != nil { - t.Fatalf("GetNutanixMachineConfigs returned error") - } - if conf == nil { - t.Fatalf("GetNutanixMachineConfigs returned conf without defaults") + t.Fatal(err) } + machineConfigs := config.NutanixMachineConfigs - nutanixMachineConfig := conf["eksa-unit-test"] + nutanixMachineConfig := machineConfigs["eksa-unit-test"] if nutanixMachineConfig == nil { t.Fatalf("Invalid yaml found") } diff --git a/pkg/api/v1alpha1/nutanixmachineconfig_types.go b/pkg/api/v1alpha1/nutanixmachineconfig_types.go index 6c52713685064..4d272cbe7a494 100644 --- a/pkg/api/v1alpha1/nutanixmachineconfig_types.go +++ b/pkg/api/v1alpha1/nutanixmachineconfig_types.go @@ -66,6 +66,9 @@ func (in *NutanixMachineConfig) SetDefaults() { // PauseReconcile pauses the reconciliation of the NutanixMachineConfig. func (in *NutanixMachineConfig) PauseReconcile() { + if in.Annotations == nil { + in.Annotations = map[string]string{} + } in.Annotations[pausedAnnotation] = "true" } diff --git a/pkg/api/v1alpha1/testdata/cluster_different_machine_configs_cloudstack.yaml b/pkg/api/v1alpha1/testdata/cluster_different_machine_configs_cloudstack.yaml deleted file mode 100644 index a182975d8f2ca..0000000000000 --- a/pkg/api/v1alpha1/testdata/cluster_different_machine_configs_cloudstack.yaml +++ /dev/null @@ -1,85 +0,0 @@ -apiVersion: anywhere.eks.amazonaws.com/v1alpha1 -kind: Cluster -metadata: - name: eksa-unit-test -spec: - clusterNetwork: - cni: cilium - pods: - cidrBlocks: - - 192.168.0.0/16 - services: - cidrBlocks: - - 10.96.0.0/12 - controlPlaneConfiguration: - count: 3 - endpoint: - host: test-ip - machineGroupRef: - kind: CloudStackMachineConfig - name: eksa-unit-test - datacenterRef: - kind: CloudStackDatacenterConfig - name: eksa-unit-test - kubernetesVersion: "1.19" - workerNodeGroupConfigurations: - - count: 3 - machineGroupRef: - kind: CloudStackMachineConfig - name: eksa-unit-test-2 - ---- -apiVersion: anywhere.eks.amazonaws.com/v1alpha1 -kind: CloudStackDatacenterConfig -metadata: - name: eksa-unit-test -spec: - account: "admin" - domain: "domain1" - insecure: false - zones: - - name: "zone1" - network: - name: "net1" - ---- -apiVersion: anywhere.eks.amazonaws.com/v1alpha1 -kind: CloudStackMachineConfig -metadata: - name: eksa-unit-test -spec: - computeOffering: - name: "m4-large" - diskOffering: - name: "Small" - mountPath: "/data-small" - device: /dev/vdb - filesystem: ext4 - label: data_disk - users: - - name: "mySshUsername" - sshAuthorizedKeys: - - "mySshAuthorizedKey" - template: - name: "centos7-k8s-118" - ---- -apiVersion: anywhere.eks.amazonaws.com/v1alpha1 -kind: CloudStackMachineConfig -metadata: - name: eksa-unit-test-2 -spec: - computeOffering: - name: "m5-xlarge" - diskOffering: - name: "Medium" - mountPath: "/data-medium" - device: /dev/vdb - filesystem: ext4 - label: data_disk - users: - - name: "mySshUsername" - sshAuthorizedKeys: - - "mySshAuthorizedKey" - template: - name: "centos7-k8s-118" diff --git a/pkg/api/v1alpha1/testdata/not_parseable_gitopsconfig.yaml b/pkg/api/v1alpha1/testdata/not_parseable_gitopsconfig.yaml index 593ac83014f31..984e14b198d74 100644 --- a/pkg/api/v1alpha1/testdata/not_parseable_gitopsconfig.yaml +++ b/pkg/api/v1alpha1/testdata/not_parseable_gitopsconfig.yaml @@ -12,7 +12,7 @@ spec: kind: VSphereMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: VSphereMachineConfig diff --git a/pkg/api/v1alpha1/testdata/not_parseable_oidcconfig.yaml b/pkg/api/v1alpha1/testdata/not_parseable_oidcconfig.yaml index 337c50bb1d9fb..caa28ebb75519 100644 --- a/pkg/api/v1alpha1/testdata/not_parseable_oidcconfig.yaml +++ b/pkg/api/v1alpha1/testdata/not_parseable_oidcconfig.yaml @@ -12,7 +12,7 @@ spec: kind: VSphereMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: VSphereMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/invalid-cluster.yaml b/pkg/api/v1alpha1/testdata/nutanix/invalid-cluster.yaml index fff54bef7291e..d3f11a59ef4a8 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/invalid-cluster.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/invalid-cluster.yaml @@ -12,7 +12,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/invalid-kind.yaml b/pkg/api/v1alpha1/testdata/nutanix/invalid-kind.yaml index fe49f17477533..91e992a0df0d4 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/invalid-kind.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/invalid-kind.yaml @@ -12,7 +12,7 @@ spec: kind: BadNutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: BadNutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/invalid-machineconfig-addtional-categories-key.yaml b/pkg/api/v1alpha1/testdata/nutanix/invalid-machineconfig-addtional-categories-key.yaml index 70618d21ecc23..0287e75c343a7 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/invalid-machineconfig-addtional-categories-key.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/invalid-machineconfig-addtional-categories-key.yaml @@ -13,7 +13,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/invalid-machineconfig-addtional-categories-value.yaml b/pkg/api/v1alpha1/testdata/nutanix/invalid-machineconfig-addtional-categories-value.yaml index 429cd911da4bd..783d9ef47533a 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/invalid-machineconfig-addtional-categories-value.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/invalid-machineconfig-addtional-categories-value.yaml @@ -13,7 +13,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-osfamily.yaml b/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-osfamily.yaml index 6183a83b4f784..cf6d14b868640 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-osfamily.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-osfamily.yaml @@ -13,7 +13,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-ssh-key.yaml b/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-ssh-key.yaml index 166ebe7fb1fc6..4f69ab9b64190 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-ssh-key.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-ssh-key.yaml @@ -13,7 +13,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-user-name.yaml b/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-user-name.yaml index a5e6f1a643a83..6b360e0ce036a 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-user-name.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-user-name.yaml @@ -13,7 +13,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-users.yaml b/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-users.yaml index ba01a3fd7067c..722f1b989b559 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-users.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/machineconfig-with-no-users.yaml @@ -13,7 +13,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/valid-cluster-extra-delimiter.yaml b/pkg/api/v1alpha1/testdata/nutanix/valid-cluster-extra-delimiter.yaml index 24991738a55bd..249df46391033 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/valid-cluster-extra-delimiter.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/valid-cluster-extra-delimiter.yaml @@ -13,7 +13,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/nutanix/valid-cluster.yaml b/pkg/api/v1alpha1/testdata/nutanix/valid-cluster.yaml index 25d13d16b6b23..7fa97c6b80b5a 100644 --- a/pkg/api/v1alpha1/testdata/nutanix/valid-cluster.yaml +++ b/pkg/api/v1alpha1/testdata/nutanix/valid-cluster.yaml @@ -13,7 +13,7 @@ spec: kind: NutanixMachineConfig kubernetesVersion: "1.16" workerNodeGroupConfigurations: - - count: four + - count: 4 machineGroupRef: name: eksa-unit-test kind: NutanixMachineConfig diff --git a/pkg/api/v1alpha1/testdata/tinkerbell_cluster_with_duplicate_mchine_config_fields.yaml b/pkg/api/v1alpha1/testdata/tinkerbell_cluster_with_duplicate_mchine_config_fields.yaml deleted file mode 100644 index 357d6dc4e596b..0000000000000 --- a/pkg/api/v1alpha1/testdata/tinkerbell_cluster_with_duplicate_mchine_config_fields.yaml +++ /dev/null @@ -1,45 +0,0 @@ -apiVersion: anywhere.eks.amazonaws.com/v1alpha1 -kind: Cluster -metadata: - name: single-node -spec: - clusterNetwork: - cniConfig: - cilium: {} - pods: - cidrBlocks: - - 192.168.0.0/16 - services: - cidrBlocks: - - 10.96.0.0/12 - controlPlaneConfiguration: - count: 1 - endpoint: - host: "10.80.8.90" - machineGroupRef: - kind: TinkerbellMachineConfig - name: single-node-cp - datacenterRef: - kind: TinkerbellDatacenterConfig - name: single-node - kubernetesVersion: "1.23" - managementCluster: - name: single-node ---- -apiVersion: anywhere.eks.amazonaws.com/v1alpha1 -kind: TinkerbellDatacenterConfig -metadata: - name: single-node -spec: - tinkerbellIP: "10.80.8.91" ---- -apiVersion: anywhere.eks.amazonaws.com/v1alpha1 -kind: TinkerbellMachineConfig -metadata: - name: single-node-cp - name: another-cp -spec: - hardwareSelector: - type: cp - osFamily: bottlerocket - templateRef: {} \ No newline at end of file diff --git a/pkg/api/v1alpha1/tinkerbellmachineconfig.go b/pkg/api/v1alpha1/tinkerbellmachineconfig.go index a1da47f0f3120..20cd5a56e4e3a 100644 --- a/pkg/api/v1alpha1/tinkerbellmachineconfig.go +++ b/pkg/api/v1alpha1/tinkerbellmachineconfig.go @@ -4,11 +4,6 @@ import ( "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - apimachineryyaml "k8s.io/apimachinery/pkg/util/yaml" - "sigs.k8s.io/yaml" - - "github.com/aws/eks-anywhere/pkg/utils/file" - yamlutil "github.com/aws/eks-anywhere/pkg/utils/yaml" ) const TinkerbellMachineConfigKind = "TinkerbellMachineConfig" @@ -57,41 +52,6 @@ func (c *TinkerbellMachineConfigGenerate) Name() string { return c.ObjectMeta.Name } -func GetTinkerbellMachineConfigs(fileName string) (map[string]*TinkerbellMachineConfig, error) { - configs := make(map[string]*TinkerbellMachineConfig) - - r, err := file.ReadFile(fileName) - if err != nil { - return nil, err - } - - resources, err := yamlutil.SplitDocuments(r) - if err != nil { - return nil, err - } - - for _, d := range resources { - var config TinkerbellMachineConfig - var strictUnmarshallErr error - if strictUnmarshallErr = apimachineryyaml.UnmarshalStrict(d, &config); strictUnmarshallErr == nil { - if config.Kind == TinkerbellMachineConfigKind { - configs[config.Name] = &config - continue - } - } - - _ = yaml.Unmarshal(d, &config) - if config.Kind == TinkerbellMachineConfigKind && strictUnmarshallErr != nil { - return nil, fmt.Errorf("unable to unmarshall content from file due to: %v", strictUnmarshallErr) - } - } - - if len(configs) == 0 { - return nil, fmt.Errorf("unable to find kind %v in file", TinkerbellMachineConfigKind) - } - return configs, nil -} - func WithTemplateRef(ref ProviderRefAccessor) TinkerbellMachineConfigGenerateOpt { return func(c *TinkerbellMachineConfigGenerate) { c.Spec.TemplateRef = Ref{ diff --git a/pkg/api/v1alpha1/tinkerbellmachineconfig_test.go b/pkg/api/v1alpha1/tinkerbellmachineconfig_test.go deleted file mode 100644 index a6fb0267af487..0000000000000 --- a/pkg/api/v1alpha1/tinkerbellmachineconfig_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package v1alpha1_test - -import ( - "errors" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/aws/eks-anywhere/pkg/api/v1alpha1" -) - -// MockReaderWithError is a mock implementation of the Reader interface that returns an error. -type MockReaderWithError struct{} - -// Read returns an error. -func (m *MockReaderWithError) Read() ([]byte, error) { - return nil, errors.New("custom error") -} - -func TestGetTinkerbellMachineConfigs(t *testing.T) { - tests := []struct { - name string - fileName string - expectedError error - }{ - { - name: "non-splitable manifest", - fileName: "testdata/invalid_manifest.yaml", - expectedError: errors.New("invalid Yaml document separator: \\nkey: value\\ninvalid_separator\\n"), - }, - { - name: "non existent file", - fileName: "testdata/non_existent_file.yaml", - expectedError: errors.New("unable to read file due to: open testdata/non_existent_file.yaml: no such file or directory"), - }, - { - name: "non existent file", - fileName: "testdata/cluster_vsphere.yaml", - expectedError: errors.New("unable to find kind TinkerbellMachineConfig in file"), - }, - { - name: "duplicate fields in machine config", - fileName: "testdata/tinkerbell_cluster_with_duplicate_mchine_config_fields.yaml", - expectedError: errors.New("unable to unmarshall content from file due to: error converting YAML to JSON: yaml: unmarshal errors:\n line 5: key \"name\" already set in map"), - }, - { - name: "valid tinkerbell manifest", - fileName: "testdata/tinkerbell_cluster_without_worker_nodes.yaml", - expectedError: nil, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - configs, err := v1alpha1.GetTinkerbellMachineConfigs(test.fileName) - - if test.expectedError != nil { - assert.Equal(t, test.expectedError.Error(), err.Error()) - } else { - require.NoError(t, err) - assert.True(t, len(configs) > 0) - } - }) - } -} diff --git a/pkg/api/v1alpha1/vspheremachineconfig.go b/pkg/api/v1alpha1/vspheremachineconfig.go index d9d05d0fb5b12..55125f6ba8ec2 100644 --- a/pkg/api/v1alpha1/vspheremachineconfig.go +++ b/pkg/api/v1alpha1/vspheremachineconfig.go @@ -4,11 +4,8 @@ import ( "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/yaml" "github.com/aws/eks-anywhere/pkg/logger" - "github.com/aws/eks-anywhere/pkg/utils/file" - yamlutil "github.com/aws/eks-anywhere/pkg/utils/yaml" ) const ( @@ -54,41 +51,6 @@ func (c *VSphereMachineConfigGenerate) Name() string { return c.ObjectMeta.Name } -func GetVSphereMachineConfigs(fileName string) (map[string]*VSphereMachineConfig, error) { - configs := make(map[string]*VSphereMachineConfig) - - r, err := file.ReadFile(fileName) - if err != nil { - return nil, err - } - - resources, err := yamlutil.SplitDocuments(r) - if err != nil { - return nil, err - } - - for _, d := range resources { - var config VSphereMachineConfig - - if err = yaml.UnmarshalStrict(d, &config); err == nil { - if config.Kind == VSphereMachineConfigKind { - configs[config.Name] = &config - continue - } - } - - _ = yaml.Unmarshal(d, &config) // this is to check if there is a bad spec in the file - if config.Kind == VSphereMachineConfigKind { - return nil, fmt.Errorf("unable to unmarshall content from file due to: %v", err) - } - } - - if len(configs) == 0 { - return nil, fmt.Errorf("unable to find kind %v in file", VSphereMachineConfigKind) - } - return configs, nil -} - func setVSphereMachineConfigDefaults(machineConfig *VSphereMachineConfig) { if len(machineConfig.Spec.Folder) <= 0 { logger.Info("VSphereMachineConfig Folder is not set or is empty. Defaulting to root vSphere folder.") diff --git a/pkg/api/v1alpha1/vspheremachineconfig_test.go b/pkg/api/v1alpha1/vspheremachineconfig_test.go index 72b847f17691f..217a95507bc8c 100644 --- a/pkg/api/v1alpha1/vspheremachineconfig_test.go +++ b/pkg/api/v1alpha1/vspheremachineconfig_test.go @@ -1,237 +1,12 @@ package v1alpha1 import ( - "reflect" "testing" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func TestGetVSphereMachineConfigs(t *testing.T) { - tests := []struct { - testName string - fileName string - wantVSphereMachineConfigs map[string]*VSphereMachineConfig - wantErr bool - }{ - { - testName: "file doesn't exist", - fileName: "testdata/fake_file.yaml", - wantVSphereMachineConfigs: nil, - wantErr: true, - }, - { - testName: "non-splitable manifest", - fileName: "testdata/invalid_manifest.yaml", - wantVSphereMachineConfigs: nil, - wantErr: true, - }, - { - testName: "not parseable file", - fileName: "testdata/not_parseable_cluster.yaml", - wantVSphereMachineConfigs: nil, - wantErr: true, - }, - { - testName: "valid 1.18", - fileName: "testdata/cluster_1_18.yaml", - wantVSphereMachineConfigs: map[string]*VSphereMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: VSphereMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: VSphereMachineConfigSpec{ - DiskGiB: 25, - MemoryMiB: 8192, - NumCPUs: 2, - OSFamily: Ubuntu, - Template: "myTemplate", - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - Datastore: "myDatastore", - Folder: "myFolder", - ResourcePool: "myResourcePool", - StoragePolicyName: "myStoragePolicyName", - }, - }, - }, - wantErr: false, - }, - { - testName: "valid 1.19", - fileName: "testdata/cluster_1_19.yaml", - wantVSphereMachineConfigs: map[string]*VSphereMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: VSphereMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: VSphereMachineConfigSpec{ - DiskGiB: 25, - MemoryMiB: 8192, - NumCPUs: 2, - OSFamily: Ubuntu, - Template: "myTemplate", - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - Datastore: "myDatastore", - Folder: "myFolder", - ResourcePool: "myResourcePool", - StoragePolicyName: "myStoragePolicyName", - }, - }, - }, - wantErr: false, - }, - { - testName: "valid with extra delimiters", - fileName: "testdata/cluster_extra_delimiters.yaml", - wantVSphereMachineConfigs: map[string]*VSphereMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: VSphereMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: VSphereMachineConfigSpec{ - DiskGiB: 25, - MemoryMiB: 8192, - NumCPUs: 2, - OSFamily: Ubuntu, - Template: "myTemplate", - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - Datastore: "myDatastore", - Folder: "myFolder", - ResourcePool: "myResourcePool", - StoragePolicyName: "myStoragePolicyName", - }, - }, - }, - wantErr: false, - }, - { - testName: "valid 1.20", - fileName: "testdata/cluster_1_20.yaml", - wantVSphereMachineConfigs: map[string]*VSphereMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: VSphereMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: VSphereMachineConfigSpec{ - DiskGiB: 25, - MemoryMiB: 8192, - NumCPUs: 2, - OSFamily: Ubuntu, - Template: "myTemplate", - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - Datastore: "myDatastore", - Folder: "myFolder", - ResourcePool: "myResourcePool", - StoragePolicyName: "myStoragePolicyName", - }, - }, - }, - wantErr: false, - }, - { - testName: "valid different machine configs", - fileName: "testdata/cluster_different_machine_configs.yaml", - wantVSphereMachineConfigs: map[string]*VSphereMachineConfig{ - "eksa-unit-test": { - TypeMeta: metav1.TypeMeta{ - Kind: VSphereMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test", - }, - Spec: VSphereMachineConfigSpec{ - DiskGiB: 25, - MemoryMiB: 8192, - NumCPUs: 2, - OSFamily: Ubuntu, - Template: "myTemplate", - Users: []UserConfiguration{{ - Name: "mySshUsername", - SshAuthorizedKeys: []string{"mySshAuthorizedKey"}, - }}, - Datastore: "myDatastore", - Folder: "myFolder", - ResourcePool: "myResourcePool", - StoragePolicyName: "myStoragePolicyName", - }, - }, - "eksa-unit-test-2": { - TypeMeta: metav1.TypeMeta{ - Kind: VSphereMachineConfigKind, - APIVersion: SchemeBuilder.GroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "eksa-unit-test-2", - }, - Spec: VSphereMachineConfigSpec{ - DiskGiB: 20, - MemoryMiB: 2048, - NumCPUs: 4, - OSFamily: Bottlerocket, - Template: "myTemplate2", - Users: []UserConfiguration{{ - Name: "mySshUsername2", - SshAuthorizedKeys: []string{"mySshAuthorizedKey2"}, - }}, - Datastore: "myDatastore2", - Folder: "myFolder2", - ResourcePool: "myResourcePool2", - StoragePolicyName: "myStoragePolicyName2", - }, - }, - }, - wantErr: false, - }, - { - testName: "invalid kind", - fileName: "testdata/cluster_invalid_kinds.yaml", - wantVSphereMachineConfigs: nil, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.testName, func(t *testing.T) { - got, err := GetVSphereMachineConfigs(tt.fileName) - if (err != nil) != tt.wantErr { - t.Fatalf("GetVSphereMachineConfigs() error = %v, wantErr %v", err, tt.wantErr) - } - if !reflect.DeepEqual(got, tt.wantVSphereMachineConfigs) { - t.Fatalf("GetVSphereMachineConfigs() = %#v, want %#v", got, tt.wantVSphereMachineConfigs) - } - }) - } -} - func TestVSphereMachineConfigValidate(t *testing.T) { tests := []struct { name string diff --git a/pkg/dependencies/factory.go b/pkg/dependencies/factory.go index 46d43aaef92cd..bf27a7485ce62 100644 --- a/pkg/dependencies/factory.go +++ b/pkg/dependencies/factory.go @@ -455,11 +455,12 @@ func (f *Factory) WithProvider(clusterConfigFile string, clusterConfig *v1alpha1 return fmt.Errorf("unable to get datacenter config from file %s: %v", clusterConfigFile, err) } - machineConfigs, err := v1alpha1.GetTinkerbellMachineConfigs(clusterConfigFile) + config, err := cluster.ParseConfigFromFile(clusterConfigFile) if err != nil { - return fmt.Errorf("unable to get machine config from file %s: %v", clusterConfigFile, err) + return err } + machineConfigs := config.TinkerbellMachineConfigs tinkerbellIP := tinkerbellBootstrapIP if tinkerbellIP == "" { logger.V(4).Info("Inferring local Tinkerbell Bootstrap IP from environment") @@ -509,11 +510,12 @@ func (f *Factory) WithProvider(clusterConfigFile string, clusterConfig *v1alpha1 return fmt.Errorf("unable to get datacenter config from file %s: %v", clusterConfigFile, err) } - machineConfigs, err := v1alpha1.GetNutanixMachineConfigs(clusterConfigFile) + config, err := cluster.ParseConfigFromFile(clusterConfigFile) if err != nil { - return fmt.Errorf("unable to get machine config from file %s: %v", clusterConfigFile, err) + return err } + machineConfigs := config.NutanixMachineConfigs skipVerifyTransport := http.DefaultTransport.(*http.Transport).Clone() skipVerifyTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} httpClient := &http.Client{Transport: skipVerifyTransport} diff --git a/pkg/providers/cloudstack/cloudstack_test.go b/pkg/providers/cloudstack/cloudstack_test.go index 0b1f5da9aee82..39027664d8a25 100644 --- a/pkg/providers/cloudstack/cloudstack_test.go +++ b/pkg/providers/cloudstack/cloudstack_test.go @@ -96,11 +96,12 @@ func givenDatacenterConfig(t *testing.T, fileName string) *v1alpha1.CloudStackDa } func givenMachineConfigs(t *testing.T, fileName string) map[string]*v1alpha1.CloudStackMachineConfig { - machineConfigs, err := v1alpha1.GetCloudStackMachineConfigs(path.Join(testDataDir, fileName)) + config, err := cluster.ParseConfigFromFile(path.Join(testDataDir, fileName)) if err != nil { t.Fatalf("unable to get machine configs from file: %v", err) } - return machineConfigs + + return config.CloudStackMachineConfigs } func givenProvider(t *testing.T) *cloudstackProvider { @@ -747,9 +748,9 @@ func TestSetupAndValidateCreateWorkloadClusterSuccess(t *testing.T) { provider.validator = givenWildcardValidator(mockCtrl, clusterSpec) for _, config := range newMachineConfigs { - kubectl.EXPECT().SearchCloudStackMachineConfig(context.TODO(), config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.CloudStackMachineConfig{}, nil) + kubectl.EXPECT().SearchCloudStackMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.CloudStackMachineConfig{}, nil) } - kubectl.EXPECT().SearchCloudStackDatacenterConfig(context.TODO(), datacenterConfig.Name, clusterSpec.ManagementCluster.KubeconfigFile, clusterSpec.Cluster.Namespace).Return([]*v1alpha1.CloudStackDatacenterConfig{}, nil) + kubectl.EXPECT().SearchCloudStackDatacenterConfig(ctx, datacenterConfig.Name, clusterSpec.ManagementCluster.KubeconfigFile, clusterSpec.Cluster.Namespace).Return([]*v1alpha1.CloudStackDatacenterConfig{}, nil) err := provider.SetupAndValidateCreateCluster(ctx, clusterSpec) if err != nil { @@ -783,10 +784,10 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfMachineExists(t *testing.T) var existingMachine string for _, config := range newMachineConfigs { if idx == 0 { - kubectl.EXPECT().SearchCloudStackMachineConfig(context.TODO(), config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.CloudStackMachineConfig{config}, nil) + kubectl.EXPECT().SearchCloudStackMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.CloudStackMachineConfig{config}, nil) existingMachine = config.Name } else { - kubectl.EXPECT().SearchCloudStackMachineConfig(context.TODO(), config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.CloudStackMachineConfig{}, nil).MaxTimes(1) + kubectl.EXPECT().SearchCloudStackMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.CloudStackMachineConfig{}, nil).MaxTimes(1) } idx++ } @@ -843,9 +844,9 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfDatacenterExists(t *testing provider.validator = givenWildcardValidator(mockCtrl, clusterSpec) for _, config := range newMachineConfigs { - kubectl.EXPECT().SearchCloudStackMachineConfig(context.TODO(), config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.CloudStackMachineConfig{}, nil) + kubectl.EXPECT().SearchCloudStackMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.CloudStackMachineConfig{}, nil) } - kubectl.EXPECT().SearchCloudStackDatacenterConfig(context.TODO(), datacenterConfig.Name, clusterSpec.ManagementCluster.KubeconfigFile, clusterSpec.Cluster.Namespace).Return([]*v1alpha1.CloudStackDatacenterConfig{datacenterConfig}, nil) + kubectl.EXPECT().SearchCloudStackDatacenterConfig(ctx, datacenterConfig.Name, clusterSpec.ManagementCluster.KubeconfigFile, clusterSpec.Cluster.Namespace).Return([]*v1alpha1.CloudStackDatacenterConfig{datacenterConfig}, nil) err := provider.SetupAndValidateCreateCluster(ctx, clusterSpec) diff --git a/pkg/providers/cloudstack/validator_test.go b/pkg/providers/cloudstack/validator_test.go index ea077b9028443..f122199fceda0 100644 --- a/pkg/providers/cloudstack/validator_test.go +++ b/pkg/providers/cloudstack/validator_test.go @@ -15,6 +15,7 @@ import ( "github.com/aws/eks-anywhere/internal/test" "github.com/aws/eks-anywhere/pkg/api/v1alpha1" + "github.com/aws/eks-anywhere/pkg/cluster" "github.com/aws/eks-anywhere/pkg/providers/cloudstack/decoder" "github.com/aws/eks-anywhere/pkg/providers/cloudstack/mocks" "github.com/aws/eks-anywhere/pkg/types" @@ -275,7 +276,11 @@ func TestValidateMachineConfigsHappyCase(t *testing.T) { func TestValidateCloudStackMachineConfig(t *testing.T) { ctx := context.Background() cmk := mocks.NewMockProviderCmkClient(gomock.NewController(t)) - machineConfigs, err := v1alpha1.GetCloudStackMachineConfigs(path.Join(testDataDir, testClusterConfigMainFilename)) + config, err := cluster.ParseConfigFromFile(path.Join(testDataDir, testClusterConfigMainFilename)) + if err != nil { + t.Fatalf("unable to get machine configs from file: %v", err) + } + machineConfigs := config.CloudStackMachineConfigs if err != nil { t.Fatalf("unable to get machine configs from file %s", testClusterConfigMainFilename) } diff --git a/pkg/providers/tinkerbell/tinkerbell_test.go b/pkg/providers/tinkerbell/tinkerbell_test.go index 0107d17c8825b..78858c7bc107c 100644 --- a/pkg/providers/tinkerbell/tinkerbell_test.go +++ b/pkg/providers/tinkerbell/tinkerbell_test.go @@ -46,11 +46,12 @@ func givenDatacenterConfig(t *testing.T, fileName string) *v1alpha1.TinkerbellDa } func givenMachineConfigs(t *testing.T, fileName string) map[string]*v1alpha1.TinkerbellMachineConfig { - machineConfigs, err := v1alpha1.GetTinkerbellMachineConfigs(path.Join(testDataDir, fileName)) + config, err := cluster.ParseConfigFromFile(path.Join(testDataDir, fileName)) if err != nil { t.Fatalf("unable to get machine configs from file: %v", err) } - return machineConfigs + + return config.TinkerbellMachineConfigs } func assertError(t *testing.T, expected string, err error) { diff --git a/pkg/providers/vsphere/vsphere_test.go b/pkg/providers/vsphere/vsphere_test.go index 0fb19b950b126..2d0488e2b5e09 100644 --- a/pkg/providers/vsphere/vsphere_test.go +++ b/pkg/providers/vsphere/vsphere_test.go @@ -1573,9 +1573,9 @@ func TestSetupAndValidateCreateWorkloadClusterSuccess(t *testing.T) { ExistingManagement: true, } for _, config := range clusterSpec.VSphereMachineConfigs { - kubectl.EXPECT().SearchVsphereMachineConfig(context.TODO(), config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{}, nil) + kubectl.EXPECT().SearchVsphereMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{}, nil) } - kubectl.EXPECT().SearchVsphereDatacenterConfig(context.TODO(), datacenterConfig.Name, clusterSpec.ManagementCluster.KubeconfigFile, clusterSpec.Cluster.Namespace).Return([]*v1alpha1.VSphereDatacenterConfig{}, nil) + kubectl.EXPECT().SearchVsphereDatacenterConfig(ctx, datacenterConfig.Name, clusterSpec.ManagementCluster.KubeconfigFile, clusterSpec.Cluster.Namespace).Return([]*v1alpha1.VSphereDatacenterConfig{}, nil) ipValidator.EXPECT().ValidateControlPlaneIPUniqueness(clusterSpec.Cluster).Return(nil) err := provider.SetupAndValidateCreateCluster(ctx, clusterSpec) @@ -1608,10 +1608,10 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfMachineExists(t *testing.T) var existingMachine string for _, config := range clusterSpec.VSphereMachineConfigs { if idx == 0 { - kubectl.EXPECT().SearchVsphereMachineConfig(context.TODO(), config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{config}, nil) + kubectl.EXPECT().SearchVsphereMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{config}, nil) existingMachine = config.Name } else { - kubectl.EXPECT().SearchVsphereMachineConfig(context.TODO(), config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{}, nil).MaxTimes(1) + kubectl.EXPECT().SearchVsphereMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{}, nil).MaxTimes(1) } idx++ } @@ -1671,9 +1671,9 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfDatacenterExists(t *testing } for _, config := range clusterSpec.VSphereMachineConfigs { - kubectl.EXPECT().SearchVsphereMachineConfig(context.TODO(), config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{}, nil) + kubectl.EXPECT().SearchVsphereMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{}, nil) } - kubectl.EXPECT().SearchVsphereDatacenterConfig(context.TODO(), datacenterConfig.Name, clusterSpec.ManagementCluster.KubeconfigFile, clusterSpec.Cluster.Namespace).Return([]*v1alpha1.VSphereDatacenterConfig{datacenterConfig}, nil) + kubectl.EXPECT().SearchVsphereDatacenterConfig(ctx, datacenterConfig.Name, clusterSpec.ManagementCluster.KubeconfigFile, clusterSpec.Cluster.Namespace).Return([]*v1alpha1.VSphereDatacenterConfig{datacenterConfig}, nil) err := provider.SetupAndValidateCreateCluster(ctx, clusterSpec) @@ -1698,8 +1698,8 @@ func TestSetupAndValidateSelfManagedClusterSkipDatacenterNameValidateSuccess(t * ExistingManagement: true, } - kubectl.EXPECT().SearchVsphereMachineConfig(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) - kubectl.EXPECT().SearchVsphereDatacenterConfig(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) + kubectl.EXPECT().SearchVsphereMachineConfig(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(0) + kubectl.EXPECT().SearchVsphereDatacenterConfig(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(0) ipValidator.EXPECT().ValidateControlPlaneIPUniqueness(clusterSpec.Cluster).Return(nil) err := provider.SetupAndValidateCreateCluster(ctx, clusterSpec) diff --git a/pkg/validations/upgradevalidations/preflightvalidations_test.go b/pkg/validations/upgradevalidations/preflightvalidations_test.go index 1bc99bb7d3340..e8bb033319d44 100644 --- a/pkg/validations/upgradevalidations/preflightvalidations_test.go +++ b/pkg/validations/upgradevalidations/preflightvalidations_test.go @@ -399,11 +399,12 @@ func TestPreflightValidationsTinkerbell(t *testing.T) { } func givenTinkerbellMachineConfigs(t *testing.T) map[string]*anywherev1.TinkerbellMachineConfig { - machineConfigs, err := anywherev1.GetTinkerbellMachineConfigs("./testdata/tinkerbell_clusterconfig.yaml") + config, err := cluster.ParseConfigFromFile("./testdata/tinkerbell_clusterconfig.yaml") if err != nil { t.Fatalf("unable to get machine configs from file: %v", err) } - return machineConfigs + + return config.TinkerbellMachineConfigs } func newProvider(datacenterConfig anywherev1.TinkerbellDatacenterConfig, machineConfigs map[string]*anywherev1.TinkerbellMachineConfig, clusterConfig *anywherev1.Cluster, writer filewriter.FileWriter, docker stack.Docker, helm stack.Helm, kubectl tinkerbell.ProviderKubectlClient, forceCleanup bool) *tinkerbell.Provider { diff --git a/test/framework/flux.go b/test/framework/flux.go index 13806e0bbee10..7e9d997f5c1f9 100644 --- a/test/framework/flux.go +++ b/test/framework/flux.go @@ -536,11 +536,13 @@ func (e *ClusterE2ETest) validateWorkerNodeMultiConfigUpdates(ctx context.Contex if err != nil { return err } - // update workernode specs - vsphereMachineConfigs, err := v1alpha1.GetVSphereMachineConfigs(clusterConfGitPath) + config, err := cluster.ParseConfigFromFile(clusterConfGitPath) if err != nil { return err } + vsphereMachineConfigs := config.VSphereMachineConfigs + + // update workernode specs cpName := e.ClusterConfig.Cluster.Spec.ControlPlaneConfiguration.MachineGroupRef.Name workerName := e.ClusterConfig.Cluster.Spec.WorkerNodeGroupConfigurations[0].MachineGroupRef.Name etcdName := "" @@ -770,6 +772,11 @@ func (e *ClusterE2ETest) updateWorkerNodeCountValue(ctx context.Context, newValu } func (e *ClusterE2ETest) providerConfig(clusterConfGitPath string) (*providerConfig, error) { + config, err := cluster.ParseConfigFromFile(clusterConfGitPath) + if err != nil { + return nil, err + } + var providerConfig providerConfig switch e.ClusterConfig.Cluster.Spec.DatacenterRef.Kind { case v1alpha1.VSphereDatacenterKind: @@ -777,10 +784,7 @@ func (e *ClusterE2ETest) providerConfig(clusterConfGitPath string) (*providerCon if err != nil { return nil, err } - machineConfigs, err := v1alpha1.GetVSphereMachineConfigs(clusterConfGitPath) - if err != nil { - return nil, err - } + machineConfigs := config.VSphereMachineConfigs providerConfig.datacenterConfig = datacenterConfig etcdName := "" if e.ClusterConfig.Cluster.Spec.ExternalEtcdConfiguration != nil { @@ -803,10 +807,7 @@ func (e *ClusterE2ETest) providerConfig(clusterConfGitPath string) (*providerCon return nil, err } providerConfig.datacenterConfig = datacenterConfig - machineConfigs, err := v1alpha1.GetCloudStackMachineConfigs(clusterConfGitPath) - if err != nil { - return nil, err - } + machineConfigs := config.CloudStackMachineConfigs etcdName := "" if e.ClusterConfig.Cluster.Spec.ExternalEtcdConfiguration != nil { etcdName = e.ClusterConfig.Cluster.Spec.ExternalEtcdConfiguration.MachineGroupRef.Name @@ -835,6 +836,11 @@ func (e *ClusterE2ETest) waitForWorkerNodeValidation() error { } func (e *ClusterE2ETest) validateWorkerNodeMachineSpec(ctx context.Context, clusterConfGitPath string) error { + config, err := cluster.ParseConfigFromFile(clusterConfGitPath) + if err != nil { + return err + } + switch e.ClusterConfig.Cluster.Spec.DatacenterRef.Kind { case v1alpha1.VSphereDatacenterKind: clusterConfig, err := v1alpha1.GetClusterConfig(clusterConfGitPath) @@ -845,10 +851,7 @@ func (e *ClusterE2ETest) validateWorkerNodeMachineSpec(ctx context.Context, clus if err != nil { return err } - vsphereMachineConfigs, err := v1alpha1.GetVSphereMachineConfigs(clusterConfGitPath) - if err != nil { - return err - } + vsphereMachineConfigs := config.VSphereMachineConfigs vsphereWorkerConfig := vsphereMachineConfigs[clusterConfig.Spec.WorkerNodeGroupConfigurations[0].MachineGroupRef.Name] return retrier.Retry(120, time.Second*10, func() error { vsMachineTemplate, err := e.KubectlClient.VsphereWorkerNodesMachineTemplate(ctx, clusterConfig.Name, e.managementKubeconfigFilePath(), constants.EksaSystemNamespace) @@ -918,10 +921,7 @@ func (e *ClusterE2ETest) validateWorkerNodeMachineSpec(ctx context.Context, clus if err != nil { return err } - cloudstackMachineConfigs, err := v1alpha1.GetCloudStackMachineConfigs(clusterConfGitPath) - if err != nil { - return err - } + cloudstackMachineConfigs := config.CloudStackMachineConfigs cloudstackWorkerConfig := cloudstackMachineConfigs[clusterConfig.Spec.WorkerNodeGroupConfigurations[0].MachineGroupRef.Name] return retrier.Retry(120, time.Second*10, func() error { csMachineTemplate, err := e.KubectlClient.CloudstackWorkerNodesMachineTemplate(ctx, clusterConfig.Name, e.managementKubeconfigFilePath(), constants.EksaSystemNamespace)