Skip to content

Commit 41e61d7

Browse files
committed
Pass portworx-api information to components
1 parent 62cc68c commit 41e61d7

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

cmd/plugin.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,9 @@ func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error {
131131
return nil
132132
}
133133

134-
// Setup environment variables
135-
authInfo := config.CM().GetCurrentAuthInfo()
136-
137134
// Get token
138135
var err error
136+
authInfo := config.CM().GetCurrentAuthInfo()
139137
token := authInfo.Token
140138
if len(authInfo.KubernetesAuthInfo.SecretName) != 0 &&
141139
len(authInfo.KubernetesAuthInfo.SecretNamespace) != 0 {
@@ -145,8 +143,14 @@ func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error {
145143
}
146144
}
147145

148-
envVars := append(os.Environ(), fmt.Sprintf("%s=%v", util.EvInKubectlPluginMode, util.InKubectlPluginMode()))
149-
envVars = append(envVars, fmt.Sprintf("%s=%v", util.EvPxcToken, token))
146+
// Setup environment variables
147+
envVars := appendToEnv(os.Environ(), util.EvInKubectlPluginMode, util.InKubectlPluginMode())
148+
envVars = appendToEnv(envVars, util.EvPxcToken, token)
149+
150+
currentCluster := config.CM().GetCurrentCluster()
151+
envVars = appendToEnv(envVars, util.EvPortworxServiceName, currentCluster.TunnelServiceName)
152+
envVars = appendToEnv(envVars, util.EvPortworxServiceNamespace, currentCluster.TunnelServiceNamespace)
153+
envVars = appendToEnv(envVars, util.EvPortworxServicePort, currentCluster.TunnelServicePort)
150154

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

156160
return nil
157161
}
162+
163+
func appendToEnv(env []string, key string, val interface{}) []string {
164+
return append(env, fmt.Sprintf("%s=%v", key, val))
165+
}

component/pxctl/pxc-pxctl

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ if [ -z "$NODE" ] ; then
4848
fi
4949

5050
echo ">> Running pxctl on $NODE"
51-
pod=$(kubectl -n kube-system get pods -l name=portworx -o wide | grep "${NODE}" | awk -P '{print $1}')
52-
kubectl -n kube-system exec -ti $pod -c portworx -- /bin/sh -c "PXCTL_AUTH_TOKEN=${PXC_TOKEN} /opt/pwx/bin/pxctl $*"
51+
pod=$(kubectl -n ${PXC_PORTWORX_SERVICE_NAMESPACE} get pods -l name=portworx -o wide | grep "${NODE}" | awk -P '{print $1}')
52+
kubectl -n ${PXC_PORTWORX_SERVICE_NAMESPACE} exec -ti $pod -c portworx -- /bin/sh -c "PXCTL_AUTH_TOKEN=${PXC_TOKEN} /opt/pwx/bin/pxctl $*"

pkg/util/utils.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ import (
2929
)
3030

3131
const (
32-
EvInKubectlPluginMode = "PXC_KUBECTL_PLUGIN_MODE"
33-
EvPxcToken = "PXC_TOKEN"
32+
EvInKubectlPluginMode = "PXC_KUBECTL_PLUGIN_MODE"
33+
EvPxcToken = "PXC_TOKEN"
34+
EvPortworxServiceNamespace = "PXC_PORTWORX_SERVICE_NAMESPACE"
35+
EvPortworxServiceName = "PXC_PORTWORX_SERVICE_NAME"
36+
EvPortworxServicePort = "PXC_PORTWORX_SERVICE_PORT"
3437
)
3538

3639
var (

0 commit comments

Comments
 (0)