Skip to content

Commit

Permalink
Keep exec behavior via env var (#1151)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chico de Guzman <pchico83@gmail.com>
  • Loading branch information
pchico83 committed Nov 6, 2020
1 parent 2018164 commit 6feec2d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 41 deletions.
3 changes: 0 additions & 3 deletions cmd/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,6 @@ func printDisplayContext(dev *model.Dev) {
}
log.Println(fmt.Sprintf(" %s %s", log.BlueString("Namespace:"), dev.Namespace))
log.Println(fmt.Sprintf(" %s %s", log.BlueString("Name:"), dev.Name))
if dev.RemoteModeEnabled() {
log.Println(fmt.Sprintf(" %s %d -> %d", log.BlueString("SSH:"), dev.RemotePort, dev.SSHServerPort))
}

if len(dev.Forward) > 0 {
log.Println(fmt.Sprintf(" %s %d -> %d", log.BlueString("Forward:"), dev.Forward[0].Local, dev.Forward[0].Remote))
Expand Down
16 changes: 14 additions & 2 deletions pkg/k8s/deployments/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ services:
Image: "web:latest",
ImagePullPolicy: apiv1.PullAlways,
Command: []string{"/var/okteto/bin/start.sh"},
Args: []string{"-s", "remote:/remote"},
Args: []string{"-r", "-s", "remote:/remote"},
WorkingDir: "/app",
Env: []apiv1.EnvVar{
{
Expand Down Expand Up @@ -236,6 +236,12 @@ services:
MountPath: "/var/syncthing",
SubPath: model.SyncthingSubPath,
},
{
Name: dev.GetVolumeName(),
ReadOnly: false,
MountPath: model.RemoteMountPath,
SubPath: model.RemoteSubPath,
},
{
Name: dev.GetVolumeName(),
ReadOnly: false,
Expand Down Expand Up @@ -523,7 +529,7 @@ persistentVolume:
Image: "web:latest",
ImagePullPolicy: apiv1.PullAlways,
Command: []string{"/var/okteto/bin/start.sh"},
Args: []string{"-e"},
Args: []string{"-r", "-e"},
WorkingDir: "",
Env: []apiv1.EnvVar{
{
Expand All @@ -542,6 +548,12 @@ persistentVolume:
MountPath: "/var/syncthing",
SubPath: model.SyncthingSubPath,
},
{
Name: dev.GetVolumeName(),
ReadOnly: false,
MountPath: model.RemoteMountPath,
SubPath: model.RemoteSubPath,
},
{
Name: oktetoSyncSecretVolume,
ReadOnly: false,
Expand Down
23 changes: 13 additions & 10 deletions pkg/model/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ const (
SourceCodeSubPath = "src"
//OktetoSyncthingMountPath syncthing volume mount path
OktetoSyncthingMountPath = "/var/syncthing"
remoteMountPath = "/var/okteto/remote"
//RemoteMountPath remote volume mount path
RemoteMountPath = "/var/okteto/remote"
//SyncthingSubPath subpath in the development container persistent volume for the syncthing data
SyncthingSubPath = "syncthing"
remoteSubPath = "okteto-remote"
//RemoteSubPath subpath in the development container persistent volume for the remote data
RemoteSubPath = "okteto-remote"
//OktetoAutoCreateAnnotation indicates if the deployment was auto generatted by okteto up
OktetoAutoCreateAnnotation = "dev.okteto.com/auto-create"
//OktetoRestartAnnotation indicates the dev pod must be recreated to pull the latest version of its image
Expand Down Expand Up @@ -722,8 +724,8 @@ func (dev *Dev) ToTranslationRule(main *Dev) *TranslationRule {
rule.Volumes,
VolumeMount{
Name: main.GetVolumeName(),
MountPath: remoteMountPath,
SubPath: remoteSubPath,
MountPath: RemoteMountPath,
SubPath: RemoteSubPath,
},
)
}
Expand Down Expand Up @@ -839,20 +841,21 @@ func (dev *Dev) GevSandbox() *appsv1.Deployment {
// RemoteModeEnabled returns true if remote is enabled
func (dev *Dev) RemoteModeEnabled() bool {
if dev == nil {
return false
return true
}

_, ok := os.LookupEnv("OKTETO_EXECUTE_SSH")
if ok {
log.Info("execute over SSH mode enabled")
if dev.RemotePort > 0 {
return true
}

if dev.RemotePort > 0 {
if len(dev.Reverse) > 0 {
return true
}

return len(dev.Reverse) > 0
if v, ok := os.LookupEnv("OKTETO_EXECUTE_SSH"); ok && v == "false" {
return false
}
return true
}

// GetKeyName returns the secret key name
Expand Down
25 changes: 0 additions & 25 deletions pkg/model/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,31 +612,6 @@ func Test_LoadForcePull(t *testing.T) {
}
}

func TestRemoteEnabled(t *testing.T) {
var dev *Dev
if dev.RemoteModeEnabled() {
t.Errorf("nil should be remote disabled")
}

dev = &Dev{}

if dev.RemoteModeEnabled() {
t.Errorf("default should be remote disabled")
}

dev = &Dev{RemotePort: 22000}

if !dev.RemoteModeEnabled() {
t.Errorf("remote should be enabled after adding a port")
}

dev = &Dev{Reverse: []Reverse{{Local: 22000, Remote: 22000}}}

if !dev.RemoteModeEnabled() {
t.Errorf("remote should be enabled after adding a remote forward")
}
}

func Test_validate(t *testing.T) {
file, err := ioutil.TempFile("/tmp", "okteto-secret-test")
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/model/translation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ services:
Image: "web:latest",
ImagePullPolicy: apiv1.PullNever,
Command: []string{"/var/okteto/bin/start.sh"},
Args: []string{},
Args: []string{"-r"},
Healthchecks: false,
Environment: []EnvVar{
{
Expand Down Expand Up @@ -94,6 +94,11 @@ services:
MountPath: OktetoSyncthingMountPath,
SubPath: SyncthingSubPath,
},
{
Name: dev.GetVolumeName(),
MountPath: RemoteMountPath,
SubPath: RemoteSubPath,
},
{
Name: dev.GetVolumeName(),
MountPath: "/app",
Expand Down

0 comments on commit 6feec2d

Please sign in to comment.