util

package
v0.1.52 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 101 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Metrics
	// TODO (jparrill): We need to separate the metrics.go from the main pkg in the hypershift-operator.
	//     Delete these references when it's done and import it from there
	HypershiftOperatorInfoName = "hypershift_operator_info"
)
View Source
const OAuthServerConfigKey = "config.yaml"

Variables

View Source
var (
	// y-stream versions supported by e2e in main
	Version419 = semver.MustParse("4.19.0")
	Version418 = semver.MustParse("4.18.0")
	Version417 = semver.MustParse("4.17.0")
	Version416 = semver.MustParse("4.16.0")
	Version415 = semver.MustParse("4.15.0")
	Version414 = semver.MustParse("4.14.0")
)

Functions

func AtLeast added in v0.1.48

func AtLeast(t *testing.T, version semver.Version)

func CleanupOIDCBucketObjects added in v0.1.4

func CleanupOIDCBucketObjects(log logr.Logger, s3Client *s3.S3, bucketName, issuerURL string)

func CorrelateDaemonSet

func CorrelateDaemonSet(ds *appsv1.DaemonSet, nodePool *hyperv1.NodePool, dsName string)

func DeleteNamespace

func DeleteNamespace(t *testing.T, ctx context.Context, client crclient.Client, namespace string) error

DeleteNamespace deletes and finalizes the given namespace, logging any failures along the way.

func DestroyOIDCProvider added in v0.1.4

func DestroyOIDCProvider(log logr.Logger, iamClient iamiface.IAMAPI, issuerURL string)

func EnsureAPIUX added in v0.1.43

