Documentation ¶
Index ¶
- Constants
- func SetTraceProvider(cfg OpenTelemetryConfig) error
- type App
- func (a *App) AddRunnable(runner app.Runnable)
- func (a *App) CallResourceCustomRoute(ctx context.Context, req *app.ResourceCustomRouteRequest) (*app.ResourceCustomRouteResponse, error)
- func (a *App) Convert(_ context.Context, req app.ConversionRequest) (*app.RawObject, error)
- func (a *App) ManagedKinds() []resource.Kind
- func (a *App) Mutate(ctx context.Context, req *app.AdmissionRequest) (*app.MutatingResponse, error)
- func (a *App) PrometheusCollectors() []prometheus.Collector
- func (a *App) RegisterKindConverter(groupKind schema.GroupKind, converter k8s.Converter)
- func (a *App) RegisterMetricsCollectors(collectors ...prometheus.Collector)
- func (a *App) Runner() app.Runnable
- func (a *App) Validate(ctx context.Context, req *app.AdmissionRequest) error
- func (a *App) ValidateManifest(manifest app.ManifestData) error
- type AppConfig
- type AppCustomRoute
- type AppCustomRouteHandler
- type AppCustomRouteHandlers
- type AppCustomRouteMethod
- type AppInformerConfig
- type AppManagedKind
- type AppProvider
- type AppUnmanagedKind
- type BasicReconcileOptions
- type Converter
- type KindMutator
- type KindValidator
- type MetricsConfig
- type Mutator
- type OTelConnType
- type OpenTelemetryConfig
- type Operator
- func (o *Operator) ClientGenerator() resource.ClientGenerator
- func (o *Operator) ConvertKind(gk metav1.GroupKind, converter k8s.Converter) error
- func (o *Operator) MutateKind(kind resource.Kind, controller resource.MutatingAdmissionController) error
- func (o *Operator) ReconcileKind(kind resource.Kind, reconciler operator.Reconciler, ...) error
- func (o *Operator) RegisterMetricsCollectors(collectors ...prometheus.Collector) error
- func (o *Operator) Run(ctx context.Context) error
- func (o *Operator) ValidateKind(kind resource.Kind, controller resource.ValidatingAdmissionController) error
- func (o *Operator) WatchKind(kind resource.Kind, watcher SyncWatcher, options operator.ListWatchOptions) error
- type OperatorConfig
- type Reconciler
- type SyncWatcher
- type TracingConfig
- type Validator
- type Watcher
- func (w *Watcher) Add(ctx context.Context, object resource.Object) error
- func (w *Watcher) Delete(ctx context.Context, object resource.Object) error
- func (w *Watcher) Sync(ctx context.Context, object resource.Object) error
- func (w *Watcher) Update(ctx context.Context, old resource.Object, new resource.Object) error
- type WebhookConfig
Constants ¶
const ( OTelConnTypeGRPC = OTelConnType("grpc") OTelConnTypeHTTP = OTelConnType("http") )
Variables ¶
This section is empty.
Functions ¶
func SetTraceProvider ¶
func SetTraceProvider(cfg OpenTelemetryConfig) error
SetTraceProvider creates a trace.TracerProvider and sets it as the global TracerProvider which is used by default for all app-sdk packages unless overridden.
Types ¶
type App ¶ added in v0.22.0
type App struct {
// contains filtered or unexported fields
}
App is a simple, opinionated implementation of app.App. It must be created with NewApp to be valid.
func NewApp ¶ added in v0.22.0
NewApp creates a new instance of App, managing the kinds provided in AppConfig.ManagedKinds. AppConfig MUST contain a valid KubeConfig to be valid. Watcher/Reconciler error handling, retry, and dequeue logic can be managed with AppConfig.InformerConfig.
func (*App) AddRunnable ¶ added in v0.22.0
AddRunnable adds an arbitrary resource.Runnable runner to the App, which will be encapsulated as part of Runner().Run(). If the provided runner also implements metrics.Provider, PrometheusCollectors() will be called when called on Runner().
func (*App) CallResourceCustomRoute ¶ added in v0.22.0
func (a *App) CallResourceCustomRoute(ctx context.Context, req *app.ResourceCustomRouteRequest) (*app.ResourceCustomRouteResponse, error)
CallResourceCustomRoute implements app.App and handles custom resource route requests
func (*App) Convert ¶ added in v0.22.0
Convert implements app.App and handles resource conversion requests
func (*App) ManagedKinds ¶ added in v0.22.0
ManagedKinds returns a slice of all Kinds managed by this App
func (*App) Mutate ¶ added in v0.22.0
func (a *App) Mutate(ctx context.Context, req *app.AdmissionRequest) (*app.MutatingResponse, error)
Mutate implements app.App and handles Mutating Admission Requests
func (*App) PrometheusCollectors ¶ added in v0.22.0
func (a *App) PrometheusCollectors() []prometheus.Collector
PrometheusCollectors implements metrics.Provider and returns prometheus collectors used by the app for exposing metrics
func (*App) RegisterKindConverter ¶ added in v0.22.0
RegisterKindConverter adds a converter for a GroupKind, which will then be processed on Convert calls
func (*App) RegisterMetricsCollectors ¶ added in v0.27.0
func (a *App) RegisterMetricsCollectors(collectors ...prometheus.Collector)
RegisterMetricsCollectors registers additional prometheus collectors for the app, in addition to those provided by any Runnables the app will run as part of Runner(). These additional prometheus collectors are exposed as a part of the list returned by PrometheusCollectors().
func (*App) Runner ¶ added in v0.22.0
Runner returns a resource.Runnable() that runs the underlying operator.InformerController and all custom runners added via AddRunnable. The returned resource.Runnable also implements metrics.Provider, allowing the caller to gather prometheus.Collector objects used by all underlying runners.
func (*App) Validate ¶ added in v0.22.0
Validate implements app.App and handles Validating Admission Requests
func (*App) ValidateManifest ¶ added in v0.22.0
func (a *App) ValidateManifest(manifest app.ManifestData) error
ValidateManifest can be called with app.ManifestData to validate that the current configuration and managed kinds fully cover the kinds and capabilities in the provided app.ManifestData. If the provided app.ManifestData contains a kind or a capability for a kind/version that is not covered by the app's currently managed kinds, an error will be returned. If the app's current managed kinds cover more than the provided app.ManifestData indicates, no error will be returned. This method can be used after initializing an app to verify it matches the loaded app.ManifestData from the app runner.
type AppConfig ¶ added in v0.22.0
type AppConfig struct { Name string KubeConfig rest.Config InformerConfig AppInformerConfig ManagedKinds []AppManagedKind UnmanagedKinds []AppUnmanagedKind Converters map[schema.GroupKind]Converter // DiscoveryRefreshInterval is the interval at which the API discovery cache should be refreshed. // This is primarily used by the DynamicPatcher in the OpinionatedWatcher/OpinionatedReconciler // for sending finalizer add/remove patches to the latest version of the kind. // This defaults to 10 minutes. DiscoveryRefreshInterval time.Duration }
AppConfig is the configuration used by App
type AppCustomRoute ¶ added in v0.22.0
type AppCustomRoute struct { Method AppCustomRouteMethod Path string }
type AppCustomRouteHandler ¶ added in v0.22.0
type AppCustomRouteHandler func(context.Context, *app.ResourceCustomRouteRequest) (*app.ResourceCustomRouteResponse, error)
type AppCustomRouteHandlers ¶ added in v0.22.0
type AppCustomRouteHandlers map[AppCustomRoute]AppCustomRouteHandler
type AppCustomRouteMethod ¶ added in v0.22.0
type AppCustomRouteMethod string
const ( AppCustomRouteMethodConnect AppCustomRouteMethod = http.MethodConnect AppCustomRouteMethodDelete AppCustomRouteMethod = http.MethodDelete AppCustomRouteMethodGet AppCustomRouteMethod = http.MethodGet AppCustomRouteMethodHead AppCustomRouteMethod = http.MethodHead AppCustomRouteMethodOptions AppCustomRouteMethod = http.MethodOptions AppCustomRouteMethodPatch AppCustomRouteMethod = http.MethodPatch AppCustomRouteMethodPost AppCustomRouteMethod = http.MethodPost AppCustomRouteMethodPut AppCustomRouteMethod = http.MethodPut AppCustomRouteMethodTrace AppCustomRouteMethod = http.MethodTrace )
type AppInformerConfig ¶ added in v0.22.0
type AppInformerConfig struct { ErrorHandler func(context.Context, error) RetryPolicy operator.RetryPolicy RetryDequeuePolicy operator.RetryDequeuePolicy FinalizerSupplier operator.FinalizerSupplier }
AppInformerConfig contains configuration for the App's internal operator.InformerController
type AppManagedKind ¶ added in v0.22.0
type AppManagedKind struct { // Kind is the resource.Kind being managed. This is equivalent to a kubernetes GroupVersionKind Kind resource.Kind // Reconciler is an optional reconciler to run for this Kind. Only one version of a Kind should have a Reconciler, // otherwise, duplicate events will be received. Reconciler operator.Reconciler // Watcher is an optional Watcher to run for this Kind. Only one version of a Kind should have a Watcher, // otherwise, duplicate events will be received. Watcher operator.ResourceWatcher // Validator is an optional ValidatingAdmissionController for the Kind. It will be run only for validation // of this specific version. Validator KindValidator // Mutator is an optional MutatingAdmissionController for the Kind. It will be run only for mutation // of this specific version. Mutator KindMutator // CustomRoutes are an optional map of subresource paths to a route handler. // If supported by the runner, calls to these subresources on this particular version will call this handler. CustomRoutes AppCustomRouteHandlers // ReconcileOptions are the options to use for running the Reconciler or Watcher for the Kind, if one exists. ReconcileOptions BasicReconcileOptions }
AppManagedKind is a Kind and associated functionality used by an App.
type AppProvider ¶ added in v0.22.0
type AppProvider struct { AppManifest app.Manifest AppSpecificConfig app.SpecificConfig NewAppFunc func(config app.Config) (app.App, error) }
AppProvider is a simple implementation of app.Provider which returns AppManifest when Manifest is called, and calls NewAppFunc when NewApp is called.
func NewAppProvider ¶ added in v0.22.0
func NewAppProvider(manifest app.Manifest, cfg app.SpecificConfig, newAppFunc func(cfg app.Config) (app.App, error)) *AppProvider
NewAppProvider is a convenience method for creating a new AppProvider
func (*AppProvider) Manifest ¶ added in v0.22.0
func (p *AppProvider) Manifest() app.Manifest
Manifest returns the AppManifest in the AppProvider
func (*AppProvider) SpecificConfig ¶ added in v0.22.0
func (p *AppProvider) SpecificConfig() app.SpecificConfig
type AppUnmanagedKind ¶ added in v0.22.0
type AppUnmanagedKind struct { // Kind is the resource.Kind the App has an interest in, but does not manage. Kind resource.Kind // Reconciler is an optional reconciler to run for this Kind. Reconciler operator.Reconciler // Watcher is an optional Watcher to run for this Kind. Watcher operator.ResourceWatcher // ReconcileOptions are the options to use for running the Reconciler or Watcher for the Kind, if one exists. ReconcileOptions BasicReconcileOptions }
AppUnmanagedKind is a Kind which an App does not manage, but still may want to watch or reconcile as part of app functionality
type BasicReconcileOptions ¶ added in v0.22.0
type BasicReconcileOptions struct { // Namespace is the namespace to use in the ListWatch request Namespace string // LabelFilters are any label filters to apply to the ListWatch request LabelFilters []string // FieldSelectors are any field selector filters to apply to the ListWatch request FieldSelectors []string // UsePlain can be set to true to avoid wrapping the Reconciler or Watcher in its Opinionated variant. UsePlain bool }
BasicReconcileOptions are settings for the ListWatch and informer setup for a reconciliation loop
type KindMutator ¶ added in v0.22.0
type KindMutator interface {
Mutate(context.Context, *app.AdmissionRequest) (*app.MutatingResponse, error)
}
KindMutator is an interface which describes an object which can mutate a kind, used in AppManagedKind
type KindValidator ¶ added in v0.22.0
type KindValidator interface {
Validate(context.Context, *app.AdmissionRequest) error
}
KindValidator is an interface which describes an object which can validate a kind, used in AppManagedKind
type MetricsConfig ¶
type MetricsConfig struct { metrics.ExporterConfig Enabled bool Namespace string }
MetricsConfig contains configuration information for exposing prometheus metrics
type Mutator ¶ added in v0.22.0
type Mutator struct {
MutateFunc func(context.Context, *app.AdmissionRequest) (*app.MutatingResponse, error)
}
Mutator is a simple implementation of KindMutator, which calls MutateFunc when Mutate is called
func (*Mutator) Mutate ¶ added in v0.22.0
func (m *Mutator) Mutate(ctx context.Context, req *app.AdmissionRequest) (*app.MutatingResponse, error)
Mutate calls MutateFunc and returns the result, if MutateFunc is non-nil (otherwise it returns nil, nil)
type OTelConnType ¶
type OTelConnType string
type OpenTelemetryConfig ¶
type OpenTelemetryConfig struct { Host string Port int ConnType OTelConnType ServiceName string }
type Operator ¶
type Operator struct { Name string // ErrorHandler, if non-nil, is called when a recoverable error is encountered in underlying components. // This is typically used for logging and/or metrics. ErrorHandler func(ctx context.Context, err error) // FinalizerGenerator consumes a schema and returns a finalizer name to use for opinionated logic. // the finalizer name MUST be 63 chars or fewer, and should be unique to the operator FinalizerGenerator func(schema resource.Schema) string // contains filtered or unexported fields }
Operator is a simple operator implementation. Instead of manually registering controllers like with operator.Operator, use WatchKind to add a watcher for a specific kind (schema) and configuration (such as namespace, label filters), ReconcileKind to add a reconciler for a specific kind (schema) and configuration (such as namespace, label filers), and ValidateKind or MutateKind to add admission control for a kind (schema).
func NewOperator ¶
func NewOperator(cfg OperatorConfig) (*Operator, error)
NewOperator creates a new Operator
func (*Operator) ClientGenerator ¶
func (o *Operator) ClientGenerator() resource.ClientGenerator
ClientGenerator returns the ClientGenerator used by the Operator for getting clients for a particular schema
func (*Operator) ConvertKind ¶
ConvertKind provides a conversion path for the provided GroupKind in the converting webhook, using the provided k8s.Converter for the conversion logic.
func (*Operator) MutateKind ¶
func (o *Operator) MutateKind(kind resource.Kind, controller resource.MutatingAdmissionController) error
MutateKind provides a mutation path for the provided kind (schema) in the mutating webhook, using the provided MutatingAdmissionController for the mutation logic.
func (*Operator) ReconcileKind ¶
func (o *Operator) ReconcileKind(kind resource.Kind, reconciler operator.Reconciler, options operator.ListWatchOptions) error
ReconcileKind will watch the specified kind (schema) with opinionated logic, passing the events on to the provided Reconciler. You can configure the query used for watching the kind using ListWatchOptions.
func (*Operator) RegisterMetricsCollectors ¶
func (o *Operator) RegisterMetricsCollectors(collectors ...prometheus.Collector) error
RegisterMetricsCollectors registers Prometheus collectors with the exporter used by the operator, and will expose those metrics via the metrics endpoint configured in the operator config on Operator.Run
func (*Operator) Run ¶
Run will start the operator and run until stopCh is closed or receives message. While running, the operator will:
* Watch/Reconcile all configured resources
* Expose all configured webhooks as an HTTPS server
* Expose a prometheus metrics endpoint if configured
func (*Operator) ValidateKind ¶
func (o *Operator) ValidateKind(kind resource.Kind, controller resource.ValidatingAdmissionController) error
ValidateKind provides a validation path for the provided kind (schema) in the validating webhook, using the provided ValidatingAdmissionController for the validation logic.
func (*Operator) WatchKind ¶
func (o *Operator) WatchKind(kind resource.Kind, watcher SyncWatcher, options operator.ListWatchOptions) error
WatchKind will watch the specified kind (schema) with opinionated logic, passing the relevant events on to the SyncWatcher. You can configure the query used for watching the kind using ListWatchOptions.
type OperatorConfig ¶
type OperatorConfig struct { Name string KubeConfig rest.Config Webhooks WebhookConfig Metrics MetricsConfig Tracing TracingConfig ErrorHandler func(ctx context.Context, err error) // FinalizerGenerator consumes a schema and returns a finalizer name to use for opinionated logic. // the finalizer name MUST be 63 chars or fewer, and should be unique to the operator FinalizerGenerator func(kind resource.Schema) string InformerCacheResyncInterval time.Duration // DiscoveryRefreshInterval is the interval at which the API discovery cache should be refreshed. // This is primarily used by the DynamicPatcher in the OpinionatedWatcher/OpinionatedReconciler // for sending finalizer add/remove patches to the latest version of the kind. // This defaults to 10 minutes. DiscoveryRefreshInterval time.Duration }
OperatorConfig is used to configure an Operator on creation
type Reconciler ¶
type Reconciler struct {
ReconcileFunc func(context.Context, operator.ReconcileRequest) (operator.ReconcileResult, error)
}
Reconciler is a simple Reconciler implementation that calls ReconcileFunc if non-nil on Reconcile requests.
func (*Reconciler) Reconcile ¶
func (s *Reconciler) Reconcile(ctx context.Context, req operator.ReconcileRequest) (operator.ReconcileResult, error)
Reconcile calls ReconcileFunc if non-nil and returns the response, or returns an empty ReconcileResult and nil error if ReconcileFunc is nil.
type SyncWatcher ¶
type SyncWatcher interface { operator.ResourceWatcher // Sync is called for resources which _may_ have experienced updates Sync(context.Context, resource.Object) error }
SyncWatcher extends operator.ResourceWatcher with a Sync method which can be called by the operator.OpinionatedWatcher
type TracingConfig ¶
type TracingConfig struct { Enabled bool OpenTelemetryConfig }
TracingConfig contains configuration information for OpenTelemetry tracing
type Validator ¶ added in v0.22.0
type Validator struct {
ValidateFunc func(context.Context, *app.AdmissionRequest) error
}
Validator is a simple implementation of KindValidator, which calls ValidateFunc when Validate is called
type Watcher ¶
type Watcher struct { AddFunc func(context.Context, resource.Object) error UpdateFunc func(context.Context, resource.Object, resource.Object) error DeleteFunc func(context.Context, resource.Object) error SyncFunc func(context.Context, resource.Object) error }
Watcher is a struct that implements operator.ResourceWatcher and SyncWatcher, but takes no action on its own. For each method in (Add, Update, Delete) the corresponding exported function field is called, if non-nil.
type WebhookConfig ¶
type WebhookConfig struct { Enabled bool // Port is the port to open the webhook server on Port int // TLSConfig is the TLS Cert and Key to use for the HTTPS endpoints exposed for webhooks TLSConfig k8s.TLSConfig // DefaultValidator is an optional Default ValidatingAdmissionController to use if a specific one for the incoming // kind cannot be found DefaultValidator resource.ValidatingAdmissionController // DefaultMutator is an optional Default MutatingAdmissionController to use if a specific one for the incoming // kind cannot be found DefaultMutator resource.MutatingAdmissionController // Validators is an optional map of schema => ValidatingAdmissionController to use for the schema on admission. // This can be empty or nil and specific ValidatingAdmissionControllers can be set later with Operator.ValidateKind Validators map[*resource.Kind]resource.ValidatingAdmissionController // Mutators is an optional map of schema => MutatingAdmissionController to use for the schema on admission. // This can be empty or nil and specific MutatingAdmissionControllers can be set later with Operator.MutateKind Mutators map[*resource.Kind]resource.MutatingAdmissionController // Converters is an optional map of GroupKind => Converter to use for CRD version conversion requests. // This can be empty or nil and specific MutatingAdmissionControllers can be set later with Operator.MutateKind Converters map[metav1.GroupKind]k8s.Converter }
WebhookConfig is a configuration for exposed kubernetes webhooks for an Operator