opendevstack / tailor

Infrastructure as Code for OpenShift
Apache License 2.0
13 stars 9 forks source link

tailor throws error if resources exist in openshift #46

Closed tjaeschke closed 6 years ago

tjaeschke commented 6 years ago

I used tailor to create sonarqube in openshift. I forgot to change the secrets in the env file to base64, so the the creation failed in the first run. After changing the secrets to base64 the next tailor update threw the following error:

Comparing templates in D:\projects\opendevstack\ods-core\sonarqube\ocp-config with OCP namespace cd.
Limiting resources to bc,dc,is,pvc,route,svc,secret with selector app=sonarqube.
--> oc process --filename=.\sonarqube.yml --output=yaml --param-file=../../../ods-configuration/ods-core/sonarqube/ocp-config\sonarqube.env
--> oc export BuildConfig,DeploymentConfig,ImageStream,PersistentVolumeClaim,Route,Secret,Service --output=yaml --namespace=cd --selector=app=sonarqube
2018/08/14 09:45:51 Fatal error: interface conversion: interface {} is nil, not map[string]interface {} - goroutine 1 [running]:
runtime/debug.Stack(0xc0422f55c0, 0x6e1ee0, 0xc04223c0c0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0xae
main.main.func1()
        /Users/michaelsauter/go/src/github.com/opendevstack/tailor/main.go:206 +0x61
panic(0x6e1ee0, 0xc04223c0c0)
        /usr/local/go/src/runtime/panic.go:505 +0x237
github.com/opendevstack/tailor/openshift.(*Config).Process(0xc04205a000, 0xc04205a001)
        /Users/michaelsauter/go/src/github.com/opendevstack/tailor/openshift/config.go:71 +0x668
github.com/opendevstack/tailor/openshift.NewConfigFromList(0xc042438000, 0x47fd, 0x7e00, 0x47fd)
        /Users/michaelsauter/go/src/github.com/opendevstack/tailor/openshift/config.go:59 +0xd5
main.assembleRemoteResourceList(0xc042158140, 0xc0421abec8, 0xc04216c080)
        /Users/michaelsauter/go/src/github.com/opendevstack/tailor/main.go:605 +0xab
main.calculateChangeset(0xc0421abec8, 0x0, 0x0, 0x0, 0x0)
        /Users/michaelsauter/go/src/github.com/opendevstack/tailor/main.go:486 +0x250
main.main()
        /Users/michaelsauter/go/src/github.com/opendevstack/tailor/main.go:377 +0xc13
.

The same error occured using tailor status The resources created by tailor existed partially in Openshift. After a complete cleanup in Openshift it has been possible to run tailor again without this error.

michaelsauter commented 6 years ago

Thanks for the detailed report! It would be interesting to know what the YAML looked like at the time of the export, but I guess you don't have that anymore? In any case, this should be relatively simple for me to reproduce ... I'll look into it next week.

clemensutschig commented 6 years ago

@tjaeschke - it was the inputstream loaded with an image that still existed, right

tjaeschke commented 6 years ago

@michaelsauter Unfortunately I don't have the yaml anymore. @clemensutschig In our debug session, yes this has been the problem, but I could reproduce the error with other resources, which remained in the system.

It seems, that the resources have to be absent or they have to be there in total, but not partially.

michaelsauter commented 6 years ago

OK, I know where the error is. oc fails during the export of a "broken" resource, and Tailor does not detect that properly as https://github.com/opendevstack/tailor/blob/master/openshift/openshift.go#L26 just gets the combined output. I did this to get running quickly, but it's not how oc works - I need to separate STDOUT and STDERR, as it is already done elsewhere, e.g. at https://github.com/opendevstack/tailor/blob/master/openshift/openshift.go#L124-L130.