Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File sync for devfiles #2681

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c6485ff
Implement devfile syncing on odo push
johnmcollier Mar 4, 2020
98f4c23
Add test for GetRemoteFilesMarkedForDeletion
johnmcollier Mar 4, 2020
0888d70
Properly retrieve sourcePath
johnmcollier Mar 5, 2020
19f0359
Don't push if not needed to
johnmcollier Mar 5, 2020
c017d17
Remove duplicate WaitAndGetPod
johnmcollier Mar 5, 2020
49a620a
Use odo volume constants
johnmcollier Mar 5, 2020
b33cea8
Fix race condition (oops)
johnmcollier Mar 5, 2020
fe7ba17
Fix gosec errors
johnmcollier Mar 5, 2020
a49eadf
Add namespace flag to odo push
johnmcollier Mar 6, 2020
48999ab
Implement integration tests for odo push
johnmcollier Mar 6, 2020
9e593e5
Address review comments on tests
johnmcollier Mar 6, 2020
5f5f59f
Remove duplicated preferences lines
johnmcollier Mar 6, 2020
ec8a692
Merge branch 'master' of github.com:openshift/odo into DevfileSyncing
johnmcollier Mar 10, 2020
03acdfb
Address review comments
johnmcollier Mar 10, 2020
1994334
Fix unit test
johnmcollier Mar 10, 2020
2625db8
Merge branch 'master' of github.com:openshift/odo into DevfileSyncing
johnmcollier Mar 11, 2020
fcd0c07
Address review comments
johnmcollier Mar 11, 2020
3364a1b
Fix rebase
johnmcollier Mar 11, 2020
fbdfc0d
Properly return error if sync fails
johnmcollier Mar 11, 2020
1c2a1fb
Sync to `/projects/<projectName>` when needed
johnmcollier Mar 11, 2020
b6b7e10
Fix unit tests
johnmcollier Mar 11, 2020
c0005c0
Remove debugging line
johnmcollier Mar 11, 2020
a010475
Add more unit tests for functions in pushlocal
johnmcollier Mar 12, 2020
f0fedb9
Add comments
johnmcollier Mar 12, 2020
18ac435
Fix test on Windows
johnmcollier Mar 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:

- <<: *base-test
stage: test
name: "watch, storage, app, project and push command integration tests"
name: "watch, storage, app, project, push, and devfile push command integration tests"
script:
- ./scripts/oc-cluster.sh
- make bin
Expand All @@ -116,6 +116,7 @@ jobs:
- travis_wait make test-cmd-app
- travis_wait make test-cmd-push
- travis_wait make test-cmd-project
- travis_wait make test-cmd-devfile-push
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1,
FYI - Travis job runs test on 3.11 cluster

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the name: field accordingly. For example

name: "watch, storage, app, project, push and devfile push command integration tests"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, updated!

- odo logout

- <<: *base-test
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ test-cmd-pref-config:
test-cmd-push:
ginkgo $(GINKGO_FLAGS) -focus="odo push command tests" tests/integration/

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

