Version: v1.2.1 Latest Latest

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

Go to latest
Published: May 26, 2021 License: Apache-2.0 Imports: 15 Imported by: 0


Controllers Package

This package contains common controller utilities and packages for each controller.




View Source
const (
	// SageMakerResourceFinalizerName is the name of the finalizer that is installed onto managed etcd resources.
	SageMakerResourceFinalizerName = "sagemaker-operator-finalizer"

	// DefaultSageMakerEndpointEnvKey is the environment variable key of the default SageMaker endpoint to use.
	// If this is set to anything other than the empty string, the controllers
	// will use its value as the endpoint with which to communicate with SageMaker.
	DefaultSageMakerEndpointEnvKey = "AWS_DEFAULT_SAGEMAKER_ENDPOINT"

	// InitializingJobStatus is the status stored on first touch of a job by a controller.
	// This status is kept until the job has a real status.
	InitializingJobStatus = "SynchronizingK8sJobWithSageMaker"

	// ErrorStatus is the status when the operator cannot recover by itself by reconciling or to indicate that an error occurred during reconciliation.
	ErrorStatus = "Error"
View Source
const SagemakerOnKubernetesUserAgentAddition = "sagemaker-on-kubernetes"

SagemakerOnKubernetesUserAgentAddition is the string that will be added to user agent. This helps to distinguish sagemaker job which has been created from kubernetes.


This section is empty.


func ContainsString

func ContainsString(slice []string, s string) bool

ContainsString is a helper functions to check and remove string from a slice of strings.

func CreateNewAWSSessionFromConfig added in v1.2.0

func CreateNewAWSSessionFromConfig(cfg aws.Config) *awssession.Session

CreateNewAWSSessionFromConfig returns an AWS session using AWS Config

func CreateSpecDiffersFromDescriptionErrorMessage

func CreateSpecDiffersFromDescriptionErrorMessage(job interface{}, status, differences string) string

CreateSpecDiffersFromDescriptionErrorMessage returns the error message to use when a spec differs from its SageMaker description.

func GetGeneratedJobName

func GetGeneratedJobName(objectMetaUID types.UID, objectMetaName string, maxNameLen int) string

GetGeneratedJobName generates a Sagemaker name for various Kubernetes objects and subresources. We need a deterministic way to identify SageMaker resources given a Kubernetes object. This generates a name based off of the UID and object meta name. SageMaker requires that names be less than a certain length. For Training and BatchTransform, the maximum name length is 63. For HPO, the maximum name length is 32.

See also: * [CreateTrainingJob#TrainingJobName]( * [CreateTransformJob#TransformJobName]( * [CreateHyperParameterTuningJob#HyperParameterTuningJobName](

func GetGeneratedResourceName

func GetGeneratedResourceName(required, optional string, maxLen int) string

GetGeneratedResourceName creates a resource name from optional and required substrings given a maximum length constraint. If the resource name length is larger than the maximum length, this will truncate first the optional substring, then, if necessary, it will truncate the required substring.

func GetOrDefault

func GetOrDefault(str *string, defaultStr string) string

GetOrDefault is a helper function to return a default value

func HasDeletionTimestamp

func HasDeletionTimestamp(obj metav1.ObjectMeta) bool

HasDeletionTimestamp is a helper method that makes logic easier to read.

func IgnoreNotFound

func IgnoreNotFound(err error) error

IgnoreNotFound ignores NotFound errors to prevent reconcile loops.

func NoRequeue

func NoRequeue() (ctrl.Result, error)

NoRequeue does not requeue when Requeue is False and duration is 0.

func Now

func Now() *metav1.Time

Now returns timestamp

func RemoveString

func RemoveString(slice []string, s string) (result []string)

RemoveString removes a specific string from a splice and returns the rest.

func RequeueAfterInterval

func RequeueAfterInterval(interval time.Duration, err error) (ctrl.Result, error)

RequeueAfterInterval requeues after a duration when duration > 0 is specified.

func RequeueIfError

func RequeueIfError(err error) (ctrl.Result, error)

RequeueIfError requeues if an error is found.

func RequeueImmediately

func RequeueImmediately() (ctrl.Result, error)

RequeueImmediately requeues immediately when Requeue is True and no duration is specified.

func RequeueImmediatelyUnlessGenerationChanged

func RequeueImmediatelyUnlessGenerationChanged(prevGeneration, curGeneration int64) (ctrl.Result, error)

RequeueImmediatelyUnlessGenerationChanged is a helper function which requeues immediately if the object generation has not changed. Otherwise, since the generation change will trigger an immediate update anyways, this will not requeue. This prevents some cases where two reconciliation loops will occur.


type AWSConfigLoader added in v1.2.0

type AWSConfigLoader struct {
	Env venv.Env

AWSConfigLoader is a simple struct to facilitate loading AWS config with region- and endpoint-overrides. This uses venv.Env for mocking in tests.

func NewAWSConfigLoader added in v1.2.0

func NewAWSConfigLoader() AWSConfigLoader

NewAWSConfigLoader creates an AWSConfigLoader with the default OS environment.

func NewAWSConfigLoaderForEnv added in v1.2.0

func NewAWSConfigLoaderForEnv(env venv.Env) AWSConfigLoader

NewAWSConfigLoaderForEnv returns a AWSConfigLoader for the specified environment.

func (AWSConfigLoader) LoadAWSConfigWithOverrides added in v1.2.0

func (l AWSConfigLoader) LoadAWSConfigWithOverrides(regionOverride *string, jobSpecificEndpointOverride *string) (aws.Config, error)

LoadAWSConfigWithOverrides loads default AWS config and apply overrides, like setting the region and using a custom SageMaker endpoint. If specified, jobSpecificEndpointOverride always overrides the endpoint. Otherwise, the environment variable specified by DefaultSageMakerEndpointEnvKey overrides the endpoint if it is set.

type ApplicationAutoscalingClientProvider added in v1.2.0

type ApplicationAutoscalingClientProvider func(aws.Config) applicationautoscalingiface.ApplicationAutoScalingAPI

ApplicationAutoscalingClientProvider is a Type for function that returns a ApplicationAutoscaling client. Used for mocking.

type ReconcileAction

type ReconcileAction string

ReconcileAction is a helper type that describes the action to perform on a resource.

const (
	NeedsCreate ReconcileAction = "NeedsCreate"
	NeedsDelete ReconcileAction = "NeedsDelete"
	NeedsNoop   ReconcileAction = "NeedsNoop"
	NeedsUpdate ReconcileAction = "NeedsUpdate"

Constants for the various reconcile actions.

type SageMakerClientProvider

type SageMakerClientProvider func(aws.Config) sagemakeriface.SageMakerAPI

SageMakerClientProvider is a Type for function that returns a SageMaker client. Used for mocking.

Jump to

Keyboard shortcuts

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