k8s

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

package k8s implements Kubernetes resources stored in a Kube API server.

Class

A k8s class corresponds to a kind of Kubernetes resource, the class name is `KIND.VERSION.GROUP` VERSION and/or GROUP can be omitted if there is no ambiguity. Example class names: `k8s:Pod.v1`, `ks8:Pod`, `k8s:Deployment.v1.apps`, `k8s:Deployment.apps`, `k8s:Deployment`

Object

Objects are represented by the standard Go types used by `k8s.io/client-go/api`, and by Kube-generated CRD struct types. Rules starting from the k8s domain should use the capitalized Go field names rather than the lowercase JSON field names.

Query

Queries are the JSON-serialized form of this struct: Query

For example:

k8s:Pod.v1.:{"namespace":"openshift-cluster-version","name":"cluster-version-operator-8d86bcb65-btlgn"}

Store

k8s stores connects to the current logged-in Kubernetes cluster, no other configuration is needed than:

domain: k8s

Index

Constants

This section is empty.

Variables

View Source
var Domain = domain{}

Domain for Kubernetes resources stored in a Kube API server.

Functions

func Create

func Create(c client.Client, objs ...client.Object) error

func EventFor

func EventFor(o client.Object, name string) *corev1.Event

func GetConfig added in v0.5.7

func GetConfig() (*rest.Config, error)

GetConfig returns a rest.Config with settings for use by korrel8r.

func GroupVersionKind added in v0.4.0

func GroupVersionKind(o client.Object) schema.GroupVersionKind

GroupVersionKind returns the GVK of o, which must be a pointer to a typed API resource struct. Returns empty if o is not a known resource type.

func NamespacedName

func NamespacedName(namespace, name string) types.NamespacedName

func New

func New[T any, PT interface {
	Object
	*T
}](namespace, name string) PT

func NewClient added in v0.1.1

func NewClient(cfg *rest.Config) (c client.Client, err error)

NewClient provides a general-purpose k8s client. It may be used by other domains that need to talk to the cluster. If cfg is nil, use GetConfig() to get a default config.

func NewHTTPClient added in v0.5.7

func NewHTTPClient() (*http.Client, error)

NewHTTPClient returns a new client for GetConfig()

func NewStore

func NewStore(c client.Client, cfg *rest.Config) (korrel8r.Store, error)

NewStore creates a new k8s store.

func SetLogger added in v0.5.7

func SetLogger(l logr.Logger)

SetLogger sets the logger for controller-runtime.

Types

type Class

Class represents a kind of kubernetes resource.

func ClassOf

func ClassOf(o client.Object) Class

ClassOf returns the Class of o, which must be a pointer to a typed API resource struct.

func (Class) Description added in v0.1.2

func (c Class) Description() string

func (Class) Domain

func (c Class) Domain() korrel8r.Domain

func (Class) GVK

func (c Class) GVK() schema.GroupVersionKind

func (Class) ID

func (c Class) ID(o korrel8r.Object) any

func (Class) Name added in v0.1.2

func (c Class) Name() string

func (Class) New

func (c Class) New() korrel8r.Object

func (Class) Preview

func (c Class) Preview(o korrel8r.Object) string

func (Class) String

func (c Class) String() string

type Object

type Object client.Object

Object is a Go struct type representing a serialized Kubernetes resource.

type Query

type Query struct {
	// Namespace restricts the search to a namespace.
	Namespace string `json:"namespace,omitempty"`
	Name      string `json:"name,omitempty"`
	// Labels restricts the search to objects with matching label values (optional)
	Labels client.MatchingLabels `json:"labels,omitempty"`
	// Fields restricts the search to objects with matching field values (optional)
	Fields client.MatchingFields `json:"fields,omitempty"`
	// K8sClass is the underlying k8s.Class object.
	K8sClass Class
}

Query represents a Kubernetes resource query.

func NewQuery

func NewQuery(c Class, namespace, name string, labels, fields map[string]string) *Query

func (Query) Class

func (q Query) Class() korrel8r.Class

func (Query) Data added in v0.6.0

func (q Query) Data() string

func (Query) String

func (q Query) String() string

type Store

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

Store implements a korrel8r.Store using the kubernetes API server.

func (Store) Client

func (s Store) Client() client.Client

func (Store) Domain

func (s Store) Domain() korrel8r.Domain

func (*Store) Get

func (s *Store) Get(ctx context.Context, query korrel8r.Query, c *korrel8r.Constraint, result korrel8r.Appender) (err error)

func (*Store) TemplateFuncs

func (s *Store) TemplateFuncs() map[string]any

Jump to

Keyboard shortcuts

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