-
Notifications
You must be signed in to change notification settings - Fork 0
Implement 'roxie shell' command for (re-)connecting to central deployment #201
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
mclasmeier
wants to merge
15
commits into
main
Choose a base branch
from
mc/resume
base: main
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
15 commits
Select commit
Hold shift + click to select a range
4d164d9
Move CentralDeploymentInfo to types
dc73a00
Wire new shell command
7cd9169
Type definitions for RoxieEnvironment
2eccf1f
types.CentralDeploymentInfo
0264601
CentralDeploymentInfo: Include username
4e6e23b
Populate username in CentralDeploymentInfo
873f263
New package for assembling roxie environments
1c4c017
New package for managing roxie manifests
38a8c66
Cleanup roxie manifest on teardown
8740688
Use new AssembleRoxieEnvironment for setting up environment
004f44e
Use new AssembleRoxieEnvironment for setting up post-deployment sub-s…
0ac32d3
Use new spawnSubShellForDeployerEnv function
059c3e3
Use new roxieenv.AssembleRoxieEnvironment function for assembling env…
ae91183
New shell command
1560e3e
Print error
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
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,88 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "time" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/stackrox/roxie/internal/env" | ||
| "github.com/stackrox/roxie/internal/logger" | ||
| "github.com/stackrox/roxie/internal/manifest" | ||
| ) | ||
|
|
||
| func newShellCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "shell [-- command [args...]]", | ||
| Short: "Open a subshell for an existing ACS Central deployment", | ||
| Long: `Open an interactive subshell with ACS environment variables | ||
| set for an existing ACS Central deployment. | ||
|
|
||
| This command reads the roxie manifest secret from the cluster, | ||
| re-fetches the CA certificate, and spawns an interactive subshell | ||
| with the environment variables set. | ||
|
|
||
| If a command is given after "--", it is executed in the modified environment | ||
| instead of spawning a subshell. | ||
|
|
||
| Examples: | ||
| roxie shell | ||
| roxie shell -- roxctl central whoami | ||
| roxie shell -- bash -c 'echo $ROX_ENDPOINT'`, | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| err := runShell(cmd, args) | ||
| if err != nil { | ||
| if exitErr, ok := errors.AsType[*exec.ExitError](err); ok { | ||
| // Propagate exit error from the child process. | ||
| os.Exit(exitErr.ExitCode()) | ||
| } | ||
| cmd.PrintErrln(err) | ||
| os.Exit(1) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| }, | ||
| DisableFlagParsing: false, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&shell, "shell", "", "Shell to spawn") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runShell(cmd *cobra.Command, args []string) error { | ||
| log := logger.New() | ||
| if err := env.Initialize(log); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if os.Getenv("ROXIE_SHELL") != "" { | ||
| return errors.New("already in a roxie sub-shell (ROXIE_SHELL environment variable is set), please exit the shell and try again") | ||
| } | ||
|
|
||
| log.Info("Loading manifest from cluster...") | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) | ||
| defer cancel() | ||
|
|
||
| m, err := manifest.LoadManifestSecret(ctx, log) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load roxie manifest: %w", err) | ||
| } | ||
| log.Dim("roxie manifest loaded") | ||
|
|
||
| // We need this for the setup of the CA cert. | ||
| tempDir, err := os.MkdirTemp("", "roxie-shell-*") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create temp dir: %w", err) | ||
| } | ||
| defer os.RemoveAll(tempDir) | ||
|
|
||
| centralDeploymentInfo, err := manifest.ManifestToCentralDeploymentInfo(ctx, log, tempDir, m) | ||
| if err != nil { | ||
| return fmt.Errorf("extracting central deployment info from manifest: %w", err) | ||
| } | ||
|
|
||
| return runCommandOrSubshell(centralDeploymentInfo, log, args) | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.