Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Support a group plugin that is a wrapper on top of managed instance groups #8

Open
dgageot opened this issue Dec 20, 2016 · 3 comments

Comments

@dgageot
Copy link
Contributor

dgageot commented Dec 20, 2016

This would help better scale a group of cattle.

@dgageot dgageot self-assigned this Dec 20, 2016
@FrenchBen
Copy link
Contributor

Out of curiosity, what's the advantage of doing something like:

type plugin struct {
	API func() (gcloud.API, error)

	flavorPlugins group_plugin.FlavorPluginLookup
	groups        map[group.ID]settings
	lock          sync.Mutex
}

// NewGCEGroupPlugin creates a new GCE group plugin for a given project
// and zone.
func NewGCEGroupPlugin(project, zone string, flavorPlugins group_plugin.FlavorPluginLookup) group.Plugin {
	_, err := gcloud.New(project, zone)
	if err != nil {
		log.Fatal(err)
	}

	return &plugin{
		API: func() (gcloud.API, error) {
			return gcloud.New(project, zone)
		},
		flavorPlugins: flavorPlugins,
		groups:        map[group.ID]settings{},
	}
}

and creating an actual client later on, instead of doing something like this:

type plugin struct {
	API gcloud.API

	flavorPlugins group_plugin.FlavorPluginLookup
	groups        map[group.ID]settings
	lock          sync.Mutex
}

// NewGCEGroupPlugin creates a new GCE group plugin for a given project
// and zone.
func NewGCEGroupPlugin(project, zone string, flavorPlugins group_plugin.FlavorPluginLookup) group.Plugin {
	api, err := gcloud.New(project, zone)
	if err != nil {
		log.Fatal(err)
	}

	return &plugin{
		API: api,
		flavorPlugins: flavorPlugins,
		groups:        map[group.ID]settings{},
	}
}

@dgageot
Copy link
Contributor Author

dgageot commented Jan 6, 2017

@FrenchBen we cannot keep a gcloud API for the whole lifetime of this plugin. So API is a factory that creates a new gcloud.API each time. In NewGCEGroupPlugin, we create create an gcloud.API instance to check that everything is well configured.

What I can do to improve the code is move this mechanism to the gcloud package.

@dgageot
Copy link
Contributor Author

dgageot commented Jan 6, 2017

@FrenchBen Actually, not reusing a compute.Service for too long might be cargo cult on my side. Will run some long running tests without it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants