targets

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package targets is the Target abstraction (feasibility §7.4): Confluent Cloud and Confluent Platform implementations behind a common set of operations. Cluster-link operations support four target-REST auth methods: HTTP basic (CP) / api_key+secret (CC), bearer token (RBAC/MDS), and mutual TLS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateCredentials added in v0.9.0

func ValidateCredentials(c *Credentials) error

ValidateCredentials applies every target-credentials rule to an already-built struct, so any caller that assembles a Credentials value itself (e.g. a test) is held to the same rules as one parsed from a file.

Types

type BasicAuth

type BasicAuth struct {
	Username           string `yaml:"username" json:"username"`
	Password           string `yaml:"password" json:"password"`
	CACert             string `yaml:"ca_cert,omitempty" json:"ca_cert,omitempty"`
	InsecureSkipVerify bool   `yaml:"insecure_skip_verify,omitempty" json:"insecure_skip_verify,omitempty"`
}

BasicAuth is HTTP basic auth (CP) — also how CC api_key/api_secret are sent.

type BearerCreds

type BearerCreds struct {
	Token              string `yaml:"token" json:"token"`
	CACert             string `yaml:"ca_cert,omitempty" json:"ca_cert,omitempty"`
	InsecureSkipVerify bool   `yaml:"insecure_skip_verify,omitempty" json:"insecure_skip_verify,omitempty"`
}

BearerCreds carries an RBAC/OAuth bearer token (e.g. an MDS-issued JWT) sent as `Authorization: Bearer <token>`.

type ConfluentPlatformTarget

type ConfluentPlatformTarget = LinkEndpoint

ConfluentPlatformTarget is a cluster-link REST endpoint that happens to be a migration target (a Confluent Server embedded Admin REST API). It is an alias for the generic LinkEndpoint: the same client type backs both the destination and the source of a source-initiated cluster link, since both expose the same /kafka/v3 REST surface. New code should prefer LinkEndpoint/NewLinkEndpoint; this name is retained for existing callers.

func NewConfluentPlatformTarget

func NewConfluentPlatformTarget(restEndpoint string, creds *Credentials, httpClient clusterlink.HTTPClient) *ConfluentPlatformTarget

NewConfluentPlatformTarget constructs a cluster-link REST client backed by a Confluent Server Admin REST endpoint. It is a thin wrapper over NewLinkEndpoint kept for existing callers. httpClient may be nil to use http.DefaultClient.

type Credentials

type Credentials struct {
	Basic     *BasicAuth   `yaml:"basic,omitempty" json:"basic,omitempty"`
	APIKey    string       `yaml:"api_key,omitempty" json:"api_key,omitempty"`
	APISecret string       `yaml:"api_secret,omitempty" json:"api_secret,omitempty"`
	Bearer    *BearerCreds `yaml:"bearer,omitempty" json:"bearer,omitempty"`
	MTLS      *MTLSCreds   `yaml:"mtls,omitempty" json:"mtls,omitempty"`

	// CACert / InsecureSkipVerify are the api_key form's TLS-trust siblings.
	CACert             string `yaml:"ca_cert,omitempty" json:"ca_cert,omitempty"`
	InsecureSkipVerify bool   `yaml:"insecure_skip_verify,omitempty" json:"insecure_skip_verify,omitempty"`
}

Credentials is the parsed target-creds.yaml. Exactly one auth block is allowed out of: basic, api_key/api_secret (CC), bearer, mtls.

ca_cert and insecure_skip_verify are top-level because the api_key form is itself flat — basic, bearer and mtls carry their own copies inside the block. They apply ONLY to the api_key form and are rejected alongside the others, rather than being silently ignored.

func LoadCredentials

func LoadCredentials(path string) (*Credentials, error)

LoadCredentials reads, parses and validates a target-creds.yaml file.

func ParseCredentials added in v0.9.0

func ParseCredentials(data []byte) (*Credentials, error)

ParseCredentials parses and validates target credentials from bytes. It is the shared entry point so every caller runs exactly the same validation — a rule can never apply to one caller and not another.

func (Credentials) Authenticator

func (c Credentials) Authenticator() clusterlink.Authenticator

Authenticator returns the request Authenticator for the configured auth block. It is the exported form of authenticator, for callers outside this package (e.g. migrate clients) that need to apply auth themselves on top of an HTTPClient built from these same credentials — HTTPClient carries only the TLS transport, never an Authorization header.

func (Credentials) HTTPClient

func (c Credentials) HTTPClient() (clusterlink.HTTPClient, error)

HTTPClient builds the HTTP client for these credentials. Always returns a fresh client cloned from the default transport (never http.DefaultClient) with TLS trust sourced from the active auth block. basic and bearer support optional ca_cert / insecure_skip_verify to reach CP/MDS targets behind a private CA. api_key (CC) uses system roots. mtls additionally presents a client certificate.

type LinkEndpoint

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

LinkEndpoint is a generic cluster-link REST client. It talks to a single Kafka REST endpoint (the v3 Admin REST API) and is agnostic about whether that endpoint is the destination or the source of a cluster link — both expose the same /kafka/v3/clusters and /links surface. Source-initiated links create/read link objects on BOTH a destination and a source endpoint; each is just a separate LinkEndpoint built with that endpoint's creds.

