Skip to content

Commit

Permalink
Merge pull request #160 from lpabon/b151
Browse files Browse the repository at this point in the history
Pass portworx-api information to components
  • Loading branch information
lpabon authored Jul 22, 2020
2 parents 62cc68c + 41e61d7 commit f4082ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
18 changes: 13 additions & 5 deletions cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error {
return nil
}

// Setup environment variables
authInfo := config.CM().GetCurrentAuthInfo()

// Get token
var err error
authInfo := config.CM().GetCurrentAuthInfo()
token := authInfo.Token
if len(authInfo.KubernetesAuthInfo.SecretName) != 0 &&
len(authInfo.KubernetesAuthInfo.SecretNamespace) != 0 {
Expand All @@ -145,8 +143,14 @@ func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error {
}
}

envVars := append(os.Environ(), fmt.Sprintf("%s=%v", util.EvInKubectlPluginMode, util.InKubectlPluginMode()))
envVars = append(envVars, fmt.Sprintf("%s=%v", util.EvPxcToken, token))
// Setup environment variables
envVars := appendToEnv(os.Environ(), util.EvInKubectlPluginMode, util.InKubectlPluginMode())
envVars = appendToEnv(envVars, util.EvPxcToken, token)

currentCluster := config.CM().GetCurrentCluster()
envVars = appendToEnv(envVars, util.EvPortworxServiceName, currentCluster.TunnelServiceName)
envVars = appendToEnv(envVars, util.EvPortworxServiceNamespace, currentCluster.TunnelServiceNamespace)
envVars = appendToEnv(envVars, util.EvPortworxServicePort, currentCluster.TunnelServicePort)

// invoke cmd binary relaying the current environment and args given
if err := pluginHandler.Execute(foundBinaryPath, cmdArgs[len(remainingArgs):], envVars); err != nil {
Expand All @@ -155,3 +159,7 @@ func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error {

return nil
}

func appendToEnv(env []string, key string, val interface{}) []string {
return append(env, fmt.Sprintf("%s=%v", key, val))
}
4 changes: 2 additions & 2 deletions component/pxctl/pxc-pxctl
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ if [ -z "$NODE" ] ; then
fi

echo ">> Running pxctl on $NODE"
pod=$(kubectl -n kube-system get pods -l name=portworx -o wide | grep "${NODE}" | awk -P '{print $1}')
kubectl -n kube-system exec -ti $pod -c portworx -- /bin/sh -c "PXCTL_AUTH_TOKEN=${PXC_TOKEN} /opt/pwx/bin/pxctl $*"
pod=$(kubectl -n ${PXC_PORTWORX_SERVICE_NAMESPACE} get pods -l name=portworx -o wide | grep "${NODE}" | awk -P '{print $1}')
kubectl -n ${PXC_PORTWORX_SERVICE_NAMESPACE} exec -ti $pod -c portworx -- /bin/sh -c "PXCTL_AUTH_TOKEN=${PXC_TOKEN} /opt/pwx/bin/pxctl $*"
7 changes: 5 additions & 2 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import (
)

const (
EvInKubectlPluginMode = "PXC_KUBECTL_PLUGIN_MODE"
EvPxcToken = "PXC_TOKEN"
EvInKubectlPluginMode = "PXC_KUBECTL_PLUGIN_MODE"
EvPxcToken = "PXC_TOKEN"
EvPortworxServiceNamespace = "PXC_PORTWORX_SERVICE_NAMESPACE"
EvPortworxServiceName = "PXC_PORTWORX_SERVICE_NAME"
EvPortworxServicePort = "PXC_PORTWORX_SERVICE_PORT"
)

var (
Expand Down

0 comments on commit f4082ce

Please sign in to comment.