Skip to content

Commit 88a4bbb

Browse files
authored
Merge pull request #113 from lpabon/component-env
Pass env var to compoments when in kubectl mode
2 parents 2a40eaa + 0e86a72 commit 88a4bbb

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

cmd/plugin.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"syscall"
2929

3030
"github.com/portworx/pxc/pkg/config"
31+
"github.com/portworx/pxc/pkg/util"
3132
)
3233

3334
// PluginHandler is capable of parsing command line arguments
@@ -129,8 +130,11 @@ func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error {
129130
return nil
130131
}
131132

133+
// Setup environment variables
134+
envVars := append(os.Environ(), fmt.Sprintf("%s=%v", util.EvInKubectlPluginMode, util.InKubectlPluginMode()))
135+
132136
// invoke cmd binary relaying the current environment and args given
133-
if err := pluginHandler.Execute(foundBinaryPath, cmdArgs[len(remainingArgs):], os.Environ()); err != nil {
137+
if err := pluginHandler.Execute(foundBinaryPath, cmdArgs[len(remainingArgs):], envVars); err != nil {
134138
return err
135139
}
136140

pkg/util/utils.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ import (
2020
"fmt"
2121
"net"
2222
"os"
23+
"strconv"
2324
"strings"
2425
"time"
2526

2627
"github.com/asaskevich/govalidator"
2728
api "github.com/libopenstorage/openstorage-sdk-clients/sdk/golang"
2829
)
2930

31+
const (
32+
EvInKubectlPluginMode = "PXC_KUBECTL_PLUGIN_MODE"
33+
)
34+
3035
var (
3136
ErrInvalidEndpoint = errors.New("Invalid Endpoint")
3237
)
@@ -204,5 +209,9 @@ func GetAclFromString(s string) (string, api.Ownership_AccessType, error) {
204209

205210
// InKubectlPluginMode returns true if running as a plugin to kubectl
206211
func InKubectlPluginMode() bool {
207-
return strings.Contains(os.Args[0], "kubectl-pxc")
212+
envInKubectlMode := false
213+
if v, err := strconv.ParseBool(os.Getenv(EvInKubectlPluginMode)); err == nil {
214+
envInKubectlMode = v
215+
}
216+
return envInKubectlMode || strings.Contains(os.Args[0], "kubectl-pxc")
208217
}

0 commit comments

Comments
 (0)