resources

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 42 Imported by: 7

Documentation

Index

Constants

View Source
const (
	EnvForceReconcileTimeout   = "ENV_FORCE_RECONCILE_TIMEOUT"
	EnvMetricsReconcileTimeout = "ENV_METRIC_RECONCILE_TIMEOUT"
	DefaultTagKeyPrefix        = "integreatly.org/"
	// Set the reconcile duration for this controller.
	// Currently it will be called once every 5 minutes
	MetricsWatchDuration = 5 * time.Minute
)
View Source
const (
	BytesInGibiBytes                        = 1073741824
	DefaultBlobStorageStatusMetricName      = "cro_blobstorage_status_phase"
	DefaultPostgresAvailMetricName          = "cro_postgres_available"
	DefaultPostgresConnectionMetricName     = "cro_postgres_connection"
	DefaultPostgresDeletionMetricName       = "cro_postgres_deletion_timestamp"
	DefaultPostgresInfoMetricName           = "cro_postgres_info"
	DefaultPostgresMaintenanceMetricName    = "cro_postgres_service_maintenance"
	DefaultPostgresSnapshotStatusMetricName = "cro_postgres_snapshot_status_phase"
	DefaultPostgresStatusMetricName         = "cro_postgres_status_phase"
	DefaultRedisAvailMetricName             = "cro_redis_available"
	DefaultRedisConnectionMetricName        = "cro_redis_connection"
	DefaultRedisDeletionMetricName          = "cro_redis_deletion_timestamp"
	DefaultRedisInfoMetricName              = "cro_redis_info"
	DefaultRedisMaintenanceMetricName       = "cro_redis_service_maintenance"
	DefaultRedisSnapshotNotAvailable        = "cro_redis_snapshot_not_found"
	DefaultRedisSnapshotStatusMetricName    = "cro_redis_snapshot_status_phase"
	DefaultRedisStatusMetricName            = "cro_redis_status_phase"
	DefaultSTSCredentialsSecretMetricName   = "cro_sts_credentials_secret" // #nosec G101 -- false positive (ref: https://securego.io/docs/rules/g101.html)
	DefaultVpcActionMetricName              = "cro_vpc_action"

	MonitoringResourceTypeRedisInstance    MonitoringResourceType = "redis_instance"
	MonitoringResourceTypeCloudsqlDatabase MonitoringResourceType = "cloudsql_database"

	PostgresFreeStorageAverageMetricName    = "cro_postgres_free_storage_average"
	PostgresCPUUtilizationAverageMetricName = "cro_postgres_cpu_utilization_average"
	PostgresFreeableMemoryAverageMetricName = "cro_postgres_freeable_memory_average"
	PostgresMaxMemoryMetricName             = "cro_postgres_max_memory"
	PostgresAllocatedStorageMetricName      = "cro_postgres_current_allocated_storage"

	RedisMemoryUsagePercentageAverageMetricName = "cro_redis_memory_usage_percentage_average"
	RedisFreeableMemoryAverageMetricName        = "cro_redis_freeable_memory_average"
	RedisCPUUtilizationAverageMetricName        = "cro_redis_cpu_utilization_average"
	RedisEngineCPUUtilizationAverageMetricName  = "cro_redis_engine_cpu_utilization_average"
)
View Source
const (
	LabelClusterIDKey   = "clusterID"
	LabelResourceIDKey  = "resourceID"
	LabelNamespaceKey   = "namespace"
	LabelInstanceIDKey  = "instanceID"
	LabelProductNameKey = "productName"
	LabelStrategyKey    = "strategy"
	LabelStatusKey      = "status"
	LabelStatusPhaseKey = "statusPhase"
)
View Source
const (
	TagDisplayName = "Name"

	TagManagedKey = "red-hat-managed"
	TagManagedVal = "true"
)
View Source
const (
	LoggingKeyAction = "action"
)

Variables

View Source
var (
	// MetricVecs create the map of vectors
	MetricVecs map[string]prometheus.GaugeVec
)

Functions

func AddLabel added in v1.1.0

func AddLabel(object metav1.Object, key, value string)

AddLabel makes sure that the provided key/value are set as a label

func Btof64

func Btof64(b bool) float64

Boolean to float64

func BuildGenericMetricLabels added in v1.0.0

func BuildGenericMetricLabels(objectMeta metav1.ObjectMeta, clusterID, instanceID, providerName string) map[string]string

