Documentation
¶
Index ¶
- Variables
- func DetectCrdName(path string) string
- func ExtractAPIVersions(objs []unstructured.Unstructured) []string
- func RawExtensionToUnstructured(objects []runtime.RawExtension) ([]unstructured.Unstructured, error)
- func VersionsMatched(v0, v1 string) bool
- type Chain
- type ChainStorage
- type CrdClientConfig
- type Event
- type EventHandlerFn
- type Response
- type Rule
- type WebhookConfig
- type WebhookHandler
- type WebhookManager
- type WebhookSettings
Constants ¶
This section is empty.
Variables ¶
var SupportedConversionReviewVersions = []string{"v1", "v1beta1"}
Functions ¶
func DetectCrdName ¶
DetectCrdName extracts crdName from the url path.
func ExtractAPIVersions ¶
func ExtractAPIVersions(objs []unstructured.Unstructured) []string
func RawExtensionToUnstructured ¶
func RawExtensionToUnstructured(objects []runtime.RawExtension) ([]unstructured.Unstructured, error)
func VersionsMatched ¶
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 ¶
HasTargetVersion returns true if there is a base path leading to an input version.
func (Chain) NextRules ¶
NextRules finds all base paths in BaseFromToIndex that starts from an input version.
func (Chain) RulesWithSimilarFromVersion ¶
RulesWithFromVersion returns all rules in PathsCache that has similar FromVersion as the input rule.
func (Chain) SearchPathForRule ¶
SearchPathForRule returns an array of base paths for an arbitrary rule.
type ChainStorage ¶
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 PrepareConversionEvent ¶
func PrepareConversionEvent(crdName string, review *v1.ConversionReview) (event Event, err error)
type EventHandlerFn ¶
type Response ¶
type Response struct { FailedMessage string `json:"failedMessage"` ConvertedObjects []unstructured.Unstructured `json:"convertedObjects,omitempty"` }
FailedMessage: Response is Success if empty string:
"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 ResponseFromFile ¶
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
func (*WebhookHandler) HandleReviewRequest ¶
func (h *WebhookHandler) HandleReviewRequest(path string, body []byte) (*v1.ConversionReview, error)
See https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#write-a-conversion-webhook-server This code always response with v1 ConversionReview: it works for 1.16+.
func (*WebhookHandler) ServeReviewRequest ¶
func (h *WebhookHandler) ServeReviewRequest(w http.ResponseWriter, r *http.Request)
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) Start ¶
func (m *WebhookManager) Start() error
Start webhook server and update spec.conversion in CRDs.