-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
odo dev store information about currently forwarded ports (#5703)
* Save state (forwarded ports + PID + timestamp) to local file and cleanup * Integration tests * Documentation * Update docs/website/versioned_docs/version-3.0.0/command-reference/dev.md Co-authored-by: Armel Soro <armel@rm3l.org> * Fail when an error happens writing state file In case of error during initialization, odo dev cleanup the resources * Fix typo * Test localPort matches a number * Remove PID and timestamp from state + rename to devstate.json * Run IBM cloud tests as non root * Fix doc * Review * Remove reference to PID/timestamp from doc Co-authored-by: Armel Soro <armel@rm3l.org>
- Loading branch information
Showing
18 changed files
with
491 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dev | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/redhat-developer/odo/pkg/api" | ||
) | ||
|
||
func Test_getForwardedPort(t *testing.T) { | ||
type args struct { | ||
mapping map[string][]int | ||
s string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want api.ForwardedPort | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "find port in container", | ||
args: args{ | ||
mapping: map[string][]int{ | ||
"container1": {3000, 4200}, | ||
"container2": {80, 8080}, | ||
}, | ||
s: "Forwarding from 127.0.0.1:40407 -> 3000", | ||
}, | ||
want: api.ForwardedPort{ | ||
ContainerName: "container1", | ||
LocalAddress: "127.0.0.1", | ||
LocalPort: 40407, | ||
ContainerPort: 3000, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "string error", | ||
args: args{ | ||
mapping: map[string][]int{ | ||
"container1": {3000, 4200}, | ||
"container2": {80, 8080}, | ||
}, | ||
s: "Forwarding from 127.0.0.1:40407 => 3000", | ||
}, | ||
want: api.ForwardedPort{}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := getForwardedPort(tt.args.mapping, tt.args.s) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("getForwardedPort() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("getForwardedPort() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package state | ||
|
||
const _filepath = "./.odo/devstate.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package state gives access to the state of the odo process stored in a local file | ||
package state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package state | ||
|
||
import "github.com/redhat-developer/odo/pkg/api" | ||
|
||
type Client interface { | ||
// SetForwardedPorts sets the forwarded ports in the state file and saves it to the file, updating the metadata | ||
SetForwardedPorts(fwPorts []api.ForwardedPort) error | ||
|
||
// SaveExit resets the state file to indicate odo is not running | ||
SaveExit() error | ||
} |
Oops, something went wrong.