Plugin Frameworks
Package framework
contains a high-level framework for writing Waypoint plugins.
The framework is split into sub-packages for specific functionality, whereas
this root package contains the highest-level functionality.
Currently, the only framework supported is for managing resources during the lifecycle
of a deployment or release. This framework gives plugin authors a way to manage
multiple resources easily without having to define a large Deploy
or Release
func
that attempts to do it all. By defining each resources CRUD functions (i.e. the
create and delete funcs, plus a status), resource manager will call the appropriate
functions depending on what operations are being taken with Waypoint.
https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/framework/resource
Implementing Resource Manager
The Waypoint Plugin SDK Framework is used to implement Resource Manager for your
plugin. By integrating this framework into your deploy
or release
lifecycle
funcs, Resource Manager can automatically handle the creation, deletion, and status
of the resources involved with deployments and releases.
Rather than having one large Deploy
or Release
function that creates or
deletes every resource, Resource Manager lets you define each resources create
and delete functions. It also is expected to store a little bit of state about
the resources being managed for easier access.
In the following example, we set up a Deployment proto that has a single resource:
When setting up a new resource manager, your plugin will want to make sure to
initialize the manager with some fields that tell it what to call when it invokes
the create
, delete
, and status
funcs.
If your deployment or release involves multiple resources, you would define
them when creating Resource Manager. When CreateAll
is invoked, each function
should be called during the deployment process for creating the required resources.
Then, you'll be ready to implement one of the functions invoked by Resource Manager.
For examples sake, let's take a look at what the resourceDeploymentCreate
might look like.
When your plugin needs to destroy the resources it manages, you can use Resource Manager to destroy them as well.
Finally, each resource can report a status if it makes sense to. Generally these statuses are reported by the platform they run on. If the resource is fairly simple, it might only have an "exists" or "does not exist" status rather than having a more complex status like a Pod in Kubernetes.
Dependencies Between Resources
Dependencies between multiple resources can be defined by including the type of one resource as an input parameter to another. The resources will be created in the appropriate order based on such dependencies. Below is an example of this:
For a more complete picture of what this implementation might look like with a real platform plugin, check out how Waypoint handles Resource Manager with the Kubernetes plugin for deployments and releases: