@@ -46,7 +46,7 @@ func Mount(namespace, pvcName, localMountPoint string) error {
46
46
return err
47
47
}
48
48
49
- podName , port , err := setupPod (clientset , namespace , pvcName , sshKey )
49
+ podName , port , err := setupPod (clientset , namespace , pvcName , sshKey , "standalone" )
50
50
if err != nil {
51
51
return err
52
52
}
@@ -115,9 +115,9 @@ func checkPVCUsage(clientset *kubernetes.Clientset, namespace, pvcName string) (
115
115
return pvc , nil
116
116
}
117
117
118
- func setupPod (clientset * kubernetes.Clientset , namespace , pvcName , sshKey string ) (string , int , error ) {
118
+ func setupPod (clientset * kubernetes.Clientset , namespace , pvcName , sshKey , role string ) (string , int , error ) {
119
119
podName , port := generatePodNameAndPort (pvcName )
120
- pod := createPodSpec (podName , port , pvcName , sshKey )
120
+ pod := createPodSpec (podName , port , pvcName , sshKey , role )
121
121
if _ , err := clientset .CoreV1 ().Pods (namespace ).Create (context .TODO (), pod , metav1.CreateOptions {}); err != nil {
122
122
return "" , 0 , fmt .Errorf ("failed to create pod: %v" , err )
123
123
}
@@ -141,7 +141,7 @@ func waitForPodReady(clientset *kubernetes.Clientset, namespace, podName string)
141
141
}
142
142
143
143
func setupPortForwarding (namespace , podName string , port int ) error {
144
- cmd := exec .Command ("kubectl" , "port-forward" , fmt .Sprintf ("pod/%s" , podName ), fmt .Sprintf ("%d:22 " , port ), "-n" , namespace )
144
+ cmd := exec .Command ("kubectl" , "port-forward" , fmt .Sprintf ("pod/%s" , podName ), fmt .Sprintf ("%d:2137 " , port ), "-n" , namespace )
145
145
cmd .Stdout = os .Stdout
146
146
cmd .Stderr = os .Stderr
147
147
if err := cmd .Start (); err != nil {
@@ -170,7 +170,22 @@ func generatePodNameAndPort(pvcName string) (string, int) {
170
170
return podName , port
171
171
}
172
172
173
- func createPodSpec (podName string , port int , pvcName , sshKey string ) * corev1.Pod {
173
+ func createPodSpec (podName string , port int , pvcName , sshKey , role string ) * corev1.Pod {
174
+ envVars := []corev1.EnvVar {
175
+ {
176
+ Name : "SSH_KEY" ,
177
+ Value : sshKey ,
178
+ },
179
+ }
180
+
181
+ // Add the ROLE environment variable if the role is "standalone"
182
+ if role == "standalone" {
183
+ envVars = append (envVars , corev1.EnvVar {
184
+ Name : "ROLE" ,
185
+ Value : "standalone" ,
186
+ })
187
+ }
188
+
174
189
return & corev1.Pod {
175
190
ObjectMeta : metav1.ObjectMeta {
176
191
Name : podName ,
@@ -187,7 +202,7 @@ func createPodSpec(podName string, port int, pvcName, sshKey string) *corev1.Pod
187
202
Image : "bfenski/volume-exposer:latest" ,
188
203
Ports : []corev1.ContainerPort {
189
204
{
190
- ContainerPort : 22 ,
205
+ ContainerPort : 2137 ,
191
206
},
192
207
},
193
208
VolumeMounts : []corev1.VolumeMount {
@@ -196,12 +211,7 @@ func createPodSpec(podName string, port int, pvcName, sshKey string) *corev1.Pod
196
211
Name : "my-pvc" ,
197
212
},
198
213
},
199
- Env : []corev1.EnvVar {
200
- {
201
- Name : "SSH_KEY" ,
202
- Value : sshKey ,
203
- },
204
- },
214
+ Env : envVars ,
205
215
},
206
216
},
207
217
Volumes : []corev1.Volume {
0 commit comments