odo: odo create fails with Access Denied on windows when used with --starter and existing devfile

/kind bug /area windows

What versions of software are you using?

Operating System: windows 10

Output of odo version: master

How did you run odo exactly?

$ odo create ahsdlk --project qwerty --starter

Actual behavior

Manually

$ mkdir tempp && cd tempp
$ odo project create qwerty
$ cp $ODO_PROJECT/test/example/source/devfiles/springboot/devfile-with-subdir.yaml   devfile.yaml
$ odo create ahsdlk --project qwerty --starter

Devfile Object Validation
V  Creating a devfile component from devfile path: C:\Users\Admin\tempp\devfile.yaml [0ns]
Validating if devfile name is correct  ...
 V  Validating if devfile name is correct [0ns]
Starter Project

 X  Downloading starter project springbootproject from https://github.com/odo-devfiles/springboot-ex.git  
 X  CreateFile C:\Users\Admin\699881763\src\main: Access is denied.

Expected behavior

odo create should pass without any error while having a devfile in current directory in windows

Any logs, error output, etc?

logs from automated test

[ssh:Windows 10] [2] + Failure [2.698 seconds]
[ssh:Windows 10] [2] odo devfile create command tests
[ssh:Windows 10] [2] C:/Users/Admin/amqp_ci_rcv_odo-windows-e2e-pr-build_PR_4658/repo/tests/integration/devfile/cmd_devfile_create_test.go:19
[ssh:Windows 10] [2]   When executing odo create with devfile component, --starter flag and subDir has a valid value
[ssh:Windows 10] [2]   C:/Users/Admin/amqp_ci_rcv_odo-windows-e2e-pr-build_PR_4658/repo/tests/integration/devfile/cmd_devfile_create_test.go:457
[ssh:Windows 10] [2]     should only extract the specified path in the subDir field [It]
[ssh:Windows 10] [2]     C:/Users/Admin/amqp_ci_rcv_odo-windows-e2e-pr-build_PR_4658/repo/tests/integration/devfile/cmd_devfile_create_test.go:458
[ssh:Windows 10] [2] 
[ssh:Windows 10] [2]     No future change is possible.  Bailing out early after 0.635s.
[ssh:Windows 10] [2]     Running odo.exe with args [odo create zphazc --project cmd-devfile-create-test458pxg --starter]
[ssh:Windows 10] [2]     Expected
[ssh:Windows 10] [2]         <int>: 1
[ssh:Windows 10] [2]     to match exit code:
[ssh:Windows 10] [2]         <int>: 0
[ssh:Windows 10] [2] 
[ssh:Windows 10] [2]     C:/Users/Admin/amqp_ci_rcv_odo-windows-e2e-pr-build_PR_4658/repo/tests/helper/helper_run.go:35
[ssh:Windows 10] [2] ------------------------------
[ssh:Windows 10] [2] Created dir: C:\Users\Admin\391290992
[ssh:Windows 10] [2] Setting KUBECONFIG=C:\Users\Admin\391290992\config
[ssh:Windows 10] [2] Creating a new project: cmd-devfile-create-test458pxg
[ssh:Windows 10] [2] Running odo.exe with args [odo project create cmd-devfile-create-test458pxg -w -v4]
[ssh:Windows 10] [2] [odo] I0517 06:38:59.036342    8236 util.go:761] Cached response used.
[ssh:Windows 10] [2] [odo] I0517 06:38:58.999632    8236 preference.go:220] The path for preference file is \cygdrive\c\Users\Admin\amqp_ci_rcv_odo-windows-e2e-pr-build_PR_4658\repo\artifacts\.odo\preference.yaml
[ssh:Windows 10] [2] [odo] I0517 06:38:59.037499    8236 runnable.go:46] Skipping telemetry question because there is no terminal (tty)
[ssh:Windows 10] [2] [odo]  -  Waiting for project to come up  ...
[ssh:Windows 10] [2] [odo] I0517 06:38:59.066002    8236 kclient.go:202] Checking if "projects" resource supported
[ssh:Windows 10] [2] [odo] I0517 06:39:00.598975    8236 projects.go:190] Status of creation of project cmd-devfile-create-test458pxg is Active
[ssh:Windows 10] [2] [odo] I0517 06:39:00.598975    8236 projects.go:195] Project cmd-devfile-create-test458pxg now exists
[ssh:Windows 10] [2] [odo] I0517 06:39:00.605008    8236 namespace.go:181] Status of creation of service account &ServiceAccount{ObjectMeta:{default  cmd-devfile-create-test458pxg /api/v1/namespaces/cmd-devfile-create-test458pxg/serviceaccounts/default 0b1889b0-562f-4d01-93db-ec51e93e02b6 21179423 0 2021-05-17 06:36:57 +0000 GMT <nil> <nil> map[] map[] [] []  []},Secrets:[]ObjectReference{ObjectReference{Kind:,Namespace:,Name:default-token-ql47s,UID:,APIVersion:,ResourceVersion:,FieldPath:,},ObjectReference{Kind:,Namespace:,Name:default-dockercfg-2mphb,UID:,APIVersion:,ResourceVersion:,FieldPath:,},},ImagePullSecrets:[]LocalObjectReference{LocalObjectReference{Name:default-dockercfg-2mphb,},},AutomountServiceAccountToken:nil,} is ready
[ssh:Windows 10] [2] [odo] 
 V  Waiting for project to come up [2s]