func NewConfluentCloudTarget

func NewConfluentCloudTarget(restEndpoint, clusterID string, creds *Credentials, httpClient clusterlink.HTTPClient) (*LinkEndpoint, error)

NewConfluentCloudTarget constructs a cluster-link REST client for a Confluent Cloud cluster. Unlike CP, CC has no GET /kafka/v3/clusters list endpoint (it 404s), so the lkc cluster id is supplied from the manifest (spec.target.clusterId) and pre-seeded here — ClusterID() then returns it without any discovery call. httpClient may be nil to use http.DefaultClient.

clusterID must be non-empty: a CC target cannot discover its own id, so an empty id would otherwise fall through to the CC-404 list endpoint. Manifest validation already requires spec.target.clusterId for CC; this enforces the invariant at the owner so a future caller can't build a CC target that silently fails with a 404.

func NewLinkEndpoint

func NewLinkEndpoint(restEndpoint string, creds *Credentials, httpClient clusterlink.HTTPClient) *LinkEndpoint

NewLinkEndpoint constructs a cluster-link REST client for an arbitrary endpoint (destination OR source). httpClient may be nil to use http.DefaultClient.

func (*LinkEndpoint) ClusterID

func (e *LinkEndpoint) ClusterID(ctx context.Context) (string, error)

ClusterID discovers the endpoint's Kafka cluster id via GET /kafka/v3/clusters. The result is cached after the first call.

func (e *LinkEndpoint) CreateClusterLink(ctx context.Context, name string, req clusterlink.CreateClusterLinkRequest) error

CreateClusterLink creates the named cluster link on the endpoint. A pre-existing link (ErrLinkExists) is silently treated as success.

func (*LinkEndpoint) CreateMirrorTopic

func (e *LinkEndpoint) CreateMirrorTopic(ctx context.Context, name, sourceTopic, mirrorTopic string) error

CreateMirrorTopic creates a mirror topic on the named link. It discovers (and caches) the cluster id first.

func (*LinkEndpoint) CreateTopic

CreateTopic creates a plain (non-mirror) topic on the endpoint's cluster. It discovers (and caches) the cluster id first.

func (e *LinkEndpoint) GetClusterLink(ctx context.Context, name string) (*clusterlink.ClusterLink, error)

GetClusterLink fetches the named cluster link from the endpoint. Returns (nil, nil) when the link does not exist so the reconciler treats absence as "to create".

func (*LinkEndpoint) GetClusterLinkConfigs

func (e *LinkEndpoint) GetClusterLinkConfigs(ctx context.Context, name string) (map[string]string, error)

GetClusterLinkConfigs returns the named link's live config key/value map (GET .../links/{name}/configs), used by the reconciler for drift detection.

func (e *LinkEndpoint) ListClusterLinks(ctx context.Context) ([]string, error)

ListClusterLinks returns the names of all cluster links on the endpoint's cluster. It discovers (and caches) the cluster id first.

func (*LinkEndpoint) ListMirrorTopics

func (e *LinkEndpoint) ListMirrorTopics(ctx context.Context, name string) ([]clusterlink.MirrorTopic, error)

ListMirrorTopics returns all mirror topics on the named link. Config.Topics is left empty by e.config(name), so the service applies no filtering and the caller gets the full existing-mirror list.

func (*LinkEndpoint) ListTopics

func (e *LinkEndpoint) ListTopics(ctx context.Context) ([]string, error)

ListTopics returns the names of all topics on the endpoint's cluster. It discovers (and caches) the cluster id first.

func (*LinkEndpoint) PartitionCount

func (e *LinkEndpoint) PartitionCount(ctx context.Context, topic string) (int, error)

PartitionCount returns the live partition count of a topic on the endpoint's cluster. It satisfies the newtopics.partitionCounter optional interface, so a LinkEndpoint target reports partition-count drift for existing topics. It discovers (and caches) the cluster id first.

type MTLSCreds

type MTLSCreds struct {
	CACert             string `yaml:"ca_cert,omitempty" json:"ca_cert,omitempty"`
	ClientCert         string `yaml:"client_cert" json:"client_cert"`
	ClientKey          string `yaml:"client_key" json:"client_key"`
	InsecureSkipVerify bool   `yaml:"insecure_skip_verify,omitempty" json:"insecure_skip_verify,omitempty"`
}

MTLSCreds carries client-certificate material for mutual TLS to the target REST API. Auth is the TLS client cert, so no Authorization header is sent.

type Target

type Target interface {
	ClusterID(ctx context.Context) (string, error)
	// GetClusterLink returns (nil, nil) when no link of that name exists.
	GetClusterLink(ctx context.Context, name string) (*clusterlink.ClusterLink, error)
	CreateClusterLink(ctx context.Context, name string, req clusterlink.CreateClusterLinkRequest) error
}

Target is the destination of a migration (feasibility §7.4). Phase 1 carries only the cluster-link operations; it grows per resource deep-dive.

Jump to

Keyboard shortcuts

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