Skip to content

A transport middleware for client-go to mutate k8s resource before send to kube-apiserver

License

Notifications You must be signed in to change notification settings

k-cloud-labs/pidalio

Repository files navigation

pidalio

pidalio-logo

Build Status codecov Go Report Card Go doc

A transport middleware working in clientside for client-go to mutate any k8s resource via (Cluster)OverridePolicy.

If you want to use it in serverside as a webhook, please use https://github.com/k-cloud-labs/kinitiras.

Quick Start

Apply crd files to your cluster

kubectl apply -f https://raw.githubusercontent.com/k-cloud-labs/pkg/main/charts/_crds/bases/policy.kcloudlabs.io_overridepolicies.yaml
kubectl apply -f https://raw.githubusercontent.com/k-cloud-labs/pkg/main/charts/_crds/bases/policy.kcloudlabs.io_clusteroverridepolicies.yaml

OverridePolicy is used to mutate object in the same namespace.
ClusterOverridePolicy can mutate object in any namespace.

For cluster scoped resource:

  • Apply ClusterOverridePolicy by policies name in ascending;

For namespaced scoped resource, apply order is:

  • First apply ClusterOverridePolicy;
  • Then apply OverridePolicy;

Add transport middleware

What you need to do is just call RegisterPolicyTransport func after rest.Config initialized and before client to initialize.

import(
	"github.com/k-cloud-labs/pidalio"
)

// the black magic code
pidalio.RegisterPolicyTransport(config, make(chan struct{}))

Feature

  • Support mutate k8s resource by (Cluster)OverridePolicy via plaintext jsonpatch.
  • Support mutate k8s resource by (Cluster)OverridePolicy programmable via CUE.
  • Support render template to cue in transport(even policy is not created by others)