-
Notifications
You must be signed in to change notification settings - Fork 84
feat(cli): add okactl command-line tool for sandbox operations #497
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
Open
Liquorice-Ma
wants to merge
10
commits into
openkruise:master
Choose a base branch
from
Liquorice-Ma:agents-cli
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4405ca1
add okactl command-line tool for sandbox operations
06fdf31
feat(cli): add set image status subcommand with auto-diagnosis for Sa…
23fe627
feat(cli): add okactl create suo command for batch sandbox image updates
f891ec2
test(e2e): add okactl CLI end-to-end tests with GitHub Actions workflow
cca229d
feat(cli): add okactl status command with short name aliases and help…
b5eaf4f
fix:okactl binary version
7d8aa63
chore: remove okactl binary from repo, add to .gitignore
b4a4e7b
Addressed 6 review comments, 1 remaining.
af064e3
Fix 4 remaining review issues from 20260615 and 20260616 proposals
2146550
fix 16 inline comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: E2E-okactl | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - release-* | ||
| pull_request: {} | ||
| workflow_dispatch: {} | ||
|
|
||
| # Declare default permissions as read only. | ||
| permissions: read-all | ||
|
|
||
| env: | ||
| # Common versions | ||
| GO_VERSION: '1.23' | ||
| KIND_VERSION: 'v0.22.0' | ||
| KIND_IMAGE: 'kindest/node:v1.32.0' | ||
| KIND_CLUSTER_NAME: 'ci-testing' | ||
|
|
||
| jobs: | ||
| okactl: | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| submodules: true | ||
| - name: Setup Go | ||
| uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| - name: Setup Kind Cluster | ||
| uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0 | ||
| with: | ||
| node_image: ${{ env.KIND_IMAGE }} | ||
| cluster_name: ${{ env.KIND_CLUSTER_NAME }} | ||
| config: ./test/kind-conf.yaml | ||
| version: ${{ env.KIND_VERSION }} | ||
| - name: Build controller image | ||
| run: | | ||
| export IMAGE="agent-sandbox-controller:latest" | ||
| docker build -f dockerfiles/agent-sandbox-controller.Dockerfile --pull --no-cache . -t $IMAGE | ||
| kind load docker-image --name=${KIND_CLUSTER_NAME} $IMAGE || { echo >&2 "kind not installed or error loading image: $IMAGE"; exit 1; } | ||
| - name: Install Kruise Agents | ||
| run: | | ||
| CONTROLLER_IMG=agent-sandbox-controller:latest make deploy-agent-sandbox-controller | ||
| bash hack/wait-agent-sandbox-controller.sh | ||
| - name: Install OpenKruise CRDs | ||
| run: | | ||
| # Install the ContainerRecreateRequest CRD so okactl restart can be tested | ||
| kubectl apply -f https://raw.githubusercontent.com/openkruise/kruise/master/config/crd/bases/apps.kruise.io_containerrecreaterequests.yaml || true | ||
| - name: Build okactl | ||
| run: | | ||
| make build-okactl | ||
| echo "$(pwd)/bin" >> $GITHUB_PATH | ||
| - name: Run okactl E2E Tests | ||
| run: | | ||
| export KUBECONFIG=/home/runner/.kube/config | ||
| export OKACTL_BIN=$(pwd)/bin/okactl | ||
| make ginkgo | ||
| ./bin/ginkgo -timeout 10m -v --fail-fast --focus='okactl CLI' test/e2e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| Copyright 2026. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/openkruise/agents/pkg/cli" | ||
| ) | ||
|
|
||
| // usageTemplate is a custom cobra usage template that displays subcommand aliases. | ||
| // It is based on cobra's defaultUsageTemplate with alias support added to the | ||
| // Available Commands sections. | ||
| const usageTemplate = `Usage:{{if .Runnable}} | ||
| {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} | ||
| {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}} | ||
|
|
||
| Aliases: | ||
| {{.NameAndAliases}}{{end}}{{if .HasExample}} | ||
|
|
||
| Examples: | ||
| {{.Example}}{{end}}{{if .HasAvailableSubCommands}}{{$cmds := .Commands}}{{if eq (len .Groups) 0}} | ||
|
|
||
| Available Commands:{{range $cmds}}{{if (or .IsAvailableCommand (eq .Name "help"))}} | ||
| {{rpad .Name .NamePadding }}{{if .Aliases}} ({{join .Aliases ", "}}){{end}} {{.Short}}{{end}}{{end}}{{else}}{{range $group := .Groups}} | ||
|
|
||
| {{.Title}}{{range $cmds}}{{if (and (eq .GroupID $group.ID) (or .IsAvailableCommand (eq .Name "help")))}} | ||
| {{rpad .Name .NamePadding }}{{if .Aliases}} ({{join .Aliases ", "}}){{end}} {{.Short}}{{end}}{{end}}{{end}}{{if not .AllChildCommandsHaveGroup}} | ||
|
|
||
| Additional Commands:{{range $cmds}}{{if (and (eq .GroupID "") (or .IsAvailableCommand (eq .Name "help")))}} | ||
| {{rpad .Name .NamePadding }}{{if .Aliases}} ({{join .Aliases ", "}}){{end}} {{.Short}}{{end}}{{end}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} | ||
|
|
||
| Flags: | ||
| {{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} | ||
|
|
||
| Global Flags: | ||
| {{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}} | ||
|
|
||
| Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} | ||
| {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}} | ||
|
|
||
| Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}} | ||
| ` | ||
|
|
||
| func main() { | ||
| const ( | ||
| groupResource = "resource" | ||
| groupOther = "other" | ||
| ) | ||
|
|
||
| globalOpts := cli.NewGlobalOptions() | ||
|
|
||
| root := &cobra.Command{ | ||
| Use: "okactl", | ||
| Short: "okactl controls the OpenKruise Agents sandbox cluster", | ||
| Long: `okactl controls the OpenKruise Agents sandbox cluster. | ||
|
|
||
| Find more information at: https://github.com/openkruise/agents`, | ||
| SilenceUsage: true, | ||
| SilenceErrors: true, | ||
| } | ||
|
|
||
| globalOpts.AddFlags(root.PersistentFlags()) | ||
|
|
||
| root.AddGroup(&cobra.Group{ID: groupResource, Title: "Resource Commands:"}) | ||
| root.AddGroup(&cobra.Group{ID: groupOther, Title: "Other Commands:"}) | ||
|
|
||
| // Register custom template functions and customize usage template to show | ||
| // subcommand aliases in the Available Commands list. | ||
| cobra.AddTemplateFunc("join", strings.Join) | ||
| root.SetUsageTemplate(usageTemplate) | ||
|
|
||
| scaleCmd := cli.NewScaleCommand(globalOpts) | ||
| scaleCmd.GroupID = groupResource | ||
| setCmd := cli.NewSetCommand(globalOpts) | ||
| setCmd.GroupID = groupResource | ||
| restartCmd := cli.NewRestartCommand(globalOpts) | ||
| restartCmd.GroupID = groupResource | ||
| createCmd := cli.NewCreateCommand(globalOpts) | ||
| createCmd.GroupID = groupResource | ||
| statusCmd := cli.NewStatusCommand(globalOpts) | ||
| statusCmd.GroupID = groupResource | ||
|
|
||
| root.AddCommand(scaleCmd, setCmd, restartCmd, createCmd, statusCmd) | ||
|
|
||
| // Assign group ID to auto-generated commands (completion, help) | ||
| for _, cmd := range root.Commands() { | ||
| if cmd.GroupID == "" { | ||
| cmd.GroupID = groupOther | ||
| } | ||
| } | ||
|
|
||
| if err := root.Execute(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description is severely outdated and does not match the actual implementation.
The PR description mentions:
agent-cli→ Actual:okactlcmd/agent-cli/→ Actual:cmd/okactl/SandboxContainerRestart(scr) → Actual: uses OpenKruiseContainerRecreateRequest(CRR), no new CRDpkg/controller/sandboxcontainerrestart/→ Actual: no new controller.gitignoreaddedPlease update the PR description to accurately reflect the current implementation.