Skip to content

Commit 7ac0548

Browse files
authored
Fix cortex cluster info cmd (#2150)
1 parent 0e165b1 commit 7ac0548

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

pkg/types/clusterconfig/cluster_config.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,14 +641,6 @@ var ManagedConfigStructFieldValidations = []*cr.StructFieldValidation{
641641
AllowExplicitNull: true,
642642
},
643643
},
644-
{
645-
StructField: "CortexPolicyARN",
646-
StringValidation: &cr.StringValidation{
647-
Required: false,
648-
AllowEmpty: true,
649-
TreatNullAsEmpty: true,
650-
},
651-
},
652644
{
653645
StructField: "IAMPolicyARNs",
654646
StringListValidation: &cr.StringListValidation{
@@ -771,6 +763,22 @@ var ManagedConfigStructFieldValidations = []*cr.StructFieldValidation{
771763
Validator: validateCIDR,
772764
},
773765
},
766+
{
767+
StructField: "CortexPolicyARN",
768+
StringValidation: &cr.StringValidation{
769+
Required: false,
770+
AllowEmpty: true,
771+
TreatNullAsEmpty: true,
772+
},
773+
},
774+
{
775+
StructField: "AccountID",
776+
StringValidation: &cr.StringValidation{
777+
Required: false,
778+
AllowEmpty: true,
779+
TreatNullAsEmpty: true,
780+
},
781+
},
774782
}
775783

776784
func CoreConfigValidations(allowExtraFields bool) *cr.StructValidation {
@@ -903,6 +911,11 @@ func (cc *Config) Validate(awsClient *aws.Client) error {
903911
return err
904912
}
905913

914+
if cc.AccountID != "" {
915+
return ErrorDisallowedField(AccountIDKey)
916+
}
917+
cc.AccountID = accountID
918+
906919
if cc.Bucket == "" {
907920
bucketID := hash.String(accountID + cc.Region)[:8] // this is to "guarantee" a globally unique name
908921
cc.Bucket = cc.ClusterName + "-" + bucketID
@@ -913,6 +926,9 @@ func (cc *Config) Validate(awsClient *aws.Client) error {
913926
}
914927
}
915928

929+
if cc.CortexPolicyARN != "" {
930+
return ErrorDisallowedField(CortexPolicyARNKey)
931+
}
916932
cc.CortexPolicyARN = DefaultPolicyARN(accountID, cc.ClusterName, cc.Region)
917933

918934
defaultPoliciesSet := strset.New(_defaultIAMPolicies...)

pkg/types/clusterconfig/config_key.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ const (
5353
APILoadBalancerSchemeKey = "api_load_balancer_scheme"
5454
OperatorLoadBalancerSchemeKey = "operator_load_balancer_scheme"
5555
VPCCIDRKey = "vpc_cidr"
56+
AccountIDKey = "account_id"
5657
TelemetryKey = "telemetry"
5758
)

pkg/types/clusterconfig/errors.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ import (
2929

3030
const (
3131
ErrInvalidProvider = "clusterconfig.invalid_provider"
32-
ErrInvalidLegacyProvider = "cli.invalid_legacy_provider"
32+
ErrInvalidLegacyProvider = "clusterconfig.invalid_legacy_provider"
3333
ErrInvalidRegion = "clusterconfig.invalid_region"
34+
ErrDisallowedField = "clusterconfig.disallowed_field"
3435
ErrNoNodeGroupSpecified = "clusterconfig.no_nodegroup_specified"
3536
ErrNodeGroupMaxInstancesIsZero = "clusterconfig.node_group_max_instances_is_zero"
3637
ErrMaxNumOfNodeGroupsReached = "clusterconfig.max_num_of_nodegroups_reached"
@@ -88,6 +89,13 @@ func ErrorInvalidLegacyProvider(providerStr string) error {
8889
})
8990
}
9091

92+
func ErrorDisallowedField(field string) error {
93+
return errors.WithStack(&errors.Error{
94+
Kind: ErrDisallowedField,
95+
Message: fmt.Sprintf("the %s field cannot be configured by the user", field),
96+
})
97+
}
98+
9199
func ErrorInvalidRegion(region string) error {
92100
return errors.WithStack(&errors.Error{
93101
Kind: ErrInvalidRegion,

0 commit comments

Comments
 (0)