func()

in internal/deployers/eksapi/cluster.go [37:96]


func (m *ClusterManager) getOrCreateCluster(infra *Infrastructure, opts *deployerOptions) (*Cluster, error) {
	targetClusterName := opts.StaticClusterName
	if targetClusterName == "" {
		klog.Infof("creating cluster...")
		input := eks.CreateClusterInput{
			Name: aws.String(m.resourceID),
			ResourcesVpcConfig: &ekstypes.VpcConfigRequest{
				EndpointPrivateAccess: aws.Bool(true),
				EndpointPublicAccess:  aws.Bool(true),
				SubnetIds:             append(infra.subnetsPublic, infra.subnetsPrivate...),
			},
			RoleArn: aws.String(infra.clusterRoleARN),
			KubernetesNetworkConfig: &ekstypes.KubernetesNetworkConfigRequest{
				IpFamily: ekstypes.IpFamily(opts.IPFamily),
			},
			Version: aws.String(opts.KubernetesVersion),
		}
		if opts.AutoMode {
			input.ComputeConfig = &ekstypes.ComputeConfigRequest{
				// we don't enable any of the default node pools, we'll create our own
				Enabled:     aws.Bool(true),
				NodeRoleArn: aws.String(infra.nodeRoleARN),
				// TODO: we can't currently enable managed compute without a default NodePool
				// the system NodePool is tainted for critical addons only, so will be ignored for our test workloads
				NodePools: []string{"system"},
			}
			input.StorageConfig = &ekstypes.StorageConfigRequest{
				BlockStorage: &ekstypes.BlockStorage{
					Enabled: aws.Bool(true),
				},
			}
			input.KubernetesNetworkConfig.ElasticLoadBalancing = &ekstypes.ElasticLoadBalancing{
				Enabled: aws.Bool(true),
			}
			input.AccessConfig = &ekstypes.CreateAccessConfigRequest{
				AuthenticationMode: ekstypes.AuthenticationModeApi,
			}
			input.BootstrapSelfManagedAddons = aws.Bool(false)
		}
		apiOpts, err := util.NewHTTPHeaderAPIOptions(opts.UpClusterHeaders)
		if err != nil {
			return nil, fmt.Errorf("failed to create API options: %v", err)
		}
		createOutput, err := m.clients.EKS().CreateCluster(context.TODO(), &input,
			func(o *eks.Options) {
				o.APIOptions = apiOpts
			})
		if err != nil {
			return nil, fmt.Errorf("failed to create cluster: %v", err)
		}
		targetClusterName = aws.ToString(createOutput.Cluster.Name)
	} else {
		klog.Infof("reusing existing static cluster %s", opts.StaticClusterName)
	}
	cluster, waitErr := m.waitForClusterActive(targetClusterName, opts.ClusterCreationTimeout)
	if waitErr != nil {
		return nil, fmt.Errorf("failed to wait for cluster to become active: %v", waitErr)
	}
	return cluster, nil
}