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

subcmd/apply: Support fail-safe approach #185

Merged
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
24 changes: 22 additions & 2 deletions cmd/topicctl/subcmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type applyCmdConfig struct {
retentionDropStepDurationStr string
skipConfirm bool
sleepLoopDuration time.Duration
failFast bool

shared sharedOptions

Expand Down Expand Up @@ -105,6 +106,12 @@ func init() {
10*time.Second,
"Amount of time to wait between partition checks",
)
applyCmd.Flags().BoolVar(
&applyConfig.failFast,
"fail-fast",
true,
"Fail upon the first error encountered during apply process",
)

addSharedConfigOnlyFlags(applyCmd, &applyConfig.shared)
RootCmd.AddCommand(applyCmd)
Expand All @@ -125,6 +132,14 @@ func applyPreRun(cmd *cobra.Command, args []string) error {
return nil
}

func appendError(aggregatedErr error, err error) error {
if aggregatedErr == nil {
return err
}

return fmt.Errorf("%v\n%v", aggregatedErr, err)
}

func applyRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -138,6 +153,8 @@ func applyRun(cmd *cobra.Command, args []string) error {

// Keep a cache of the admin clients with the cluster config path as the key
adminClients := map[string]admin.Client{}
// Keep track of any errors that occur during the apply process
var errs error

defer func() {
for _, adminClient := range adminClients {
Expand All @@ -160,7 +177,10 @@ func applyRun(cmd *cobra.Command, args []string) error {
for _, match := range matches {
matchCount++
if err := applyTopic(ctx, match, adminClients); err != nil {
return err
if applyConfig.failFast {
return err
}
errs = appendError(errs, err)
}
}
}
Expand All @@ -169,7 +189,7 @@ func applyRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("No topic configs match the provided args (%+v)", args)
}

return nil
return errs
}

func applyTopic(
Expand Down
Loading