Skip to content

Commit

Permalink
Fix #3838: Component is left in broken state after redeployment of th…
Browse files Browse the repository at this point in the history
…e pod (#3859)

* Add additional logic and integration test

* Respond to review comments

* Respond to review comments
  • Loading branch information
jgwest authored Sep 1, 2020
1 parent a674741 commit a7408ed
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/sync/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ func (a Adapter) SyncFiles(syncParameters common.SyncParameters) (isPushRequired
}
}

// run the indexer and find the modified/added/deleted/renamed files
// If the pod changed, reset the index, which will cause the indexer to walk the directory
// tree and resync all local files.
if syncParameters.PodChanged {
err = util.DeleteIndexFile(pushParameters.Path)
if err != nil {
return false, errors.Wrap(err, "unable to reset the index file")
}
}

// Run the indexer and find the modified/added/deleted/renamed files
ret, err = util.RunIndexer(pushParameters.Path, absIgnoreRules)
s.End(true)

Expand Down
83 changes: 82 additions & 1 deletion tests/integration/devfile/cmd_devfile_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"net/http"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"time"

"github.com/openshift/odo/pkg/util"

"github.com/openshift/odo/tests/helper"
"github.com/openshift/odo/tests/integration/devfile/utils"

Expand Down Expand Up @@ -595,6 +595,87 @@ var _ = Describe("odo devfile push command tests", func() {

})

Context("Verify files are correctly synced", func() {

// Tests https://github.com/openshift/odo/issues/3838
ensureFilesSyncedTest := func(namespace string, shouldForcePush bool) {
helper.CmdShouldPass("odo", "create", "java-springboot", "--project", namespace, cmpName)
helper.CopyExample(filepath.Join("source", "devfiles", "springboot", "project"), context)

fmt.Fprintf(GinkgoWriter, "Testing with force push %v", shouldForcePush)

// 1) Push a standard spring boot project
output := helper.CmdShouldPass("odo", "push", "--namespace", namespace)
Expect(output).To(ContainSubstring("Changes successfully pushed to component"))

// 2) Update the devfile.yaml, causing push to redeploy the component
helper.ReplaceString("devfile.yaml", "memoryLimit: 768Mi", "memoryLimit: 769Mi")
commands := []string{"push", "-v", "4", "--namespace", namespace}
if shouldForcePush {
// Test both w/ and w/o '-f'
commands = append(commands, "-f")
}

// 3) Ensure the build passes, indicating that all files were correctly synced to the new pod
output = helper.CmdShouldPass("odo", commands...)
Expect(output).To(ContainSubstring("BUILD SUCCESS"))

// 4) Acquire files from remote container, filtering out target/* and .*
podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace)
output = cliRunner.Exec(podName, namespace, "find", sourcePath)
remoteFiles := []string{}
outputArr := strings.Split(output, "\n")
for _, line := range outputArr {

if !strings.HasPrefix(line, sourcePath+"/") {
continue
}

newLine, err := filepath.Rel(sourcePath, line)
Expect(err).ToNot(HaveOccurred())

newLine = filepath.ToSlash(newLine)
if strings.HasPrefix(newLine, "target/") || newLine == "target" || strings.HasPrefix(newLine, ".") {
continue
}

remoteFiles = append(remoteFiles, newLine)
}

// 5) Acquire file from local context, filtering out .*
localFiles := []string{}
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

newPath := filepath.ToSlash(path)

if strings.HasPrefix(newPath, ".") {
return nil
}

localFiles = append(localFiles, newPath)
return nil
})
Expect(err).ToNot(HaveOccurred())

// 6) Sort and compare the local and remote files; they should match
sort.Strings(localFiles)
sort.Strings(remoteFiles)
Expect(localFiles).To(Equal(remoteFiles))
}

It("Should ensure that files are correctly synced on pod redeploy, with force push specified", func() {
ensureFilesSyncedTest(namespace, true)
})

It("Should ensure that files are correctly synced on pod redeploy, without force push specified", func() {
ensureFilesSyncedTest(namespace, false)
})

})

Context("Verify devfile volume components work", func() {

It("should error out when duplicate volume components exist", func() {
Expand Down

0 comments on commit a7408ed

Please sign in to comment.