Skip to content

Commit

Permalink
Merge 6f51b75 into 06b95fc
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l authored Jan 9, 2023
2 parents 06b95fc + 6f51b75 commit e2ef2d8
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 27 deletions.
42 changes: 42 additions & 0 deletions pkg/dev/podmandev/podmandev.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package podmandev

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"path/filepath"
"strings"

"github.com/devfile/library/pkg/devfile/parser"
"k8s.io/klog"

"github.com/redhat-developer/odo/pkg/dev"
"github.com/redhat-developer/odo/pkg/dev/common"
"github.com/redhat-developer/odo/pkg/devfile"
"github.com/redhat-developer/odo/pkg/devfile/adapters"
"github.com/redhat-developer/odo/pkg/devfile/location"
"github.com/redhat-developer/odo/pkg/exec"
"github.com/redhat-developer/odo/pkg/log"
odocontext "github.com/redhat-developer/odo/pkg/odo/context"
"github.com/redhat-developer/odo/pkg/podman"
"github.com/redhat-developer/odo/pkg/state"
Expand Down Expand Up @@ -158,6 +166,8 @@ func (o *DevClient) checkVolumesFree(pod *corev1.Pod) error {
}

func (o *DevClient) watchHandler(ctx context.Context, pushParams adapters.PushParameters, watchParams watch.WatchParameters, componentStatus *watch.ComponentStatus) error {
printWarningsOnDevfileChanges(ctx, watchParams)

startOptions := dev.StartOptions{
IgnorePaths: watchParams.FileIgnores,
Debug: watchParams.Debug,
Expand All @@ -169,3 +179,35 @@ func (o *DevClient) watchHandler(ctx context.Context, pushParams adapters.PushPa
}
return o.reconcile(ctx, watchParams.Out, watchParams.ErrOut, startOptions, componentStatus)
}

func printWarningsOnDevfileChanges(ctx context.Context, parameters watch.WatchParameters) {
var warning string
currentDevfile := odocontext.GetDevfileObj(ctx)
newDevfile, err := devfile.ParseAndValidateFromFileWithVariables(location.DevfileLocation(""), parameters.Variables)
if err != nil {
warning = fmt.Sprintf("error while reading the Devfile. Please restart 'odo dev' if you made any changes to the Devfile. Error message is: %v", err)
} else {
devfileEquals := func(d1, d2 parser.DevfileObj) (bool, error) {
// Compare two Devfile objects by comparing the result of their JSON encoding,
// because reflect.DeepEqual does not work properly with the parser.DevfileObj structure.
d1Json, jsonErr := json.Marshal(d1.Data)
if jsonErr != nil {
return false, jsonErr
}
d2Json, jsonErr := json.Marshal(d2.Data)
if jsonErr != nil {
return false, jsonErr
}
return bytes.Equal(d1Json, d2Json), nil
}
equal, eqErr := devfileEquals(*currentDevfile, newDevfile)
if eqErr != nil {
klog.V(5).Infof("error while checking if Devfile has changed: %v", eqErr)
} else if !equal {
warning = "Detected changes in the Devfile, but this is not supported yet on Podman. Please restart 'odo dev' for such changes to be applied."
}
}
if warning != "" {
log.Fwarning(parameters.Out, warning+"\n")
}
}
62 changes: 35 additions & 27 deletions tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,45 +692,53 @@ ComponentSettings:
Expect(err).ToNot(HaveOccurred())
})

if !podman {
When("modifying memoryLimit for container in Devfile", func() {
BeforeEach(func() {
src := "memoryLimit: 1024Mi"
dst := "memoryLimit: 1023Mi"
helper.ReplaceString("devfile.yaml", src, dst)
if manual {
if os.Getenv("SKIP_KEY_PRESS") == "true" {
Skip("This is a unix-terminal specific scenario, skipping")
}

devSession.PressKey('p')
When("modifying memoryLimit for container in Devfile", func() {
var stdout string
BeforeEach(func() {
src := "memoryLimit: 1024Mi"
dst := "memoryLimit: 1023Mi"
helper.ReplaceString("devfile.yaml", src, dst)
if manual {
if os.Getenv("SKIP_KEY_PRESS") == "true" {
Skip("This is a unix-terminal specific scenario, skipping")
}
var err error
_, _, ports, err = devSession.WaitSync()
Expect(err).Should(Succeed())
})

It("should expose the endpoint on localhost", func() {
devSession.PressKey('p')
}
var err error
var stdoutBytes []byte
stdoutBytes, _, ports, err = devSession.WaitSync()
Expect(err).Should(Succeed())
stdout = string(stdoutBytes)
})

It("should expose the endpoint on localhost", func() {
if podman {
By("warning users that odo dev needs to be restarted", func() {
Expect(stdout).To(ContainSubstring(
"Detected changes in the Devfile, but this is not supported yet on Podman. Please restart 'odo dev' for such changes to be applied."))
})
} else {
By("updating the pod", func() {
podName := commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project)
bufferOutput := commonVar.CliRunner.Run("get", "pods", podName, "-o", "jsonpath='{.spec.containers[0].resources.requests.memory}'").Out.Contents()
output := string(bufferOutput)
Expect(output).To(ContainSubstring("1023Mi"))
})
}

By("exposing the endpoint", func() {
url := fmt.Sprintf("http://%s", ports["3000"])
resp, err := http.Get(url)
Expect(err).ToNot(HaveOccurred())
defer resp.Body.Close()
By("exposing the endpoint", func() {
url := fmt.Sprintf("http://%s", ports["3000"])
resp, err := http.Get(url)
Expect(err).ToNot(HaveOccurred())
defer resp.Body.Close()

body, _ := io.ReadAll(resp.Body)
helper.MatchAllInOutput(string(body), []string{"Hello from Node.js Starter Application!"})
Expect(err).ToNot(HaveOccurred())
})
body, _ := io.ReadAll(resp.Body)
helper.MatchAllInOutput(string(body), []string{"Hello from Node.js Starter Application!"})
Expect(err).ToNot(HaveOccurred())
})
})
}
})
})
})

Expand Down

0 comments on commit e2ef2d8

Please sign in to comment.