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

FLI Issue 3222: Import issue when --address and --drop is used #3530

Merged
merged 6 commits into from
Oct 27, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(ext): drop namespaces during import with address
Signed-off-by: devumesh <[email protected]>
devumesh committed Oct 26, 2024
commit d3f3f4d891e8d435e890ea8417e8fe0bd88fb222
32 changes: 32 additions & 0 deletions cmd/flipt/import.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"errors"
"fmt"
"io"
@@ -10,6 +11,8 @@ import (
"github.com/spf13/cobra"
"go.flipt.io/flipt/internal/ext"
"go.flipt.io/flipt/internal/storage/sql"
"go.flipt.io/flipt/rpc/flipt"
sdk "go.flipt.io/flipt/sdk/go"
)

type importCommand struct {
@@ -107,6 +110,11 @@ func (c *importCommand) run(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if c.dropBeforeImport {
if err := dropNamespaces(ctx, client); err != nil {
return fmt.Errorf("dropping namespaces: %w", err)
}
}
return ext.NewImporter(client).Import(ctx, enc, in, c.skipExisting)
}

@@ -161,3 +169,27 @@ func (c *importCommand) run(cmd *cobra.Command, args []string) error {
server,
).Import(ctx, enc, in, c.skipExisting)
}

func dropNamespaces(ctx context.Context, client *sdk.Flipt) error {
namespaces, err := client.ListNamespaces(ctx, &flipt.ListNamespaceRequest{})
if err != nil {
return err
}

for _, ns := range namespaces.Namespaces {
if err := client.DeleteNamespace(ctx, &flipt.DeleteNamespaceRequest{
Key: ns.Key,
Force: true,
}); err != nil {
return err
}
}

_, err = client.CreateNamespace(ctx, &flipt.CreateNamespaceRequest{
Key: "default",
Name: "Default",
Description: "Default namespace",
})

return err
}