Documentation
¶
Index ¶
- Variables
- func CancelActiveOperations(ctx context.Context, dbClient DBClient, transaction DBTransaction, ...) ([]string, error)
- func CosmosGenericToInternal[InternalAPIType any](cosmosObj *GenericDocument[InternalAPIType]) (*InternalAPIType, error)
- func CosmosToInternal[InternalAPIType, CosmosAPIType any](obj *CosmosAPIType) (*InternalAPIType, error)
- func CosmosToInternalCluster(cosmosObj *HCPCluster) (*api.HCPOpenShiftCluster, error)
- func CosmosToInternalExternalAuth(cosmosObj *ExternalAuth) (*api.HCPOpenShiftClusterExternalAuth, error)
- func CosmosToInternalNodePool(cosmosObj *NodePool) (*api.HCPOpenShiftClusterNodePool, error)
- func Delay(ctx context.Context, delay time.Duration) error
- func GetOrCreateServiceProviderCluster(ctx context.Context, dbClient DBClient, ...) (*api.ServiceProviderCluster, error)
- func GetOrCreateServiceProviderNodePool(ctx context.Context, dbClient DBClient, ...) (*api.ServiceProviderNodePool, error)
- func InternalToCosmos[InternalAPIType, CosmosAPIType any](obj *InternalAPIType) (*CosmosAPIType, error)
- func IsBadRequestError(err error) bool
- func IsConflictError(err error) bool
- func IsNotFoundError(err error) bool
- func IsPreconditionFailedError(err error) bool
- func ListAll[InternalAPIType any](ctx context.Context, pageSize int32, ...) ([]*InternalAPIType, error)
- func NewClusterResourceID(subscriptionID, resourceGroupName, clusterName string) *azcorearm.ResourceID
- func NewCosmosDatabaseClient(url string, dbName string, clientOptions azcore.ClientOptions) (*azcosmos.DatabaseClient, error)
- func NewCosmosResourceCRUD[InternalAPIType, CosmosAPIType any](containerClient *azcosmos.ContainerClient, ...) *nestedCosmosResourceCRUD[InternalAPIType, CosmosAPIType]
- func NewNodePoolResourceID(subscriptionID, resourceGroupName, clusterName, nodePoolName string) *azcorearm.ResourceID
- func NewNotFoundError() *azcore.ResponseError
- func NewOperation(request OperationRequest, externalID *azcorearm.ResourceID, ...) *api.Operation
- func NewPartitionKey(subscriptionID string) azcosmos.PartitionKey
- func OldResourceIDToCosmosID(resourceID *azcorearm.ResourceID) (string, error)
- func ToStatus(doc *api.Operation) *arm.Operation
- type BaseDocument
- type BillingDocCRUD
- type BillingDocument
- type BillingDocumentList
- type BillingDocumentPatchOperations
- type ClusterInternalState
- type ControllerContainer
- type CosmosDBTransactionDetails
- type CosmosDBTransactionStep
- type CosmosDBTransactionStepDetails
- type DBClient
- type DBClientIterator
- type DBClientIteratorItem
- type DBClientListActiveOperationDocsOptions
- type DBClientListResourceDocsOptions
- type DBTransaction
- type DBTransactionCallback
- type DBTransactionResult
- type ExternalAuth
- type ExternalAuthInternalState
- type ExternalAuthProperties
- type ExternalAuthsCRUD
- type GenericDocument
- type GlobalLister
- type GlobalListers
- type HCPCluster
- type HCPClusterCRUD
- type HCPClusterProperties
- type LockClient
- func (c *LockClient) AcquireLock(ctx context.Context, id string, timeout *time.Duration) (*azcosmos.ItemResponse, error)
- func (c *LockClient) GetDefaultTimeToLive() time.Duration
- func (c *LockClient) HoldLock(ctx context.Context, item *azcosmos.ItemResponse) (cancelCtx context.Context, stop StopHoldLock)
- func (c *LockClient) ReleaseLock(ctx context.Context, item *azcosmos.ItemResponse) error
- func (c *LockClient) RenewLock(ctx context.Context, item *azcosmos.ItemResponse) (*azcosmos.ItemResponse, error)
- func (c *LockClient) SetName(name string)
- func (c *LockClient) SetRetryAfterHeader(header http.Header)
- func (c *LockClient) TryAcquireLock(ctx context.Context, id string) (*azcosmos.ItemResponse, error)
- type LockClientInterface
- type ManagementClusterContentCRUD
- type ManagementClusterContentContainer
- type NodePool
- type NodePoolInternalState
- type NodePoolProperties
- type NodePoolsCRUD
- type OperationCRUD
- type OperationRequest
- type ResourceCRUD
- type ResourceDocument
- type ResourceDocumentStateFilter
- type ServiceProviderClusterCRUD
- type ServiceProviderNodePoolCRUD
- type StopHoldLock
- type SubscriptionCRUD
- type TypedDocument
- type TypedDocumentAccessor
- type UntypedResourceCRUD
Constants ¶
This section is empty.
Variables ¶
var ErrAmbiguousResult = errors.New("ambiguous result")
ErrAmbiguousResult occurs when a database query intended to yield a single item unexpectedly yields multiple items.
var ErrItemNotFound = errors.New("item not found")
ErrItemNotFound occurs when the requested item ID was not found, such as in a DBTransactionResult.
var ErrWrongPartition = errors.New("wrong partition key for transaction")
ErrWrongPartition occurs in a DBTransaction create step when the document has a partition key that differs from the transaction's partition key.
Functions ¶
func CancelActiveOperations ¶
func CancelActiveOperations(ctx context.Context, dbClient DBClient, transaction DBTransaction, opts *DBClientListActiveOperationDocsOptions) ([]string, error)
CancelActiveOperations queries for operation documents with a non-terminal status using the filters specified in opts. For every document returned in the query result, CancelActiveOperations adds patch operations to the given DBTransaction to mark the document as canceled.
func CosmosGenericToInternal ¶
func CosmosGenericToInternal[InternalAPIType any](cosmosObj *GenericDocument[InternalAPIType]) (*InternalAPIType, error)
func CosmosToInternal ¶
func CosmosToInternalCluster ¶
func CosmosToInternalCluster(cosmosObj *HCPCluster) (*api.HCPOpenShiftCluster, error)
func CosmosToInternalExternalAuth ¶
func CosmosToInternalExternalAuth(cosmosObj *ExternalAuth) (*api.HCPOpenShiftClusterExternalAuth, error)
func CosmosToInternalNodePool ¶
func CosmosToInternalNodePool(cosmosObj *NodePool) (*api.HCPOpenShiftClusterNodePool, error)
func GetOrCreateServiceProviderCluster ¶
func GetOrCreateServiceProviderCluster( ctx context.Context, dbClient DBClient, clusterResourceID *azcorearm.ResourceID, ) (*api.ServiceProviderCluster, error)
GetOrCreateServiceProviderCluster gets the singleton ServiceProviderCluster instance named `default` for the given cluster resource ID. If it doesn't exist, it creates a new one.
func GetOrCreateServiceProviderNodePool ¶
func GetOrCreateServiceProviderNodePool( ctx context.Context, dbClient DBClient, nodePoolResourceID *azcorearm.ResourceID, ) (*api.ServiceProviderNodePool, error)
GetOrCreateServiceProviderNodePool gets the singleton ServiceProviderNodePool instance named `default` for the given node pool resource ID. If it doesn't exist, it creates a new one.
func InternalToCosmos ¶
func IsBadRequestError ¶
func IsConflictError ¶
IsConflictError returns true if err represents an HTTP 409 Conflict response.
func IsNotFoundError ¶
IsNotFoundError returns true if err represents an HTTP 404 Not Found response.
func IsPreconditionFailedError ¶
IsPreconditionFailedError returns true if err represents an HTTP 412 Precondition Failed response.
func ListAll ¶
func ListAll[InternalAPIType any]( ctx context.Context, pageSize int32, listFn func(ctx context.Context, opts *DBClientListResourceDocsOptions) (DBClientIterator[InternalAPIType], error), ) ([]*InternalAPIType, error)
ListAll accumulates all pages from a DB GlobalLister into a slice. It calls listFn with a page size hint of pageSize and follows continuation tokens until all items have been collected. Any failure to list or iterate causes an early return because the caller needs the complete set of data to make correct decisions. listFn is expected to accept a opts *DBClientListResourceDocsOptions that supports paging via the PageSizeHint attribute. ListAll assists client code in breaking large list queries into multiple smaller chunks of pageSize or smaller. This helps reduce the load on the database at the cost of more round trips. pageSize determines the maximum number of items to be retrieved at once. A negative value will set a dynamic page size controlled by Cosmos.
func NewClusterResourceID ¶
func NewClusterResourceID(subscriptionID, resourceGroupName, clusterName string) *azcorearm.ResourceID
func NewCosmosDatabaseClient ¶
func NewCosmosDatabaseClient(url string, dbName string, clientOptions azcore.ClientOptions) (*azcosmos.DatabaseClient, error)
NewCosmosDatabaseClient instantiates a generic Cosmos database client.
func NewCosmosResourceCRUD ¶
func NewCosmosResourceCRUD[InternalAPIType, CosmosAPIType any]( containerClient *azcosmos.ContainerClient, parentResourceID *azcorearm.ResourceID, resourceType azcorearm.ResourceType) *nestedCosmosResourceCRUD[InternalAPIType, CosmosAPIType]
func NewNodePoolResourceID ¶
func NewNodePoolResourceID(subscriptionID, resourceGroupName, clusterName, nodePoolName string) *azcorearm.ResourceID
func NewNotFoundError ¶
func NewNotFoundError() *azcore.ResponseError
func NewOperation ¶
func NewOperation( request OperationRequest, externalID *azcorearm.ResourceID, internalID ocm.InternalID, location, tenantID, clientID, notificationURI string, correlationData *arm.CorrelationData, ) *api.Operation
func NewPartitionKey ¶
func NewPartitionKey(subscriptionID string) azcosmos.PartitionKey
NewPartitionKey creates a partition key from an Azure subscription ID.
func OldResourceIDToCosmosID ¶
func OldResourceIDToCosmosID(resourceID *azcorearm.ResourceID) (string, error)
Types ¶
type BaseDocument ¶
type BaseDocument struct {
ID string `json:"id,omitempty"`
// https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/time-to-live
TimeToLive int `json:"ttl,omitempty"`
// System-defined properties generated by Cosmos DB
CosmosResourceID string `json:"_rid,omitempty"`
CosmosSelf string `json:"_self,omitempty"`
CosmosETag azcore.ETag `json:"_etag,omitempty"`
CosmosAttachments string `json:"_attachments,omitempty"`
CosmosTimestamp int `json:"_ts,omitempty"`
}
BaseDocument includes fields common to all container items.
type BillingDocCRUD ¶
type BillingDocCRUD interface {
// Create a new billing document
Create(ctx context.Context, doc *BillingDocument) error
// GetByID retrieves a billing document by its ID
GetByID(ctx context.Context, billingDocID string) (*BillingDocument, error)
// List returns an iterator for all billing documents in the given subscription partition.
// This includes both active and deleted billing documents.
List(ctx context.Context) (DBClientIterator[BillingDocument], error)
// ListActive lists all active billing documents (without deletion time) for the subscription
ListActive(ctx context.Context) ([]*BillingDocument, error)
// ListActiveForCluster lists active billing documents for a specific cluster
ListActiveForCluster(ctx context.Context, resourceID *azcorearm.ResourceID) ([]*BillingDocument, error)
// PatchByID patches a billing document by its ID
PatchByID(ctx context.Context, billingDocID string, ops BillingDocumentPatchOperations) error
// PatchByClusterID patches all active billing documents for a cluster
PatchByClusterID(ctx context.Context, resourceID *azcorearm.ResourceID, ops BillingDocumentPatchOperations) error
}
BillingDocCRUD provides a CRUD interface for managing billing documents within a subscription partition.
func NewBillingDocCRUD ¶
func NewBillingDocCRUD(containerClient *azcosmos.ContainerClient, subscriptionID string) BillingDocCRUD
NewBillingDocCRUD creates a new BillingDocCRUD instance for a subscription
type BillingDocument ¶
type BillingDocument struct {
BaseDocument
// The cluster creation time represents the time when the cluster was provisioned successfully
CreationTime time.Time `json:"creationTime,omitempty"`
// The cluster deletion time
DeletionTime *time.Time `json:"deletionTime,omitempty"`
// The location of the HCP cluster
Location string `json:"location,omitempty"`
// The tenant ID of the HCP cluster
TenantID string `json:"tenantId,omitempty"`
// The subscription ID of the HCP cluster (also the partition key)
SubscriptionID string `json:"subscriptionId,omitempty"`
// The HCP cluster ARM resource ID
ResourceID *azcorearm.ResourceID `json:"resourceId,omitempty"`
// The ARM resource ID of the managed resource group of the HCP cluster
ManagedResourceGroup string `json:"managedResourceGroup,omitempty"`
}
BillingDocument records timestamps of Hosted Control Plane OpenShift cluster creation and deletion for the purpose of customer billing.
func NewBillingDocument ¶
func NewBillingDocument(id string, resourceID *azcorearm.ResourceID) *BillingDocument
func (*BillingDocument) DeepCopy ¶
func (in *BillingDocument) DeepCopy() *BillingDocument
DeepCopy creates a deep copy of the BillingDocument.
func (*BillingDocument) DeepCopyObject ¶
func (in *BillingDocument) DeepCopyObject() runtime.Object
DeepCopyObject creates a deep copy of the BillingDocument as runtime.Object.
func (*BillingDocument) GetObjectKind ¶
func (in *BillingDocument) GetObjectKind() schema.ObjectKind
GetObjectKind returns the object kind for BillingDocument.
func (*BillingDocument) GetObjectMeta ¶
func (in *BillingDocument) GetObjectMeta() metav1.Object
GetObjectMeta returns metadata that allows Kubernetes informer machinery to key billing documents by their ID.
type BillingDocumentList ¶
type BillingDocumentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
ResourceVersion string
Items []BillingDocument `json:"items"`
}
BillingDocumentList is a list of billing documents for use with Kubernetes informers.
func (*BillingDocumentList) DeepCopy ¶
func (in *BillingDocumentList) DeepCopy() *BillingDocumentList
DeepCopy creates a deep copy of the BillingDocumentList.
func (*BillingDocumentList) DeepCopyObject ¶
func (in *BillingDocumentList) DeepCopyObject() runtime.Object
DeepCopyObject creates a deep copy of the BillingDocumentList as runtime.Object.
func (*BillingDocumentList) GetObjectKind ¶
func (l *BillingDocumentList) GetObjectKind() schema.ObjectKind
GetObjectKind returns the object kind for BillingDocumentList.
type BillingDocumentPatchOperations ¶
type BillingDocumentPatchOperations struct {
azcosmos.PatchOperations
}
BillingDocumentPatchOperations represents a patch request for a BillingDocument.
func (*BillingDocumentPatchOperations) SetDeletionTime ¶
func (p *BillingDocumentPatchOperations) SetDeletionTime(deletionTime time.Time)
SetDeletionTime appends a set operation for the DeletionTime field.
type ClusterInternalState ¶
type ClusterInternalState struct {
InternalAPI api.HCPOpenShiftCluster `json:"internalAPI"`
}
type ControllerContainer ¶
type ControllerContainer interface {
// TODO controllers are a concept that is at this scope and at lower scopes and sometimes you want to query all like it
// TODO they look a lot like operations, though we can model them as a one-off to start.
Controllers(hcpClusterID string) ResourceCRUD[api.Controller]
}
type CosmosDBTransactionDetails ¶
type CosmosDBTransactionDetails struct {
PartitionKey string `json:"partitionKey"`
Steps []CosmosDBTransactionStepDetails `json:"steps"`
}
type CosmosDBTransactionStep ¶
type CosmosDBTransactionStep func(b *azcosmos.TransactionalBatch) (string, error)
type DBClient ¶
type DBClient interface {
// GetLockClient returns a LockClient, or nil if the DBClient does not support a LockClient.
GetLockClient() LockClientInterface
// NewTransaction initiates a new transactional batch for the given partition key.
NewTransaction(pk string) DBTransaction
// UntypedCRUD provides access documents in the subscription
UntypedCRUD(parentResourceID azcorearm.ResourceID) (UntypedResourceCRUD, error)
// HCPClusters retrieves a CRUD interface for managing HCPCluster resources and their nested resources.
HCPClusters(subscriptionID, resourceGroupName string) HCPClusterCRUD
// Operations retrieves a CRUD interface for managing operations. Remember that operations are not directly accessible
// to end users via ARM. They must also survive the thing they are deleting, so they live under a subscription directly.
Operations(subscriptionID string) OperationCRUD
Subscriptions() SubscriptionCRUD
// BillingDocs retrieves a CRUD interface for managing billing documents within a subscription.
BillingDocs(subscriptionID string) BillingDocCRUD
ServiceProviderClusters(subscriptionID, resourceGroupName, clusterName string) ServiceProviderClusterCRUD
// GlobalListers returns interfaces for listing all resources of a particular
// type across all partitions, intended for feeding SharedInformers.
GlobalListers() GlobalListers
ServiceProviderNodePools(subscriptionID, resourceGroupName, clusterName, nodePoolName string) ServiceProviderNodePoolCRUD
}
DBClient provides a customized interface to the Cosmos DB containers used by the ARO-HCP resource provider.
func NewDBClient ¶
NewDBClient instantiates a DBClient from a Cosmos DatabaseClient instance targeting the Frontends async database.
type DBClientIterator ¶
type DBClientListActiveOperationDocsOptions ¶
type DBClientListActiveOperationDocsOptions struct {
// Request matches the type of asynchronous operation requested
Request *OperationRequest
// ExternalID matches (case-insensitively) the Azure resource ID of the cluster or node pool
ExternalID *azcorearm.ResourceID
// IncludeNestedResources includes nested resources under ExternalID
IncludeNestedResources bool
}
DBClientListActiveOperationDocsOptions allows for limiting the results of DBClient.ListActiveOperationDocs.
type DBClientListResourceDocsOptions ¶
type DBClientListResourceDocsOptions struct {
// ResourceType matches (case-insensitively) the Azure resource type. If unspecified,
// DBClient.ListResourceDocs will match resource documents for any resource type.
ResourceType *azcorearm.ResourceType
// PageSizeHint can limit the number of items returned at once. A negative value will cause
// the returned iterator to yield all matching documents (same as leaving the option nil).
// A positive value will cause the returned iterator to include a continuation token if
// additional items are available.
PageSizeHint *int32
// ContinuationToken can be supplied when limiting the number of items returned at once
// through PageSizeHint.
ContinuationToken *string
}
DBClientListResourceDocsOptions allows for limiting the results of DBClient.ListResourceDocs.
type DBTransaction ¶
type DBTransaction interface {
// AddStep adds a transaction function to the list to perform
AddStep(CosmosDBTransactionStepDetails, CosmosDBTransactionStep)
// GetPartitionKey returns the transaction's partition key.
GetPartitionKey() string
// OnSuccess adds a function to call if the transaction executes successfully.
OnSuccess(callback DBTransactionCallback)
// Execute submits the prepared transaction.
Execute(ctx context.Context, o *azcosmos.TransactionalBatchOptions) (DBTransactionResult, error)
}
type DBTransactionCallback ¶
type DBTransactionCallback func(DBTransactionResult)
type DBTransactionResult ¶
type DBTransactionResult interface {
// GetItem returns the internal API representation for the cosmosUID.
// That is consistent with other returns from our database layer.
// The Item is only available if the transaction was
// executed with the EnableContentResponseOnWrite option set, or
// the document was requested with DBTransaction.ReadDoc.
GetItem(cosmosUID string) (any, error)
}
type ExternalAuth ¶
type ExternalAuth struct {
TypedDocument `json:",inline"`
ExternalAuthProperties `json:"properties"`
}
func InternalToCosmosExternalAuth ¶
func InternalToCosmosExternalAuth(internalObj *api.HCPOpenShiftClusterExternalAuth) (*ExternalAuth, error)
func (*ExternalAuth) GetTypedDocument ¶
func (o *ExternalAuth) GetTypedDocument() *TypedDocument
type ExternalAuthInternalState ¶
type ExternalAuthInternalState struct {
InternalAPI api.HCPOpenShiftClusterExternalAuth `json:"internalAPI"`
}
type ExternalAuthProperties ¶
type ExternalAuthProperties struct {
// when we switch to inlining the internalObj, this will be in the right spot. We add it now so that we can switch our
// queries to select on cosmosMetata.ResourceID instead of resourceId
CosmosMetadata api.CosmosMetadata `json:"cosmosMetadata"`
// IntermediateResourceDoc exists so that we can stop inlining the resource document so that we can directly
// embed the InternalAPIType which has colliding serialization fields.
IntermediateResourceDoc *ResourceDocument `json:"intermediateResourceDoc"`
// TODO we may need look-aside data that we want to store in the same place. Build the nesting to allow it
InternalState ExternalAuthInternalState `json:"internalState"`
}
type ExternalAuthsCRUD ¶
type ExternalAuthsCRUD interface {
ResourceCRUD[api.HCPOpenShiftClusterExternalAuth]
ControllerContainer
}
type GenericDocument ¶
type GenericDocument[InternalAPIType any] struct { TypedDocument `json:",inline"` Content InternalAPIType `json:"properties"` }
pointer of InternalAPIType needs to be arm.CosmosMetadataAccessor
func InternalToCosmosGeneric ¶
func InternalToCosmosGeneric[InternalAPIType any](internalObj *InternalAPIType) (*GenericDocument[InternalAPIType], error)
type GlobalLister ¶
type GlobalLister[T any] interface { List(ctx context.Context, options *DBClientListResourceDocsOptions) (DBClientIterator[T], error) }
GlobalLister lists all resources of a particular type across all partitions.
type GlobalListers ¶
type GlobalListers interface {
Subscriptions() GlobalLister[arm.Subscription]
Clusters() GlobalLister[api.HCPOpenShiftCluster]
NodePools() GlobalLister[api.HCPOpenShiftClusterNodePool]
ExternalAuths() GlobalLister[api.HCPOpenShiftClusterExternalAuth]
ServiceProviderClusters() GlobalLister[api.ServiceProviderCluster]
ServiceProviderNodePools() GlobalLister[api.ServiceProviderNodePool]
Controllers() GlobalLister[api.Controller]
// ManagementClusterContents lists ManagementClusterContent documents across
// partitions for every Cosmos resource type where managementClusterContents
// is nested as a direct child resource. Those types are registered on the lister implementation.
ManagementClusterContents() GlobalLister[api.ManagementClusterContent]
Operations() GlobalLister[api.Operation]
ActiveOperations() GlobalLister[api.Operation]
BillingDocs() GlobalLister[BillingDocument]
}
GlobalListers provides access to global listers for each resource type. These are intended to feed SharedInformers via ListerWatchers.
func NewCosmosGlobalListers ¶
func NewCosmosGlobalListers(resources *azcosmos.ContainerClient, billing *azcosmos.ContainerClient) GlobalListers
type HCPCluster ¶
type HCPCluster struct {
TypedDocument `json:",inline"`
HCPClusterProperties `json:"properties"`
}
func InternalToCosmosCluster ¶
func InternalToCosmosCluster(internalObj *api.HCPOpenShiftCluster) (*HCPCluster, error)
func (*HCPCluster) GetTypedDocument ¶
func (o *HCPCluster) GetTypedDocument() *TypedDocument
type HCPClusterCRUD ¶
type HCPClusterCRUD interface {
ResourceCRUD[api.HCPOpenShiftCluster]
ControllerContainer
ManagementClusterContentContainer
ExternalAuth(hcpClusterID string) ExternalAuthsCRUD
NodePools(hcpClusterID string) NodePoolsCRUD
}
func NewHCPClusterCRUD ¶
func NewHCPClusterCRUD(containerClient *azcosmos.ContainerClient, subscriptionID, resourceGroupName string) HCPClusterCRUD
type HCPClusterProperties ¶
type HCPClusterProperties struct {
// when we switch to inlining the internalObj, this will be in the right spot. We add it now so that we can switch our
// queries to select on cosmosMetata.ResourceID instead of resourceId
CosmosMetadata api.CosmosMetadata `json:"cosmosMetadata"`
// IntermediateResourceDoc exists so that we can stop inlining the resource document so that we can directly
// embed the InternalAPIType which has colliding serialization fields.
IntermediateResourceDoc *ResourceDocument `json:"intermediateResourceDoc"`
// TODO we may need look-aside data that we want to store in the same place. Build the nesting to allow it
InternalState ClusterInternalState `json:"internalState"`
}
type LockClient ¶
type LockClient struct {
// contains filtered or unexported fields
}
func NewLockClient ¶
func NewLockClient(ctx context.Context, containerClient *azcosmos.ContainerClient) (*LockClient, error)
NewLockClient creates a LockClient around a ContainerClient. It attempts to read container properties to extract a default TTL. If this fails or if the container does not define a default TTL, the function returns an error.
func (*LockClient) AcquireLock ¶
func (c *LockClient) AcquireLock(ctx context.Context, id string, timeout *time.Duration) (*azcosmos.ItemResponse, error)
AcquireLock persistently tries to acquire a lock for the given ID. If a timeout is provided, the function will cease after the timeout duration and return a context.DeadlineExceeded error.
func (*LockClient) GetDefaultTimeToLive ¶
func (c *LockClient) GetDefaultTimeToLive() time.Duration
GetDefaultTimeToLive returns the default time-to-live value of the container as a time.Duration.
func (*LockClient) HoldLock ¶
func (c *LockClient) HoldLock(ctx context.Context, item *azcosmos.ItemResponse) (cancelCtx context.Context, stop StopHoldLock)
HoldLock tries to hold an acquired lock by renewing it periodically from a goroutine until the returned stop function is called. The function also returns a new context which is cancelled if the lock is lost or some other error occurs. The stop function terminates the goroutine and returns the current lock, or nil if the lock was lost.
func (*LockClient) ReleaseLock ¶
func (c *LockClient) ReleaseLock(ctx context.Context, item *azcosmos.ItemResponse) error
ReleaseLock attempts to release an acquired lock. Errors should be logged but not treated as fatal, since the container item's TTL value guarantees that it will be released eventually.
func (*LockClient) RenewLock ¶
func (c *LockClient) RenewLock(ctx context.Context, item *azcosmos.ItemResponse) (*azcosmos.ItemResponse, error)
RenewLock attempts to renew an acquired lock. If successful it returns a new lock. If the lock was somehow lost, it returns a nil azcosmos.ItemResponse and no error.
func (*LockClient) SetName ¶
func (c *LockClient) SetName(name string)
SetName overrides how a lock item identifies the owner. This is for informational purposes only. LockClient uses the hostname by default.
func (*LockClient) SetRetryAfterHeader ¶
func (c *LockClient) SetRetryAfterHeader(header http.Header)
SetRetryAfterHeader sets a "Retry-After" header to the default TTL value.
func (*LockClient) TryAcquireLock ¶
func (c *LockClient) TryAcquireLock(ctx context.Context, id string) (*azcosmos.ItemResponse, error)
TryAcquireLock tries once to acquire a lock for the given ID. If the lock is already taken, it returns a nil azcosmos.ItemResponse and no error.
type LockClientInterface ¶
type LockClientInterface interface {
GetDefaultTimeToLive() time.Duration
SetRetryAfterHeader(header http.Header)
AcquireLock(ctx context.Context, id string, timeout *time.Duration) (*azcosmos.ItemResponse, error)
TryAcquireLock(ctx context.Context, id string) (*azcosmos.ItemResponse, error)
HoldLock(ctx context.Context, item *azcosmos.ItemResponse) (context.Context, StopHoldLock)
RenewLock(ctx context.Context, item *azcosmos.ItemResponse) (*azcosmos.ItemResponse, error)
ReleaseLock(ctx context.Context, item *azcosmos.ItemResponse) error
}
type ManagementClusterContentCRUD ¶
type ManagementClusterContentCRUD interface {
ResourceCRUD[api.ManagementClusterContent]
}
type ManagementClusterContentContainer ¶
type ManagementClusterContentContainer interface {
ManagementClusterContents(resourceName string) ManagementClusterContentCRUD
}
type NodePool ¶
type NodePool struct {
TypedDocument `json:",inline"`
NodePoolProperties `json:"properties"`
}
func InternalToCosmosNodePool ¶
func InternalToCosmosNodePool(internalObj *api.HCPOpenShiftClusterNodePool) (*NodePool, error)
func (*NodePool) GetTypedDocument ¶
func (o *NodePool) GetTypedDocument() *TypedDocument
type NodePoolInternalState ¶
type NodePoolInternalState struct {
InternalAPI api.HCPOpenShiftClusterNodePool `json:"internalAPI"`
}
type NodePoolProperties ¶
type NodePoolProperties struct {
// when we switch to inlining the internalObj, this will be in the right spot. We add it now so that we can switch our
// queries to select on cosmosMetata.ResourceID instead of resourceId
CosmosMetadata api.CosmosMetadata `json:"cosmosMetadata"`
// IntermediateResourceDoc exists so that we can stop inlining the resource document so that we can directly
// embed the InternalAPIType which has colliding serialization fields.
IntermediateResourceDoc *ResourceDocument `json:"intermediateResourceDoc"`
// TODO we may need look-aside data that we want to store in the same place. Build the nesting to allow it
InternalState NodePoolInternalState `json:"internalState"`
}
type NodePoolsCRUD ¶
type NodePoolsCRUD interface {
ResourceCRUD[api.HCPOpenShiftClusterNodePool]
ControllerContainer
ManagementClusterContentContainer
}
type OperationCRUD ¶
type OperationCRUD interface {
ResourceCRUD[api.Operation]
// ListActiveOperations returns an iterator that searches for asynchronous operation documents
// with a non-terminal status in the "Resources" container under the given partition key. The
// options argument can further limit the search to documents that match the provided values.
//
// Note that ListActiveOperations does not perform the search, but merely prepares an iterator
// to do so. Hence the lack of a Context argument. The search is performed by calling Items() on
// the iterator in a ranged for loop.
ListActiveOperations(options *DBClientListActiveOperationDocsOptions) DBClientIterator[api.Operation]
}
func NewOperationCRUD ¶
func NewOperationCRUD(containerClient *azcosmos.ContainerClient, subscriptionID string) OperationCRUD
type OperationRequest ¶
type OperationRequest = api.OperationRequest
const ( OperationRequestCreate OperationRequest = "Create" OperationRequestUpdate OperationRequest = "Update" OperationRequestDelete OperationRequest = "Delete" // These are for POST actions on resources. OperationRequestRequestCredential OperationRequest = "RequestCredential" OperationRequestRevokeCredentials OperationRequest = "RevokeCredentials" )
type ResourceCRUD ¶
type ResourceCRUD[InternalAPIType any] interface { GetByID(ctx context.Context, cosmosID string) (*InternalAPIType, error) Get(ctx context.Context, resourceID string) (*InternalAPIType, error) List(ctx context.Context, opts *DBClientListResourceDocsOptions) (DBClientIterator[InternalAPIType], error) Create(ctx context.Context, newObj *InternalAPIType, options *azcosmos.ItemOptions) (*InternalAPIType, error) Replace(ctx context.Context, newObj *InternalAPIType, options *azcosmos.ItemOptions) (*InternalAPIType, error) Delete(ctx context.Context, resourceID string) error AddCreateToTransaction(ctx context.Context, transaction DBTransaction, newObj *InternalAPIType, opts *azcosmos.TransactionalBatchItemOptions) (string, error) AddReplaceToTransaction(ctx context.Context, transaction DBTransaction, newObj *InternalAPIType, opts *azcosmos.TransactionalBatchItemOptions) (string, error) }
func NewControllerCRUD ¶
func NewControllerCRUD( containerClient *azcosmos.ContainerClient, parentResourceID *azcorearm.ResourceID, resourceType azcorearm.ResourceType) ResourceCRUD[api.Controller]
type ResourceDocument ¶
type ResourceDocument struct {
ResourceID *azcorearm.ResourceID `json:"resourceId,omitempty"`
InternalID ocm.InternalID `json:"internalId,omitempty"`
ActiveOperationID string `json:"activeOperationId,omitempty"`
ProvisioningState arm.ProvisioningState `json:"provisioningState,omitempty"`
Identity *arm.ManagedServiceIdentity `json:"identity,omitempty"`
SystemData *arm.SystemData `json:"systemData,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
InternalState map[string]any `json:"internalState,omitempty"`
}
ResourceDocument captures the mapping of an Azure resource ID to an internal resource ID (the OCM API path), as well as any ARM-specific metadata for the resource.
func NewResourceDocument ¶
func NewResourceDocument(resourceID *azcorearm.ResourceID) *ResourceDocument
func (*ResourceDocument) SetResourceID ¶
func (o *ResourceDocument) SetResourceID(newResourceID *azcorearm.ResourceID)
type ResourceDocumentStateFilter ¶
type ResourceDocumentStateFilter interface {
// RemoveUnknownFields checks the customerDesiredState and serviceProviderState and removes unknown fields.
// The simplest implementation is "remove everything" and the next simplest is round-tripping through JSON.
RemoveUnknownFields(*ResourceDocument) error
}
ResourceDocumentStateFilter is used to remove unknown fields from ResourceDocumentProperties. Long-term, we want to reach a point where we store different types so we have full type-safety throughout the stack. Short-term, we want a low-touch modification that makes it safe to store new fields.
type ServiceProviderClusterCRUD ¶
type ServiceProviderClusterCRUD interface {
ResourceCRUD[api.ServiceProviderCluster]
}
type ServiceProviderNodePoolCRUD ¶
type ServiceProviderNodePoolCRUD interface {
ResourceCRUD[api.ServiceProviderNodePool]
}
type StopHoldLock ¶
type StopHoldLock func() *azcosmos.ItemResponse
type SubscriptionCRUD ¶
type SubscriptionCRUD interface {
ResourceCRUD[arm.Subscription]
}
type TypedDocument ¶
type TypedDocument struct {
BaseDocument
PartitionKey string `json:"partitionKey"`
ResourceID *azcorearm.ResourceID `json:"resourceID"`
ResourceType string `json:"resourceType"`
Properties json.RawMessage `json:"properties"`
}
TypedDocument is a BaseDocument with a ResourceType field to help distinguish heterogeneous items in a Cosmos DB container. The Properties field can be unmarshalled to any type that implements the DocumentProperties interface.
func (*TypedDocument) GetTypedDocument ¶
func (td *TypedDocument) GetTypedDocument() *TypedDocument
type TypedDocumentAccessor ¶
type TypedDocumentAccessor interface {
GetTypedDocument() *TypedDocument
}
type UntypedResourceCRUD ¶
type UntypedResourceCRUD interface {
Get(ctx context.Context, resourceID *azcorearm.ResourceID) (*TypedDocument, error)
// List returns back only direct descendents from the parent.
List(ctx context.Context, opts *DBClientListResourceDocsOptions) (DBClientIterator[TypedDocument], error)
// ListRecursive returns back every descendent from the parent. For instance, if you ListRecursive on a cluster,
// you will get the controllers for the cluster, the nodepools, the controllers for each nodepool, the external auths,
// the controllers for the external auths, etc.
ListRecursive(ctx context.Context, opts *DBClientListResourceDocsOptions) (DBClientIterator[TypedDocument], error)
Delete(ctx context.Context, resourceID *azcorearm.ResourceID) error
DeleteByCosmosID(ctx context.Context, partitionKey, cosmosID string) error
Child(resourceType azcorearm.ResourceType, resourceName string) (UntypedResourceCRUD, error)
}
func NewUntypedCRUD ¶
func NewUntypedCRUD(containerClient *azcosmos.ContainerClient, parentResourceID azcorearm.ResourceID) UntypedResourceCRUD
Source Files
¶
- convert_any.go
- convert_cluster.go
- convert_externalauth.go
- convert_generic.go
- convert_nodepool.go
- crud_billing.go
- crud_hcpcluster.go
- crud_helpers.go
- crud_management_cluster_content.go
- crud_nested_resource.go
- crud_serviceprovider_types.go
- crud_serviceprovidernodepools_types.go
- crud_subscription.go
- crud_untyped_resource.go
- database.go
- document.go
- errors.go
- global_lister.go
- iterators.go
- lock.go
- operation_status.go
- service_provider_cluster.go
- service_provider_nodepool.go
- transaction.go
- types_basedocument.go
- types_billingdocument.go
- types_externalauth.go
- types_generic.go
- types_hcpcluster.go
- types_nodepool.go
- types_operation.go
- types_resource.go
- types_typeddocument.go