sqlproxy

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 47 Imported by: 1

Documentation

Overview

Package sqlproxy implements the proxy store, which is responsible for either interfacing directly with the Kubernetes API, or in the case of List, interfacing with an on-disk cache of items in the Kubernetes API.

Index

Constants

This section is empty.

Variables

View Source
var TypeGuidanceTable = map[schema.GroupVersionKind]map[string]string{
	schema.GroupVersionKind{Group: "management.cattle.io", Version: "v3", Kind: "Cluster"}: {
		"status.allocatable.cpuRaw":    "REAL",
		"status.allocatable.memoryRaw": "REAL",
		"status.allocatable.pods":      "INT",
		"status.requested.cpuRaw":      "REAL",
		"status.requested.memoryRaw":   "REAL",
		"status.requested.pods":        "INT",
	},
	schema.GroupVersionKind{Group: "provisioning.cattle.io", Version: "v1", Kind: "Cluster"}: {
		"status.allocatable.cpuRaw":    "REAL",
		"status.allocatable.memoryRaw": "REAL",
		"status.allocatable.pods":      "INT",
		"status.requested.cpuRaw":      "REAL",
		"status.requested.memoryRaw":   "REAL",
		"status.requested.pods":        "INT",
	},
	schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"}: {
		"metadata.fields[2]": "INT",
	},
	schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ServiceAccount"}: {
		"metadata.fields[1]": "INT",
	},
	schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"}: {
		"metadata.fields[1]": "INT",
	},
}
View Source
var (

	// Please keep the gvkKey entries in alphabetical order, on a field-by-field basis
	TypeSpecificIndexedFields = map[string][][]string{
		gvkKey("", "v1", "Event"): {
			{"_type"},
			{"involvedObject", "kind"},
			{"involvedObject", "uid"},
			{"message"},
			{"reason"},
		},
		gvkKey("", "v1", "Namespace"): {
			{"spec", "displayName"},
		},
		gvkKey("", "v1", "Node"): {
			{"status", "nodeInfo", "kubeletVersion"},
			{"status", "nodeInfo", "operatingSystem"}},
		gvkKey("", "v1", "PersistentVolume"): {
			{"status", "reason"},
			{"spec", "persistentVolumeReclaimPolicy"},
		},
		gvkKey("", "v1", "PersistentVolumeClaim"): {
			{"spec", "volumeName"}},
		gvkKey("", "v1", "Pod"): {
			{"spec", "containers", "image"},
			{"spec", "nodeName"},
			{"status", "podIP"},
		},
		gvkKey("", "v1", "ReplicationController"): {
			{"spec", "template", "spec", "containers", "image"}},
		gvkKey("", "v1", "Secret"): {
			{"metadata", "annotations", "management.cattle.io/project-scoped-secret-copy"},
			{"spec", "clusterName"},
			{"spec", "displayName"},
		},
		gvkKey("", "v1", "Service"): {
			{"spec", "clusterIP"},
			{"spec", "type"},
		},
		gvkKey("apps", "v1", "DaemonSet"): {
			{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
			{"spec", "template", "spec", "containers", "image"},
		},
		gvkKey("apps", "v1", "Deployment"): {
			{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
			{"spec", "template", "spec", "containers", "image"},
		},
		gvkKey("apps", "v1", "ReplicaSet"): {
			{"spec", "template", "spec", "containers", "image"},
		},
		gvkKey("apps", "v1", "StatefulSet"): {
			{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
			{"spec", "template", "spec", "containers", "image"},
		},
		gvkKey("autoscaling", "v2", "HorizontalPodAutoscaler"): {
			{"spec", "scaleTargetRef", "name"},
			{"spec", "minReplicas"},
			{"spec", "maxReplicas"},
			{"status", "currentReplicas"},
		},
		gvkKey("batch", "v1", "CronJob"): {
			{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
			{"spec", "jobTemplate", "spec", "template", "spec", "containers", "image"},
			{"status", "lastScheduleTime"},
			{"status", "lastSuccessfulTime"},
		},
		gvkKey("batch", "v1", "Job"): {
			{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
			{"spec", "template", "spec", "containers", "image"},
		},
		gvkKey("catalog.cattle.io", "v1", "App"): {
			{"spec", "chart", "metadata", "name"},
		},
		gvkKey("catalog.cattle.io", "v1", "ClusterRepo"): {
			{"metadata", "annotations", "clusterrepo.cattle.io/hidden"},
			{"spec", "gitBranch"},
			{"spec", "gitRepo"},
		},
		gvkKey("catalog.cattle.io", "v1", "Operation"): {
			{"status", "action"},
			{"status", "namespace"},
			{"status", "releaseName"},
		},
		gvkKey("cluster.x-k8s.io", "v1beta1", "Machine"): {
			{"spec", "clusterName"}},
		gvkKey("cluster.x-k8s.io", "v1beta1", "MachineDeployment"): {
			{"spec", "clusterName"}},
		gvkKey("management.cattle.io", "v3", "Cluster"): {
			{"spec", "internal"},
			{"spec", "displayName"},
			{"status", "allocatable", "cpu"},
			{"status", "allocatable", "cpuRaw"},
			{"status", "allocatable", "memory"},
			{"status", "allocatable", "memoryRaw"},
			{"status", "allocatable", "pods"},
			{"status", "requested", "cpu"},
			{"status", "requested", "cpuRaw"},
			{"status", "requested", "memory"},
			{"status", "requested", "memoryRaw"},
			{"status", "requested", "pods"},
			{"status", "connected"},
			{"status", "provider"},
		},
		gvkKey("management.cattle.io", "v3", "ClusterRoleTemplateBinding"): {
			{"clusterName"},
			{"userName"},
			{"userPrincipalName"},
		},
		gvkKey("management.cattle.io", "v3", "GlobalRoleBinding"): {
			{"userName"},
			{"userPrincipalName"},
		},
		gvkKey("management.cattle.io", "v3", "Node"): {
			{"status", "nodeName"}},
		gvkKey("management.cattle.io", "v3", "NodePool"): {
			{"spec", "clusterName"}},
		gvkKey("management.cattle.io", "v3", "NodeTemplate"): {
			{"spec", "clusterName"}},
		gvkKey("management.cattle.io", "v3", "Project"): {
			{"spec", "clusterName"},
			{"spec", "displayName"},
		},
		gvkKey("management.cattle.io", "v3", "ProjectRoleTemplateBinding"): {
			{"userName"},
			{"userPrincipalName"},
		},
		gvkKey("management.cattle.io", "v3", "RoleTemplate"): {
			{"context"},
		},
		gvkKey("networking.k8s.io", "v1", "Ingress"): {
			{"spec", "rules", "host"},
			{"spec", "ingressClassName"},
		},
		gvkKey("provisioning.cattle.io", "v1", "Cluster"): {
			{"metadata", "annotations", "provisioning.cattle.io/management-cluster-display-name"},
			{"status", "allocatable", "cpu"},
			{"status", "allocatable", "cpuRaw"},
			{"status", "allocatable", "memory"},
			{"status", "allocatable", "memoryRaw"},
			{"status", "allocatable", "pods"},
			{"status", "clusterName"},
			{"status", "provider"},
			{"status", "requested", "cpu"},
			{"status", "requested", "cpuRaw"},
			{"status", "requested", "memory"},
			{"status", "requested", "memoryRaw"},
			{"status", "requested", "pods"},
		},
		gvkKey("rke.cattle.io", "v1", "ETCDSnapshot"): {
			{"snapshotFile", "createdAt"},
			{"spec", "clusterName"},
		},
		gvkKey("storage.k8s.io", "v1", "StorageClass"): {
			{"provisioner"},
			{"metadata", "annotations", "storageclass.kubernetes.io/is-default-class"},
		},
	}
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// ListByOptions returns objects according to the specified list options and partitions.
	// Specifically:
	//   - an unstructured list of resources belonging to any of the specified partitions
	//   - the total number of resources (returned list might be a subset depending on pagination options in lo)
	//   - a summary object, containing the possible values for each field specified in a summary= subquery
	//   - a continue token, if there are more pages after the returned one
	//   - an error instead of all of the above if anything went wrong
	ListByOptions(ctx context.Context, lo *sqltypes.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, *types.APISummary, string, error)
}

type CacheFactory

type CacheFactory interface {
	CacheFor(ctx context.Context, fields [][]string, externalUpdateInfo *sqltypes.ExternalGVKUpdates, selfUpdateInfo *sqltypes.ExternalGVKUpdates, transform cache.TransformFunc, client dynamic.ResourceInterface, gvk schema.GroupVersionKind, typeGuidance map[string]string, namespaced bool, watchable bool) (*factory.Cache, error)
	DoneWithCache(*factory.Cache)
	Stop(gvk schema.GroupVersionKind) error
}

type CacheFactoryInitializer

type CacheFactoryInitializer func() (CacheFactory, error)

type ClientGetter

type ClientGetter interface {
	IsImpersonating() bool
	K8sInterface(ctx *types.APIRequest) (kubernetes.Interface, error)
	AdminK8sInterface() (kubernetes.Interface, error)
	Client(ctx *types.APIRequest, schema *types.APISchema, namespace string, warningHandler rest.WarningHandler) (dynamic.ResourceInterface, error)
	DynamicClient(ctx *types.APIRequest, warningHandler rest.WarningHandler) (dynamic.Interface, error)
	AdminClient(ctx *types.APIRequest, schema *types.APISchema, namespace string, warningHandler rest.WarningHandler) (dynamic.ResourceInterface, error)
	TableClient(ctx *types.APIRequest, schema *types.APISchema, namespace string, warningHandler rest.WarningHandler) (dynamic.ResourceInterface, error)
	TableAdminClient(ctx *types.APIRequest, schema *types.APISchema, namespace string, warningHandler rest.WarningHandler) (dynamic.ResourceInterface, error)
	TableClientForWatch(ctx *types.APIRequest, schema *types.APISchema, namespace string, warningHandler rest.WarningHandler) (dynamic.ResourceInterface, error)
	TableAdminClientForWatch(ctx *types.APIRequest, schema *types.APISchema, namespace string, warningHandler rest.WarningHandler) (dynamic.ResourceInterface, error)
}

ClientGetter is a dynamic kubernetes client factory.

type RelationshipNotifier

type RelationshipNotifier interface {
	OnInboundRelationshipChange(ctx context.Context, schema *types.APISchema, namespace string) <-chan *summary.Relationship
}

RelationshipNotifier is an interface for handling wrangler summary.Relationship events.

type SchemaColumnSetter

type SchemaColumnSetter interface {
	SetColumns(ctx context.Context, schema *types.APISchema) error
}

type Store

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

func NewProxyStore

func NewProxyStore(ctx context.Context, c SchemaColumnSetter, clientGetter ClientGetter, notifier RelationshipNotifier, scache virtualCommon.SummaryCache, factory CacheFactory, needToInitNamespaceCache bool) (*Store, error)

NewProxyStore returns a Store implemented directly on top of kubernetes.

func (*Store) ByID

func (s *Store) ByID(apiOp *types.APIRequest, schema *types.APISchema, id string) (*unstructured.Unstructured, []types.Warning, error)

ByID looks up a single object by its ID.

func (*Store) Create

func (s *Store) Create(apiOp *types.APIRequest, schema *types.APISchema, params types.APIObject) (*unstructured.Unstructured, []types.Warning, error)

Create creates a single object in the store.

func (*Store) Delete

func (s *Store) Delete(apiOp *types.APIRequest, schema *types.APISchema, id string) (*unstructured.Unstructured, []types.Warning, error)

Delete deletes an object from a store.

func (*Store) ListByPartitions

func (s *Store) ListByPartitions(apiOp *types.APIRequest, apiSchema *types.APISchema, partitions []partition.Partition) (list *unstructured.UnstructuredList, total int, summary *types.APISummary, continueToken string, err error)

ListByPartitions returns:

  • an unstructured list of resources belonging to any of the specified partitions
  • the total number of resources (returned list might be a subset depending on pagination options in apiOp)
  • a summary object, containing the possible values for each field specified in a summary= subquery
  • a continue token, if there are more pages after the returned one
  • an error instead of all of the above if anything went wrong

func (*Store) Reset

func (s *Store) Reset(gvk schema.GroupVersionKind) error

Reset locks the store, resets the underlying cache factory, and warm the namespace cache.

func (*Store) Update

func (s *Store) Update(apiOp *types.APIRequest, schema *types.APISchema, params types.APIObject, id string) (*unstructured.Unstructured, []types.Warning, error)

Update updates a single object in the store.

func (*Store) Watch

func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.WatchRequest) (chan watch.Event, error)

Watch returns a channel of events for a list or resource.

func (*Store) WatchByPartitions

func (s *Store) WatchByPartitions(apiOp *types.APIRequest, schema *types.APISchema, wr types.WatchRequest, partitions []partition.Partition) (chan watch.Event, error)

WatchByPartitions returns a channel of events for a list or resource belonging to any of the specified partitions

func (*Store) WatchNames

func (s *Store) WatchNames(apiOp *types.APIRequest, schema *types.APISchema, w types.WatchRequest, names sets.Set[string]) (chan watch.Event, error)

WatchNames returns a channel of events filtered by an allowed set of names. In plain kubernetes, if a user has permission to 'list' or 'watch' a defined set of resource names, performing the list or watch will result in a Forbidden error, because the user does not have permission to list *all* resources. With this filter, the request can be performed successfully, and only the allowed resources will be returned in watch.

type TransformBuilder

type TransformBuilder interface {
	GetTransformFunc(gvk schema.GroupVersionKind, colDefs []common.ColumnDefinition, isCRD bool) cache.TransformFunc
}

type WarningBuffer

type WarningBuffer []types.Warning

WarningBuffer holds warnings that may be returned from the kubernetes api

func (*WarningBuffer) HandleWarningHeader

func (w *WarningBuffer) HandleWarningHeader(code int, agent string, text string)

HandleWarningHeader takes the components of a kubernetes warning header and stores them

type Watchers added in v0.6.7

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

Directories

Path Synopsis
Package tablelistconvert provides a client that will use a table client but convert *UnstructuredList and *Unstructured objects returned by ByID and List to resemble those returned by non-table clients while preserving some table-related data.
Package tablelistconvert provides a client that will use a table client but convert *UnstructuredList and *Unstructured objects returned by ByID and List to resemble those returned by non-table clients while preserving some table-related data.

Jump to

Keyboard shortcuts

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