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

Refactoring Context #4081

Closed
1 of 6 tasks
adisky opened this issue Oct 6, 2020 · 24 comments
Closed
1 of 6 tasks

Refactoring Context #4081

adisky opened this issue Oct 6, 2020 · 24 comments
Labels
area/refactoring Issues or PRs related to code refactoring triage/needs-information Indicates an issue needs more information in order to work on it.

Comments

@adisky
Copy link
Contributor

adisky commented Oct 6, 2020

Some ideas to refactor context

  • Only make available single context function outside package, as with multiple functions it behaves differently
    everywhere
    https://github.com/openshift/odo/blob/master/pkg/odo/genericclioptions/context.go#L31
    add parameters to specify devfile/s2i, or if possible move the devfile/s2i detection to context,
    internally detect if clusterAccess is required for the command or not.

  • Avoid using util.LogErrorAndExit(err, "") at every where in the code. All other functions to return proper errors to NewContext function.
    call LogErrorAndExit from NewContext only by checking the errors and responding with proper wrapped message.
    This way we can properly handle errors from cluster(forbidden/timeout) and make it work for those commands that does not require cluster access.

Acceptance Criteria

  • Unify Context functions to one function -> NewContext()
    It will also include detection of s2i or devfile component in context and return context accordingly.
  • Segregate functions into separate files, so that each utility function visible clearly. (at some places we are rewriting the code that is available as function in context package)
  • Make sure some functionalities available only via context route e.g init config/envinfo, resolve app/project and remove their recurring occurrences
  • Add Annotations to the commands that does not require cluster access and ignore client initialization error for them.
  • Consolidate error handling at one place in the context package to have consistency in errors returned to the users.
  • Move the localConfigProvider interface to some common package and extend it in way that all localConfig/Envinfo data get accessed through it.
@girishramnani girishramnani added this to For consideration in Sprint 191 via automation Oct 7, 2020
@girishramnani girishramnani self-assigned this Oct 7, 2020
@girishramnani girishramnani added the triage/needs-information Indicates an issue needs more information in order to work on it. label Oct 7, 2020
@girishramnani girishramnani moved this from For consideration to To do in Sprint 191 Oct 8, 2020
@metacosm
Copy link
Contributor

There shouldn't be any parameters for devfile/s2i/whatever: NewContext should do the detection automatically, the whole point is to isolate things so that clients don't need to know or care the type of components they're dealing with.

@adisky
Copy link
Contributor Author

adisky commented Oct 13, 2020

There shouldn't be any parameters for devfile/s2i/whatever: NewContext should do the detection automatically, the whole point is to isolate things so that clients don't need to know or care the type of components they're dealing with.

agreed, no parameters in NewContext autodetect s2i/devfile, requirement of cluster access and remove existing parameters as well ignoreMissingConfiguration, createAppIfNeeded

@girishramnani girishramnani added this to the Post v2.0 milestone Oct 20, 2020
@girishramnani girishramnani added this to For consideration in Sprint 192 via automation Oct 27, 2020
@girishramnani girishramnani removed this from To do in Sprint 191 Oct 27, 2020
@girishramnani girishramnani moved this from For consideration to To do in Sprint 192 Oct 27, 2020
@adisky
Copy link
Contributor Author

adisky commented Oct 28, 2020

@metacosm
Copy link
Contributor

metacosm commented Oct 28, 2020

@adisky I've added some comments on the document, please also see: #4057 (comment)

@adisky
Copy link
Contributor Author

adisky commented Oct 29, 2020

@metacosm Thanks for your suggestions, I am trying to understand those

Pasting here the interface you suggested for context

package context

type Context interface {
	GetComponents() map[string]Component
	GetCurrentComponent() Component
	GetApplications() map[string]Application
	GetCurrentApplication() Application
	GetCurrentPath() string
	GetOptions() map[string]string // access command flags if needed
	GetClient() (Client, error)
	SetClient(client Client) error
}

don't you think it would be expensive to parse/evaluate with each call?

or you want to suggest, calculate and store once and give field access through functions?

type Context struct {
  application     string
  project            string
  client             Client
  options map[string] string
}

func GetContext(command  *cobra.Command) *Context {

}

func (context *Context)GetApplication() string{
}

func (context *Context)GetProject() string {
}

// all other options (e.g maxcpu, mincpu, storage for s2i or  e.g. runmode, pushcomand for devfile for devfile)
func(context *Context) GetOptions() map[string]string {

}

@metacosm
Copy link
Contributor

@metacosm Thanks for your suggestions, I am trying to understand those

don't you think it would be expensive to parse/evaluate with each call?

What makes you think that things would be evaluated each time?

or you want to suggest, calculate and store once and give field access through functions?

The implementation of each function might depend on what needs to be done. That's the beauty of interfaces: you can do what you want and the calling code doesn't need to care. If you don't want to compute a value as soon as you create the underlying object, then you can defer until you actually need that value. If you can cache things, you can do it. If you need to re-compute things based on the current state of the application, you can also do it. None of these things can be done if your client code accesses the struct directly.

@adisky
Copy link
Contributor Author

adisky commented Oct 29, 2020

@metacosm Thanks for your suggestions, I am trying to understand those
don't you think it would be expensive to parse/evaluate with each call?

What makes you think that things would be evaluated each time?

I got confused from your comments on the doc (taken not expose struct as not create) :)

@girishramnani girishramnani removed this from To do in Sprint 192 Oct 29, 2020
@adisky adisky self-assigned this Nov 11, 2020
@dharmit dharmit added this to For Consideration in Sprint 193 via automation Nov 18, 2020
@adisky
Copy link
Contributor Author

adisky commented Nov 18, 2020

Updated the acceptance criteria after the discussions and inputs from the team.

@dharmit
Copy link
Member

dharmit commented Nov 18, 2020

  • Add Annotations to the commands that does not require cluster access and ignore client initialization error for them.

@adisky Silly question alert - would this part help in indirectly addressing/fixing #3779?

@adisky
Copy link
Contributor Author

adisky commented Nov 18, 2020

  • Add Annotations to the commands that does not require cluster access and ignore client initialization error for them.

@adisky Silly question alert - would this part help in indirectly addressing/fixing #3779?

right it would fix those issues.

@adisky adisky moved this from For Consideration to In progress in Sprint 193 Nov 18, 2020
@adisky
Copy link
Contributor Author

adisky commented Nov 18, 2020

for this sprint

  • Unify Context functions to one function -> NewContext()
    It will also include detection of s2i or devfile component in context and return context accordingly.
  • Segregate functions into separate files, so that each utility function visible clearly. (at some places we are rewriting the code that is available as function in context package)
  • Make sure some functionalities available only via context route e.g init config/envinfo, resolve app/project and remove their recurring occurrences
  • Add Annotations to the commands that does not require cluster access and ignore client initialization error for them.

@dharmit dharmit added the estimated-size/XL (40-60) Rough sizing for Epics. About 3 sprints of work for a person label Nov 19, 2020
@adisky
Copy link
Contributor Author

adisky commented Nov 24, 2020

  • Add Annotations to the commands that does not require cluster access and ignore client initialization error for them.

After working on this part i realized it is not possible to implement this on command level, e.g for odo catalog list components for s2i components we require cluster access and for devfile it is needed, for odo list inside context dir we do not require cluster access but outside we require, so this problem could not be solved using annotations at command level :|

@adisky
Copy link
Contributor Author

adisky commented Dec 8, 2020

Summarizing

  • Unify Context functions to one function -> NewContext()
    It will also include detection of s2i or devfile component in context and return context accordingly.
    We need to think about this one if we are going to implement use Devfiles for s2i components #4281, as redirecting the s2i path to devfile the context might be the same for both.

  • Segregate functions into separate files, so that each utility function visible clearly. (at some places we are rewriting the code that is available as function in context package)
    This is done

  • Make sure some functionalities available only via context route e.g init config/envinfo, resolve app/project and remove their recurring occurrences
    This needs to be done

  • Add Annotations to the commands that does not require cluster access and ignore client initialization error for them.
    Stated the reason above, why it cannot be it cannot be done

  • Consolidate error handling at one place in the context package to have consistency in errors returned to the users.
    This needs to be done

  • Move the localConfigProvider interface to some common package and extend it in way that all localConfig/Envinfo data get accessed through it.
    This needs to be done

So finally following thing needs to be done

  • Move the localConfigProvider interface to some common package and extend it in way that all localConfig/Envinfo data get accessed through it.
  • Consolidate error handling at one place in the context package to have consistency in errors returned to the users.
  • Make sure some functionalities available only via context route e.g init config/envinfo, resolve app/project and remove their recurring occurrences

@dharmit dharmit added this to For Consideration in Sprint 195 via automation Dec 28, 2020
@dharmit dharmit removed this from For Consideration in Sprint 194 Dec 28, 2020
@dharmit dharmit removed the estimated-size/XL (40-60) Rough sizing for Epics. About 3 sprints of work for a person label Dec 30, 2020
@girishramnani girishramnani removed this from For Consideration in Sprint 195 Mar 1, 2021
@openshift-bot
Copy link

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci-robot openshift-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 30, 2021
@openshift-bot
Copy link

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

@openshift-ci-robot openshift-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 29, 2021
@openshift-bot
Copy link

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-ci openshift-ci bot closed this as completed May 30, 2021
@openshift-ci
Copy link

openshift-ci bot commented May 30, 2021

@openshift-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@feloy feloy reopened this Nov 24, 2021
@feloy
Copy link
Contributor

feloy commented Nov 24, 2021

Reopening the issue as more work would need to be done on Context refactoring

@dharmit
Copy link
Member

dharmit commented Nov 26, 2021

/remove-lifecycle rotten

@openshift-ci openshift-ci bot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Nov 26, 2021
@rm3l rm3l removed this from the Post v2.0 milestone Oct 3, 2022
@rm3l rm3l added area/refactoring Issues or PRs related to code refactoring and removed kind/code-refactoring labels Jun 19, 2023
@feloy
Copy link
Contributor

feloy commented Aug 3, 2023

This has been resolved as part of the refactorings done in 2022/2023

@feloy feloy closed this as completed Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/refactoring Issues or PRs related to code refactoring triage/needs-information Indicates an issue needs more information in order to work on it.
Projects
Archived in project
Development

No branches or pull requests

8 participants