-
Notifications
You must be signed in to change notification settings - Fork 189
/
cmd.go
4178 lines (3811 loc) · 129 KB
/
cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2020 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
import (
"errors"
"fmt"
"net"
"os"
"reflect"
"strconv"
"strings"
"time"
awssdk "github.com/aws/aws-sdk-go-v2/aws"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
clustervalidations "github.com/openshift-online/ocm-common/pkg/cluster/validations"
idputils "github.com/openshift-online/ocm-common/pkg/idp/utils"
passwordValidator "github.com/openshift-online/ocm-common/pkg/idp/validations"
diskValidator "github.com/openshift-online/ocm-common/pkg/machinepool/validations"
kmsArnRegexpValidator "github.com/openshift-online/ocm-common/pkg/resource/validations"
accountsv1 "github.com/openshift-online/ocm-sdk-go/accountsmgmt/v1"
v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/openshift/rosa/cmd/create/admin"
"github.com/openshift/rosa/cmd/create/idp"
"github.com/openshift/rosa/cmd/create/oidcprovider"
"github.com/openshift/rosa/cmd/create/operatorroles"
clusterdescribe "github.com/openshift/rosa/cmd/describe/cluster"
installLogs "github.com/openshift/rosa/cmd/logs/install"
"github.com/openshift/rosa/pkg/arguments"
"github.com/openshift/rosa/pkg/aws"
"github.com/openshift/rosa/pkg/aws/tags"
"github.com/openshift/rosa/pkg/clusterautoscaler"
"github.com/openshift/rosa/pkg/fedramp"
"github.com/openshift/rosa/pkg/helper"
mpHelpers "github.com/openshift/rosa/pkg/helper/machinepools"
"github.com/openshift/rosa/pkg/helper/roles"
"github.com/openshift/rosa/pkg/helper/versions"
"github.com/openshift/rosa/pkg/ingress"
"github.com/openshift/rosa/pkg/interactive"
"github.com/openshift/rosa/pkg/interactive/confirm"
"github.com/openshift/rosa/pkg/interactive/consts"
interactiveOidc "github.com/openshift/rosa/pkg/interactive/oidc"
"github.com/openshift/rosa/pkg/interactive/securitygroups"
interactiveSgs "github.com/openshift/rosa/pkg/interactive/securitygroups"
"github.com/openshift/rosa/pkg/ocm"
"github.com/openshift/rosa/pkg/output"
"github.com/openshift/rosa/pkg/properties"
"github.com/openshift/rosa/pkg/reporter"
"github.com/openshift/rosa/pkg/rosa"
)
const (
OidcConfigIdFlag = "oidc-config-id"
ClassicOidcConfigFlag = "classic-oidc-config"
ExternalAuthProvidersEnabledFlag = "external-auth-providers-enabled"
workerDiskSizeFlag = "worker-disk-size"
// #nosec G101
Ec2MetadataHttpTokensFlag = "ec2-metadata-http-tokens"
clusterAutoscalerFlagsPrefix = "autoscaler-"
MinReplicasSingleAZ = 2
MinReplicaMultiAZ = 3
listInputMessage = "Format should be a comma-separated list."
listBillingAccountMessage = "To see the list of billing account options, you can use interactive mode by passing '-i'."
// nolint:lll
createVpcForHcpDoc = "https://docs.openshift.com/rosa/rosa_hcp/rosa-hcp-sts-creating-a-cluster-quickly.html#rosa-hcp-creating-vpc"
)
var args struct {
// Watch logs during cluster installation
watch bool
// Simulate creating a cluster
dryRun bool
// Create a fake cluster with no AWS resources
fakeCluster bool
// Set custom properties in cluster spec
properties []string
// Use local AWS credentials instead of the 'osdCcsAdmin' user
useLocalCredentials bool
// Disable SCP checks in the installer
disableSCPChecks bool
// Basic options
private bool
privateLink bool
multiAZ bool
expirationDuration time.Duration
expirationTime string
clusterName string
domainPrefix string
region string
version string
channelGroup string
flavour string
disableWorkloadMonitoring bool
ec2MetadataHttpTokens string
//Encryption
etcdEncryption bool
fips bool
enableCustomerManagedKey bool
kmsKeyARN string
etcdEncryptionKmsARN string
// Scaling options
computeMachineType string
computeNodes int
autoscalingEnabled bool
minReplicas int
maxReplicas int
defaultMachinePoolLabels string
// Networking options
networkType string
machineCIDR net.IPNet
serviceCIDR net.IPNet
podCIDR net.IPNet
hostPrefix int
// The Subnet IDs to use when installing the cluster.
// SubnetIDs should come in pairs; two per availability zone, one private and one public,
// unless using PrivateLink, in which case it should only be one private per availability zone
subnetIDs []string
// Selecting availability zones for a non-BYOVPC cluster
availabilityZones []string
// Force STS mode for interactive and validation
sts bool
// Force IAM mode (mint mode) for interactive
nonSts bool
// Account IAM Roles
roleARN string
externalID string
supportRoleARN string
controlPlaneRoleARN string
workerRoleARN string
// Operator IAM Roles
operatorIAMRoles []string
operatorRolesPrefix string
operatorRolesPermissionsBoundary string
// Oidc Config
oidcConfigId string
classicOidcConfig bool
externalAuthProvidersEnabled bool
// Proxy
enableProxy bool
httpProxy string
httpsProxy string
noProxySlice []string
additionalTrustBundleFile string
tags []string
// Hypershift options:
hostedClusterEnabled bool
billingAccount string
noCni bool
additionalAllowedPrincipals []string
// Cluster Admin
createAdminUser bool
clusterAdminPassword string
clusterAdminUser string
// Audit Log Forwarding
AuditLogRoleARN string
// Default Ingress Attributes
defaultIngressRouteSelectors string
defaultIngressExcludedNamespaces string
defaultIngressWildcardPolicy string
defaultIngressNamespaceOwnershipPolicy string
defaultIngressClusterRoutesHostname string
defaultIngressClusterRoutesTlsSecretRef string
// Storage
machinePoolRootDiskSize string
// Shared VPC
privateHostedZoneID string
sharedVPCRoleARN string
baseDomain string
// Worker machine pool attributes
additionalComputeSecurityGroupIds []string
// Infra machine pool attributes
additionalInfraSecurityGroupIds []string
// Control Plane machine pool attributes
additionalControlPlaneSecurityGroupIds []string
}
var autoscalerArgs *clusterautoscaler.AutoscalerArgs
var userSpecifiedAutoscalerValues []*pflag.Flag
var Cmd = makeCmd()
func makeCmd() *cobra.Command {
return &cobra.Command{
Use: "cluster",
Short: "Create cluster",
Long: "Create cluster.",
Example: ` # Create a cluster named "mycluster"
rosa create cluster --cluster-name=mycluster
# Create a cluster in the us-east-2 region
rosa create cluster --cluster-name=mycluster --region=us-east-2`,
Run: run,
Args: cobra.NoArgs,
}
}
func init() {
initFlags(Cmd)
}
func initFlags(cmd *cobra.Command) {
flags := cmd.Flags()
flags.SortFlags = false
// Basic options
flags.StringVarP(
&args.clusterName,
"name",
"n",
"",
"Name of the cluster.",
)
flags.MarkDeprecated("name", "use --cluster-name instead")
flags.StringVarP(
&args.clusterName,
"cluster-name",
"c",
"",
"The unique name of the cluster. The name can be used as the identifier of the cluster."+
" The maximum length is 54 characters."+
"Once set, the cluster name cannot be changed",
)
flags.StringVar(
&args.domainPrefix,
"domain-prefix",
"",
"An optional unique domain prefix of the cluster. This will be used when generating a "+
"sub-domain for your cluster on openshiftapps.com. It must be unique per organization "+
"and consist of lowercase alphanumeric characters or '-', start with an alphabetic "+
"character, and end with an alphanumeric character. The maximum length is 15 characters. "+
"Once set, the cluster domain prefix cannot be changed",
)
flags.BoolVar(
&args.sts,
"sts",
false,
"Use AWS Security Token Service (STS) instead of IAM credentials to deploy your cluster.",
)
flags.BoolVar(
&args.nonSts,
"non-sts",
false,
"Use legacy method of creating clusters (IAM mode).",
)
flags.BoolVar(
&args.nonSts,
"mint-mode",
false,
"Use legacy method of creating clusters (IAM mode). This is an alias for --non-sts.",
)
flags.StringVar(
&args.roleARN,
"role-arn",
"",
"The Amazon Resource Name of the role that OpenShift Cluster Manager will assume to create the cluster.",
)
flags.StringVar(
&args.externalID,
"external-id",
"",
"An optional unique identifier that might be required when you assume a role in another account.",
)
flags.StringVar(
&args.supportRoleARN,
"support-role-arn",
"",
"The Amazon Resource Name of the role used by Red Hat SREs to enable "+
"access to the cluster account in order to provide support.",
)
flags.StringVar(
&args.controlPlaneRoleARN,
"controlplane-iam-role-arn",
"",
"The IAM role ARN that will be attached to control plane instances.",
)
flags.StringVar(
&args.controlPlaneRoleARN,
"master-iam-role",
"",
"The IAM role ARN that will be attached to master instances.",
)
flags.MarkDeprecated("master-iam-role", "use --controlplane-iam-role-arn instead")
flags.StringVar(
&args.workerRoleARN,
"worker-iam-role-arn",
"",
"The IAM role ARN that will be attached to worker instances.",
)
flags.StringArrayVar(
&args.operatorIAMRoles,
"operator-iam-roles",
nil,
"List of OpenShift name and namespace, and role ARNs used to perform credential "+
"requests by operators needed in the OpenShift installer.",
)
flags.MarkDeprecated("operator-iam-roles", "use --operator-roles-prefix instead")
flags.StringVar(
&args.operatorRolesPrefix,
"operator-roles-prefix",
"",
"Prefix to use for all IAM roles used by the operators needed in the OpenShift installer. "+
"Leave empty to use an auto-generated one.",
)
flags.StringVar(
&args.oidcConfigId,
OidcConfigIdFlag,
"",
"Registered OIDC Configuration ID to use for cluster creation",
)
flags.BoolVar(
&args.classicOidcConfig,
ClassicOidcConfigFlag,
false,
"Use classic OIDC configuration without registering an ID.",
)
flags.MarkHidden(ClassicOidcConfigFlag)
flags.BoolVar(
&args.externalAuthProvidersEnabled,
ExternalAuthProvidersEnabledFlag,
false,
"Enable external authentication configuration for a Hosted Control Plane cluster.",
)
flags.StringSliceVar(
&args.tags,
"tags",
nil,
"Apply user defined tags to all resources created by ROSA in AWS. "+
"Tags are comma separated, for example: 'key value, foo bar'",
)
flags.BoolVar(
&args.multiAZ,
"multi-az",
false,
"Deploy to multiple data centers.",
)
arguments.AddRegionFlag(flags)
flags.StringVar(
&args.version,
"version",
"",
"Version of OpenShift that will be used to install the cluster, for example \"4.3.10\"",
)
flags.StringVar(
&args.channelGroup,
"channel-group",
ocm.DefaultChannelGroup,
"Channel group is the name of the group where this image belongs, for example \"stable\" or \"fast\".",
)
flags.MarkHidden("channel-group")
flags.StringVar(
&args.flavour,
"flavour",
"osd-4",
"Set of predefined properties of a cluster",
)
flags.MarkHidden("flavour")
flags.BoolVar(
&args.etcdEncryption,
"etcd-encryption",
false,
"Add etcd encryption. By default etcd data is encrypted at rest. "+
"This option configures etcd encryption on top of existing storage encryption.",
)
flags.BoolVar(
&args.fips,
"fips",
false,
"Create cluster that uses FIPS Validated / Modules in Process cryptographic libraries.",
)
flags.StringVar(
&args.httpProxy,
"http-proxy",
"",
"A proxy URL to use for creating HTTP connections outside the cluster. The URL scheme must be http.",
)
flags.StringVar(
&args.httpsProxy,
"https-proxy",
"",
"A proxy URL to use for creating HTTPS connections outside the cluster.",
)
flags.StringSliceVar(
&args.noProxySlice,
"no-proxy",
nil,
"A comma-separated list of destination domain names, domains, IP addresses or "+
"other network CIDRs to exclude proxying.",
)
flags.StringVar(
&args.additionalTrustBundleFile,
"additional-trust-bundle-file",
"",
"A file contains a PEM-encoded X.509 certificate bundle that will be "+
"added to the nodes' trusted certificate store.")
flags.StringSliceVar(
&args.additionalAllowedPrincipals,
"additional-allowed-principals",
nil,
"A comma-separated list of additional allowed principal ARNs "+
"to be added to the Hosted Control Plane's VPC Endpoint Service to enable additional "+
"VPC Endpoint connection requests to be automatically accepted.",
)
flags.BoolVar(&args.enableCustomerManagedKey,
"enable-customer-managed-key",
false,
"Enable to specify your KMS Key to encrypt EBS instance volumes. By default account’s default "+
"KMS key for that particular region is used.")
flags.StringVar(&args.kmsKeyARN,
"kms-key-arn",
"",
"The key ARN is the Amazon Resource Name (ARN) of a CMK. It is a unique, "+
"fully qualified identifier for the CMK. A key ARN includes the AWS account, Region, and the key ID.")
flags.StringVar(&args.etcdEncryptionKmsARN,
"etcd-encryption-kms-arn",
"",
"The etcd encryption kms key ARN is the key used to encrypt etcd. "+
"If set it will override etcd-encryption flag to true. It is a unique, "+
"fully qualified identifier for the CMK. A key ARN includes the AWS account, Region, and the key ID.")
flags.StringVar(
&args.expirationTime,
"expiration-time",
"",
"Specific time when cluster should expire (RFC3339). Only one of expiration-time / expiration may be used.",
)
flags.DurationVar(
&args.expirationDuration,
"expiration",
0,
"Expire cluster after a relative duration like 2h, 8h, 72h. Only one of expiration-time / expiration may be used.",
)
// Cluster expiration is not supported in production
flags.MarkHidden("expiration-time")
flags.MarkHidden("expiration")
flags.BoolVar(
&args.privateLink,
"private-link",
false,
"Provides private connectivity between VPCs, AWS services, and your on-premises networks, "+
"without exposing your traffic to the public internet.",
)
flags.StringVar(
&args.ec2MetadataHttpTokens,
Ec2MetadataHttpTokensFlag,
"",
"Should cluster nodes use both v1 and v2 endpoints or just v2 endpoint "+
"of EC2 Instance Metadata Service (IMDS)",
)
flags.StringSliceVar(
&args.subnetIDs,
"subnet-ids",
nil,
"The Subnet IDs to use when installing the cluster. "+
"Format should be a comma-separated list. "+
"Leave empty for installer provisioned subnet IDs.",
)
flags.StringSliceVar(
&args.availabilityZones,
"availability-zones",
nil,
"The availability zones to use when installing a non-BYOVPC cluster. "+
"Format should be a comma-separated list. "+
"Leave empty for the installer to pick availability zones")
// Scaling options
flags.StringVar(
&args.computeMachineType,
"compute-machine-type",
"",
"Instance type for the compute nodes. Determines the amount of memory and vCPU allocated to each compute node.",
)
flags.IntVar(
&args.computeNodes,
"compute-nodes",
2,
"Number of worker nodes to provision. Single zone clusters need at least 2 nodes, "+
"multizone clusters need at least 3 nodes.",
)
flags.MarkDeprecated("compute-nodes", "use --replicas instead")
flags.IntVar(
&args.computeNodes,
"replicas",
2,
"Number of worker nodes to provision. Single zone clusters need at least 2 nodes, "+
"multizone clusters need at least 3 nodes. Hosted clusters require that the number of worker nodes be a "+
"multiple of the number of private subnets.",
)
flags.BoolVar(
&args.autoscalingEnabled,
"enable-autoscaling",
false,
"Enable autoscaling of compute nodes.",
)
autoscalerArgs = clusterautoscaler.AddClusterAutoscalerFlags(cmd, clusterAutoscalerFlagsPrefix)
// iterates through all autoscaling flags and stores them in slice to track user input
flags.VisitAll(func(f *pflag.Flag) {
if strings.HasPrefix(f.Name, clusterAutoscalerFlagsPrefix) {
userSpecifiedAutoscalerValues = append(userSpecifiedAutoscalerValues, f)
}
})
flags.IntVar(
&args.minReplicas,
"min-replicas",
2,
"Minimum number of compute nodes.",
)
flags.IntVar(
&args.maxReplicas,
"max-replicas",
2,
"Maximum number of compute nodes.",
)
flags.SetNormalizeFunc(arguments.NormalizeFlags)
flags.StringVar(
&args.defaultMachinePoolLabels,
arguments.NewDefaultMPLabelsFlag,
"",
"Labels for the worker machine pool. Format should be a comma-separated list of 'key=value'. "+
"This list will overwrite any modifications made to Node labels on an ongoing basis.",
)
flags.StringVar(
&args.networkType,
"network-type",
"",
"The main controller responsible for rendering the core networking components.",
)
flags.MarkHidden("network-type")
cmd.RegisterFlagCompletionFunc("network-type", networkTypeCompletion)
flags.IPNetVar(
&args.machineCIDR,
"machine-cidr",
net.IPNet{},
"Block of IP addresses used by OpenShift while installing the cluster, for example \"10.0.0.0/16\".",
)
flags.IPNetVar(
&args.serviceCIDR,
"service-cidr",
net.IPNet{},
"Block of IP addresses for services, for example \"172.30.0.0/16\".",
)
flags.IPNetVar(
&args.podCIDR,
"pod-cidr",
net.IPNet{},
"Block of IP addresses from which Pod IP addresses are allocated, for example \"10.128.0.0/14\".",
)
flags.IntVar(
&args.hostPrefix,
"host-prefix",
0,
"Subnet prefix length to assign to each individual node. For example, if host prefix is set "+
"to \"23\", then each node is assigned a /23 subnet out of the given CIDR.",
)
flags.BoolVar(
&args.private,
"private",
false,
"Restrict master API endpoint and application routes to direct, private connectivity.",
)
flags.BoolVar(
&args.disableSCPChecks,
"disable-scp-checks",
false,
"Indicates if cloud permission checks are disabled when attempting installation of the cluster.",
)
flags.BoolVar(
&args.disableWorkloadMonitoring,
"disable-workload-monitoring",
false,
"Enables you to monitor your own projects in isolation from Red Hat Site Reliability Engineer (SRE) "+
"platform metrics.",
)
flags.BoolVarP(
&args.watch,
"watch",
"w",
false,
"Watch cluster installation logs.",
)
flags.BoolVar(
&args.dryRun,
"dry-run",
false,
"Simulate creating the cluster.",
)
flags.BoolVar(
&args.fakeCluster,
"fake-cluster",
false,
"Create a fake cluster that uses no AWS resources.",
)
flags.MarkHidden("fake-cluster")
flags.StringArrayVar(
&args.properties,
"properties",
nil,
"User defined properties for tagging and querying.",
)
flags.MarkHidden("properties")
flags.BoolVar(
&args.useLocalCredentials,
"use-local-credentials",
false,
"Use local AWS credentials instead of the 'osdCcsAdmin' user. This is not supported.",
)
flags.MarkHidden("use-local-credentials")
flags.StringVar(
&args.operatorRolesPermissionsBoundary,
"permissions-boundary",
"",
"The ARN of the policy that is used to set the permissions boundary for the operator "+
"roles in STS clusters.",
)
// Options related to HyperShift:
flags.BoolVar(
&args.hostedClusterEnabled,
"hosted-cp",
false,
"Enable the use of Hosted Control Planes",
)
flags.StringVar(&args.machinePoolRootDiskSize,
workerDiskSizeFlag,
"",
"Default worker machine pool root disk size with a **unit suffix** like GiB or TiB, "+
"e.g. 200GiB.")
flags.StringVar(
&args.billingAccount,
"billing-account",
"",
"Account used for billing subscriptions purchased via the AWS marketplace",
)
flags.BoolVar(
&args.createAdminUser,
"create-admin-user",
false,
`Create cluster admin named "cluster-admin"`,
)
flags.BoolVar(
&args.noCni,
"no-cni",
false,
"Disable CNI creation to let users bring their own CNI.",
)
flags.MarkHidden("no-cni")
flags.StringVar(
&args.clusterAdminUser,
"cluster-admin-user",
"",
`Username of Cluster Admin. Username must not contain /, :, or %%`,
)
flags.StringVar(
&args.clusterAdminPassword,
"cluster-admin-password",
"",
`The password must
- Be at least 14 characters (ASCII-standard) without whitespaces
- Include uppercase letters, lowercase letters, and numbers or symbols (ASCII-standard characters only)`,
)
flags.MarkHidden("cluster-admin-user")
flags.StringVar(
&args.AuditLogRoleARN,
"audit-log-arn",
"",
"The ARN of the role that is used to forward audit logs to AWS CloudWatch.",
)
flags.StringVar(
&args.defaultIngressRouteSelectors,
ingress.DefaultIngressRouteSelectorFlag,
"",
"Route Selector for ingress. Format should be a comma-separated list of 'key=value'. "+
"If no label is specified, all routes will be exposed on both routers."+
" For legacy ingress support these are inclusion labels, otherwise they are treated as exclusion label.",
)
flags.StringVar(
&args.defaultIngressExcludedNamespaces,
ingress.DefaultIngressExcludedNamespacesFlag,
"",
"Excluded namespaces for ingress. Format should be a comma-separated list 'value1, value2...'. "+
"If no values are specified, all namespaces will be exposed.",
)
flags.StringVar(
&args.defaultIngressWildcardPolicy,
ingress.DefaultIngressWildcardPolicyFlag,
"",
fmt.Sprintf("Wildcard Policy for ingress. Options are %s. Default is '%s'.",
strings.Join(ingress.ValidWildcardPolicies, ","), ingress.DefaultWildcardPolicy),
)
flags.StringVar(
&args.defaultIngressNamespaceOwnershipPolicy,
ingress.DefaultIngressNamespaceOwnershipPolicyFlag,
"",
fmt.Sprintf("Namespace Ownership Policy for ingress. Options are %s. Default is '%s'.",
strings.Join(ingress.ValidNamespaceOwnershipPolicies, ","), ingress.DefaultNamespaceOwnershipPolicy),
)
flags.StringVar(
&args.privateHostedZoneID,
"private-hosted-zone-id",
"",
"ID assigned by AWS to private Route 53 hosted zone associated with intended shared VPC, "+
"e.g., 'Z05646003S02O1ENCDCSN'.",
)
flags.StringVar(
&args.sharedVPCRoleARN,
"shared-vpc-role-arn",
"",
"AWS IAM role ARN with a policy attached, granting permissions necessary to create and manage Route 53 DNS records "+
"in private Route 53 hosted zone associated with intended shared VPC.",
)
flags.StringVar(
&args.baseDomain,
"base-domain",
"",
"Base DNS domain name previously reserved and matching the hosted zone name of the private Route 53 hosted zone "+
"associated with intended shared VPC, e.g., '1vo8.p1.openshiftapps.com'.",
)
flags.StringSliceVar(
&args.additionalComputeSecurityGroupIds,
securitygroups.ComputeSecurityGroupFlag,
nil,
"The additional Security Group IDs to be added to the default worker machine pool. "+
listInputMessage,
)
flags.StringSliceVar(
&args.additionalInfraSecurityGroupIds,
securitygroups.InfraSecurityGroupFlag,
nil,
"The additional Security Group IDs to be added to the infra worker nodes. "+
listInputMessage,
)
flags.StringSliceVar(
&args.additionalControlPlaneSecurityGroupIds,
securitygroups.ControlPlaneSecurityGroupFlag,
nil,
"The additional Security Group IDs to be added to the control plane nodes. "+
listInputMessage,
)
interactive.AddModeFlag(cmd)
interactive.AddFlag(flags)
output.AddFlag(cmd)
confirm.AddFlag(flags)
}
func networkTypeCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return ocm.NetworkTypes, cobra.ShellCompDirectiveDefault
}
func run(cmd *cobra.Command, _ []string) {
r := rosa.NewRuntime().WithAWS().WithOCM()
defer r.Cleanup()
// Validate mode
mode, err := interactive.GetMode()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
for _, val := range userSpecifiedAutoscalerValues {
if val.Changed && !args.autoscalingEnabled {
r.Reporter.Errorf("Using autoscaling flag '%s', requires flag '--enable-autoscaling'. "+
"Please try again with flag", val.Name)
os.Exit(1)
}
}
// validate flags for cluster admin
isHostedCP := args.hostedClusterEnabled
if isHostedCP && fedramp.Enabled() {
r.Reporter.Errorf("Fedramp does not currently support Hosted Control Plane clusters. Please use classic")
os.Exit(1)
}
supportedRegions, err := r.OCMClient.GetDatabaseRegionList()
if err != nil {
r.Reporter.Errorf("Unable to retrieve supported regions: %v", err)
}
awsClient := aws.GetAWSClientForUserRegion(r.Reporter, r.Logger, supportedRegions, args.useLocalCredentials)
r.AWSClient = awsClient
awsCreator, err := awsClient.GetCreator()
if err != nil {
r.Reporter.Errorf("Unable to get IAM credentials: %v", err)
os.Exit(1)
}
shardPinningEnabled := false
for _, value := range args.properties {
if strings.HasPrefix(value, properties.ProvisionShardId) {
shardPinningEnabled = true
break
}
}
isBYOVPC := cmd.Flags().Changed("subnet-ids")
isAvailabilityZonesSet := cmd.Flags().Changed("availability-zones")
// Setting subnet IDs is choosing BYOVPC implicitly,
// and selecting availability zones is only allowed for non-BYOVPC clusters
if isBYOVPC && isAvailabilityZonesSet {
r.Reporter.Errorf("Setting availability zones is not supported for BYO VPC. " +
"ROSA autodetects availability zones from subnet IDs provided")
}
// Select a multi-AZ cluster implicitly by providing three availability zones
if len(args.availabilityZones) == clustervalidations.MultiAZCount {
args.multiAZ = true
}
if interactive.Enabled() {
r.Reporter.Infof("Interactive mode enabled.\n" +
"Any optional fields can be left empty and a default will be selected.")
}
// Get cluster name
clusterName := strings.Trim(args.clusterName, " \t")
if clusterName == "" && !interactive.Enabled() {
interactive.Enable()
r.Reporter.Infof("Enabling interactive mode")
}
if interactive.Enabled() {
clusterName, err = interactive.GetString(interactive.Input{
Question: "Cluster name",
Help: cmd.Flags().Lookup("cluster-name").Usage,
Default: clusterName,
Required: true,
Validators: []interactive.Validator{
ocm.ClusterNameValidator,
},
})
if err != nil {
r.Reporter.Errorf("Expected a valid cluster name: %s", err)
os.Exit(1)
}
}
// Trim names to remove any leading/trailing invisible characters
clusterName = strings.Trim(clusterName, " \t")
if !ocm.IsValidClusterName(clusterName) {
r.Reporter.Errorf("Cluster name must consist"+
" of no more than %d lowercase alphanumeric characters or '-', "+
"start with a letter, and end with an alphanumeric character.", ocm.MaxClusterNameLength)
os.Exit(1)
}
// Get cluster domain prefix
domainPrefix := strings.Trim(args.domainPrefix, " \t")
if interactive.Enabled() {
domainPrefix, err = interactive.GetString(interactive.Input{
Question: "Domain prefix",
Help: cmd.Flags().Lookup("domain-prefix").Usage,
Default: domainPrefix,
Required: false,
Validators: []interactive.Validator{
ocm.ClusterDomainPrefixValidator,
},
})
if err != nil {
r.Reporter.Errorf("Expected a valid domain prefix: %s", err)
os.Exit(1)
}
}
// Trim domain prefix to remove any leading/trailing invisible characters
domainPrefix = strings.Trim(domainPrefix, " \t")
if domainPrefix != "" && !ocm.IsValidClusterDomainPrefix(domainPrefix) {
r.Reporter.Errorf("Domain prefix must consist"+
" of no more than %d lowercase alphanumeric characters or '-', "+
"start with a letter, and end with an alphanumeric character.", ocm.MaxClusterDomainPrefixLength)
os.Exit(1)
}
if clusterHasLongNameWithoutDomainPrefix(clusterName, domainPrefix) {
prompt := "Your cluster has a name longer than 15 characters, it will contain" +
" an autogenerated domain prefix as a sub-domain for your cluster on " +
"openshiftapps.com when provisioned. Do you want to proceed?"
if !confirm.ConfirmRaw(prompt) {
r.Reporter.Warnf("You opted out from creating a cluster with an autogenerated " +
"sub-domain for your cluster on openshiftapps.com. To customise the sub-domain" +
", use the '--domain-prefix' flag")
os.Exit(0)
}
}
if interactive.Enabled() && !fedramp.Enabled() {
isHostedCP, err = interactive.GetBool(interactive.Input{
Question: "Deploy cluster with Hosted Control Plane",
Help: cmd.Flags().Lookup("hosted-cp").Usage,
Default: isHostedCP,
Required: false,
})
if err != nil {
r.Reporter.Errorf("Expected a valid --hosted-cp value: %s", err)