Skip to content

Commit

Permalink
Merge pull request #106 from iawia002/cancel-submit
Browse files Browse the repository at this point in the history
Add unpush subcommand to undo the submission
  • Loading branch information
iawia002 authored Aug 13, 2024
2 parents 215f39f + 1d952a4 commit 4e07c30
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Login Succeeded

### Push and submit the extension

Use the `ksbuilder push` subcommand to submit the plugin to KubeSphere Cloud. The `push` subcommand is similar to `publish` and the target can be either a directory or a packaged `.tgz` file:
Use the `ksbuilder push` subcommand to submit the extension to KubeSphere Cloud. The `push` subcommand is similar to `publish` and the target can be either a directory or a packaged `.tgz` file:

```
$ ksbuilder push tower
Expand Down Expand Up @@ -185,4 +185,26 @@ SNAPSHOT ID VERSION STATUS UPDATE TIME
515518094316217510 1.0.0 submitted 2024-05-27 09:37:05
```
### Unpush a snapshot
Use the `ksbuilder unpush` subcommand to cancel the submission of a snapshot in KubeSphere Cloud.
When we submit an extension, its snapshot status is marked as `submitted`. If we want to make some new changes to the extension at this point, we can use this command to undo the submission. After undoing, the status of the extension will revert to `draft`, allowing it to be pushed again.
To undo the submission, we first need to use the `get` subcommand to obtain the corresponding snapshot ID:
```
$ ksbuilder get tower
Name: tower
ID: 515518094316151974
Status: draft

SNAPSHOT ID VERSION STATUS UPDATE TIME
515518094316217510 1.0.0 submitted 2024-05-27 17:37:05 CST

$ ksbuilder unpush 515518094316217510
unpush snapshot 515518094316217510
Snapshot 515518094316217510 has been unsubmitted and reverted to draft state
```
Please refer to [KubeSphere extension development guide](https://dev-guide.kubesphere.io/extension-dev-guide/en/packaging-and-release/) for more details on extension packaging and releasing.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewRootCmd(version string) *cobra.Command {
cmd.AddCommand(pushCmd())
cmd.AddCommand(getCmd())
cmd.AddCommand(listCmd())
cmd.AddCommand(unpushCmd())

return cmd
}
Expand Down
38 changes: 38 additions & 0 deletions cmd/unpush.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/kubesphere/ksbuilder/pkg/cloud"
)

type unpushOptions struct{}

func unpushCmd() *cobra.Command {
o := unpushOptions{}

return &cobra.Command{
Use: "unpush",
Short: "Unpush a snapshot of an extension",
Args: cobra.ExactArgs(1),
RunE: o.unpush,
}
}

func (o *unpushOptions) unpush(_ *cobra.Command, args []string) error {
snapshot := args[0]
fmt.Printf("unpush snapshot %s\n", snapshot)

client, err := cloud.NewClient()
if err != nil {
return fmt.Errorf("login failed: %v", err)
}

if err = client.CancelSubmitExtension(snapshot); err != nil {
return err
}
fmt.Printf("Snapshot %s has been unsubmitted and reverted to draft state\n", snapshot)
return nil
}
13 changes: 13 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ func (c *Client) SubmitExtension(snapshotID string) error {
)
}

func (c *Client) CancelSubmitExtension(snapshotID string) error {
body := &bytes.Buffer{}
body.WriteString(`{"message": "cancel submit"}`)

return c.sendRequest(
http.MethodPost,
fmt.Sprintf("/apis/extension/v1/users/%s/snapshots/%s/action:cancel-submit", c.userID, snapshotID),
body,
map[string]string{"Content-Type": "application/json"},
nil,
)
}

func (c *Client) ListExtensions() (*ListExtensionsResponse, error) {
body := &bytes.Buffer{}
body.WriteString(fmt.Sprintf(`{"developer_ids": ["%s"], "statuses": ["*"]}`, c.userID))
Expand Down

0 comments on commit 4e07c30

Please sign in to comment.