BuildGenericMetricLabels returns generic labels to be added to every metric

func BuildInfoMetricLabels added in v1.0.0

func BuildInfoMetricLabels(r metav1.ObjectMeta, status string, clusterID, cacheName, providerName string) map[string]string

BuildInfoMetricLabels adds extra information to labels around resource

func BuildInfraName added in v1.0.0

func BuildInfraName(ctx context.Context, c client.Client, postfix string, n int) (string, error)

BuildInfraName builds and returns an id used for infra resources

func BuildInfraNameFromObject added in v1.0.0

func BuildInfraNameFromObject(ctx context.Context, c client.Client, om controllerruntime.ObjectMeta, n int) (string, error)

func BuildStatusMetricsLabels added in v1.0.0

func BuildStatusMetricsLabels(r metav1.ObjectMeta, clusterID, cacheName, providerName string, phase croType.StatusPhase) map[string]string

func BuildTimestampedInfraNameFromObject added in v1.0.0

func BuildTimestampedInfraNameFromObject(ctx context.Context, c client.Client, om controllerruntime.ObjectMeta, n int) (string, error)

func BuildTimestampedInfraNameFromObjectCreation added in v1.0.0

func BuildTimestampedInfraNameFromObjectCreation(ctx context.Context, c client.Client, om controllerruntime.ObjectMeta, n int) (string, error)

func Contains

func Contains(list []string, s string) bool

Contains checks if a string exists in a slice of strings

func CreateFinalizer

func CreateFinalizer(ctx context.Context, c client.Client, inst client.Object, df string) error

func GeneratePassword

func GeneratePassword() (string, error)

func GetAWSRegion

func GetAWSRegion(ctx context.Context, c client.Client) (string, error)

func GetClusterID

func GetClusterID(ctx context.Context, c client.Client) (string, error)

func GetClusterInfrastructure

func GetClusterInfrastructure(ctx context.Context, c client.Client) (*configv1.Infrastructure, error)

func GetConfigMapOrDefault

func GetConfigMapOrDefault(ctx context.Context, c client.Client, name types.NamespacedName, def *v1.ConfigMap) (*v1.ConfigMap, error)

func GetForcedReconcileTimeOrDefault

func GetForcedReconcileTimeOrDefault(defaultTo time.Duration) time.Duration

GetForcedReconcileTimeOrDefault returns envar for reconcile time else returns default time

func GetGCPProject added in v1.0.0

func GetGCPProject(ctx context.Context, c client.Client) (string, error)

func GetGCPRegion added in v1.0.0

func GetGCPRegion(ctx context.Context, c client.Client) (string, error)

func GetK8Client

func GetK8Client() (*kubernetes.Clientset, error)

func GetLabel added in v1.1.0

func GetLabel(object metav1.Object, key string) string

GetLabel retrieves a label value

func GetMetricReconcileTimeOrDefault

func GetMetricReconcileTimeOrDefault(defaultTo time.Duration) time.Duration

GetMetricReconcileTimeOrDefault returns envar for reconcile time else returns default time

func GetOrganizationTag

func GetOrganizationTag() string

func GetPlatformType added in v1.0.0

func GetPlatformType(ctx context.Context, c client.Client) (configv1.PlatformType, error)

func HasFinalizer

func HasFinalizer(om *controllerruntime.ObjectMeta, finalizer string) bool

func HasLabel added in v1.1.0

func HasLabel(object metav1.Object, key string) bool

HasLabel returns true if the label is already set

func HasLabelWithValue added in v1.1.0

func HasLabelWithValue(object metav1.Object, key, value string) bool

HasLabelWithValue returns true if the label with corresponding value matches

func IsCompoundMetric added in v1.0.0

func IsCompoundMetric(metric string) bool

func IsComputedCpuMetric added in v1.0.0

func IsComputedCpuMetric(metric string) bool

func IsConflictError added in v1.0.0

func IsConflictError(err error) bool

func IsLastResource added in v1.0.0

func IsLastResource(ctx context.Context, c client.Client) (bool, error)

func IsNotFoundError added in v1.0.0

func IsNotFoundError(err error) bool

func NewActionLogger

func NewActionLogger(logger *logrus.Entry, action string) *logrus.Entry

func NewActionLoggerWithFields