func EnsureAPIUX(t *testing.T, ctx context.Context, hostClient crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureAdmissionPolicies added in v0.1.44

func EnsureAdmissionPolicies(t *testing.T, ctx context.Context, mgmtClient crclient.Client, hc *hyperv1.HostedCluster)

func EnsureAllContainersHavePullPolicyIfNotPresent

func EnsureAllContainersHavePullPolicyIfNotPresent(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureAllReqServingPodsLandOnReqServingNodes added in v0.1.16

func EnsureAllReqServingPodsLandOnReqServingNodes(t *testing.T, ctx context.Context, client crclient.Client)

func EnsureAllRoutesUseHCPRouter

func EnsureAllRoutesUseHCPRouter(t *testing.T, ctx context.Context, hostClient crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureCustomLabels added in v0.1.52

func EnsureCustomLabels(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureGuestWebhooksValidated added in v0.1.10

func EnsureGuestWebhooksValidated(t *testing.T, ctx context.Context, guestClient crclient.Client)

func EnsureHCPContainersHaveResourceRequests

func EnsureHCPContainersHaveResourceRequests(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureHCPPodsAffinitiesAndTolerations added in v0.1.16

func EnsureHCPPodsAffinitiesAndTolerations(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureMachineDeploymentGeneration

func EnsureMachineDeploymentGeneration(t *testing.T, ctx context.Context, hostClient crclient.Client, hostedCluster *hyperv1.HostedCluster, expectedGeneration int64)

func EnsureNetworkPolicies added in v0.1.10

func EnsureNetworkPolicies(t *testing.T, ctx context.Context, c crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureNoCrashingPods

func EnsureNoCrashingPods(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureNoHCPPodsLandOnDefaultNode added in v0.1.17

func EnsureNoHCPPodsLandOnDefaultNode(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureNoPodsWithTooHighPriority

func EnsureNoPodsWithTooHighPriority(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureNodeCommunication

func EnsureNodeCommunication(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureNodeCountMatchesNodePoolReplicas

func EnsureNodeCountMatchesNodePoolReplicas(t *testing.T, ctx context.Context, hostClient, guestClient crclient.Client, platform hyperv1.PlatformType, nodePoolNamespace string)

func EnsureNodesLabelsAndTaints added in v0.1.10

func EnsureNodesLabelsAndTaints(t *testing.T, nodePool hyperv1.NodePool, nodes []corev1.Node)

func EnsureNodesRuntime added in v0.1.51

func EnsureNodesRuntime(t *testing.T, nodes []corev1.Node)

EnsureNodesRuntime ensures that all nodes in the NodePool have the expected runtime handlers. This is only supported on 4.18+ when the default runtime is changed to crun.

func EnsureOAPIMountsTrustBundle added in v0.1.40

func EnsureOAPIMountsTrustBundle(t *testing.T, ctx context.Context, mgmtClient crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureOAuthWithIdentityProvider added in v0.1.2

func EnsureOAuthWithIdentityProvider(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureOnlyRequestServingPodsOnRequestServingNodes added in v0.1.16

func EnsureOnlyRequestServingPodsOnRequestServingNodes(t *testing.T, ctx context.Context, client crclient.Client)

func EnsurePSANotPrivileged added in v0.1.10

func EnsurePSANotPrivileged(t *testing.T, ctx context.Context, guestClient crclient.Client)

func EnsurePayloadArchSetCorrectly added in v0.1.48

func EnsurePayloadArchSetCorrectly(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsurePodsWithEmptyDirPVsHaveSafeToEvictAnnotations added in v0.1.10

func EnsurePodsWithEmptyDirPVsHaveSafeToEvictAnnotations(t *testing.T, ctx context.Context, hostClient crclient.Client, hcpNs string)

func EnsureSATokenNotMountedUnlessNecessary added in v0.1.19

func EnsureSATokenNotMountedUnlessNecessary(t *testing.T, ctx context.Context, c crclient.Client, hostedCluster *hyperv1.HostedCluster)

func EnsureSecretEncryptedUsingKMS

func EnsureSecretEncryptedUsingKMS(t *testing.T, ctx context.Context, hostedCluster *hyperv1.HostedCluster, guestClient crclient.Client)

func EnsureSecretEncryptedUsingKMSV1 added in v0.1.43

func EnsureSecretEncryptedUsingKMSV1(t *testing.T, ctx context.Context, hostedCluster *hyperv1.HostedCluster, guestClient crclient.Client)

func EnsureSecretEncryptedUsingKMSV2 added in v0.1.43

func EnsureSecretEncryptedUsingKMSV2(t *testing.T, ctx context.Context, hostedCluster *hyperv1.HostedCluster, guestClient crclient.Client)

func EventuallyObject added in v0.1.38

func EventuallyObject[T client.Object](t *testing.T, ctx context.Context, objective string, getter func(context.Context) (T, error), predicates []Predicate[T], options ...EventuallyOption)

EventuallyObject polls until the predicate is fulfilled on the object.

func EventuallyObjects added in v0.1.38

func EventuallyObjects[T client.Object](t *testing.T, ctx context.Context, objective string, getter func(context.Context) ([]T, error), groupPredicates []Predicate[[]T], predicates []Predicate[T], options ...EventuallyOption)

EventuallyObjects polls until the predicate is fulfilled on each of a set of objects.

func GetClient

func GetClient() (crclient.Client, error)

GetClient creates a controller-runtime client for Kubernetes

func GetConfig

func GetConfig() (*rest.Config, error)

GetConfig creates a REST config from current context

func GetGuestKubeconfigHost added in v0.1.40

func GetGuestKubeconfigHost(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster) (string, error)

func GetIAMClient added in v0.1.4

func GetIAMClient(awsCreds, awsRegion string) iamiface.IAMAPI

func GetKMSKeyArn

func GetKMSKeyArn(awsCreds, awsRegion, alias string) (*string, error)

func GetS3Client added in v0.1.4

func GetS3Client(awsCreds, awsRegion string) *s3.S3

func GetUserForToken added in v0.1.2

func GetUserForToken(config *restclient.Config, token string) (*userv1.User, error)

func IsLessThan added in v0.1.48

func IsLessThan(version semver.Version) bool

func NewHypershiftTest added in v0.1.10

func NewHypershiftTest(t *testing.T, ctx context.Context, test hypershiftTestFunc) *hypershiftTest

func NewLogr

func NewLogr(t *testing.T) logr.Logger

func NewPrometheusClient added in v0.1.6

func NewPrometheusClient(ctx context.Context) (prometheusv1.API, error)

func NoticePreemptionOrFailedScheduling

func NoticePreemptionOrFailedScheduling(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func RunCommandInPod added in v0.1.10

func RunCommandInPod(ctx context.Context, c crclient.Client, component, namespace string, command []string, containerName string, timeout time.Duration) (string, error)

func SetReleaseImageVersion added in v0.1.48

func SetReleaseImageVersion(ctx context.Context, latestReleaseImage string, pullSecretFile string) error

func SetupReqServingClusterNodePools added in v0.1.17

func SetupReqServingClusterNodePools(ctx context.Context, t *testing.T, kubeconfigPath, mgmtHCNamespace, mgmtHCName string) []*hyperv1.NodePool

func TearDownNodePools added in v0.1.17

func TearDownNodePools(ctx context.Context, t *testing.T, kubeconfigPath string, nodePools []*hyperv1.NodePool)

func UpdateObject added in v0.1.6

func UpdateObject[T crclient.Object](t *testing.T, ctx context.Context, client crclient.Client, original T, mutate func(obj T)) error

func ValidateMetrics added in v0.1.10

func ValidateMetrics(t *testing.T, ctx context.Context, hc *hyperv1.HostedCluster, metricsNames []string, areMetricsExpectedToBePresent bool)

Verifies that the given metrics are defined for the given hosted cluster if areMetricsExpectedToBePresent is set to true. Verifies that the given metrics are not defined otherwise.

func ValidatePrivateCluster added in v0.1.10

func ValidatePrivateCluster(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster, clusterOpts *PlatformAgnosticOptions)

func ValidatePublicCluster added in v0.1.10

func ValidatePublicCluster(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster, clusterOpts *PlatformAgnosticOptions)

func WaitForConditionsOnHostedControlPlane

func WaitForConditionsOnHostedControlPlane(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster, image string)

func WaitForGuestClient

func WaitForGuestClient(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster) crclient.Client

func WaitForGuestKubeConfig

func WaitForGuestKubeConfig(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster) []byte

func WaitForGuestKubeconfigHostUpdate added in v0.1.40

func WaitForGuestKubeconfigHostUpdate(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster, oldHost string)

func WaitForImageRollout

func WaitForImageRollout(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster, image string)

func WaitForNReadyNodes

func WaitForNReadyNodes(t *testing.T, ctx context.Context, client crclient.Client, n int32, platform hyperv1.PlatformType) []corev1.Node

func WaitForNReadyNodesWithOptions added in v0.1.40

func WaitForNReadyNodesWithOptions(t *testing.T, ctx context.Context, client crclient.Client, n int32, platform hyperv1.PlatformType, suffix string, opts ...NodePoolPollOption) []corev1.Node

func WaitForNodePoolConfigUpdateComplete added in v0.1.51

func WaitForNodePoolConfigUpdateComplete(t *testing.T, ctx context.Context, client crclient.Client, np *hyperv1.NodePool)

func WaitForNodePoolDesiredNodes added in v0.1.6

func WaitForNodePoolDesiredNodes(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func WaitForOAuthRouteReady added in v0.1.2

func WaitForOAuthRouteReady(t *testing.T, ctx context.Context, client crclient.Client, restConfig *restclient.Config, hostedCluster *hyperv1.HostedCluster) *routev1.Route

func WaitForOAuthToken added in v0.1.2

func WaitForOAuthToken(t *testing.T, ctx context.Context, oauthRoute *routev1.Route, restConfig *restclient.Config, username, password string) string

func WaitForOauthConfig added in v0.1.6

func WaitForOauthConfig(t *testing.T, ctx context.Context, client crclient.Client, hostedCluster *hyperv1.HostedCluster)

func WaitForReadyNodesByNodePool added in v0.1.40

func WaitForReadyNodesByNodePool(t *testing.T, ctx context.Context, client crclient.Client, np *hyperv1.NodePool, platform hyperv1.PlatformType, opts ...NodePoolPollOption) []corev1.Node

Types

type Condition added in v0.1.38

type Condition struct {
	Type    string
	Status  metav1.ConditionStatus
	Reason  string
	Message string
}

Condition is a generic structure required to adapt all the different concrete condition types into one.

func Conditions added in v0.1.38

func Conditions(item client.Object) ([]Condition, error)

Conditions extracts conditions from the item and adapts them to the generic wrapper.

func (Condition) Matches added in v0.1.38

func (needle Condition) Matches(condition Condition) bool

func (Condition) String added in v0.1.38

func (c Condition) String() string

String formats a condition in the canonical way.

type DefaultRemoteExecutor

type DefaultRemoteExecutor struct{}

DefaultRemoteExecutor is the standard implementation of remote command execution

func (*DefaultRemoteExecutor) Execute

func (*DefaultRemoteExecutor) Execute(ctx context.Context, method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error

type EventuallyOption added in v0.1.38

type EventuallyOption func(*EventuallyOptions)

EventuallyOption configures a

func WithDelayedStart added in v0.1.38

func WithDelayedStart() EventuallyOption

WithDelayedStart configures the asynchronous assertion to start immediately.

func WithFilteredConditionDump added in v0.1.38

func WithFilteredConditionDump(matchers ...Condition) EventuallyOption

WithFilteredConditionDump configures the asynchronous assertion to only dump the specified conditions.

func WithInterval added in v0.1.38

func WithInterval(interval time.Duration) EventuallyOption

WithInterval sets the polling interval.

func WithTimeout added in v0.1.38

func WithTimeout(timeout time.Duration) EventuallyOption

WithTimeout sets the polling timeout.

func WithoutConditionDump added in v0.1.38

func WithoutConditionDump() EventuallyOption

WithoutConditionDump configures the asynchronous assertion to dump conditions on failure.

type EventuallyOptions added in v0.1.38

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

EventuallyOptions configure asynchronous assertion behavior.

type KubeVirtInfra added in v0.1.32

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

func NewKubeVirtInfra added in v0.1.32

func NewKubeVirtInfra(ctx context.Context, mgmtClient crclient.Client, hostedCluster *hyperv1.HostedCluster) KubeVirtInfra

func (KubeVirtInfra) ComposeOVNKLayer2NAD added in v0.1.32

func (k KubeVirtInfra) ComposeOVNKLayer2NAD(namespace string) (client.Object, error)

func (KubeVirtInfra) CreateOVNKLayer2NAD added in v0.1.32

func (k KubeVirtInfra) CreateOVNKLayer2NAD(namespace string) error

func (KubeVirtInfra) Ctx added in v0.1.32

func (k KubeVirtInfra) Ctx() context.Context

func (KubeVirtInfra) DiscoverClient added in v0.1.32

func (k KubeVirtInfra) DiscoverClient() (crclient.Client, error)

func (KubeVirtInfra) HostedCluster added in v0.1.32

func (k KubeVirtInfra) HostedCluster() *hyperv1.HostedCluster

func (KubeVirtInfra) MGMTClient added in v0.1.32

func (k KubeVirtInfra) MGMTClient() crclient.Client

func (KubeVirtInfra) NADName added in v0.1.32

func (k KubeVirtInfra) NADName() string

func (KubeVirtInfra) Namespace added in v0.1.32

func (k KubeVirtInfra) Namespace() string

type NameGenerator

type NameGenerator interface {
	// GenerateName generates a valid name from the base name, adding a random suffix to the
	// the base. If base is valid, the returned name must also be valid. The generator is
	// responsible for knowing the maximum valid name length.
	GenerateName(base string) string
}

NameGenerator generates names for objects. Some backends may have more information available to guide selection of new names and this interface hides those details.

var SimpleNameGenerator NameGenerator = simpleNameGenerator{}

SimpleNameGenerator is a generator that returns the name plus a random suffix of five alphanumerics when a name is requested. The string is guaranteed to not exceed the length of a standard Kubernetes name (63 characters)

type NodePoolPollOption added in v0.1.40

type NodePoolPollOption func(*NodePoolPollOptions)

func WithClientOptions added in v0.1.40

func WithClientOptions(clientOpts ...crclient.ListOption) NodePoolPollOption

func WithCollectionPredicates added in v0.1.40

func WithCollectionPredicates(predicates ...Predicate[[]*corev1.Node]) NodePoolPollOption

func WithPredicates added in v0.1.40

func WithPredicates(predicates ...Predicate[*corev1.Node]) NodePoolPollOption

func WithSuffix added in v0.1.40

func WithSuffix(suffix string) NodePoolPollOption

type NodePoolPollOptions added in v0.1.40

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

type PlatformAgnosticOptions added in v0.1.38

type PlatformAgnosticOptions struct {
	core.RawCreateOptions

	NonePlatform      none.RawCreateOptions
	AWSPlatform       aws.RawCreateOptions
	KubevirtPlatform  kubevirt.RawCreateOptions
	AzurePlatform     azure.RawCreateOptions
	PowerVSPlatform   powervs.RawCreateOptions
	OpenStackPlatform openstack.RawCreateOptions
}

type PodExecOptions

type PodExecOptions struct {
	StreamOptions

	Command []string

	PodName       string
	Namespace     string
	ContainerName string

	Timeout time.Duration

	Executor RemoteExecutor
	Config   *restclient.Config
}

PodExecOptions declare the arguments accepted by the Exec command

func (*PodExecOptions) Run

func (p *PodExecOptions) Run(ctx context.Context) error

Run executes a validated remote execution against a pod.

func (*PodExecOptions) Validate

func (p *PodExecOptions) Validate() error

Validate checks that the provided exec options are specified.

type Predicate added in v0.1.38

type Predicate[T any] func(T) (done bool, reasons string, err error)

Predicate evaluates an object. Return whether the object in question matches your predicate, the reasons why or why not, and whether an error occurred. If determining that an object does not match a predicate, a message is required. Returning an error is fatal to the asynchronous assertion using this predicate.

func ConditionPredicate added in v0.1.38

func ConditionPredicate[T client.Object](needle Condition) Predicate[T]

ConditionPredicate returns a predicate that validates that a particular condition type exists and has the requisite status, reason and/or message.

type PrometheusResponse added in v0.1.6

type PrometheusResponse struct {
	Data prometheusResponseData `json:"data"`
}

PrometheusResponse is used to contain prometheus query results

func RunQueryAtTime added in v0.1.6

func RunQueryAtTime(ctx context.Context, log logr.Logger, prometheusClient prometheusv1.API, query string, evaluationTime time.Time) (*PrometheusResponse, error)

type RemoteExecutor

type RemoteExecutor interface {
	Execute(ctx context.Context, method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error
}

RemoteExecutor defines the interface accepted by the Exec command - provided for test stubbing

type StreamOptions

type StreamOptions struct {
	Stdin bool
	TTY   bool

	genericclioptions.IOStreams
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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