client

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package client provides dynamic Kubernetes client utilities.

Index

Constants

View Source
const (
	// DefaultResyncPeriod is the default resync period for informers.
	DefaultResyncPeriod = 10 * time.Minute
)

Variables

View Source
var (
	// KubernetesClusterGVR addresses the edges provider's KubernetesCluster kind
	// (cluster-scoped).
	KubernetesClusterGVR = schema.GroupVersionResource{
		Group:    "edges.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "kubernetesclusters",
	}
	// LinuxServerGVR addresses the edges provider's LinuxServer kind
	// (cluster-scoped).
	LinuxServerGVR = schema.GroupVersionResource{
		Group:    "edges.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "linuxservers",
	}
	// MacOSServerGVR addresses the edges provider's MacOSServer kind
	// (cluster-scoped).
	MacOSServerGVR = schema.GroupVersionResource{
		Group:    "edges.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "macosservers",
	}
	// WorkloadGVR addresses the edges provider's Workload kind
	// (namespaced): a workload scheduled across matching KubernetesCluster edges.
	WorkloadGVR = schema.GroupVersionResource{
		Group:    "edges.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "workloads",
	}
	// PlacementGVR addresses the edges provider's Placement kind (namespaced):
	// one Workload placed on one edge.
	PlacementGVR = schema.GroupVersionResource{
		Group:    "edges.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "placements",
	}

	// UserGVR points at the new tenants.railgrid.ai User CRD. PRs
	// #204-#207 introduced the tenants.railgrid.ai group; this GVR
	// previously pointed at the legacy railgrid.ai group, which left
	// User writes from the auth handler invisible to the org bootstrap
	// controller (which watches the new group). Migration in roadmap
	// step 7+ aligns both sides on tenants.railgrid.ai.
	UserGVR = schema.GroupVersionResource{
		Group:    "tenants.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "users",
	}

	// UserMembershipIndexGVR points at the cluster-scoped UMI CRD
	// (see apis/tenancy/v1alpha1/types_user_membership_index.go).
	// One UMI per User; the tenant middleware reads this on every
	// request to authorise (Org, Workspace) header pairs.
	UserMembershipIndexGVR = schema.GroupVersionResource{
		Group:    "tenants.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "usermembershipindices",
	}

	// GrantGVR points at the cluster-scoped Grant CRD (see
	// apis/tenancy/v1alpha1/types_grant.go): the capabilities a tenant
	// accepted for a subject (today: a provider) in a workspace. Lives in
	// root:railgrid:system:tenants beside the UMI.
	GrantGVR = schema.GroupVersionResource{
		Group:    "tenants.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "grants",
	}

	// ScopedIdentityGVR points at the cluster-scoped ScopedIdentity CRD (see
	// apis/tenancy/v1alpha1/types_scoped_identity.go): the hub's record of one
	// TTL'd identity minted for a tenant object. Lives in
	// root:railgrid:system:tenants beside Grant, so no tenant or provider can
	// read or edit one.
	ScopedIdentityGVR = schema.GroupVersionResource{
		Group:    "tenants.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "scopedidentities",
	}

	// OrganizationGVR points at the cluster-scoped Organization CRD
	// (see apis/tenancy/v1alpha1/types_organization.go). Used by the
	// step 10 REST surface for Org CRUD against root:railgrid:users.
	OrganizationGVR = schema.GroupVersionResource{
		Group:    "tenants.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "organizations",
	}

	// UserPreferencesGVR points at the cluster-scoped UserPreferences CRD
	// (see apis/tenancy/v1alpha1/types_user_preferences.go). One object per
	// User; the portal's dashboard-layout REST handlers read/write it to
	// remember each workspace's tile arrangement across browsers.
	UserPreferencesGVR = schema.GroupVersionResource{
		Group:    "tenants.railgrid.ai",
		Version:  "v1alpha1",
		Resource: "userpreferences",
	}
)

Functions

func EdgeGVRForType

func EdgeGVRForType(edgeType string) schema.GroupVersionResource

EdgeGVRForType maps an edge type ("kubernetes" | "server" | "macos") to the connectable resource's GVR. Unknown and empty types retain the historic KubernetesCluster default.

func EdgeKindForType

func EdgeKindForType(edgeType string) string

EdgeKindForType returns the Kubernetes kind corresponding to an agent edge type. It is kept next to EdgeGVRForType so callers cannot accidentally map a resource to the wrong kind when constructing an unstructured object.

func EdgeTypeForGVR

func EdgeTypeForGVR(gvr schema.GroupVersionResource) string