[ssh:Windows 10] [2] [odo]  V  Project 'cmd-devfile-create-test458pxg' is ready for use
[ssh:Windows 10] [2] [odo]  V  New project created and now using project: cmd-devfile-create-test458pxg
[ssh:Windows 10] [2] [odo] I0517 06:39:00.620664    8236 segment.go:207] Sending telemetry disabled by ODO_DISABLE_TELEMETRY=true
[ssh:Windows 10] [2] [odo] I0517 06:39:00.620664    8236 odo.go:73] Could not get the latest release information in time. Never mind, exiting gracefully :)
[ssh:Windows 10] [2] Current working dir: C:\Users\Admin\amqp_ci_rcv_odo-windows-e2e-pr-build_PR_4658\repo\tests\integration\devfile
[ssh:Windows 10] [2] Setting current dir to: C:\Users\Admin\391290992
[ssh:Windows 10] [2] Created dir: C:\Users\Admin\250328335
[ssh:Windows 10] [2] Setting current dir to: C:\Users\Admin\250328335
[ssh:Windows 10] [2] Running odo.exe with args [odo create zphazc --project cmd-devfile-create-test458pxg --starter]
[ssh:Windows 10] [2] [odo] I0517 06:39:00.814679    6404 util.go:761] Cached response used.
[ssh:Windows 10] [2] [odo] I0517 06:39:00.785526    6404 util.go:422] path .odo\config.yaml doesn't exist, skipping it
[ssh:Windows 10] [2] [odo] I0517 06:39:00.814679    6404 util.go:422] path .odo\env\env.yaml doesn't exist, skipping it
[ssh:Windows 10] [2] [odo] I0517 06:39:00.814679    6404 util.go:422] path .odo\env\env.yaml doesn't exist, skipping it
[ssh:Windows 10] [2] [odo] Devfile Object Validation
[ssh:Windows 10] [2] [odo]  -  Creating a devfile component from devfile path: C:\Users\Admin\250328335\devfile.yaml  ...
[ssh:Windows 10] [2] [odo] 
 V  Creating a devfile component from devfile path: C:\Users\Admin\250328335\devfile.yaml [0ns]
[ssh:Windows 10] [2] [odo] Validation
[ssh:Windows 10] [2] [odo]  -  Validating if devfile name is correct  ...
[ssh:Windows 10] [2] [odo] 
 V  Validating if devfile name is correct [0ns]
[ssh:Windows 10] [2] [odo] I0517 06:39:00.815837    6404 content.go:33] converted devfile YAML to JSON
[ssh:Windows 10] [2] [odo] I0517 06:39:00.815837    6404 apiVersion.go:42] devfile schemaVersion: '2.0.0'
[ssh:Windows 10] [2] [odo] I0517 06:39:00.815837    6404 helper.go:41] devfile apiVersion '2.0.0' is supported
[ssh:Windows 10] [2] [odo] I0517 06:39:00.821609    6404 schema.go:46] validated devfile schema
[ssh:Windows 10] [2] [odo] I0517 06:39:00.822655    6404 validate.go:50] Successfully validated devfile sections
[ssh:Windows 10] [2] [odo] I0517 06:39:00.822655    6404 preference.go:220] The path for preference file is C:\Users\Admin\391290992\preference.yaml
[ssh:Windows 10] [2] [odo] 
[ssh:Windows 10] [2] [odo] Starter Project
[ssh:Windows 10] [2] [odo]  -  Downloading starter project springbootproject from https://github.com/odo-devfiles/springboot-ex.git  ...
[ssh:Windows 10] [2] [odo] 
 X  Downloading starter project springbootproject from https://github.com/odo-devfiles/springboot-ex.git [455ms]
