Skip to content

Commit

Permalink
backport of commit 2ae7bd4
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed Oct 12, 2023
1 parent a4b2ecd commit 2241e15
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
30 changes: 23 additions & 7 deletions internal/catalog/internal/types/failover_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ func validateFailoverConfig(config *pbcatalog.FailoverConfig, ported bool, wrapE
Wrapped: fmt.Errorf("not supported in this release"),
}))
}

if len(config.Regions) > 0 {
merr = multierror.Append(merr, wrapErr(resource.ErrInvalidField{
Name: "regions",
Wrapped: fmt.Errorf("not supported in this release"),
}))
}

// TODO(peering/v2): remove this bypass when we know what to do with

if (len(config.Destinations) > 0) == (config.SamenessGroup != "") {
Expand All @@ -194,18 +202,26 @@ func validateFailoverConfig(config *pbcatalog.FailoverConfig, ported bool, wrapE
}
}

switch config.Mode {
case pbcatalog.FailoverMode_FAILOVER_MODE_UNSPECIFIED:
// means pbcatalog.FailoverMode_FAILOVER_MODE_SEQUENTIAL
case pbcatalog.FailoverMode_FAILOVER_MODE_SEQUENTIAL:
case pbcatalog.FailoverMode_FAILOVER_MODE_ORDER_BY_LOCALITY:
default:
if config.Mode != pbcatalog.FailoverMode_FAILOVER_MODE_UNSPECIFIED {
merr = multierror.Append(merr, wrapErr(resource.ErrInvalidField{
Name: "mode",
Wrapped: fmt.Errorf("not a supported enum value: %v", config.Mode),
Wrapped: fmt.Errorf("not supported in this release"),
}))
}

// TODO(v2): uncomment after this is supported
// switch config.Mode {
// case pbcatalog.FailoverMode_FAILOVER_MODE_UNSPECIFIED:
// // means pbcatalog.FailoverMode_FAILOVER_MODE_SEQUENTIAL
// case pbcatalog.FailoverMode_FAILOVER_MODE_SEQUENTIAL:
// case pbcatalog.FailoverMode_FAILOVER_MODE_ORDER_BY_LOCALITY:
// default:
// merr = multierror.Append(merr, wrapErr(resource.ErrInvalidField{
// Name: "mode",
// Wrapped: fmt.Errorf("not a supported enum value: %v", config.Mode),
// }))
// }

// TODO: validate sameness group requirements

return merr
Expand Down
27 changes: 21 additions & 6 deletions internal/catalog/internal/types/failover_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,30 @@ func TestValidateFailoverPolicy(t *testing.T) {
// TODO(v2): remove after this is supported
expectErr: `invalid "sameness_group" field: not supported in this release`,
},
"mode: invalid": {
"regions without dest": {
config: &pbcatalog.FailoverConfig{
Mode: 99,
Destinations: []*pbcatalog.FailoverDestination{
{Ref: newRef(pbcatalog.ServiceType, "api-backup")},
},
Regions: []string{"us-east1", "us-west2"},
},
expectErr: `invalid "mode" field: not a supported enum value: 99`,
// TODO(v2): remove after this is supported
expectErr: `invalid "regions" field: not supported in this release`,
},
"mode without dest": {
config: &pbcatalog.FailoverConfig{
Mode: pbcatalog.FailoverMode_FAILOVER_MODE_SEQUENTIAL,
},
// TODO(v2): remove after this is supported
expectErr: `invalid "mode" field: not supported in this release`,
},
// TODO(v2): uncomment after this is supported
// "mode: invalid": {
// config: &pbcatalog.FailoverConfig{
// Mode: 99,
// Destinations: []*pbcatalog.FailoverDestination{
// {Ref: newRef(pbcatalog.ServiceType, "api-backup")},
// },
// },
// expectErr: `invalid "mode" field: not a supported enum value: 99`,
// },
"dest: no ref": {
config: &pbcatalog.FailoverConfig{
Destinations: []*pbcatalog.FailoverDestination{
Expand Down

0 comments on commit 2241e15

Please sign in to comment.