# Run odo storage command tests
.PHONY: test-cmd-storage
test-cmd-storage:
Expand Down
19 changes: 1 addition & 18 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func PushLocal(client *occlient.Client, componentName string, applicationName st
glog.V(4).Infof("PushLocal: componentName: %s, applicationName: %s, path: %s, files: %s, delFiles: %s, isForcePush: %+v", componentName, applicationName, path, files, delFiles, isForcePush)

// Edge case: check to see that the path is NOT empty.
emptyDir, err := isEmpty(path)
emptyDir, err := util.IsEmpty(path)
if err != nil {
return errors.Wrapf(err, "Unable to check directory: %s", path)
} else if emptyDir {
Expand Down Expand Up @@ -1455,23 +1455,6 @@ func GetMachineReadableFormatForList(components []Component) ComponentList {

}

// isEmpty checks to see if a directory is empty
// shamelessly taken from: https://stackoverflow.com/questions/30697324/how-to-check-if-directory-on-path-is-empty
// this helps detect any edge cases where an empty directory is copied over
func isEmpty(name string) (bool, error) {
f, err := os.Open(name)
if err != nil {
return false, err
}
defer f.Close() // #nosec G307

_, err = f.Readdirnames(1) // Or f.Readdir(1)
if err == io.EOF {
return true, nil
}
return false, err // Either not empty or error, suits both cases
}

// getStorageFromConfig gets all the storage from the config
// returns a list of storage in storage struct format
func getStorageFromConfig(localConfig *config.LocalConfigInfo) storage.StorageList {
Expand Down
4 changes: 2 additions & 2 deletions pkg/devfile/adapters/common/interface.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package common

// ComponentAdapter defines the component functions that platform-specific adapters must implement
// ComponentAdapter defines the functions that platform-specific adapters must implement
type ComponentAdapter interface {
Create() error
Push(path string, ignoredFiles []string, forceBuild bool, globExps []string) error
}

// StorageAdapter defines the storage functions that platform-specific adapters must implement
Expand Down
17 changes: 14 additions & 3 deletions pkg/devfile/adapters/helper.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package adapters

import (
"fmt"

"github.com/openshift/odo/pkg/devfile"
"github.com/openshift/odo/pkg/devfile/adapters/common"
"github.com/openshift/odo/pkg/devfile/adapters/kubernetes"
"github.com/openshift/odo/pkg/kclient"
)

// NewPlatformAdapter returns a Devfile adapter for the targeted platform
func NewPlatformAdapter(componentName string, devObj devfile.DevfileObj) (PlatformAdapter, error) {
func NewPlatformAdapter(componentName string, devObj devfile.DevfileObj, platformContext interface{}) (PlatformAdapter, error) {

adapterContext := common.AdapterContext{
ComponentName: componentName,
Expand All @@ -17,14 +19,23 @@ func NewPlatformAdapter(componentName string, devObj devfile.DevfileObj) (Platfo

// Only the kubernetes adapter is implemented at the moment
// When there are others this function should be updated to retrieve the correct adapter for the desired platform target
return createKubernetesAdapter(adapterContext)
kc, ok := platformContext.(kubernetes.KubernetesContext)
if !ok {
return nil, fmt.Errorf("Error retrieving context for Kubernetes")
}
return createKubernetesAdapter(adapterContext, kc.Namespace)
}

func createKubernetesAdapter(adapterContext common.AdapterContext) (PlatformAdapter, error) {
func createKubernetesAdapter(adapterContext common.AdapterContext, namespace string) (PlatformAdapter, error) {
client, err := kclient.New()
if err != nil {
return nil, err
}

// If a namespace was passed in
if namespace != "" {
client.Namespace = namespace
}
return newKubernetesAdapter(adapterContext, *client)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/adapters/interface.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package adapters

type PlatformAdapter interface {
Start() error
Push(path string, ignoredFiles []string, forceBuild bool, globExps []string) error
}
10 changes: 7 additions & 3 deletions pkg/devfile/adapters/kubernetes/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type Adapter struct {
componentAdapter common.ComponentAdapter
}

type KubernetesContext struct {
Namespace string
}

// New instantiates a kubernetes adapter
func New(adapterContext common.AdapterContext, client kclient.Client) Adapter {

Expand All @@ -22,10 +26,10 @@ func New(adapterContext common.AdapterContext, client kclient.Client) Adapter {
}
}

// Start creates Kubernetes resources that correspond to the devfile if they don't already exist
func (k Adapter) Start() error {
// Push creates Kubernetes resources that correspond to the devfile if they don't already exist
func (k Adapter) Push(path string, ignoredFiles []string, forceBuild bool, globExps []string) error {

err := k.componentAdapter.Create()
err := k.componentAdapter.Push(path, ignoredFiles, forceBuild, globExps)
if err != nil {
return errors.Wrap(err, "Failed to create the component")
}
Expand Down
Loading