[ssh:Windows 10] [2] [odo] I0517 06:39:01.278830    6404 segment.go:207] Sending telemetry disabled by ODO_DISABLE_TELEMETRY=true
[ssh:Windows 10] [2] [odo]  X  CreateFile C:\Users\Admin\699881763\src\main: Access is denied.
[ssh:Windows 10] [2] Setting current dir to: C:\Users\Admin\391290992
[ssh:Windows 10] [2] Deleting project: cmd-devfile-create-test458pxg
[ssh:Windows 10] [2] Running odo.exe with args [odo project delete cmd-devfile-create-test458pxg -f]
[ssh:Windows 10] [2] [odo] I0517 06:39:01.485862    9016 kclient.go:202] Checking if "projects" resource supported
[ssh:Windows 10] [2] [odo] I0517 06:39:01.499053    9016 util.go:761] Cached response used.
[ssh:Windows 10] [2] [odo] I0517 06:39:01.528603    9016 kclient.go:202] Checking if "projects" resource supported
[ssh:Windows 10] [2] [odo]  V  Deleted project : cmd-devfile-create-test458pxg
[ssh:Windows 10] [2] [odo]  !  Warning! Projects are deleted from the cluster asynchronously. Odo does its best to delete the project. Due to multi-tenant clusters, the project may still exist on a different node.
[ssh:Windows 10] [2] [odo] I0517 06:39:01.552926    9016 segment.go:207] Sending telemetry disabled by ODO_DISABLE_TELEMETRY=true
[ssh:Windows 10] [2] [odo] I0517 06:39:01.552926    9016 odo.go:73] Could not get the latest release information in time. Never mind, exiting gracefully :)
[ssh:Windows 10] [2] Setting current dir to: C:\Users\Admin\amqp_ci_rcv_odo-windows-e2e-pr-build_PR_4658\repo\tests\integration\devfile
[ssh:Windows 10] [2] Deleting dir: C:\Users\Admin\391290992

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

If you add a defer Close() here, it will be executed after removeAll(). Instead, you can make a new function that handles all the copy stuff, defering the Close at the end of this sub-function:

Sorry missed the deletion at the end of the function. Closing the file after the directory read or before the folder deletion might work as well.

hmm ok lemme try th

It might be because the directory is not closed before deleting https://github.com/openshift/odo/blob/3196871acd1ee55dcc96d2bf8b1d6bfb247dfc8b/pkg/util/util.go#L1418

Please try adding defer outputDirRead.Close() after this line. I recently faced this problem and noticed that linux can handle deletion with closing the file but windows system cannot.

ok lemme try that

If you add a defer Close() here, it will be executed after removeAll(). Instead, you can make a new function that handles all the copy stuff, defering the Close at the end of this sub-function:

func gitSubDir(srcPath, destinationPath, subDir string, fs filesystem.Filesystem) error {
	go StartSignalWatcher(func() {
		err := cleanDir(destinationPath, map[string]bool{
			"devfile.yaml": true,
		}, fs)
		if err != nil {
			klog.V(4).Infof("error %v occurred while calling handleInterruptedSubDir", err)
		}
		err = fs.RemoveAll(srcPath)
		if err != nil {
			klog.V(4).Infof("error %v occurred during temp folder clean up", err)
		}
	})

        copyDirectory(...)

	return fs.RemoveAll(srcPath)
}

Hmm yea that actually makes sense. Tho as that code is not repeated, I guess we could just do anonymous func

    func() {
        //copy code here
    }()

wdyt @feloy ?

It might be because the directory is not closed before deleting https://github.com/openshift/odo/blob/3196871acd1ee55dcc96d2bf8b1d6bfb247dfc8b/pkg/util/util.go#L1418 Please try adding defer outputDirRead.Close() after this line.

I faced this problem recently and noticed that linux can handle deletions without closing the file, most of the time, but windows system cannot.