Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support add replica in tcld #337

Merged
merged 4 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 62 additions & 3 deletions app/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.uber.org/multierr"

"github.com/temporalio/tcld/protogen/api/auth/v1"
"github.com/temporalio/tcld/protogen/api/common/v1"
"github.com/temporalio/tcld/protogen/api/sink/v1"

"github.com/kylelemons/godebug/diff"
Expand All @@ -26,6 +27,7 @@ import (

const (
namespaceRegionFlagName = "region"
regionCloudProviderFlagName = "cloud-provider"
CaCertificateFlagName = "ca-certificate"
CaCertificateFileFlagName = "ca-certificate-file"
caCertificateFingerprintFlagName = "ca-certificate-fingerprint"
Expand Down Expand Up @@ -269,6 +271,37 @@ func (c *NamespaceClient) createNamespace(n *namespace.Namespace, p []*auth.User
return PrintProto(res)
}

func (c *NamespaceClient) addRegion(ctx *cli.Context) error {
var resourceVersion string
if v := ctx.String(ResourceVersionFlagName); v != "" {
resourceVersion = v
}

region := ctx.String(namespaceRegionFlagName)
yux0 marked this conversation as resolved.
Show resolved Hide resolved
if len(region) == 0 {
return fmt.Errorf("namespace region is required")
}

cloudProvider := ctx.String(regionCloudProviderFlagName)
if len(cloudProvider) == 0 {
return fmt.Errorf("namespace cloud provider is required")
}

res, err := c.client.GlobalizeNamespace(c.ctx, &namespaceservice.GlobalizeNamespaceRequest{
RequestId: ctx.String(RequestIDFlagName),
Namespace: ctx.String(NamespaceFlagName),
TargetRegion: &common.RegionID{
CloudProvider: cloudProvider,
Name: region,
},
ResourceVersion: resourceVersion,
})
if err != nil {
return err
}
return PrintProto(res)
}

func (c *NamespaceClient) listNamespaces() error {
totalRes := &namespaceservice.ListNamespacesResponse{}
pageToken := ""
Expand Down Expand Up @@ -492,9 +525,6 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut,
Namespace: ctx.String(NamespaceFlagName),
}

n.Spec = &namespace.NamespaceSpec{
Region: ctx.String(namespaceRegionFlagName),
}
regions := ctx.StringSlice(namespaceRegionFlagName)
if len(regions) == 0 {
return fmt.Errorf("namespace region is required")
Expand Down Expand Up @@ -588,6 +618,35 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut,
return c.createNamespace(n, unp)
},
},
{
Name: "add-region",
yux0 marked this conversation as resolved.
Show resolved Hide resolved
Usage: "Add an new region to the temporal namespace",
Aliases: []string{"c"},
Flags: []cli.Flag{
RequestIDFlag,
ResourceVersionFlag,
&cli.StringFlag{
yux0 marked this conversation as resolved.
Show resolved Hide resolved
Name: NamespaceFlagName,
Usage: "The namespace hosted on temporal cloud",
Aliases: []string{"n"},
Required: true,
},
&cli.StringSliceFlag{
Name: namespaceRegionFlagName,
Usage: "New region to add to the namespace.",
Aliases: []string{"re"},
Required: true,
},
&cli.StringFlag{
Name: regionCloudProviderFlagName,
Usage: "The cloud provider of the region. Default: aws",
Value: "aws",
},
},
Action: func(ctx *cli.Context) error {
return c.addRegion(ctx)
},
},
{
Name: "delete",
Usage: "Delete a temporal namespace",
Expand Down
Loading
Loading