object_patch

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: Apache-2.0 Imports: 24 Imported by: 38

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Schemas = map[string]string{
	"v0": `
definitions:
  common:
    type: object
    properties:
      subresource:
        type: string
  create:
    required:
    - object
    properties:
      object:
        type: object
        additionalProperties: true
        minProperties: 1
  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

type: object
additionalProperties: false
properties:
  operation: {}
  namespace: {}
  subresource: {}
  apiVersion: {}
  kind: {}
  name: {}
  object: {}
  jsonPatch: {}
  jqFilter: {}
  mergePatch: {}

oneOf:
- allOf:
  - properties:
      operation:
        type: string
        enum: ["Create", "CreateOrUpdate"]
  - "$ref": "#/definitions/common"
  - "$ref": "#/definitions/create"
- allOf:
  - properties:
      operation:
        type: string
        enum: ["Delete", "DeleteInBackground", "DeleteNonCascading"]
  - "$ref": "#/definitions/common"
  - "$ref": "#/definitions/delete"
- allOf:
  - oneOf:
    - properties:
        operation:
          type: string
          enum: ["JQPatch"]
        jqFilter:
          type: string
          minimum: 1
    - properties:
        operation:
          type: string
          enum: ["MergePatch"]
        mergePatch:
          type: object
          minProperties: 1
    - properties:
        operation:
          type: string
          enum: ["JSONPatch"]
        jsonPatch:
          type: array
          minItems: 1
          items:
          - type: object
            required: ["op", "path", "value"]
            properties:
              op:
                type: string
                minLength: 1
              path:
                type: string
                minLength: 1
              value: {}
  - "$ref": "#/definitions/common"
  - "$ref": "#/definitions/patch"
`,
}
View Source
var SchemasCache = map[string]*spec.Schema{}

Functions

func GetSchema

func GetSchema(name string) *spec.Schema

GetSchema returns loaded schema.

func LoadSchema

func LoadSchema(name string) (*spec.Schema, error)

LoadSchema returns spec.Schema object loaded from yaml in Schemas map.

Types

type ObjectPatcher

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

func NewObjectPatcher

func NewObjectPatcher(kubeClient kube.KubernetesClient) *ObjectPatcher

func (*ObjectPatcher) CreateObject

func (o *ObjectPatcher) CreateObject(object *unstructured.Unstructured, subresource string) error

func (*ObjectPatcher) CreateOrUpdateObject

func (o *ObjectPatcher) CreateOrUpdateObject(object *unstructured.Unstructured, subresource string) error

func (*ObjectPatcher) DeleteObject

func (o *ObjectPatcher) DeleteObject(apiVersion, kind, namespace, name, subresource string) error

func (*ObjectPatcher) DeleteObjectInBackground

func (o *ObjectPatcher) DeleteObjectInBackground(apiVersion, kind, namespace, name, subresource string) error

func (*ObjectPatcher) DeleteObjectNonCascading

func (o *ObjectPatcher) DeleteObjectNonCascading(apiVersion, kind, namespace, name, subresource string) error

func (*ObjectPatcher) FilterObject

func (o *ObjectPatcher) FilterObject(filterFunc func(*unstructured.Unstructured) (*unstructured.Unstructured, error),
	apiVersion, kind, namespace, name, subresource string) error

func (*ObjectPatcher) GenerateFromJSONAndExecuteOperations

func (o *ObjectPatcher) GenerateFromJSONAndExecuteOperations(specs []OperationSpec) error

func (*ObjectPatcher) JQPatchObject

func (o *ObjectPatcher) JQPatchObject(jqPatch, apiVersion, kind, namespace, name, subresource string) error

func (*ObjectPatcher) JSONPatchObject

func (o *ObjectPatcher) JSONPatchObject(jsonPatch []byte, apiVersion, kind, namespace, name, subresource string) error

func (*ObjectPatcher) MergePatchObject

func (o *ObjectPatcher) MergePatchObject(mergePatch []byte, apiVersion, kind, namespace, name, subresource string) 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     map[string]interface{} `json:"object,omitempty" yaml:"object,omitempty"`
	JQFilter   string                 `json:"jqFilter,omitempty" yaml:"jqFilter,omitempty"`
	MergePatch map[string]interface{} `json:"mergePatch,omitempty" yaml:"mergePatch,omitempty"`
	JSONPatch  []interface{}          `json:"jsonPatch,omitempty" yaml:"jsonPatch,omitempty"`
}

func ParseSpecs

func ParseSpecs(specBytes []byte) ([]OperationSpec, error)

type OperationType

type OperationType string
const (
	CreateOrUpdate OperationType = "CreateOrUpdate"
	Create         OperationType = "Create"

	Delete             OperationType = "Delete"
	DeleteInBackground OperationType = "DeleteInBackground"
	DeleteNonCascading OperationType = "DeleteNonCascading"

	JQPatch    OperationType = "JQPatch"
	MergePatch OperationType = "MergePatch"
	JSONPatch  OperationType = "JSONPatch"
)

Jump to

Keyboard shortcuts

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