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

No "global" exec runner instance inside cloudfoundry pkg #1771

Conversation

marcusholl
Copy link
Member

We have to be able to provide the cloudfoundry instance from outside to the cloudfoundry package in order to eg. perform a login. Reason: There are some environment variables which controls the behaviour of the cf cli (e.g. CF_TRACE, CF_HOME).

When we work upon a shared instance for all our tasks we have these issues:

1.) when the instance is global we have to ensure we perform a cleanup each time we are done with a task (e.g. resetting environment variables, streams (stdout, stderr)
2.) we cannot use that global instance in a parallel way. Currently we don't use that instance in a parallel mode, but in principle concurrency is well supported in go and we should be prepared for this.

)

//ReadServiceKeyAbapEnvironment from Cloud Foundry and returns it.
//Depending on user/developer requirements if he wants to perform further Cloud Foundry actions the cfLogoutOption parameters gives the option to logout after reading ABAP communication arrangement or not.
func ReadServiceKeyAbapEnvironment(options ServiceKeyOptions, cfLogoutOption bool) (ServiceKey, error) {
func (cf *CFUtils) ReadServiceKeyAbapEnvironment(options ServiceKeyOptions, cfLogoutOption bool) (ServiceKey, error) {
Copy link

Choose a reason for hiding this comment

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

Method CFUtils.ReadServiceKeyAbapEnvironment has 51 lines of code (exceeds 50 allowed). Consider refactoring.

Copy link
Member

@dominiklendle dominiklendle left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@@ -26,11 +30,11 @@ func LoginCheck(options LoginOptions) (bool, error) {
var cfCheckLoginScript = append([]string{"api", options.CfAPIEndpoint}, options.CfAPIOpts...)

var cfLoginBytes bytes.Buffer
c.Stdout(&cfLoginBytes)
_c.Stdout(&cfLoginBytes)
Copy link
Member

Choose a reason for hiding this comment

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

Does this make stdout inmutable for LoginCheck function?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. I already spottet that too. We have to reset the old stdout afterwards. But at the moment it is not possible to retrieve the current stdout via our wrapper. Needs to be added. At least the underlying cmd allow to get the currently set stream(s).

The point is: we have to ensure that the "cmdRunner" is not permanently changed inside the func. I had this already. As a result logging output stopped after calling login. Of course also for the subsequent cf deploy.

Copy link
Member

@dominiklendle dominiklendle Jul 8, 2020

Choose a reason for hiding this comment

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

I would propose to finalize on discussion in #1760 . This probably solves this whole problem and we can leave the whole function out

@marcusholl marcusholl force-pushed the pr/noGlobalExecRunnerInstanceInCloudfoundryPkg branch 2 times, most recently from be30204 to 91a9018 Compare July 10, 2020 06:22
…package

o Up to now we work on a private and shared instance of command.Command inside
  the cloudfounrdy package. We need to be able either configure this instance
  (environment variables) according to the use case. One option is to hand over
  an already configured instance which is used elsewhere. This is what we do with
  this commit.

o With this commit we remove the instance which is shared within the cloudfounrdy
  package and to provide an instance with a receiver which gets handed over to the
  functions. Hence we are thread save: parallel invoctation of e.g. Login will not
  affect each other.
@marcusholl marcusholl force-pushed the pr/noGlobalExecRunnerInstanceInCloudfoundryPkg branch from 91a9018 to e24d442 Compare July 10, 2020 06:29
@marcusholl
Copy link
Member Author

@dominiklendle @DanielMieg @fwilhe; the behaviour is: we can provide an instance of command.Command at the receiver instance "CFUtils". If provided that instance will be used. In case there is no instance provided we will create our own instance. This does not set anything. Hence the default in the cf cli are assumed for e.g. CF_HOME, CF_PLUGIN_HOME. There is also nothing configured wrt stream handling on that instance. This means - in contrast to the command.Command provided by our generated coding - output issued inside that command.Command instance will not apprear in the log.

Do you have concerns wrt this default behaviour? Other option would be to fail in case there is no command.Command instance set on CFUtils

Copy link
Member

@DanielMieg DanielMieg left a comment

Choose a reason for hiding this comment

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

Looks good 👍

Copy link
Contributor

@fwilhe fwilhe left a comment

Choose a reason for hiding this comment

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

lgtm

@marcusholl
Copy link
Member Author

/it

@marcusholl
Copy link
Member Author

Reality check performed by a merge commit between this PR and the cloudFoundryDeploy PR --> this works as expected.

@marcusholl
Copy link
Member Author

/it

@marcusholl marcusholl merged commit bda9a9f into SAP:master Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants