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

Implement managed package refactor #39

Open
WilboMo opened this issue Apr 14, 2021 · 2 comments
Open

Implement managed package refactor #39

WilboMo opened this issue Apr 14, 2021 · 2 comments

Comments

@WilboMo
Copy link
Contributor

WilboMo commented Apr 14, 2021

Instead you could create a new type Instance, i think which I suggested somewhere else and maintain a list of this type whose items gets modified/deleted/added throught the update process.

What data would be held in type called Instance? Would it be a tuple of (instanceID, containerInstanceARN)?

Taking a named struct (see above) might have helped here as well.

I think you're on the right track - I'd want to take it further than the Instance type thought.

The behavior in this main function looks like it could be collected into a management type.. or even just a package with a "main" type fed into most of its functions:

package managed // import path: updater/managed

type ClusterInstances struct {
  // ...
}

func (ci *ClusterInstances) Instances() []Instance {
  // ...
}

// CollectCluster retrieves a set of cluster instances to manage in the named ECS cluster.
func CollectCluster(ecsiface.ECS, clusterName string) (*managed.ClusterInstances, error) {
  // list instances and collect cluster instances that should be managed
  
  // ...
}

type Instance interface {
  Cluster() string
  ContainerInstanceARN() string
  InstanceID() string
  // ...
}

func Drain(ecsiface.ECS, instances []Instance) error {
  for _, inst := range instances {
    // build request
  }
  // send drain request
}
Me, carried away..

With such a package, main can look like (with some filling in where needed):

func _main() error {
  // build clients
  mci, err := managed.CollectCluster(ecsclient, *flagCluster)
  if err != nil {
    // ...
  }
  
  // filter set of instances as necessary or just do all of them.. for example:
  err = managed.Drain(ecsclient, mci.Instances()) 
  if err != // ...

  // more fictional types, just to get carried away.
  ssmcommander.Run(ssmclient, mci.Instances(),
	&api.ClientCommand{
      Command: "update check",
    })
  
  // ... and on ...
}

Originally posted by @jahkeup in #35 (comment)

@WilboMo WilboMo mentioned this issue Apr 15, 2021
@WilboMo
Copy link
Contributor Author

WilboMo commented Apr 15, 2021

#35 (comment)

@WilboMo
Copy link
Contributor Author

WilboMo commented Apr 15, 2021

#38 (comment)

@jhaynes jhaynes added this to the GA milestone May 11, 2021
@WilboMo WilboMo removed this from the GA milestone May 12, 2021
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

No branches or pull requests

2 participants