Documentation
¶
Index ¶
- Variables
- func GetPatchStatusOperationsOnHookError(operations []sdkpkg.PatchCollectorOperation) []sdkpkg.PatchCollectorOperation
- func GetSchema(name string) *spec.Schema
- func LoadSchema(name string) (*spec.Schema, error)
- func NewCreateIfNotExistsOperation(obj any) sdkpkg.PatchCollectorOperation
- func NewCreateOperation(obj any) sdkpkg.PatchCollectorOperation
- func NewCreateOrUpdateOperation(obj any) sdkpkg.PatchCollectorOperation
- func NewDeleteInBackgroundOperation(apiVersion string, kind string, namespace string, name string) sdkpkg.PatchCollectorOperation
- func NewDeleteNonCascadingOperation(apiVersion string, kind string, namespace string, name string) sdkpkg.PatchCollectorOperation
- func NewDeleteOperation(apiVersion string, kind string, namespace string, name string) sdkpkg.PatchCollectorOperation
- func NewFromOperationSpec(spec OperationSpec) sdkpkg.PatchCollectorOperation
- func NewJSONPatchOperation(jsonpatch any, apiVersion string, kind string, namespace string, name string, ...) sdkpkg.PatchCollectorOperation
- func NewMergePatchOperation(mergePatch any, apiVersion string, kind string, namespace string, name string, ...) sdkpkg.PatchCollectorOperation
- func NewPatchWithJQOperation(jqQuery string, apiVersion string, kind string, namespace string, name string, ...) sdkpkg.PatchCollectorOperation
- func NewPatchWithMutatingFuncOperation(fn func(*unstructured.Unstructured) (*unstructured.Unstructured, error), ...) sdkpkg.PatchCollectorOperation
- func ParseOperations(specBytes []byte) ([]sdkpkg.PatchCollectorOperation, error)
- func ValidateOperationSpec(obj any, s *spec.Schema, rootName string) error
- type KubeClient
- type ObjectPatcher
- type OperationSpec
- type OperationType
- type Option
- type PatchCollector
- func (dop *PatchCollector) Create(object any)
- func (dop *PatchCollector) CreateIfNotExists(object any)
- func (dop *PatchCollector) CreateOrUpdate(object any)
- func (dop *PatchCollector) Delete(apiVersion, kind, namespace, name string)
- func (dop *PatchCollector) DeleteInBackground(apiVersion, kind, namespace, name string)
- func (dop *PatchCollector) DeleteNonCascading(apiVersion, kind, namespace, name string)
- func (dop *PatchCollector) JQFilter(jqfilter, apiVersion, kind, namespace, name string, ...)
- func (dop *PatchCollector) JSONPatch(jsonPatch any, apiVersion, kind, namespace, name string, ...)
- func (dop *PatchCollector) MergePatch(mergePatch any, apiVersion, kind, namespace, name string, ...)
- func (dop *PatchCollector) Operations() []sdkpkg.PatchCollectorOperation
- func (dop *PatchCollector) PatchWithJQ(jqfilter string, apiVersion string, kind string, namespace string, name string, ...)
- func (dop *PatchCollector) PatchWithJSON(jsonPatch any, apiVersion string, kind string, namespace string, name string, ...)
- func (dop *PatchCollector) PatchWithMerge(mergePatch any, apiVersion string, kind string, namespace string, name string, ...)
- func (dop *PatchCollector) PatchWithMutatingFunc(fn func(*unstructured.Unstructured) (*unstructured.Unstructured, error), ...)
Constants ¶
This section is empty.
Variables ¶
var Schemas = map[string]string{
"v0": `
definitions:
common:
type: object
properties:
subresource:
type: string
create:
required:
- object
properties:
object:
oneOf:
- type: object
additionalProperties: true
minProperties: 1
- type: string
delete:
type: object
required:
- kind
- name
properties:
apiVersion:
type: string
kind:
type: string
name:
type: string
patch:
type: object
required:
- kind
- name
properties:
apiVersion:
type: string
kind:
type: string
name:
type: string
ignoreMissingObject:
type: boolean
ignoreHookError:
type: boolean
type: object
additionalProperties: false
properties:
operation: {}
namespace: {}
subresource: {}
apiVersion: {}
kind: {}
name: {}
object: {}
jsonPatch: {}
jqFilter: {}
mergePatch: {}
ignoreMissingObject: {}
ignoreHookError: {}
oneOf:
- allOf:
- properties:
operation:
type: string
enum: ["Create", "CreateOrUpdate", "CreateIfNotExists"]
- "$ref": "#/definitions/common"
- "$ref": "#/definitions/create"
- allOf:
- properties:
operation:
type: string
enum: ["Delete", "DeleteInBackground", "DeleteNonCascading"]
- "$ref": "#/definitions/common"
- "$ref": "#/definitions/delete"
- allOf:
- oneOf:
- required:
- operation
- jqFilter
properties:
operation:
type: string
enum: ["JQPatch"]
jqFilter:
type: string
minimum: 1
- required:
- operation
- mergePatch
properties:
operation:
type: string
enum: ["MergePatch"]
mergePatch:
oneOf:
- type: object
minProperties: 1
- type: string
- required:
- operation
- jsonPatch
properties:
operation:
type: string
enum: ["JSONPatch"]
jsonPatch:
oneOf:
- type: array
minItems: 1
items:
- type: object
required: ["op", "path", "value"]
properties:
op:
type: string
minLength: 1
path:
type: string
minLength: 1
value: {}
- type: string
- "$ref": "#/definitions/common"
- "$ref": "#/definitions/patch"
`,
}
var SchemasCache = map[string]*spec.Schema{}
Functions ¶
func GetPatchStatusOperationsOnHookError ¶ added in v1.4.0
func GetPatchStatusOperationsOnHookError(operations []sdkpkg.PatchCollectorOperation) []sdkpkg.PatchCollectorOperation
GetPatchStatusOperationsOnHookError returns list of Patch/Filter operations eligible for execution on Hook Error
func LoadSchema ¶
LoadSchema returns spec.Schema object loaded from yaml in Schemas map.
func NewCreateIfNotExistsOperation ¶ added in v1.6.0
func NewCreateIfNotExistsOperation(obj any) sdkpkg.PatchCollectorOperation
func NewCreateOperation ¶ added in v1.0.2
func NewCreateOperation(obj any) sdkpkg.PatchCollectorOperation
func NewCreateOrUpdateOperation ¶ added in v1.6.0
func NewCreateOrUpdateOperation(obj any) sdkpkg.PatchCollectorOperation
func NewDeleteInBackgroundOperation ¶ added in v1.6.0
func NewDeleteNonCascadingOperation ¶ added in v1.6.0
func NewDeleteOperation ¶ added in v1.0.2
func NewFromOperationSpec ¶ added in v1.0.2
func NewFromOperationSpec(spec OperationSpec) sdkpkg.PatchCollectorOperation
func NewJSONPatchOperation ¶ added in v1.0.2
func NewJSONPatchOperation(jsonpatch any, apiVersion string, kind string, namespace string, name string, opts ...sdkpkg.PatchCollectorOption) sdkpkg.PatchCollectorOperation
func NewMergePatchOperation ¶ added in v1.0.2
func NewMergePatchOperation(mergePatch any, apiVersion string, kind string, namespace string, name string, opts ...sdkpkg.PatchCollectorOption) sdkpkg.PatchCollectorOperation
func NewPatchWithJQOperation ¶ added in v1.6.0
func NewPatchWithJQOperation(jqQuery string, apiVersion string, kind string, namespace string, name string, opts ...sdkpkg.PatchCollectorOption) sdkpkg.PatchCollectorOperation
func NewPatchWithMutatingFuncOperation ¶ added in v1.6.0
func NewPatchWithMutatingFuncOperation(fn func(*unstructured.Unstructured) (*unstructured.Unstructured, error), apiVersion string, kind string, namespace string, name string, opts ...sdkpkg.PatchCollectorOption) sdkpkg.PatchCollectorOperation
func ParseOperations ¶ added in v1.0.2
func ParseOperations(specBytes []byte) ([]sdkpkg.PatchCollectorOperation, error)
func ValidateOperationSpec ¶
Types ¶
type KubeClient ¶ added in v1.0.2
type KubeClient interface {
kubernetes.Interface
Dynamic() dynamic.Interface
GroupVersionResource(apiVersion string, kind string) (schema.GroupVersionResource, error)
}
type ObjectPatcher ¶
type ObjectPatcher struct {
// contains filtered or unexported fields
}
func NewObjectPatcher ¶
func NewObjectPatcher(kubeClient KubeClient, logger *log.Logger) *ObjectPatcher
func (*ObjectPatcher) ExecuteOperation ¶ added in v1.0.2
func (o *ObjectPatcher) ExecuteOperation(operation sdkpkg.PatchCollectorOperation) error
func (*ObjectPatcher) ExecuteOperations ¶ added in v1.0.2
func (o *ObjectPatcher) ExecuteOperations(ops []sdkpkg.PatchCollectorOperation) error
type OperationSpec ¶
type OperationSpec struct {
Operation OperationType `json:"operation" yaml:"operation"`
ApiVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Subresource string `json:"subresource,omitempty" yaml:"subresource,omitempty"`
Object any `json:"object,omitempty" yaml:"object,omitempty"`
JQFilter string `json:"jqFilter,omitempty" yaml:"jqFilter,omitempty"`
MergePatch any `json:"mergePatch,omitempty" yaml:"mergePatch,omitempty"`
JSONPatch any `json:"jsonPatch,omitempty" yaml:"jsonPatch,omitempty"`
IgnoreMissingObject bool `json:"ignoreMissingObject" yaml:"ignoreMissingObject"`
IgnoreHookError bool `json:"ignoreHookError" yaml:"ignoreHookError"`
}
OperationSpec a JSON and YAML representation of the operation for shell hooks
type OperationType ¶
type OperationType string
const ( CreateOrUpdate OperationType = "CreateOrUpdate" Create OperationType = "Create" CreateIfNotExists OperationType = "CreateIfNotExists" Delete OperationType = "Delete" DeleteInBackground OperationType = "DeleteInBackground" DeleteNonCascading OperationType = "DeleteNonCascading" JQPatch OperationType = "JQPatch" MergePatch OperationType = "MergePatch" JSONPatch OperationType = "JSONPatch" )
type Option ¶ added in v1.6.0
type Option func(o sdkpkg.PatchCollectorOptionApplier)
func WithIgnoreHookError ¶ added in v1.4.0
func WithIgnoreHookError() Option
func WithIgnoreMissingObject ¶ added in v1.0.2
func WithIgnoreMissingObject() Option
func WithSubresource ¶ added in v1.0.2
func (Option) Apply ¶ added in v1.6.0
func (opt Option) Apply(o sdkpkg.PatchCollectorOptionApplier)
type PatchCollector ¶ added in v1.0.2
type PatchCollector struct {
// contains filtered or unexported fields
}
func NewPatchCollector ¶ added in v1.0.2
func NewPatchCollector() *PatchCollector
NewPatchCollector creates Operation collector to use within Go hooks.
func (*PatchCollector) Create ¶ added in v1.0.2
func (dop *PatchCollector) Create(object any)
Create an object.
Options:
- WithSubresource - create a specified subresource
func (*PatchCollector) CreateIfNotExists ¶ added in v1.6.0
func (dop *PatchCollector) CreateIfNotExists(object any)
Create if not exists an object.
Options:
- WithSubresource - create a specified subresource
func (*PatchCollector) CreateOrUpdate ¶ added in v1.6.0
func (dop *PatchCollector) CreateOrUpdate(object any)
Create or update an object.
Options:
- WithSubresource - create a specified subresource
func (*PatchCollector) Delete ¶ added in v1.0.2
func (dop *PatchCollector) Delete(apiVersion, kind, namespace, name string)
Delete uses apiVersion, kind, namespace and name to delete object from cluster. remove object when all dependants are removed
Options:
- WithSubresource - delete a specified subresource
Missing object is ignored by default.
func (*PatchCollector) DeleteInBackground ¶ added in v1.6.0
func (dop *PatchCollector) DeleteInBackground(apiVersion, kind, namespace, name string)
Delete uses apiVersion, kind, namespace and name to delete object from cluster. remove object immediately, dependants remove in background
Options:
- WithSubresource - delete a specified subresource
Missing object is ignored by default.
func (*PatchCollector) DeleteNonCascading ¶ added in v1.6.0
func (dop *PatchCollector) DeleteNonCascading(apiVersion, kind, namespace, name string)
Delete uses apiVersion, kind, namespace and name to delete object from cluster. remove object, dependants become orphan
Options:
- WithSubresource - delete a specified subresource
Missing object is ignored by default.
func (*PatchCollector) JQFilter ¶ added in v1.6.0
func (dop *PatchCollector) JQFilter( jqfilter, apiVersion, kind, namespace, name string, opts ...sdkpkg.PatchCollectorOption, )
Filter retrieves a specified object, modified it with filterFunc and calls update.
Options:
- WithSubresource — a subresource argument for Patch call.
- IgnoreMissingObject — do not return error if the specified object is missing.
- IgnoreHookError — allows applying patches for a Status subresource even if the hook fails
func (*PatchCollector) JSONPatch ¶ added in v1.0.2
func (dop *PatchCollector) JSONPatch(jsonPatch any, apiVersion, kind, namespace, name string, opts ...sdkpkg.PatchCollectorOption)
JSONPatch applies a json patch to the specified object using API call Patch.
Options:
- WithSubresource — a subresource argument for Patch call.
- IgnoreMissingObject — do not return error if the specified object is missing.
- IgnoreHookError — allows applying patches for a Status subresource even if the hook fails
func (*PatchCollector) MergePatch ¶ added in v1.0.2
func (dop *PatchCollector) MergePatch(mergePatch any, apiVersion, kind, namespace, name string, opts ...sdkpkg.PatchCollectorOption)
MergePatch applies a merge patch to the specified object using API call Patch.
Options:
- WithSubresource — a subresource argument for Patch call.
- IgnoreMissingObject — do not return error if the specified object is missing.
- IgnoreHookError — allows applying patches for a Status subresource even if the hook fails
func (*PatchCollector) Operations ¶ added in v1.0.2
func (dop *PatchCollector) Operations() []sdkpkg.PatchCollectorOperation
Operations returns all collected operations
func (*PatchCollector) PatchWithJQ ¶ added in v1.6.0
func (dop *PatchCollector) PatchWithJQ(jqfilter string, apiVersion string, kind string, namespace string, name string, opts ...sdkpkg.PatchCollectorOption)
func (*PatchCollector) PatchWithJSON ¶ added in v1.6.0
func (dop *PatchCollector) PatchWithJSON(jsonPatch any, apiVersion string, kind string, namespace string, name string, opts ...sdkpkg.PatchCollectorOption)
func (*PatchCollector) PatchWithMerge ¶ added in v1.6.0
func (dop *PatchCollector) PatchWithMerge(mergePatch any, apiVersion string, kind string, namespace string, name string, opts ...sdkpkg.PatchCollectorOption)
func (*PatchCollector) PatchWithMutatingFunc ¶ added in v1.6.0
func (dop *PatchCollector) PatchWithMutatingFunc( fn func(*unstructured.Unstructured) (*unstructured.Unstructured, error), apiVersion, kind, namespace, name string, opts ...sdkpkg.PatchCollectorOption, )
Filter retrieves a specified object, modified it with filterFunc and calls update.
Options:
- WithSubresource — a subresource argument for Patch call.
- IgnoreMissingObject — do not return error if the specified object is missing.
- IgnoreHookError — allows applying patches for a Status subresource even if the hook fails
Note: do not modify and return argument in filterFunc, use FromUnstructured to instantiate a concrete type or modify after DeepCopy.