Skip to content

Implement managed package refactor #39

@WilboMo

Description

@WilboMo

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions