-
Notifications
You must be signed in to change notification settings - Fork 1
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
DEVOPS-3141 teleport changes #118
Changes from 14 commits
d6140ae
72f0473
21a7ff4
1b406f6
cb5407d
c120737
1655be7
b7d3bd5
251215c
eee31bd
02d5ff1
959aa32
7754bc2
638338a
d78e798
66921c2
2dca9ee
966c6a7
ba06b7d
bb6f498
f746cf7
c0a911e
afc521e
f5dbf19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,17 +14,72 @@ limitations under the License. | |
package exec | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
"path/filepath" | ||
) | ||
|
||
func Exec(command []string) error { | ||
binary, err := exec.LookPath(command[0]) | ||
var ( | ||
//go:embed bin/tsh | ||
tsh []byte | ||
//go:embed bin/tsh.md5 | ||
tshMD5 string | ||
) | ||
|
||
func InstallTsh() error { | ||
executablePath, _ := os.Executable() | ||
dir, err := filepath.Abs(filepath.Dir(executablePath)) | ||
if err != nil { | ||
return err | ||
} | ||
err = syscall.Exec(binary, command, os.Environ()) | ||
// Panic rather than returning since this should never happen. | ||
panic(err) | ||
return os.WriteFile(dir+"/tsh", tsh, 0755) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might cause issue in m1 where after executing the command it just returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm.. I will check on it. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you face above issue with a binary built-for arm or x86_64? We are not planning to build an arm-based binary but relaying on rosetta to the job on m1/2 macs. 🤞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. There is no issue with x86_64. Using Rosetta would mean people will have to install it. The issue occurs on arm machines only. Even homebrew guys had to implement a workaround. Homebrew/brew@4c19d67 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or installation can be manual. Like it is done for |
||
} | ||
|
||
func GetTshMd5Hash() string { | ||
return tshMD5 | ||
} | ||
|
||
func CheckBinary(binary string) (string, bool) { | ||
binaryPath, err := exec.LookPath(binary) | ||
return binaryPath, err == nil | ||
} | ||
|
||
// ExecuteCommand uses os/exec Command fucntion to execute command, | ||
// which returns the process output/error to parent process, | ||
// If detachProcess flag set to true, then ridectl will exit with | ||
// no error irrespective of given command's exit code. | ||
func ExecuteCommand(binary string, args []string, detachProcess bool) error { | ||
binaryPath, err := exec.LookPath(binary) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c := exec.Command(binaryPath, args...) | ||
c.Stdin = os.Stdin | ||
|
||
// Execute a process by seperating it's Stderr and Stdout streams from ridectl code | ||
// Here we will just execute the command, and complete ridectl command with no error | ||
// Mainly used by "kubectl exec" and "psql" commands | ||
if detachProcess { | ||
c.Stdout = os.Stdout | ||
c.Stderr = os.Stderr | ||
_ = c.Run() | ||
return nil | ||
} | ||
|
||
// Here we will capture Stderr from given command output | ||
// Mainly used by "tsh status" and "tsh db login" commands | ||
var stderr bytes.Buffer | ||
c.Stderr = &stderr | ||
err = c.Run() | ||
if err != nil { | ||
if stderr.String() != "" { | ||
return fmt.Errorf(stderr.String()) | ||
} | ||
return fmt.Errorf("Error while executing command: %s", err.Error()) | ||
} | ||
return nil | ||
} |
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.
Instead of embedding the md5 hash file into the binary, we can set md5Sum string value at build time using -ldflags, something like shubhindia/go-m1temperature@1d0084b. Embedding the file will unnecessarily increase the overall binary size. 😁
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.
Thanks @shubhindia for suggestion, also we are already using -ldflags for version, we can use that for md5 hash too.