@@ -3,11 +3,13 @@ package cmdutils
3
3
import (
4
4
"path/filepath"
5
5
6
+ "github.com/aws/aws-sdk-go-v2/aws"
6
7
. "github.com/onsi/ginkgo/v2"
7
8
. "github.com/onsi/gomega"
8
9
"github.com/spf13/cobra"
9
10
"github.com/spf13/pflag"
10
11
12
+ clusterutils "github.com/weaveworks/eksctl/integration/utilities/cluster"
11
13
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
12
14
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils/filter"
13
15
)
@@ -471,6 +473,123 @@ var _ = Describe("cmdutils configfile", func() {
471
473
testClusterEndpointAccessDefaults ("test_data/cluster-with-vpc-private-access.yaml" , true , true )
472
474
})
473
475
})
476
+
477
+ type bareClusterEntry struct {
478
+ updateClusterConfig func (* api.ClusterConfig )
479
+ expectErr bool
480
+ }
481
+
482
+ DescribeTable ("Bare Cluster validation" , func (e bareClusterEntry ) {
483
+ cmd := & Cmd {
484
+ CobraCommand : newCmd (),
485
+ ClusterConfigFile : "-" ,
486
+ ClusterConfig : api .NewClusterConfig (),
487
+ ProviderConfig : api.ProviderConfig {},
488
+ }
489
+ clusterConfig := api .NewClusterConfig ()
490
+ clusterConfig .Metadata .Name = "cluster"
491
+ clusterConfig .Metadata .Region = api .DefaultRegion
492
+ clusterConfig .AddonsConfig .DisableDefaultAddons = true
493
+ clusterConfig .Addons = []* api.Addon {
494
+ {
495
+ Name : api .CoreDNSAddon ,
496
+ },
497
+ }
498
+ e .updateClusterConfig (clusterConfig )
499
+ err := NewCreateClusterLoader (cmd , filter .NewNodeGroupFilter (), nil , & CreateClusterCmdParams {
500
+ ConfigReader : clusterutils .Reader (clusterConfig ),
501
+ }).Load ()
502
+ if e .expectErr {
503
+ Expect (err ).To (MatchError ("fields nodeGroups, managedNodeGroups, fargateProfiles, karpenter, gitops, iam.serviceAccounts, " +
504
+ "and iam.podIdentityAssociations are not supported during cluster creation in a cluster without VPC CNI; please remove these fields " +
505
+ "and add them back after cluster creation is successful" ))
506
+ } else {
507
+ Expect (err ).NotTo (HaveOccurred ())
508
+ }
509
+ },
510
+ Entry ("nodeGroups" , bareClusterEntry {
511
+ updateClusterConfig : func (c * api.ClusterConfig ) {
512
+ ng := api .NewNodeGroup ()
513
+ ng .Name = "ng"
514
+ ng .DesiredCapacity = aws .Int (1 )
515
+ c .NodeGroups = []* api.NodeGroup {ng }
516
+ },
517
+ expectErr : true ,
518
+ }),
519
+ Entry ("managedNodeGroups" , bareClusterEntry {
520
+ updateClusterConfig : func (c * api.ClusterConfig ) {
521
+ ng := api .NewManagedNodeGroup ()
522
+ ng .Name = "mng"
523
+ ng .DesiredCapacity = aws .Int (1 )
524
+ c .ManagedNodeGroups = []* api.ManagedNodeGroup {ng }
525
+ },
526
+ expectErr : true ,
527
+ }),
528
+ Entry ("fargateProfiles" , bareClusterEntry {
529
+ updateClusterConfig : func (c * api.ClusterConfig ) {
530
+ c .FargateProfiles = []* api.FargateProfile {
531
+ {
532
+ Name : "test" ,
533
+ Selectors : []api.FargateProfileSelector {
534
+ {
535
+ Namespace : "default" ,
536
+ },
537
+ },
538
+ },
539
+ }
540
+ },
541
+ expectErr : true ,
542
+ }),
543
+ Entry ("gitops" , bareClusterEntry {
544
+ updateClusterConfig : func (c * api.ClusterConfig ) {
545
+ c .GitOps = & api.GitOps {
546
+ Flux : & api.Flux {
547
+ GitProvider : "github" ,
548
+ Flags : api.FluxFlags {
549
+ "owner" : "aws" ,
550
+ },
551
+ },
552
+ }
553
+ },
554
+ expectErr : true ,
555
+ }),
556
+ Entry ("karpenter" , bareClusterEntry {
557
+ updateClusterConfig : func (c * api.ClusterConfig ) {
558
+ c .Karpenter = & api.Karpenter {}
559
+ },
560
+ expectErr : true ,
561
+ }),
562
+ Entry ("iam.serviceAccounts" , bareClusterEntry {
563
+ updateClusterConfig : func (c * api.ClusterConfig ) {
564
+ c .IAM .WithOIDC = api .Enabled ()
565
+ c .IAM .ServiceAccounts = []* api.ClusterIAMServiceAccount {
566
+ {
567
+ ClusterIAMMeta : api.ClusterIAMMeta {
568
+ Name : "test" ,
569
+ Namespace : "test" ,
570
+ },
571
+ AttachPolicyARNs : []string {"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" },
572
+ },
573
+ }
574
+ },
575
+ expectErr : true ,
576
+ }),
577
+ Entry ("iam.podIdentityAssociations" , bareClusterEntry {
578
+ updateClusterConfig : func (c * api.ClusterConfig ) {
579
+ c .Addons = append (c .Addons , & api.Addon {Name : api .PodIdentityAgentAddon })
580
+ c .IAM .PodIdentityAssociations = []api.PodIdentityAssociation {
581
+ {
582
+ Namespace : "test" ,
583
+ PermissionPolicyARNs : []string {"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" },
584
+ },
585
+ }
586
+ },
587
+ expectErr : true ,
588
+ }),
589
+ Entry ("no unsupported field set" , bareClusterEntry {
590
+ updateClusterConfig : func (c * api.ClusterConfig ) {},
591
+ }),
592
+ )
474
593
})
475
594
476
595
Describe ("SetLabelLoader" , func () {
0 commit comments