utils

package
v0.10.0 Latest Latest
Warning

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

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

Documentation

Overview

Package utils contains multiple utility functions used across the Redpanda's terraform codebase

Package utils contains multiple utility functions used across the Redpanda's terraform codebase

Package utils contains multiple utility functions used across the Redpanda's terraform codebase

Index

Constants

View Source
const CloudProviderStringAws = "aws"

CloudProviderStringAws is the string representation of the CLOUD_PROVIDER_AWS enum

View Source
const CloudProviderStringAzure = "azure"

CloudProviderStringAzure is the string representation of the CLOUD_PROVIDER_AZURE enum

View Source
const CloudProviderStringGcp = "gcp"

CloudProviderStringGcp is the string representation of the CLOUD_PROVIDER_GCP enum

Variables

This section is empty.

Functions

func AreWeDoneYet

AreWeDoneYet checks an operation's state until one of completion, failure or timeout is reached.

func CloudProviderToString

func CloudProviderToString(provider controlplanev1beta2.CloudProvider) string

CloudProviderToString returns the cloud provider string based on the controlplanev1beta2's CloudProvider code.

func ClusterTypeToString

func ClusterTypeToString(provider controlplanev1beta2.Cluster_Type) string

ClusterTypeToString returns the cloud cluster type string based on the controlplanev1beta2's Cluster_Type code.

func ConnectionTypeToString

func ConnectionTypeToString(t controlplanev1beta2.Cluster_ConnectionType) string

ConnectionTypeToString returns the cloud cluster connection type string based on the controlplanev1beta2's Cluster_ConnectionType code.

func DeserializeGrpcError added in v0.10.0

func DeserializeGrpcError(err error) string

DeserializeGrpcError err.Error() if it is a standard error. If it is a GRPC error, it returns status and codes for sure and details if they're set. Mild formatting to put details on a separate line for readability

func FindTopicByName

FindTopicByName searches for a topic by name using the provided client.

func FindUserByName

FindUserByName searches for a user by name using the provided client

func GenerateProtobufDiffAndUpdateMask added in v0.10.0

func GenerateProtobufDiffAndUpdateMask[P interface {
	*T
	proto.Message
}, T any](newMessage, oldMessage P) (*T, *fieldmaskpb.FieldMask)

GenerateProtobufDiffAndUpdateMask takes two proto.Message objects and calculates the diff in toplevel fields between them. It returns a new proto.Message object with only the differing values and a fieldmaskpb.FieldMask object with the names of the differing fields. If there are no differing fields, it returns a proto.Message object with no fields set and a FieldMask with an empty Paths slice.

func Int32ToNumber

func Int32ToNumber(i int32) types.Number

Int32ToNumber converts an int32 to a types.Number

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if the passed error is a NotFoundError or a GRPC NotFound error

func MapToCreateTopicConfiguration

func MapToCreateTopicConfiguration(cfg types.Map) ([]*dataplanev1alpha2.CreateTopicRequest_Topic_Config, error)

MapToCreateTopicConfiguration converts a cfg map to a slice of dataplanev1alpha2.CreateTopicRequest_Topic_Config

func MapToSetTopicConfiguration added in v0.5.0

MapToSetTopicConfiguration converts a cfg map to a slice of dataplanev1alpha2.SetTopicConfigurationsRequest_SetConfiguration

func NumberToInt32

func NumberToInt32(n types.Number) *int32

NumberToInt32 converts a types.Number to an *int32

func Retry added in v0.10.0

func Retry(ctx context.Context, timeout time.Duration, f func() *RetryError) error

Retry will retry a function with a delay between each invocation until it no longer returns an error, the timeout is reached, or the context is cancelled. It uses exponential backoff between each call of the function, up to a max of 1 minute, and resets the delay whenever the function returns an error with a different string. Similar to https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/retry#RetryContext

func RetryGetCluster added in v0.10.0

func RetryGetCluster(ctx context.Context, timeout time.Duration, clusterID string, client *cloud.ControlPlaneClientSet, f func(*controlplanev1beta2.Cluster) *RetryError) (*controlplanev1beta2.Cluster, error)

RetryGetCluster will retry a function, passing in the latest state of the given cluster id, until it either no longer returns an error or times out

func SplitSchemeDefPort

func SplitSchemeDefPort(url, def string) (string, error)

SplitSchemeDefPort splits the schema from the url and return url+port. If there is no port, we use the provided default.

func StringSliceToTypeList added in v0.10.0

func StringSliceToTypeList(elements []string) types.List

StringSliceToTypeList safely converts a string slice into a Terraform types.List

