operations

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

README

Storage Operations

Operations holds helper functions for creating and understanding GCS related jobs that operate on configuring notifications on GCS.

Usage

Directly

The Job that can be made:

  • NewNotificationOps - Operations related to notifications.

Job accepts an Action, supported Actions are:

  • create, will attempt to create the GCS notification
  • delete, will attempt to delete the GCS notification
Within Reconcilers

These jobs are used with Storage reconciler and provides the following methods:

  • EnsureNotification - Confirm or Create notification.
  • EnsureNotificationDeleted - Delete notification.

Why Jobs?

The Jobs are designed to be run in the namespace in which the Storage exists with the auth provided. The Job has to run local to the resource to avoid copying service accounts or secrets into the cloud-run-events namespace.

The controller will re-reconcile the resource if the create job is deleted, this could be used as a healing operation by the operator if the GCS notification is deleted using gsutil or the Cloud Console by mistake.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNotificationOps

func NewNotificationOps(arg NotificationArgs) (*batchv1.Job, error)

NewNotificationOps returns a new batch Job resource.

func NotificationJobLabels

func NotificationJobLabels(owner kmeta.OwnerRefable, action string) map[string]string

NotificationJobLabels creates a label to find a job again. keys is recommended to be (name, kind, action)

func NotificationJobName

func NotificationJobName(owner kmeta.OwnerRefable, action string) string

NotificationJobName creates the name of a notification ops job.

Types

type NotificationActionResult

type NotificationActionResult struct {
	// Result is the result the operation attempted.
	Result bool `json:"result,omitempty"`
	// Error is the error string if failure occurred
	Error string `json:"error,omitempty"`
	// NotificationId holds the notification ID for GCS
	// and is filled in during create operation.
	NotificationId string `json:"notificationId,omitempty"`
	// Project is the project id that we used (this might have
	// been defaulted, to we'll expose it).
	ProjectId string `json:"projectId,omitempty"`
}

type NotificationArgs

type NotificationArgs struct {
	// UID of the resource that caused the action to be taken. Will
	// be added as a label to the podtemplate.
	UID string
	// Image is the actual binary that we'll run to operate on the
	// notification.
	Image string
	// Action is what the binary should do
	Action    string
	ProjectID string
	// Bucket
	Bucket string
	// TopicID we'll use for pubsub target.
	TopicID string
	// NotificationId is the notifification ID that GCS gives
	// back to us. We need that to delete it.
	NotificationId string
	// EventTypes is an array of strings specifying which
	// event types we want the notification to fire on.
	EventTypes []string
	// ObjectNamePrefix is an optional filter
	ObjectNamePrefix string
	// CustomAttributes is the list of additional attributes to have
	// GCS supply back to us when it sends a notification.
	CustomAttributes map[string]string
	Secret           corev1.SecretKeySelector
	Owner            kmeta.OwnerRefable
}

NotificationArgs are the configuration required to make a NewNotificationOps.

type NotificationOps

type NotificationOps struct {
	StorageOps

	// Action is the operation the job should run.
	// Options: [exists, create, delete]
	Action string `envconfig:"ACTION" required:"true"`

	// Topic is the environment variable containing the PubSub Topic being
	// subscribed to's name. In the form that is unique within the project.
	// E.g. 'laconia', not 'projects/my-gcp-project/topics/laconia'.
	Topic string `envconfig:"PUBSUB_TOPIC_ID" required:"false"`

	// Bucket to operate on
	Bucket string `envconfig:"BUCKET" required:"true"`

	// NotificationId is the environment variable containing the name of the
	// subscription to use.
	NotificationId string `envconfig:"NOTIFICATION_ID" required:"false" default:""`

	// EventTypes is a : separated eventtypes, if omitted all will be used.
	// TODO: Look at native envconfig list support
	EventTypes string `envconfig:"EVENT_TYPES" required:"false" default:""`

	// ObjectNamePrefix is an optional filter for the GCS
	ObjectNamePrefix string `envconfig:"OBJECT_NAME_PREFIX" required:"false" default:""`
}

NotificationOps defines the configuration to use for this operation.

func (*NotificationOps) Run

func (n *NotificationOps) Run(ctx context.Context) error

Run will perform the action configured upon a subscription.

type StorageOps

type StorageOps struct {
	// Environment variable containing project id.
	Project string `envconfig:"PROJECT_ID"`

	// Client is the GCS client used by Ops.
	Client *storage.Client
}

func (*StorageOps) CreateClient

func (s *StorageOps) CreateClient(ctx context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL