preview

package
v1.154.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 52 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultServerUrlFor deprecated

func DefaultServerUrlFor(config *rest.Config) (*url.URL, string, error)

Deprecated: Replace with rest.DefaultServerUrlFor DefaultServerUrlFor is shared between IsConfigTransportTLS and RESTClientFor. It requires Host and Version to be set prior to being called.

func FormatFieldIDs added in v1.145.0

func FormatFieldIDs(diffs *structuredreporting.Diff) string

func GetAlternativeControllerExpectedMap added in v1.147.1

func GetAlternativeControllerExpectedMap(configMap resourceconfig.ResourcesControllerMap) map[schema.GroupKind]k8s.ReconcilerType

Types

type Action

type Action string

Action indicates whether we blocked or ignored the requested action.

const (
	// ActionIgnored indicates that the action was ignored.
	ActionIgnored Action = "ignored"
	// ActionBlocked indicates that the action was blocked.
	ActionBlocked Action = "blocked"
)

type BlockedGCPError

type BlockedGCPError struct {
	Method     string
	URL        string
	Body       string
	UpdateMask []string
}

BlockedGCPError is an error that occurs when a GCP API call is blocked.

func ExtractBlockedGCPError

func ExtractBlockedGCPError(err error) (*BlockedGCPError, bool)

ExtractBlockedGCPError will unwrap a BlockedGCPError. To tolerate terraform using string-wrapping of error messages, we also parse a json-encoded form.

func (BlockedGCPError) Error

func (e BlockedGCPError) Error() string

Error implements the error interface.

type ClientOptions

type ClientOptions struct {
	HTTPClient *http.Client
	BaseURL    *url.URL
}

ClientOptions are the options for creating a StreamingClient.

type EventType

type EventType string
const (
	EventTypeReconcileStart EventType = "reconcileStart"
	EventTypeReconcileEnd   EventType = "reconcileEnd"
	EventTypeDiff           EventType = "diff"
	EventTypeKubeAction     EventType = "kubeAction"
	EventTypeGCPAction      EventType = "gcpAction"
)

type GKNN

type GKNN struct {
	Group     string
	Kind      string
	Namespace string
	Name      string
}

GKNN is the canonical identity for a kube object; it is short for Group-Kind-Namespaced-Name (Version is an encoding artifact, and does not change the identity of the object)

type GKNNReconciledResult added in v1.145.0

type GKNNReconciledResult struct {
	GKNN            GKNN
	ControllerType  k8s.ReconcilerType
	ReconcileStatus ReconcileStatus
	Diffs           *structuredreporting.Diff
	GCPActions      []*gcpAction
}

GKNNReconciledResult is the result of reconciling a GKNN object with a specific controller type.

func (*GKNNReconciledResult) FormatGKNNReconciledResult added in v1.145.0

func (r *GKNNReconciledResult) FormatGKNNReconciledResult() string

FormatGKNNReconciledResult formats the GKNNReconciledResult into a string.

type GroupVersionResource

type GroupVersionResource struct {
	Group    string
	Version  string
	Resource string
}

GroupVersionResource is a group, version, and resource.

type ListListener

type ListListener interface {
	OnListBegin(metadata ListMetadata)
	OnListObject(ctx context.Context, obj Object) error
	OnListEnd()
}

ListListener is a listener for list operations.

type ListMetadata

type ListMetadata struct {
	APIVersion      string
	Kind            string
	ResourceVersion string
}

ListMetadata is the metadata for a list operation.

type Object

type Object interface {
	GetNamespace() string
	GetName() string
}

Object is the fields we need from a Kubernetes object.

type ObjectTransformer added in v1.147.0

type ObjectTransformer func(ctx context.Context, obj client.Object) error

ObjectTransformer transforms a Kubernetes object.

func NewSetAlternativeOverrideTransformer added in v1.147.0

func NewSetAlternativeOverrideTransformer(namespace string) ObjectTransformer

NewSetAlternativeOverrideTransformer returns a transformer that sets the controller override to the alternative controller for each resource.

type PreviewInstance

type PreviewInstance struct {

	// Namespace is the namespace of the cluster to preview
	// If empty, all namespaces are previewed
	// Namespace is the namespace of the cluster to preview
	// If empty, all namespaces are previewed
	Namespace string

	ObjectTransformers []ObjectTransformer
	// contains filtered or unexported fields
}

PreviewInstance runs KCC but intercepts GCP and Kubernetes API calls. We allow read-only operations to pass through, but block and log write operations. It is useful for testing the behavior of KCC without actually making any changes to GCP or Kubernetes.

func NewPreviewInstance

func NewPreviewInstance(recorder *Recorder, options PreviewInstanceOptions) (*PreviewInstance, error)

NewPreviewInstance creates a new PreviewInstance.

func (*PreviewInstance) Start

func (i *PreviewInstance) Start(ctx context.Context) error

Start starts the PreviewInstance.

type PreviewInstanceOptions