func NewActionLoggerWithFields(logger *logrus.Entry, fields logrus.Fields) *logrus.Entry

func NewMockAPIError added in v1.0.0

func NewMockAPIError(grpcCode grpcCodes.Code) *googleGRPC.APIError

NewMockAPIError is used for mocking errors from package github.com/googleapis/gax-go/v2/apierror

func RemoveFinalizer

func RemoveFinalizer(om *controllerruntime.ObjectMeta, finalizer string)

func RemoveLabel added in v1.1.0

func RemoveLabel(object metav1.Object, key string)

RemoveLabel makes sure that the provided label is removed

func ResetMetric added in v0.33.0

func ResetMetric(name string)

func ResetSTSCredentialsSecretMetric added in v0.40.0

func ResetSTSCredentialsSecretMetric()

ResetSTSCredentialsSecretMetric resets cro_sts_credentials_secret metric

func ResetVpcAction added in v0.35.0

func ResetVpcAction()

ResetVpcAction resets cro_vpc_action metric

func SafeStringDereference

func SafeStringDereference(s *string) string

func SafeTimeDereference

func SafeTimeDereference(t *time.Time) time.Time

func SetMetric

func SetMetric(name string, labels map[string]string, value float64)

SetMetric Set exports a Prometheus Gauge

func SetMetricCurrentTime

func SetMetricCurrentTime(name string, labels map[string]string)

SetMetricCurrentTime Set current time wraps set metric

func SetSTSCredentialsSecretMetric added in v0.40.0

func SetSTSCredentialsSecretMetric(ns string, err error)

SetSTSCredentialsSecretMetric sets cro_sts_credentials_secret metric

func SetVpcAction added in v0.35.0

func SetVpcAction(action string, status string, err string, code float64)

SetVpcAction sets cro_vpc_action metric

func ShortenString

func ShortenString(s string, n int) string

ShortenString Cut string size, but maintain a reference to the original string using a hash of the full string in the result

func StartGaugeVector

func StartGaugeVector()

StartGaugeVector periodic loop that is wiping all known vectors.

func StringOrDefault

func StringOrDefault(str, defaultTo string) string

StringOrDefault checks string and returns given default string if empty

func TagsContains added in v1.0.0

func TagsContains(tags []*Tag, key, value string) bool

func TagsContainsAll added in v1.0.0

func TagsContainsAll(as []*Tag, bs []*Tag) bool

TagsContainsAll checks whether all tags in first parameter are contained within second parameter

func UpdatePhase

func UpdatePhase(ctx context.Context, client client.Client, inst client.Object, phase croType.StatusPhase, msg croType.StatusMessage) error

UpdatePhase Updates the custom resource with the current phase

func UpdateSnapshotPhase

func UpdateSnapshotPhase(ctx context.Context, client client.Client, inst client.Object, phase croType.StatusPhase, msg croType.StatusMessage) error

UpdateSnapshotPhase Updates the snapshot custom resource with the current phase

func VerifyPostgresMaintenanceWindow added in v0.41.0

func VerifyPostgresMaintenanceWindow(ctx context.Context, client k8sclient.Client, namespace string, name string) (bool, error)

func VerifyRedisMaintenanceWindow added in v0.41.0

func VerifyRedisMaintenanceWindow(ctx context.Context, client k8sclient.Client, namespace string, name string) (bool, error)

func VerifyVersionUpgradeNeeded

func VerifyVersionUpgradeNeeded(currentVersion string, desiredVersion string) (bool, error)

Types

type ConnectionTestManager added in v1.0.0

type ConnectionTestManager struct{}

func NewConnectionTestManager added in v1.0.0

func NewConnectionTestManager() *ConnectionTestManager

func (*ConnectionTestManager) TCPConnection added in v1.0.0

func (m *ConnectionTestManager) TCPConnection(host string, port int) bool

TCPConnection trys to create a tcp connection, if none can be made it returns an error

type ConnectionTester added in v1.0.0

type ConnectionTester interface {
	TCPConnection(host string, port int) bool
}

type ConnectionTesterMock added in v1.0.0

type ConnectionTesterMock struct {
	// TCPConnectionFunc mocks the TCPConnection method.
	TCPConnectionFunc func(host string, port int) bool
	// contains filtered or unexported fields
}

ConnectionTesterMock is a mock implementation of ConnectionTester.