EdgeTypeForGVR returns the CLI/agent type for a connectable resource GVR. Unknown resources retain the Kubernetes default for backwards compatibility with callers that historically treated every non-server edge as Kubernetes.

Types

type Client

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

Client provides typed access to railgrid custom resources via the dynamic client.

func NewForConfig

func NewForConfig(config *rest.Config) (*Client, error)

NewForConfig creates a new Client for the given rest config.

func NewFromDynamic

func NewFromDynamic(d dynamic.Interface) *Client

NewFromDynamic creates a new Client from an existing dynamic.Interface.

func (*Client) Dynamic

func (c *Client) Dynamic() dynamic.Interface

Dynamic returns the underlying dynamic client.

func (*Client) Grants

Grants returns a typed interface for the cluster-scoped Grant CRD. The provider Enable flow writes grants and the hub-access gate reads them to authorize a provider's delegated token.

func (*Client) Organizations

Organizations returns a typed interface for the cluster-scoped Organization CRD. Used by the step 10 REST surface.

func (*Client) ScopedIdentities added in v0.2.7

ScopedIdentities returns a typed interface for the cluster-scoped ScopedIdentity CRD. The hub identity service writes one record per minted identity and its reconciler garbage-collects them when the owner is gone.

func (*Client) UserMembershipIndices

UserMembershipIndices returns a typed interface for the UMI CRD (cluster-scoped). One UMI per User; the tenant middleware uses this to authorise X-Railgrid-Org / X-Railgrid-Workspace headers on every /api/* request.

func (*Client) UserPreferences

UserPreferences returns a typed interface for the cluster-scoped UserPreferences CRD (one per User). Used by the portal's dashboard layout REST handlers to persist tile arrangement per workspace.

func (*Client) Users

Users returns a typed interface for User resources (cluster-scoped).

type InformerFactory

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

InformerFactory wraps a dynamic shared informer factory and provides convenience methods for getting informers for railgrid resources.

func NewFilteredInformerFactory

func NewFilteredInformerFactory(client dynamic.Interface, resyncPeriod time.Duration, namespace string, tweakListOptions dynamicinformer.TweakListOptionsFunc) *InformerFactory

NewFilteredInformerFactory creates a new InformerFactory with list option tweaks.

func NewInformerFactory

func NewInformerFactory(client dynamic.Interface, resyncPeriod time.Duration) *InformerFactory

NewInformerFactory creates a new InformerFactory for railgrid resources.

func (*InformerFactory) ForResource

ForResource returns a SharedIndexInformer for a specific GVR.

func (*InformerFactory) Start

func (f *InformerFactory) Start(stopCh <-chan struct{})

Start starts all informers.

func (*InformerFactory) WaitForCacheSync

func (f *InformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool

WaitForCacheSync waits for all informer caches to sync.

type TypedResource

type TypedResource[T any, L any] struct {
	// contains filtered or unexported fields
}

TypedResource provides typed CRUD operations for a specific resource type. gvk is used to populate apiVersion/kind on objects before sending them to the dynamic client. The Go structs have TypeMeta tagged `omitempty`, so callers that forget to set apiVersion/kind would otherwise produce a JSON payload missing both fields — which the API server rejects with "Object 'Kind' is missing".

func (*TypedResource[T, L]) Create

func (r *TypedResource[T, L]) Create(ctx context.Context, obj *T, opts metav1.CreateOptions) (*T, error)

Create creates a new resource.

func (*TypedResource[T, L]) Delete

func (r *TypedResource[T, L]) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error

Delete removes a resource by name.

func (*TypedResource[T, L]) Get

func (r *TypedResource[T, L]) Get(ctx context.Context, name string, opts metav1.GetOptions) (*T, error)

Get retrieves a resource by name.

func (*TypedResource[T, L]) List

func (r *TypedResource[T, L]) List(ctx context.Context, opts metav1.ListOptions) (*L, error)

List retrieves all resources matching the given options.

func (*TypedResource[T, L]) Patch

func (r *TypedResource[T, L]) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*T, error)

Patch applies a patch to a resource.

func (*TypedResource[T, L]) Update

func (r *TypedResource[T, L]) Update(ctx context.Context, obj *T, opts metav1.UpdateOptions) (*T, error)

Update updates an existing resource.

func (*TypedResource[T, L]) UpdateStatus

func (r *TypedResource[T, L]) UpdateStatus(ctx context.Context, obj *T, opts metav1.UpdateOptions) (*T, error)

UpdateStatus updates the status subresource.

Jump to

Keyboard shortcuts

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