func StringToCloudProvider

func StringToCloudProvider(p string) (controlplanev1beta2.CloudProvider, error)

StringToCloudProvider returns the controlplanev1beta2's CloudProvider code based on the input string.

func StringToClusterType

func StringToClusterType(p string) (controlplanev1beta2.Cluster_Type, error)

StringToClusterType returns the controlplanev1beta2's Cluster_Type code based on the input string.

func StringToConnectionType

func StringToConnectionType(s string) controlplanev1beta2.Cluster_ConnectionType

StringToConnectionType returns the controlplanev1beta2's Cluster_ConnectionType code based on the input string.

func StringToStringPointer

func StringToStringPointer(s string) *string

StringToStringPointer converts a string to a pointer to a string

func StringToUserMechanism

func StringToUserMechanism(s string) dataplanev1alpha2.SASLMechanism

StringToUserMechanism converts a string to a dataplanev1alpha2.SASLMechanism

func TopicConfigurationToMap

func TopicConfigurationToMap(cfg []*dataplanev1alpha2.Topic_Configuration) (types.Map, error)

TopicConfigurationToMap converts a slice of dataplanev1alpha2.Topic_Configuration to a slice of models.TopicConfiguration

func TrimmedStringValue

func TrimmedStringValue(s string) types.String

TrimmedStringValue returns the string value of a types.String with the quotes removed. This is necessary as terraform has a tendency to slap these bad boys in at random which causes the API to fail

func TypeListToStringSlice

func TypeListToStringSlice(t types.List) []string

TypeListToStringSlice converts a types.List to a []string, stripping surrounding quotes for each element.

func TypeMapToStringMap added in v0.7.0

func TypeMapToStringMap(tags types.Map) map[string]string

TypeMapToStringMap converts a types.Map to a map[string]string

func UserMechanismToString

func UserMechanismToString(m *dataplanev1alpha2.SASLMechanism) string

UserMechanismToString converts a dataplanev1alpha2.SASLMechanism to a string

Types

type ByocClient added in v0.10.0

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

ByocClient holds the information and clients needed to download and interact with the rpk byoc plugin.

func NewByocClient added in v0.10.0

func NewByocClient(conf ByocClientConfig) *ByocClient

NewByocClient creates a new ByocClient.

func (*ByocClient) RunByoc added in v0.10.0

func (cl *ByocClient) RunByoc(ctx context.Context, clusterID, verb string) error

RunByoc downloads and runs the rpk byoc plugin for a given cluster id and verb ("apply" or "destroy").

type ByocClientConfig added in v0.10.0

type ByocClientConfig struct {
	AuthToken               string
	AzureSubscriptionID     string
	GcpProject              string
	InternalAPIURL          string
	AzureClientID           string
	AzureClientSecret       string
	AzureTenantID           string
	GoogleCredentials       string
	GoogleCredentialsBase64 string
}

ByocClientConfig represents the options that must be passed to NewByocClient.

type DefaultBoolValue

type DefaultBoolValue struct {
	Value    bool
	Desc     string
	MarkDesc string
}

DefaultBoolValue follows the TF framework bool type.

func (*DefaultBoolValue) DefaultBool

DefaultBool sets the default bool value in resp.PlanValue.

func (*DefaultBoolValue) Description

func (d *DefaultBoolValue) Description(_ context.Context) string

Description return the description string.

func (*DefaultBoolValue) MarkdownDescription

func (d *DefaultBoolValue) MarkdownDescription(_ context.Context) string

MarkdownDescription returns the markdown description string.

type NotFoundError added in v0.10.0

type NotFoundError struct {
	Message string
}

NotFoundError represents a resource that couldn't be found

func (NotFoundError) Error added in v0.10.0

func (e NotFoundError) Error() string

Error returns the error message

type RetryError added in v0.10.0

type RetryError struct {
	Err       error
	Retryable bool
}

RetryError is the required return type of functions passed to Retry

func NonRetryableError added in v0.10.0

func NonRetryableError(err error) *RetryError

NonRetryableError is a helper to create a RetryError that's _not_ retryable

func RetryableError added in v0.10.0

func RetryableError(err error) *RetryError

RetryableError is a helper to create a RetryError that's retryable

type TimeoutError added in v0.10.0

type TimeoutError struct {
	Timeout time.Duration
	Wrapped error
}

TimeoutError is returned when Retry times out

func (*TimeoutError) Error added in v0.10.0

func (err *TimeoutError) Error() string

func (*TimeoutError) Unwrap added in v0.10.0

func (err *TimeoutError) Unwrap() error

Jump to

Keyboard shortcuts

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