func TestSomethingThatUsesConnectionTester(t *testing.T) {

	// make and configure a mocked ConnectionTester
	mockedConnectionTester := &ConnectionTesterMock{
		TCPConnectionFunc: func(host string, port int) bool {
			panic("mock out the TCPConnection method")
		},
	}

	// use mockedConnectionTester in code that requires ConnectionTester
	// and then make assertions.

}

func BuildMockConnectionTester added in v1.0.0

func BuildMockConnectionTester() *ConnectionTesterMock

func (*ConnectionTesterMock) TCPConnection added in v1.0.0

func (mock *ConnectionTesterMock) TCPConnection(host string, port int) bool

TCPConnection calls TCPConnectionFunc.

func (*ConnectionTesterMock) TCPConnectionCalls added in v1.0.0

func (mock *ConnectionTesterMock) TCPConnectionCalls() []struct {
	Host string
	Port int
}

TCPConnectionCalls gets all the calls that were made to TCPConnection. Check the length with:

len(mockedConnectionTester.TCPConnectionCalls())

type ErrorGRPC added in v1.0.0

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

func (ErrorGRPC) Error added in v1.0.0

func (e ErrorGRPC) Error() string

func (ErrorGRPC) GRPCStatus added in v1.0.0

func (e ErrorGRPC) GRPCStatus() *status.Status

type MonitoringResourceType added in v1.0.0

type MonitoringResourceType string

type OpenShiftPodCommander

type OpenShiftPodCommander struct {
	ClientSet *kubernetes.Clientset
}

func (*OpenShiftPodCommander) ExecIntoPod

func (pc *OpenShiftPodCommander) ExecIntoPod(dpl *appsv1.Deployment, cmd string) error

type PodCommander

type PodCommander interface {
	ExecIntoPod(dpl *appsv1.Deployment, cmd string) error
}

type PodCommanderMock

type PodCommanderMock struct {
	// ExecIntoPodFunc mocks the ExecIntoPod method.
	ExecIntoPodFunc func(dpl *appsv1.Deployment, cmd string) error
	// contains filtered or unexported fields
}

PodCommanderMock is a mock implementation of PodCommander.

func TestSomethingThatUsesPodCommander(t *testing.T) {

	// make and configure a mocked PodCommander
	mockedPodCommander := &PodCommanderMock{
		ExecIntoPodFunc: func(dpl *appsv1.Deployment, cmd string) error {
			panic("mock out the ExecIntoPod method")
		},
	}

	// use mockedPodCommander in code that requires PodCommander
	// and then make assertions.

}

func (*PodCommanderMock) ExecIntoPod

func (mock *PodCommanderMock) ExecIntoPod(dpl *appsv1.Deployment, cmd string) error

ExecIntoPod calls ExecIntoPodFunc.

func (*PodCommanderMock) ExecIntoPodCalls

func (mock *PodCommanderMock) ExecIntoPodCalls() []struct {
	Dpl *appsv1.Deployment
	Cmd string
}

ExecIntoPodCalls gets all the calls that were made to ExecIntoPod. Check the length with:

len(mockedPodCommander.ExecIntoPodCalls())

type ReconcileResourceProvider

type ReconcileResourceProvider struct {
	Client client.Client
	Scheme *runtime.Scheme
	Logger *logrus.Entry
}

func (*ReconcileResourceProvider) ReconcileResultSecret

func (r *ReconcileResourceProvider) ReconcileResultSecret(ctx context.Context, o client.Object, d map[string][]byte) error

type Tag added in v1.0.0

type Tag struct {
	Key   string
	Value string
}

generic key-value tag

func BuildManagedTag added in v1.0.0

func BuildManagedTag() *Tag

func GetDefaultResourceTags added in v1.0.0

func GetDefaultResourceTags(ctx context.Context, c client.Client, specType string, name string, prodName string) ([]*Tag, string, error)

func GetUserInfraTags added in v1.0.0

func GetUserInfraTags(ctx context.Context, c client.Client) ([]*Tag, error)

func MergeTags added in v1.0.0

func MergeTags(generalTags []*Tag, infraTags []*Tag) []*Tag

MergeTags merges generalTags and infraTags, where any duplicate key in infraTags is discarded in favour of the value in infraTags

func (*Tag) Equal added in v1.0.0

func (a *Tag) Equal(b *Tag) bool

Jump to

Keyboard shortcuts

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