utils

package
v0.0.0-...-a0d0389 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Finalizer is a constant containing the Kubernetes finalizer used by the AWS Account Operator
	Finalizer = "finalizer.aws.managed.openshift.io"

	// WaitTime is the default wait time for an account to become ready, before erroring
	WaitTime = 25

	// SREAssumeRole is the name of the role that SREs need to use to role-chain to get temporary
	// credentials for a CCS account
	SREAssumeRole = "RH-SREP-CCS-Access"

	// AwsSecretName is a constant for the name of the Kubernetes secret that holds the AWS Credentials
	AwsSecretName = "aws-account-operator-credentials" // #nosec G101 -- This is a false positive
)
View Source
const (
	// DevModeProduction (aka non-development mode) is the default running mode. Metrics are
	// served from the operator at the /metrics path under the route it creates. AWS support cases
	// are managed for real.
	DevModeProduction devMode = ""
	// DevModeLocal should be used when running via operator-sdk in "local" mode. Metrics are
	// served up at http://localhost:${metricsPort}/${metricsPath} (metricsP* defined in main.go).
	// All AWS support case interactions are skipped.
	DevModeLocal devMode = "local"
	// DevModeCluster should be used when doing development in a "real" cluster via a Deployment
	// such as the one in deploy/operator.yaml. Metrics are served as normal (see
	// DevModeProduction), but AWS support case interactions are skipped (see DevModeLocal).
	DevModeCluster devMode = "cluster"
)

Variables

View Source
var ControllerMaxReconciles map[string]int = map[string]int{}
View Source
var DetectDevMode devMode = devMode(strings.ToLower(os.Getenv(envDevMode)))

DetectDevMode gets the envDevMode environment variable to detect if we are running in production or a development environment.

Functions

func AccountCRHasIAMUserIDLabel

func AccountCRHasIAMUserIDLabel(accountCR *awsv1alpha1.Account) bool

AccountCRHasIAMUserIDLabel check for label

func AddControllerMetricsTransportWrapper

func AddControllerMetricsTransportWrapper(cfg *rest.Config, controllerName string)

AddControllerMetricsTransportWrapper adds a transport wrapper to the given rest config which exposes metrics based on the requests being made.

func AddFinalizer

func AddFinalizer(object metav1.Object, finalizer string)

AddFinalizer adds a finalizer to an object

func AddLabels

func AddLabels(object metav1.Object, labels map[string]string)

AddLabels adds a map of labels to an object

func Contains

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

Contains returns true a list of strings includes a specific string

func CreationConditionOlderThan

func CreationConditionOlderThan(account awsv1alpha1.Account, duration time.Duration) bool

creationOlderThan returns true if the given account has been in a creation state for longer than the given time, else false

func DoNotRequeue

func DoNotRequeue() (reconcile.Result, error)

func FindAWSFederatedAccountAccessCondition

FindAWSFederatedAccountAccessCondition Condition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil. TODO: This should be moved to the AccountAccess struct

func FindAWSFederatedRoleCondition

FindAWSFederatedRoleCondition Condition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil. TODO: this should be moved to the FederatedRole struct

func FindAccountClaimCondition

func FindAccountClaimCondition(conditions []awsv1alpha1.AccountClaimCondition, conditionType awsv1alpha1.AccountClaimConditionType) *awsv1alpha1.AccountClaimCondition

FindAccountClaimCondition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil. TODO: this should probably be handled within the AccountClaim struct

func FindAccountCondition

func FindAccountCondition(conditions []awsv1alpha1.AccountCondition, conditionType awsv1alpha1.AccountConditionType) *awsv1alpha1.AccountCondition

FindAccountCondition finds in the condition that has the specified condition type in the given list. If none exists, then returns nil. TODO: this should be moved to the account struct

func GenerateLabel

func GenerateLabel(key, value string) map[string]string

GenerateLabel returns a ObjectMeta Labels

func GenerateShortUID

func GenerateShortUID() string

GenerateShortUID Generates a short UID

func GetControllerMaxReconciles

func GetControllerMaxReconciles(controllerName string) (int, error)

GetControllerMaxReconciles gets the default configMap and then gets the amount of concurrent reconciles to run from it

func GetEnvironmentBool

func GetEnvironmentBool(key string, fallback bool) bool

func GetOperatorConfigMap

func GetOperatorConfigMap(kubeClient client.Client) (*corev1.ConfigMap, error)

GetOperatorConfigMap retrieves the default configMap data for the AWS Account Operator from Kubernetes

func GetOperatorStartTime

func GetOperatorStartTime() *metav1.Time

GetOperatorStartTime returns the time at which the operator was brought up, assuming said bringup was well-behaved and invoked InitOperatorStartTime(). If not, this will return the zero time.

func InitControllerMaxReconciles

func InitControllerMaxReconciles(kubeClient client.Client) []error

func InitOperatorStartTime

func InitOperatorStartTime() error

InitOperatorStartTime should be invoked exactly once, early in operator bringup, before controllers are started. The value can subsequently be retrieved via GetOperatorStartTime(). Returns an error if the time was already initialized.

func JoinLabelMaps

func JoinLabelMaps(m1, m2 map[string]string) map[string]string

JoinLabelMaps adds a label to CR

func LogAwsError

func LogAwsError(logger logr.Logger, errMsg string, customError error, err error)

LogAwsError formats and logs aws error and returns if err was an awserr

func MarshalIAMPolicy

func MarshalIAMPolicy(role awsv1alpha1.AWSFederatedRole) (string, error)

MarshalIAMPolicy converts a role CR into a JSON policy that is acceptable to AWS

func NewClientWithMetricsOrDie

func NewClientWithMetricsOrDie(log logr.Logger, mgr manager.Manager, controller string) (client.Client, error)

NewClientWithMetricsOrDie creates a new controller-runtime client with a wrapper which increments metrics for requests by controller name, HTTP method, URL path, and HTTP status. The client will re-use the manager's cache. This should be used in all controllers.

func NewReconcilerWithMetrics

func NewReconcilerWithMetrics(wrapped reconcile.Reconciler, controllerName string) reconcile.Reconciler

NewReconcilerWithMetrics wraps an existing Reconciler such that calls to Reconcile report the reconcileDuration metric.

func Remove

func Remove(list []string, s string) []string

Remove removes a string from a list of strings

func RequeueAfter

func RequeueAfter(after time.Duration) (reconcile.Result, error)

func RequeueWithError

func RequeueWithError(err error) (reconcile.Result, error)

func SetAWSFederatedAccountAccessCondition

func SetAWSFederatedAccountAccessCondition(
	conditions []awsv1alpha1.AWSFederatedAccountAccessCondition,
	conditionType awsv1alpha1.AWSFederatedAccountAccessConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) []awsv1alpha1.AWSFederatedAccountAccessCondition

SetAWSFederatedAccountAccessCondition sets a condition on a Account resource's status TODO: this should be moved to the FederatedAccountAccess struct

func SetAWSFederatedRoleCondition

func SetAWSFederatedRoleCondition(
	conditions []awsv1alpha1.AWSFederatedRoleCondition,
	conditionType awsv1alpha1.AWSFederatedRoleConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
) []awsv1alpha1.AWSFederatedRoleCondition

SetAWSFederatedRoleCondition sets a condition on a AWSFederatedRole resource's status TODO: This should be moved to the FederatedRole CR

func SetAccountClaimCondition

func SetAccountClaimCondition(
	conditions []awsv1alpha1.AccountClaimCondition,
	conditionType awsv1alpha1.AccountClaimConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
	ccs bool,
) []awsv1alpha1.AccountClaimCondition

SetAccountClaimCondition sets a condition on a AccountClaim resource's status TODO: this should probably be handled within the AccountClaim struct

func SetAccountClaimStatus

func SetAccountClaimStatus(awsAccountClaim *awsv1alpha1.AccountClaim, message string, reason string, ctype awsv1alpha1.AccountClaimConditionType, state awsv1alpha1.ClaimStatus)

SetAccountClaimStatus sets the condition and state of an accountClaim

func SetAccountCondition

func SetAccountCondition(
	conditions []awsv1alpha1.AccountCondition,
	conditionType awsv1alpha1.AccountConditionType,
	status corev1.ConditionStatus,
	reason string,
	message string,
	updateConditionCheck UpdateConditionCheck,
	ccs bool,
) []awsv1alpha1.AccountCondition

SetAccountCondition sets a condition on a Account resource's status TODO: This should probably be handled within the Account Struct

func SetAccountStatus

func SetAccountStatus(awsAccount *awsv1alpha1.Account, message string, ctype awsv1alpha1.AccountConditionType, state string)

SetAccountStatus sets the condition and state of an account

func UpdateConditionAlways

func UpdateConditionAlways(_, _, _, _ string) bool

UpdateConditionAlways returns true. The condition will always be updated.

func UpdateConditionIfReasonOrMessageChange

func UpdateConditionIfReasonOrMessageChange(oldReason, oldMessage, newReason, newMessage string) bool

UpdateConditionIfReasonOrMessageChange returns true if there is a change in the reason or the message of the condition.

func UpdateConditionNever

func UpdateConditionNever(_, _, _, _ string) bool

UpdateConditionNever return false. The condition will never be updated, unless there is a change in the status of the condition.

Types

type ControllerMetricsTripper

type ControllerMetricsTripper struct {
	http.RoundTripper
	Controller string
}

ControllerMetricsTripper is a RoundTripper implementation which tracks our metrics for client requests.

func (*ControllerMetricsTripper) RoundTrip

func (cmt *ControllerMetricsTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http RoundTripper interface. We simply call the wrapped RoundTripper and register the call with our apiCallCount metric.

type UpdateConditionCheck

type UpdateConditionCheck func(oldReason, oldMessage, newReason, newMessage string) bool

UpdateConditionCheck tests whether a condition should be updated from the old condition to the new condition. Returns true if the condition should be updated.

Jump to

Keyboard shortcuts

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