Skip to content

Commit

Permalink
Add devfile command flags to watch (redhat-developer#3075)
Browse files Browse the repository at this point in the history
* save non default devfile cmd in env.yaml for push and watch

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Add and update tests for envinfo

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Update watch test to incl new watch param

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* watch integration test

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Display msg when devfile commands are changed via odo push

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Change Logic for watch flag + feedback 1

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Update Watch tests with feedback

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* disable watch test on kube since we now use oc

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Watch test feedback 2

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
  • Loading branch information
maysunfaisal authored and mik-dass committed May 28, 2020
1 parent bae87ae commit 0dde0fd
Show file tree
Hide file tree
Showing 13 changed files with 548 additions and 124 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ jobs:

- <<: *base-test
stage: test
name: "docker devfile push, url, catalog, delete command integration tests"
name: "docker devfile push, watch, catalog and delete command integration tests"
script:
- make bin
- sudo cp odo /usr/bin
- travis_wait make test-cmd-docker-devfile-push
- travis_wait make test-cmd-docker-devfile-watch
- travis_wait make test-cmd-docker-devfile-catalog
- travis_wait make test-cmd-docker-devfile-delete
- travis_wait make test-cmd-docker-devfile-url
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ test-cmd-devfile-url:
test-cmd-docker-devfile-push:
ginkgo $(GINKGO_FLAGS) -focus="odo docker devfile push command tests" tests/integration/devfile/docker/

# Run odo watch docker devfile command tests
.PHONY: test-cmd-docker-devfile-watch
test-cmd-docker-devfile-watch:
ginkgo $(GINKGO_FLAGS) -focus="odo docker devfile watch command tests" tests/integration/devfile/docker/

# Run odo url docker devfile command tests
.PHONY: test-cmd-docker-devfile-url
test-cmd-docker-devfile-url:
Expand Down
2 changes: 2 additions & 0 deletions pkg/devfile/adapters/docker/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) {
if err != nil {
return errors.Wrapf(err, "Unable to process volumes for component %s", a.ComponentName)
}

a.devfileInitCmd = parameters.DevfileInitCmd
a.devfileBuildCmd = parameters.DevfileBuildCmd
a.devfileRunCmd = parameters.DevfileRunCmd

Expand Down
49 changes: 35 additions & 14 deletions pkg/envinfo/envinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@ import (
"github.com/openshift/odo/pkg/util"
)

const (
envInfoEnvName = "ENVINFO"
envInfoFileName = "env.yaml"
)

// ComponentSettings holds all component related information
type ComponentSettings struct {
Name string `yaml:"Name,omitempty"`
Namespace string `yaml:"Namespace,omitempty"`
URL *[]EnvInfoURL `yaml:"Url,omitempty"`
Name string `yaml:"Name,omitempty"`
Namespace string `yaml:"Namespace,omitempty"`
URL *[]EnvInfoURL `yaml:"Url,omitempty"`
PushCommand *EnvInfoPushCommand `yaml:"PushCommand,omitempty"`
}

// URLKind is an enum to indicate the type of the URL i.e ingress/route
type URLKind string

const (
INGRESS URLKind = "ingress"
ROUTE URLKind = "route"
DOCKER URLKind = "docker"
DOCKER URLKind = "docker"
INGRESS URLKind = "ingress"
ROUTE URLKind = "route"
envInfoEnvName = "ENVINFO"
envInfoFileName = "env.yaml"
)

// EnvInfoURL holds URL related information
Expand All @@ -44,7 +42,7 @@ type EnvInfoURL struct {
// Indicates if the URL should be a secure https one
Secure bool `yaml:"Secure,omitempty"`
// Cluster host
Host string `yaml:"host,omitempty"`
Host string `yaml:"Host,omitempty"`
// TLS secret name to create ingress to provide a secure URL
TLSSecret string `yaml:"TLSSecret,omitempty"`
// Exposed port number for docker container, required for local scenarios
Expand All @@ -53,7 +51,14 @@ type EnvInfoURL struct {
Kind URLKind `yaml:"Kind,omitempty"`
}

// EnvInfo holds all the env specific infomation relavent to a specific Component.
// EnvInfoPushCommand holds the devfile push commands for the component
type EnvInfoPushCommand struct {
Init string `yaml:"Init,omitempty"`
Build string `yaml:"Build,omitempty"`
Run string `yaml:"Run,omitempty"`
}

// EnvInfo holds all the env specific information relavent to a specific Component.
type EnvInfo struct {
componentSettings ComponentSettings `yaml:"ComponentSettings,omitempty"`
}
Expand Down Expand Up @@ -161,6 +166,9 @@ func (esi *EnvSpecificInfo) SetConfiguration(parameter string, value interface{}
} else {
esi.componentSettings.URL = &[]EnvInfoURL{urlValue}
}
case "push":
pushCommandValue := value.(EnvInfoPushCommand)
esi.componentSettings.PushCommand = &pushCommandValue
}

return esi.writeToFile()
Expand Down Expand Up @@ -266,6 +274,14 @@ func (ei *EnvInfo) GetURL() []EnvInfoURL {
return *ei.componentSettings.URL
}

// GetPushCommand returns the EnvInfoPushCommand, returns default if nil
func (ei *EnvInfo) GetPushCommand() EnvInfoPushCommand {
if ei.componentSettings.PushCommand == nil {
return EnvInfoPushCommand{}
}
return *ei.componentSettings.PushCommand
}

// GetName returns the component name
func (ei *EnvInfo) GetName() string {
if ei.componentSettings.Name == "" {
Expand All @@ -287,16 +303,21 @@ const (
Create = "CREATE"
// CreateDescription is the description of Create parameter
CreateDescription = "Create parameter is the action to write devfile metadata to env.yaml"
// URL
// URL parameter
URL = "URL"
// URLDescription is the description of URL
URLDescription = "URL to access the component"
// Push parameter
Push = "PUSH"
// PushDescription is the description of URL
PushDescription = "Push parameter is the action to write devfile commands to env.yaml"
)

var (
supportedLocalParameterDescriptions = map[string]string{
Create: CreateDescription,
URL: URLDescription,
Push: PushDescription,
}

lowerCaseLocalParameters = util.GetLowerCaseParameters(GetLocallySupportedParameters())
Expand Down
202 changes: 172 additions & 30 deletions pkg/envinfo/envinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ func TestSetEnvInfo(t *testing.T) {
testURL := EnvInfoURL{Name: "testURL", Host: "1.2.3.4.nip.io", TLSSecret: "testTLSSecret"}
invalidParam := "invalidParameter"
testCreate := ComponentSettings{Name: "componentName", Namespace: "namespace"}
testPush := EnvInfoPushCommand{Init: "myinit", Build: "myBuild", Run: "myRun"}

tests := []struct {
name string
parameter string
value interface{}
existingEnvInfo EnvInfo
expectError bool
name string
parameter string
value interface{}
existingEnvInfo EnvInfo
checkConfigSetting []string
expectError bool
}{
{
name: fmt.Sprintf("Case 1: %s to test", URL),
Expand All @@ -39,7 +41,8 @@ func TestSetEnvInfo(t *testing.T) {
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{},
},
expectError: false,
checkConfigSetting: []string{"URL"},
expectError: false,
},
{
name: fmt.Sprintf("Case 2: %s to test", invalidParam),
Expand All @@ -48,7 +51,8 @@ func TestSetEnvInfo(t *testing.T) {
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{},
},
expectError: true,
checkConfigSetting: []string{"URL"},
expectError: true,
},
{
name: "Case 3: Test fields setup from create parameter",
Expand All @@ -57,7 +61,18 @@ func TestSetEnvInfo(t *testing.T) {
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{},
},
expectError: false,
checkConfigSetting: []string{"Name", "Namespace"},
expectError: false,
},
{
name: "Case 4: Test fields setup from push parameter",
parameter: Push,
value: testPush,
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{},
},
checkConfigSetting: []string{"PushCommand"},
expectError: false,
},
}
for _, tt := range tests {
Expand All @@ -68,29 +83,15 @@ func TestSetEnvInfo(t *testing.T) {
}
esi.EnvInfo = tt.existingEnvInfo
err = esi.SetConfiguration(tt.parameter, tt.value)
if err == nil && tt.expectError {
t.Errorf("expected error for SetConfiguration with %s", tt.parameter)
} else if !tt.expectError {
if err != nil {
t.Error(err)
}

if !tt.expectError && err != nil {
t.Errorf("unexpected error for SetConfiguration with %s: %v", tt.parameter, err)
} else if !tt.expectError && err == nil {
isSet := false

if tt.parameter == Create {
parameters := []string{"Name", "Namespace"}
for _, parameter := range parameters {
isSet = esi.IsSet(parameter)
if !isSet {
t.Errorf("the '%v' is not set", parameter)
}
for _, configSetting := range tt.checkConfigSetting {
isSet = esi.IsSet(configSetting)
if !isSet {
t.Errorf("the setting '%s' is not set", configSetting)
}
} else {
isSet = esi.IsSet(tt.parameter)
}

if !isSet {
t.Errorf("the '%v' is not set", tt.parameter)
}

}
Expand Down Expand Up @@ -234,8 +235,149 @@ func TestDeleteURLFromMultipleURLs(t *testing.T) {

}

func TestGetPushCommand(t *testing.T) {
tempEnvFile, err := ioutil.TempFile("", "odoenvinfo")
if err != nil {
t.Fatal(err)
}
defer tempEnvFile.Close()
os.Setenv(envInfoEnvName, tempEnvFile.Name())

tests := []struct {
name string
existingEnvInfo EnvInfo
wantPushCommand EnvInfoPushCommand
}{
{
name: "Case 1: Init, Build & Run commands present",
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{
PushCommand: &EnvInfoPushCommand{
Init: "myinit",
Build: "mybuild",
Run: "myrun",
},
},
},
wantPushCommand: EnvInfoPushCommand{
Init: "myinit",
Run: "myrun",
Build: "mybuild",
},
},
{
name: "Case 2: Build & Run commands present",
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{
PushCommand: &EnvInfoPushCommand{
Build: "mybuild",
Run: "myrun",
},
},
},
wantPushCommand: EnvInfoPushCommand{
Run: "myrun",
Build: "mybuild",
},
},
{
name: "Case 3: Build & Init commands present",
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{
PushCommand: &EnvInfoPushCommand{
Build: "mybuild",
Init: "myinit",
},
},
},
wantPushCommand: EnvInfoPushCommand{
Init: "myinit",
Build: "mybuild",
},
},
{
name: "Case 4: Init & Run commands present",
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{
PushCommand: &EnvInfoPushCommand{
Init: "myinit",
Run: "myrun",
},
},
},
wantPushCommand: EnvInfoPushCommand{
Run: "myrun",
Init: "myinit",
},
},
{
name: "Case 5: Build command present",
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{
PushCommand: &EnvInfoPushCommand{
Build: "mybuild",
},
},
},
wantPushCommand: EnvInfoPushCommand{
Build: "mybuild",
},
},
{
name: "Case 6: Run command present",
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{
PushCommand: &EnvInfoPushCommand{
Run: "myrun",
},
},
},
wantPushCommand: EnvInfoPushCommand{
Run: "myrun",
},
},
{
name: "Case 7: Init command present",
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{
PushCommand: &EnvInfoPushCommand{
Init: "myinit",
},
},
},
wantPushCommand: EnvInfoPushCommand{
Init: "myinit",
},
},
{
name: "Case 8: No commands present",
existingEnvInfo: EnvInfo{
componentSettings: ComponentSettings{
PushCommand: &EnvInfoPushCommand{},
},
},
wantPushCommand: EnvInfoPushCommand{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
esi, err := NewEnvSpecificInfo("")
if err != nil {
t.Error(err)
}
esi.EnvInfo = tt.existingEnvInfo
pushCommand := esi.GetPushCommand()

if !reflect.DeepEqual(tt.wantPushCommand, pushCommand) {
t.Errorf("TestGetPushCommand error: push commands mismatch, expected: %v got: %v", tt.wantPushCommand, pushCommand)
}
})
}

}

func TestLowerCaseParameterForLocalParameters(t *testing.T) {
expected := map[string]bool{"create": true, "url": true}
expected := map[string]bool{"create": true, "push": true, "url": true}
actual := util.GetLowerCaseParameters(GetLocallySupportedParameters())
if !reflect.DeepEqual(expected, actual) {
t.Errorf("expected '%v', got '%v'", expected, actual)
Expand Down
Loading

0 comments on commit 0dde0fd

Please sign in to comment.