operations

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

README

Scheduler Operations

Operations holds helper functions for creating and understanding Google Cloud Scheduler related jobs that operate on managing Scheduler Jobs.

Usage

Directly

The Job that can be made:

  • NewJobOps - Operations related to scheduler jobs.

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:

  • EnsureSchedulerJob - Confirm or Create SchedulerJob.
  • EnsureSchedulerJobDeleted - Delete Scheduler Job.

Why Jobs?

The Jobs are designed to be run in the namespace in which the Scheduler 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 Scheduler Job is deleted using gcloud or the Cloud Console by mistake.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJobOps

func NewJobOps(arg JobArgs) (*batchv1.Job, error)

NewJobOps returns a new batch Job resource.

func SchedulerJobLabels

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

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

func SchedulerJobName

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

SchedulerJobName creates the name of a scheduler ops job.

Types

type JobActionResult

type JobActionResult 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"`
	// JobName holds the name of the created job
	// and is filled in during create operation.
	JobName string `json:"jobName,omitempty"`
	// Project is the project id that we used (this might have
	// been defaulted, to we'll expose it).
	ProjectId string `json:"projectId,omitempty"`
}

TODO: the job could output the resolved projectID.

type JobArgs

type JobArgs 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

	// TopicID we'll use for pubsub target.
	TopicID string

	// JobName is the name of the Scheduler Job that we're
	// operating on. The format is like so:
	// projects/PROJECT_ID/locations/LOCATION_ID/jobs/JobId
	JobName string

	// Schedule for the Job
	Schedule string

	// Data to send in the payload
	Data string

	Secret corev1.SecretKeySelector
	Owner  kmeta.OwnerRefable
}

JobArgs are the configuration required to make a NewJobOps.

type JobOps

type JobOps struct {
	SchedulerOps

	// 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"`

	// Schedule specification
	Schedule string `envconfig:"SCHEDULE" required:"false"`

	// JobName is the environment variable containing the name of the
	// job to operate on. F
	JobName string `envconfig:"JOB_NAME" required:"false" default:""`

	// Parent is the parent of the job.
	Parent string `envconfig:"JOB_PARENT" required:"false" default:""`

	// Data is the data to send in the payload.
	Data string `envconfig:"DATA" required:"false" default:""`
}

JobOps defines the configuration to use for this operation.

func (*JobOps) Run

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

Run will perform the action configured upon a subscription.

type SchedulerOps

type SchedulerOps struct {
	// Environment variable containing project id.
	Project string `envconfig:"PROJECT_ID"`
	// contains filtered or unexported fields
}

func (*SchedulerOps) CreateClient

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

Jump to

Keyboard shortcuts

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