type PreviewInstanceOptions struct {
	// UpstreamRESTConfig is the rest configuration to use when talking to upstream (real) kube-apiserver
	// (Upstream kube-apiserver may be mocked in tests)
	UpstreamRESTConfig *rest.Config

	// UpstreamGCPAuthorization is the authorization to use when talking to upstream (real) GCP
	// (Upstream GCP may be mocked in tests)
	UpstreamGCPAuthorization oauth2.TokenSource

	// UpstreamGCPHTTPClient is the http client to use when talking to upstream (real) GCP
	// (Upstream GCP may be mocked in tests)
	UpstreamGCPHTTPClient *http.Client

	// UpstreamGCPQPS is the QPS to use when talking to upstream (real) GCP
	// This limit is per API.
	UpstreamGCPQPS float64

	// UpstreamGCPBurst is the burst to use when talking to upstream (real) GCP
	// This limit is per API.
	UpstreamGCPBurst int

	// Namespace is the namespace of the cluster to preview
	// If empty, all namespaces are previewed
	Namespace string

	// ObjectTransformers are the transformers to apply to objects
	ObjectTransformers []ObjectTransformer
}

PreviewInstanceOptions are the options for creating a PreviewInstance.

type ReconcileStatus added in v1.145.0

type ReconcileStatus int
const (
	ReconcileStatusUnknown ReconcileStatus = iota
	ReconcileStatusHealthy
	ReconcileStatusUnhealthy
)

ReconcileStatus is the status of a GKNN object after being reconciled.

func (ReconcileStatus) String added in v1.145.0

func (s ReconcileStatus) String() string

type Recorder

type Recorder struct {

	// Track if a resource has been reconciled.
	ReconciledResources map[GKNN]bool
	// Number of resources has not been reconciled.
	RemainResourcesCount int
	// contains filtered or unexported fields
}

Recorder holds the information from reconciling the objects

func NewRecorder

func NewRecorder() *Recorder

NewRecorder creates a new Recorder.

func (*Recorder) DeepCopy added in v1.147.1

func (r *Recorder) DeepCopy() *Recorder

func (*Recorder) DoneReconciling added in v1.137.0

func (r *Recorder) DoneReconciling() bool

func (*Recorder) ExportDetailObjectsEvent added in v1.137.0

func (r *Recorder) ExportDetailObjectsEvent(filename string) error

ExportObjectsEvent writes all captured GKNN and its event to filename.

func (*Recorder) GKNNDoneReconcile added in v1.137.0

func (r *Recorder) GKNNDoneReconcile(gknn GKNN) bool

func (*Recorder) GenerateRecorderReconciledResults added in v1.145.0

func (r *Recorder) GenerateRecorderReconciledResults() *RecorderReconciledResults

func (*Recorder) GetOrCreateReconciledResults added in v1.147.1

func (recorder *Recorder) GetOrCreateReconciledResults() *RecorderReconciledResults

func (*Recorder) GetRemainResourcesCount added in v1.147.1

func (r *Recorder) GetRemainResourcesCount() int

func (*Recorder) NewStructuredReportingListener

func (r *Recorder) NewStructuredReportingListener() structuredreporting.Listener

NewStructuredReportingListener creates a new StructuredReportingListener.

func (*Recorder) PreloadGKNN added in v1.137.0

func (r *Recorder) PreloadGKNN(ctx context.Context, config *rest.Config, namespace string) error

TODO: Implement concurrent worker by GVRs.

func (*Recorder) RecordBlockedKubeMethod

func (r *Recorder) RecordBlockedKubeMethod(ctx context.Context, scheme *runtime.Scheme, method string, args ...any)

RecordBlockedKubeMethod is called by the interceptingKubeClient when a write operation is blocked.

func (*Recorder) RecordIgnoredKubeMethod

func (r *Recorder) RecordIgnoredKubeMethod(ctx context.Context, scheme *runtime.Scheme, method string, args ...any)

RecordIgnoredKubeMethod is called by the interceptingKubeClient when a read operation is ignored.

type RecorderReconciledResults added in v1.145.0

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

RecorderReconciledResults is the result of reconciling all GKNN objects recorded by the recorder.

func (*RecorderReconciledResults) AddResult added in v1.145.0

func (r *RecorderReconciledResults) AddResult(gknn GKNN, result *GKNNReconciledResult)

func (*RecorderReconciledResults) BadResultReport added in v1.145.0

func (r *RecorderReconciledResults) BadResultReport(badResultFile string, badResult []*GKNNReconciledResult) error

func (*RecorderReconciledResults) CombinedSummaryReport added in v1.147.1

func (r *RecorderReconciledResults) CombinedSummaryReport(summaryFile string, altResult *RecorderReconciledResults, altExpectedMap map[schema.GroupKind]k8s.ReconcilerType) error

type StreamingClient

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

StreamingClient is a client for streaming Kubernetes API responses.

func NewStreamingClient

func NewStreamingClient(opt ClientOptions) *StreamingClient

NewStreamingClient creates a new StreamingClient.

func (*StreamingClient) Get

func (c *StreamingClient) Get(ctx context.Context, typeInfo *typeInfo, namespace, name string, dest Object) error

Get gets the requested object

func (*StreamingClient) List

func (c *StreamingClient) List(ctx context.Context, typeInfo *typeInfo, namespace string, listener ListListener) error

List lists the objects for the given type.

func (*StreamingClient) Watch

func (c *StreamingClient) Watch(ctx context.Context, typeInfo *typeInfo, namespace string, watchOptions WatchOptions, listener WatchListener) error

Watch watches the given type.

type WatchListener

type WatchListener interface {
	OnWatchEvent(ctx context.Context, eventType string, object Object) error
}

WatchListener is a listener for watch operations.

type WatchOptions

type WatchOptions struct {
	ResourceVersion     string
	AllowWatchBookmarks bool
}

WatchOptions are the options for a watch operation.

Jump to

Keyboard shortcuts

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