declarative

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

application.go manages an Application[1]

[1] https://github.com/kubernetes-sigs/application

The declarative package contains tools and a controller compatible with http://sigs.k8s.io/controller-runtime to manage a Kubernetes deployment based off of a instance of a CustomResource in the cluster.

Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var Options struct {
	// Begin options are applied before evaluating controller specific options
	Begin []reconcilerOption
	// End options are applied after evaluating controller specific options
	End []reconcilerOption
}

Options are a set of reconcilerOptions applied to all controllers

Functions

func DefaultObjectOrder

func DefaultObjectOrder(ctx context.Context) func(o *manifest.Object) int

func ExtractApplication

func ExtractApplication(objects *manifest.Objects) (*manifest.Object, error)

ExtractApplication extracts a single app.k8s.io/Application from objects.

- 0 Application: (nil, nil) - 1 Application: (*app, nil) - >1 Application: (nil, err)

func WatchAll

func WatchAll(config *rest.Config, ctrl controller.Controller, recnl Source, labelMaker LabelMaker) (chan struct{}, error)

WatchAll creates a Watch on ctrl for all objects reconciled by recnl

func WithApplyPrune

func WithApplyPrune() reconcilerOption

WithApplyPrune turns on the --prune behavior of kubectl apply. This behavior deletes any objects that exist in the API server that are not deployed by the current version of the manifest which match a label specific to the addon instance.

This option requires WithLabels to be used

func WithGroupVersionKind

func WithGroupVersionKind(gvk schema.GroupVersionKind) reconcilerOption

WithGroupVersionKind specifies the GroupVersionKind of the managed custom resource This option is required.

func WithLabels

func WithLabels(labelMaker LabelMaker) reconcilerOption

WithLabels sets a fixed set of labels configured provided by a LabelMaker to all deployment objecs for a given DeclarativeObject

func WithManagedApplication

func WithManagedApplication(labelMaker LabelMaker) reconcilerOption

WithManagedApplication is a transform that will modify the Application object in the deployment to match the configuration of the rest of the deployment.

func WithManifestController

func WithManifestController(mc ManifestController) reconcilerOption

WithManifestController overrides the default source for loading manifests

func WithObjectTransform

func WithObjectTransform(operations ...ObjectTransform) reconcilerOption

WithObjectTransform adds the specified ObjectTransforms to the chain of manifest changes

func WithOwner

func WithOwner(ownerFn OwnerSelector) reconcilerOption

WithOwner sets an owner ref on each deployed object by the OwnerSelector

func WithPreserveNamespace

func WithPreserveNamespace() reconcilerOption

WithPreserveNamespace preserves the namespaces defined in the deployment manifest instead of matching the namespace of the DeclarativeObject

func WithRawManifestOperation

func WithRawManifestOperation(operations ...ManifestOperation) reconcilerOption

WithRawManifestOperation adds the specific ManifestOperations to the chain of manifest changes

func WithStatus

func WithStatus(status Status) reconcilerOption

WithStatus provides a Status interface that will be used during Reconcile

Types

type DeclarativeObject

type DeclarativeObject interface {
	runtime.Object
	metav1.Object
}

func SourceAsOwner

SourceAsOwner is a OwnerSelector that selects the source DeclarativeObject as the owner

type DynamicWatch

type DynamicWatch interface {
	// Add registers a watch for changes to 'trigger' filtered by 'options' to raise an event on 'target'
	Add(trigger schema.GroupVersionKind, options metav1.ListOptions, target metav1.ObjectMeta) error
}

type LabelMaker

type LabelMaker = func(context.Context, DeclarativeObject) map[string]string

LabelMaker returns a fixed set of labels for a given DeclarativeObject

func SourceLabel

func SourceLabel(scheme *runtime.Scheme) LabelMaker

SourceLabel returns a fixed label based on the type and name of the DeclarativeObject

type ManifestController

type ManifestController interface {
	// ResolveManifest returns a raw manifest as a string for a given CR object
	ResolveManifest(ctx context.Context, object runtime.Object) (string, error)
}

type ManifestLoaderFunc

type ManifestLoaderFunc func() ManifestController
var DefaultManifestLoader ManifestLoaderFunc

DefaultManifestLoader is the manifest loader we use when a manifest loader is not otherwise configured

type ManifestOperation

type ManifestOperation = func(context.Context, DeclarativeObject, string) (string, error)

ManifestOperation is an operation that transforms raw string manifests before applying it

type ObjectTransform

type ObjectTransform = func(context.Context, DeclarativeObject, *manifest.Objects) error

ObjectTransform is an operation that transforms the manifest objects before applying it

func AddLabels

func AddLabels(labels map[string]string) ObjectTransform

AddLabels returns an ObjectTransform that adds labels to all the objects

func ImageRegistryTransform

func ImageRegistryTransform(registry, imagePullSecret string) ObjectTransform

ImageRegistryTransform modifies all Pods to use registry for the image source and adds the imagePullSecret

type OwnerSelector

OwnerSelector selects a runtime.Object to be the owner of a given manifest.Object

type Preflight

type Preflight interface {
	// Preflight validates if the current state of the world is ready for reconciling.
	// Returning a non-nil error on this object will prevent Reconcile from running.
	// The caller is encouraged to surface the error status on the DeclarativeObject.
	Preflight(context.Context, DeclarativeObject) error
}

type Reconciled

type Reconciled interface {
	// Reconciled is triggered when Reconciliation has occured.
	// The caller is encouraged to determine and surface the health of the reconcilation
	// on the DeclarativeObject.
	Reconciled(context.Context, DeclarativeObject, *manifest.Objects) error
}

type Reconciler

type Reconciler struct {
	// contains filtered or unexported fields
}

func (*Reconciler) BuildDeploymentObjects

func (r *Reconciler) BuildDeploymentObjects(ctx context.Context, name types.NamespacedName, instance DeclarativeObject) (*manifest.Objects, error)

BuildDeploymentObjects performs all manifest operations to build a final set of objects for deployment

func (*Reconciler) Init

func (r *Reconciler) Init(mgr manager.Manager, prototype DeclarativeObject, opts ...reconcilerOption) error

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(request reconcile.Request) (reconcile.Result, error)

+rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete

func (*Reconciler) SetSink

func (r *Reconciler) SetSink(sink Sink)

SetSink provides a Sink that will be notified for all deployments

type Sink

type Sink interface {
	// Notify tells the Sink that all objs have been created
	Notify(ctx context.Context, dest DeclarativeObject, objs *manifest.Objects) error
}

type Source

type Source interface {
	SetSink(sink Sink)
}

type Status

type Status interface {
	Reconciled
	Preflight
}

Status provides health and readiness information for a given DeclarativeObject

type StatusBuilder

type StatusBuilder struct {
	ReconciledImpl Reconciled
	PreflightImpl  Preflight
}

StatusBuilder provides a pluggable implementation of Status

func (*StatusBuilder) Preflight

func (s *StatusBuilder) Preflight(ctx context.Context, src DeclarativeObject) error

func (*StatusBuilder) Reconciled

func (s *StatusBuilder) Reconciled(ctx context.Context, src DeclarativeObject, objs *manifest.Objects) error

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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