Skip to content

Add k6 cloud project and k6 cloud project list commands#5650

Open
oleiade wants to merge 1 commit intomasterfrom
feat/cloud-project-list
Open

Add k6 cloud project and k6 cloud project list commands#5650
oleiade wants to merge 1 commit intomasterfrom
feat/cloud-project-list

Conversation

@oleiade
Copy link
Copy Markdown
Contributor

@oleiade oleiade commented Feb 12, 2026

What?

This pull request introduces a new cloud project command group to the CLI, with a k6 cloud project list subcommand allowing users to list their Grafana Cloud k6 projects. It adds the implementation, command wiring, output formatting (including JSON support), and comprehensive tests for the new functionality.

CleanShot 2026-02-13 at 08 50 19 CleanShot 2026-02-13 at 08 51 00

Why?

As per #5644.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

#5644

@oleiade oleiade added this to the v1.7.0 milestone Feb 12, 2026
@oleiade oleiade self-assigned this Feb 12, 2026
@oleiade oleiade requested a review from a team as a code owner February 12, 2026 09:52
@oleiade oleiade requested review from inancgumus and mstoykov and removed request for a team February 12, 2026 09:52
@oleiade oleiade changed the title feat: add k6 cloud project, and k6 cloud project list commands Add k6 cloud project and k6 cloud project list commands Feb 12, 2026
@oleiade oleiade requested a review from AgnesToulet February 12, 2026 09:54
@oleiade
Copy link
Copy Markdown
Contributor Author

oleiade commented Feb 12, 2026

Adding you as a reviewer @AgnesToulet as you've been working actively on this recently 🙇🏻

@oleiade oleiade temporarily deployed to azure-trusted-signing February 12, 2026 10:00 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing February 12, 2026 10:02 — with GitHub Actions Inactive
@oleiade oleiade force-pushed the feat/cloud-project-list branch from 8773e25 to 021ae2f Compare February 12, 2026 10:30
@oleiade oleiade temporarily deployed to azure-trusted-signing February 12, 2026 10:37 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing February 12, 2026 10:39 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing February 12, 2026 14:58 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing February 12, 2026 15:01 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing February 13, 2026 08:01 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing February 13, 2026 08:04 — with GitHub Actions Inactive
return c.outputJSON(resp.Value)
}

stackHeader := fmt.Sprintf("Projects for stack %d:\n\n", cloudConfig.StackID.Int64)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think if we have the StackURL field non-empty, we should use it instead of the stack ID (but it might be empty).

Comment on lines +76 to +78
return errors.New(
"no stack configured. Please run `k6 cloud login --stack <your-stack>` to set a default stack",
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be worth creating a constant for this error, we'll probably use it a lot in other parts of the codebase in the future.

Copy link
Copy Markdown
Contributor

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@joanlopez
Copy link
Copy Markdown
Contributor

Moving it to the next milestone to unlock the ongoing release process.

@mstoykov mstoykov force-pushed the feat/cloud-project-list branch from b1a3519 to 54a482d Compare April 16, 2026 09:30
@mstoykov
Copy link
Copy Markdown
Contributor

@oleiade it seems that this needs some updates 😬

t.Parallel()

srv := mockProjectListServer(t)
defer srv.Close()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this should be within a t.Cleanup(...), and perhaps, that could even be called inside mockProjectListServer, as it already receives t, and so this way no caller will ever forget to do so.

Wdyt?

listCmd.SetUsageTemplate(defaultUsageTemplate)
cloudProjectCommand.AddCommand(listCmd)

cloudProjectCommand.SetUsageTemplate(`Usage:
Copy link
Copy Markdown
Contributor

@joanlopez joanlopez Apr 16, 2026

Choose a reason for hiding this comment

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

I see the list command help is convoluted, would make sense to use something like this there as well? I'm wondering if we should even define this as a function/const to be reused more widely.

Comment on lines +49 to +53
if !checkIfMigrationCompleted(c.globalState) {
if err := migrateLegacyConfigFileIfAny(c.globalState); err != nil {
return err
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally, I'd prefer if we could do this in a single place. If not, it's okay.

I haven't digged into Cobra details since a while ago, so I forgot almost all my knowledge about it, but I was wondering if there's a way so any k6 cloud ... command executes this code, as a "pre-run" or something like that, but defined in a single place. Would that make sense? Not sure if possible, tho.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess the same reasoning could apply to the lines below, again, if possible, as ideally I'd like to not end up with the same code in ~20 places if we start adding support for more project operations or support for other types of resources (e.g., load tests).

if len(resp.Value) == 0 {
printToStdout(c.globalState, stackHeader+
"No projects found.\n"+
"To create a project, visit https://grafana.com/docs/grafana-cloud/testing/k6/projects/\n")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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


if !cloudConfig.StackID.Valid || cloudConfig.StackID.Int64 == 0 {
return errors.New(
"no stack configured. Please run `k6 cloud login --stack <your-stack>` to set a default stack",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this suggestion is no longer consistent with #5833
cc/ @codebien

In other words; if I run this k6 cloud login --stack <your-stack>, it will throw an error, so it's better if we suggest something that will work from the first attempt.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"no stack configured. Please run `k6 cloud login --stack <your-stack>` to set a default stack",
"no stack configured. Please run `k6 cloud login` to set a default stack",

I agree. We should just suggest k6 cloud login. However, we already have this logic for checking the user session. We should reuse that logic from a shared place so we don't reinvent the wheel here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants