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

feat: adds support for migrations #14

Merged
merged 5 commits into from
Aug 22, 2024
Merged

feat: adds support for migrations #14

merged 5 commits into from
Aug 22, 2024

Conversation

gene-redpanda
Copy link
Member

@gene-redpanda gene-redpanda commented Aug 22, 2024

Adds support for migrations to the admin api

// ExecuteMigration executes a specific action on a migration identified by its ID. The action must be one of:
// prepare, execute, finish, cancel.
func (a *AdminAPI) ExecuteMigration(ctx context.Context, id int, action string) error {
validActions := map[string]bool{
Copy link
Member

@bojand bojand Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be just a single var declared outside of the method?

Also minor nit / optimization might be to use the empty struct for the values as it caries 0 size.

var validActions = map[string]struct{}{
	"prepare": struct{}{},
	"execute": struct{}{},
	"finish":  struct{}{},
	"cancel":  struct{}{},
}

and then the check can be something like:

if _, valid := validActions[action]; !valid {
	// ...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only used in one place so I felt like that was the right place to declare it. I can change it if needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup tradeoffs. I don't feel strongly about it either way.

@bojand
Copy link
Member

bojand commented Aug 22, 2024

The golangci-lint timeout is due to 1.23 Go usage and golangci-lint being an older version. We need to update the golangci-lint action and go version used for linting.

@gene-redpanda
Copy link
Member Author

@bojand I cleaned up the linter CI setup some

@gene-redpanda gene-redpanda merged commit b4a4c04 into main Aug 22, 2024
1 of 2 checks passed
@gene-redpanda gene-redpanda deleted the add-migrations branch August 22, 2024 17:18
Copy link
Contributor

@r-vasquez r-vasquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments

btw, how did GH let us merge this one with a linter failure? https://github.com/redpanda-data/common-go/actions/runs/10511516964/job/29122660139 🤔

Comment on lines +23 to +25
// AddMigration adds a migration to the cluster. It accepts one of InboundMigration or OutboundMigration.
func (a *AdminAPI) AddMigration(ctx context.Context, migration any) (int, error) {
migrationType := reflect.TypeOf(migration)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid having any in the input, what do you think of splitting the AddMigration to AddInboudMigration and AddOutbountMigration. It's easier for the caller to figure the usage.

with:
version: v1.56
version: v1.60.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseMigrationEndpoint = "/v1/migrations/"
)

// AddMigration adds a migration to the cluster. It accepts one of InboundMigration or OutboundMigration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document what is the integer in the response means to the end user?

Comment on lines +30 to +34
var response AddMigrationResponse
if err := a.sendOne(ctx, http.MethodPut, baseMigrationEndpoint, migration, &response, false); err != nil {
return -1, err
}
return response.ID, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return the response.ID and not the AddMigrationResponse? it will be better if we return the struct if more information gets added to the response in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants