createClusterStack creates the cluster stack
(ctx context.Context, stackName string, resourceSet builder.ResourceSetReader, errCh chan error)
| 182 | |
| 183 | // createClusterStack creates the cluster stack |
| 184 | func (c *StackCollection) createClusterStack(ctx context.Context, stackName string, resourceSet builder.ResourceSetReader, errCh chan error) error { |
| 185 | clusterTags := map[string]string{ |
| 186 | api.ClusterOIDCEnabledTag: strconv.FormatBool(api.IsEnabled(c.spec.IAM.WithOIDC)), |
| 187 | } |
| 188 | stack, err := c.createStackRequest(ctx, stackName, resourceSet, clusterTags, nil) |
| 189 | if err != nil { |
| 190 | return err |
| 191 | } |
| 192 | |
| 193 | go func() { |
| 194 | defer close(errCh) |
| 195 | troubleshoot := func() { |
| 196 | stack, err := c.DescribeStack(ctx, stack) |
| 197 | if err != nil { |
| 198 | logger.Info("error describing stack to troubleshoot the cause of the failure; "+ |
| 199 | "check the CloudFormation console for further details", err) |
| 200 | return |
| 201 | } |
| 202 | |
| 203 | logger.Critical("unexpected status %q while waiting for CloudFormation stack %q", stack.StackStatus, *stack.StackName) |
| 204 | c.TroubleshootStackFailureCause(ctx, stack, types.StackStatusCreateComplete) |
| 205 | } |
| 206 | |
| 207 | ctx, cancelFunc := context.WithTimeout(context.Background(), c.waitTimeout) |
| 208 | defer cancelFunc() |
| 209 | |
| 210 | stack, err := waiter.WaitForStack(ctx, c.cloudformationAPI, *stack.StackId, *stack.StackName, waiter.ClusterCreationNextDelay) |
| 211 | |
| 212 | if err != nil { |
| 213 | troubleshoot() |
| 214 | errCh <- err |
| 215 | return |
| 216 | } |
| 217 | |
| 218 | if err := resourceSet.GetAllOutputs(*stack); err != nil { |
| 219 | errCh <- fmt.Errorf("getting stack %q outputs: %w", *stack.StackName, err) |
| 220 | return |
| 221 | } |
| 222 | |
| 223 | errCh <- nil |
| 224 | }() |
| 225 | |
| 226 | return nil |
| 227 | } |
| 228 | |
| 229 | func (c *StackCollection) createStackRequest(ctx context.Context, stackName string, resourceSet builder.ResourceSetReader, tags, parameters map[string]string) (*Stack, error) { |
| 230 | stack := &Stack{StackName: &stackName} |
no test coverage detected