conversion

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 20 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedConversionReviewVersions = []string{"v1", "v1beta1"}

Functions

func ExtractAPIVersions

func ExtractAPIVersions(objs []unstructured.Unstructured) []string

func VersionsMatched

func VersionsMatched(v0, v1 string) bool

VersionsMatched when: - ver0 equals to ver1 - ver0 is short and ver1 is full and short ver1 is equals to ver0 - ver0 is full and ver1 is short and short ver0 is equals to ver1 Note that ver0 and ver1 with different groups are not matched (e.g. stable/v1 and unstable/v1)

Types

type Chain

type Chain struct {
	// A cache of calculated paths. A key is an arbitrary path and value is a sequence of base paths.
	PathsCache map[Rule][]Rule
	// An index to search for base paths by given From and To.
	BaseFromToIndex map[string]map[string]struct{}
}

func (Chain) HasTargetVersion

func (c Chain) HasTargetVersion(target string) bool

HasTargetVersion returns true if there is a base path leading to an input version.

func (Chain) NextRules

func (c Chain) NextRules(fromVer string) []Rule

NextRules finds all base paths in BaseFromToIndex that starts from an input version.

func (*Chain) Put

func (c *Chain) Put(rule Rule)

Put adds a base path defined by Rule to a cache and updates a FromTo index.

func (Chain) RulesWithSimilarFromVersion

func (c Chain) RulesWithSimilarFromVersion(rule Rule) []Rule

RulesWithFromVersion returns all rules in PathsCache that has similar FromVersion as the input rule.

func (Chain) SearchPathForRule

func (c Chain) SearchPathForRule(rule Rule) []Rule

SearchPathForRule returns an array of base paths for an arbitrary rule.

type ChainStorage

type ChainStorage struct {
	Chains map[string]*Chain
}

func NewChainStorage

func NewChainStorage() *ChainStorage

func (ChainStorage) FindConversionChain

func (cs ChainStorage) FindConversionChain(crdName string, rule Rule) []Rule

Calculations FindConversionChain returns an array of ConverionsRules that should be

func (ChainStorage) Get

func (cs ChainStorage) Get(crdName string) *Chain

Access a Chain by CRD full name (e.g. crontab.stable.example.com)

type CrdClientConfig

type CrdClientConfig struct {
	KubeClient  *klient.Client
	CrdName     string
	Namespace   string
	ServiceName string
	Path        string
	CABundle    []byte
}

A clientConfig for a particular CRD.

func (*CrdClientConfig) Update

func (c *CrdClientConfig) Update() error

type Event

type Event struct {
	CrdName string
	Review  *v1.ConversionReview
	Objects []unstructured.Unstructured
}

func (Event) GetReview

func (e Event) GetReview() map[string]interface{}

Mimic a v1.ConversionReview structure but with the array of unstructured Objects instead of the array of runtime.RawExtension

type EventHandlerFn

type EventHandlerFn func(event Event) (*Response, error)

type Response

type Response struct {
	FailedMessage    string                      `json:"failedMessage"`
	ConvertedObjects []unstructured.Unstructured `json:"convertedObjects,omitempty"`
}

Response is a holder of the conversion hook response.

Unlike ConverionsResponse, only one filed (FailedMessage) is used to determine success or fail:

Response is Success if FailedMessage is empty:

"result": {
  "status": "Success"
},

Response is Failed:

"result": {
  "status": "Failed",
  "message": FailedMessage
}

ConvertedObjects: # Objects must match the order of request.objects, and have apiVersion set to <request.desiredAPIVersion>. # kind, metadata.uid, metadata.name, and metadata.namespace fields must not be changed by the webhook. # metadata.labels and metadata.annotations fields may be changed by the webhook. # All other changes to metadata fields by the webhook are ignored.

func ResponseFromBytes

func ResponseFromBytes(data []byte) (*Response, error)

func ResponseFromFile

func ResponseFromFile(filePath string) (*Response, error)

func ResponseFromReader

func ResponseFromReader(r io.Reader) (*Response, error)

func (*Response) Dump

func (r *Response) Dump() string

type Rule

type Rule struct {
	FromVersion string `json:"fromVersion"`
	ToVersion   string `json:"toVersion"`
}

func (Rule) ShortFromVersion

func (r Rule) ShortFromVersion() string

func (Rule) ShortToVersion

func (r Rule) ShortToVersion() string

func (Rule) String

func (r Rule) String() string

type WebhookConfig

type WebhookConfig struct {
	Rules    []Rule
	CrdName  string // This name is used as a suffix to create different URLs for clientConfig in CRD.
	Metadata struct {
		Name         string
		DebugName    string
		LogLabels    map[string]string
		MetricLabels map[string]string
	}
}

WebhookConfig

type WebhookHandler

type WebhookHandler struct {
	Manager *WebhookManager
	Router  chi.Router
}

func NewWebhookHandler

func NewWebhookHandler() *WebhookHandler

type WebhookManager

type WebhookManager struct {
	KubeClient *klient.Client

	EventHandlerFn EventHandlerFn
	Settings       *WebhookSettings
	Namespace      string

	Server        *server.WebhookServer
	ClientConfigs map[string]*CrdClientConfig
	Handler       *WebhookHandler
}

WebhookManager is a public interface to be used from operator.go.

No dynamic configuration for now. The steps are: - Init():

  • Create a router to distinguish conversion requests between CRDs
  • Create a handler to handle ConversionReview
  • Create a server that listens for Kubernetes requests
  • Call AddWebhook() to register a CRD name in conversion bindings in hooks

- Start():

  • Start server loop.
  • Update clientConfig in each registered CRD.

func NewWebhookManager

func NewWebhookManager() *WebhookManager

func (*WebhookManager) AddWebhook

func (m *WebhookManager) AddWebhook(webhook *WebhookConfig)

func (*WebhookManager) Init

func (m *WebhookManager) Init() error

Init creates dependencies

func (*WebhookManager) Start

func (m *WebhookManager) Start() error

Start webhook server and update spec.conversion in CRDs.

type WebhookSettings

type WebhookSettings struct {
	server.Settings
	CAPath   string
	CABundle []byte
}

Jump to

Keyboard shortcuts

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