util

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestLeaseDurationSeconds = 1
	TestDir                  = "/tmp/registration-integration-test"
)
View Source
const (
	KubeDriver = "kube"
	MQTTDriver = "mqtt"
)
View Source
const AutoApprovalBootstrapUser = "autoapproval-user"
View Source
const MQTTBrokerHost = "127.0.0.1:1883"

Variables

View Source
var (
	CertDir = path.Join(TestDir, "client-certs")

	DefaultTestAuthn = NewTestAuthn(caFile, caKeyFile)
)

Functions

func AcceptManagedCluster

func AcceptManagedCluster(clusterClient clusterclientset.Interface, spokeClusterName string) error

func AcceptManagedClusterWithLeaseDuration

func AcceptManagedClusterWithLeaseDuration(clusterClient clusterclientset.Interface, spokeClusterName string, leaseDuration int32) error

func AppliedManifestWorkName added in v0.15.0

func AppliedManifestWorkName(sourceDriver, hubHash string, work *workapiv1.ManifestWork) string

func AssertAppliedManifestWorkDeleted

func AssertAppliedManifestWorkDeleted(name string, workClient workclientset.Interface, eventuallyTimeout, eventuallyInterval int)

func AssertAppliedResources

func AssertAppliedResources(appliedManifestWorkName string, gvrs []schema.GroupVersionResource, namespaces, names []string,
	workClient workclientset.Interface, eventuallyTimeout, eventuallyInterval int)

AssertAppliedResources check if applied resources in work status are updated correctly

func AssertClusterManagerCondition

func AssertClusterManagerCondition(
	name string, operatorClient operatorclientset.Interface, expectedType, expectedReason string, expectedWorkStatus metav1.ConditionStatus)

func AssertExistenceOfConfigMaps

func AssertExistenceOfConfigMaps(manifests []workapiv1.Manifest, kubeClient kubernetes.Interface, eventuallyTimeout, eventuallyInterval int)

AssertExistenceOfConfigMaps check if all manifests are applied

func AssertExistenceOfResources

func AssertExistenceOfResources(gvrs []schema.GroupVersionResource, namespaces, names []string,
	dynamicClient dynamic.Interface, eventuallyTimeout, eventuallyInterval int)

AssertExistenceOfResources check the existence of resource with GVR, namespace and name

func AssertFinalizerAdded

func AssertFinalizerAdded(namespace, name, expectedFinalizer string, workClient workclientset.Interface, eventuallyTimeout, eventuallyInterval int)

AssertFinalizerAdded check if finalizer is added

func AssertKlusterletCondition

func AssertKlusterletCondition(
	name string, operatorClient operatorclientset.Interface, expectedType, expectedReason string, expectedWorkStatus metav1.ConditionStatus)

func AssertNonexistenceOfConfigMaps

func AssertNonexistenceOfConfigMaps(manifests []workapiv1.Manifest, kubeClient kubernetes.Interface,
	eventuallyTimeout, eventuallyInterval int)

AssertNonexistenceOfConfigMaps check if configmap does not exist

func AssertNonexistenceOfResources

func AssertNonexistenceOfResources(gvrs []schema.GroupVersionResource, namespaces, names []string,
	dynamicClient dynamic.Interface, eventuallyTimeout, eventuallyInterval int)

AssertNonexistenceOfResources check if resource with GVR, namespace and name does not exists

func AssertWorkCondition

func AssertWorkCondition(namespace, name string, workClient workclientset.Interface, expectedType string, expectedWorkStatus metav1.ConditionStatus,
	expectedManifestStatuses []metav1.ConditionStatus, eventuallyTimeout, eventuallyInterval int)

func AssertWorkDeleted

func AssertWorkDeleted(namespace, name, appliedManifestWorkName string, manifests []workapiv1.Manifest,
	workClient, spokeWorkClient workclientset.Interface, spokeKubeClient kubernetes.Interface,
	eventuallyTimeout, eventuallyInterval int)

AssertWorkDeleted check if work is deleted

func AssertWorkGeneration

func AssertWorkGeneration(namespace, name string, workClient workclientset.Interface, expectedType string, eventuallyTimeout, eventuallyInterval int)

func CmpResourceQuantity

func CmpResourceQuantity(key string, nodeResourceList corev1.ResourceList, clusterResorceList clusterv1.ResourceList) bool

func CordonNode

func CordonNode(kubeClient kubernetes.Interface, name string) error

func CreateKubeconfigFile

func CreateKubeconfigFile(clientConfig *rest.Config, filename string) error

func CreateMQTTConfigFile added in v0.15.0

func CreateMQTTConfigFile(configFileName, sourceID string) error

func CreateNode

func CreateNode(kubeClient kubernetes.Interface, name string, capacity, allocatable corev1.ResourceList) error

func FindAddOnCSRs

func FindAddOnCSRs(kubeClient kubernetes.Interface, spokeClusterName, addOnName string) ([]*certificates.CertificateSigningRequest, error)

func FindAutoApprovedSpokeCSR

func FindAutoApprovedSpokeCSR(kubeClient kubernetes.Interface, spokeClusterName string) (*certificates.CertificateSigningRequest, error)

func FindUnapprovedAddOnCSR

func FindUnapprovedAddOnCSR(kubeClient kubernetes.Interface, spokeClusterName, addOnName string) (*certificates.CertificateSigningRequest, error)

func FindUnapprovedSpokeCSR

func FindUnapprovedSpokeCSR(kubeClient kubernetes.Interface, spokeClusterName string) (*certificates.CertificateSigningRequest, error)

func GetBootstrapKubeConfigData added in v0.14.0

func GetBootstrapKubeConfigData(filePath string) (map[string][]byte, error)

func GetFilledHubKubeConfigSecret

func GetFilledHubKubeConfigSecret(kubeClient kubernetes.Interface, secretNamespace, secretName string) (*corev1.Secret, error)

func GetManagedCluster

func GetManagedCluster(clusterClient clusterclientset.Interface, spokeClusterName string) (*clusterv1.ManagedCluster, error)

func GetManagedClusterLease added in v0.13.0

func GetManagedClusterLease(kubeClient kubernetes.Interface, spokeClusterName string) (*coordinationv1.Lease, error)

func GetResource

func GetResource(namespace, name string, gvr schema.GroupVersionResource, dynamicClient dynamic.Interface) (*unstructured.Unstructured, error)

func GuestbookCr

func GuestbookCr(namespace, name string) (cr *unstructured.Unstructured, gvr schema.GroupVersionResource, err error)

func GuestbookCrd

func GuestbookCrd() (crd *unstructured.Unstructured, gvr schema.GroupVersionResource, err error)

func HasCondition

func HasCondition(
	conditions []metav1.Condition,
	expectedType, expectedReason string,
	expectedStatus metav1.ConditionStatus,
) bool

func HaveManifestCondition

func HaveManifestCondition(conditions []workapiv1.ManifestCondition, expectedType string, expectedStatuses []metav1.ConditionStatus) bool

func NewCert

func NewCert(notAfter time.Time) []byte

func NewClusterRole added in v0.13.0

func NewClusterRole(namespace, name string) (*unstructured.Unstructured, schema.GroupVersionResource)

func NewConfigmap

func NewConfigmap(namespace, name string, data map[string]string, finalizers []string) *corev1.ConfigMap

func NewDaesonSet added in v0.14.0

func NewDaesonSet(namespace, name string) (u *unstructured.Unstructured, gvr schema.GroupVersionResource, err error)

func NewDeployment

func NewDeployment(namespace, name, sa string) (u *unstructured.Unstructured, gvr schema.GroupVersionResource, err error)

func NewIntegrationTestEventRecorder

func NewIntegrationTestEventRecorder(component string) events.Recorder

func NewKubeConfig

func NewKubeConfig(config *rest.Config) []byte

func NewMQTTSourceOptions added in v0.15.0

func NewMQTTSourceOptions(sourceID string) *mqtt.MQTTOptions

func NewManifestWork

func NewManifestWork(namespace, name string, manifests []workapiv1.Manifest) *workapiv1.ManifestWork

func NewResourceList

func NewResourceList(cpu, mem int) corev1.ResourceList

func NewRole

func NewRole(namespace, name string) (*unstructured.Unstructured, schema.GroupVersionResource)

func NewRoleBinding

func NewRoleBinding(namespace, name, sa, role string) (*unstructured.Unstructured, schema.GroupVersionResource)

func NewRoleBindingForManifest

func NewRoleBindingForManifest(namespace, name string, rule rbacv1.RoleRef,
	subjects ...rbacv1.Subject) *rbacv1.RoleBinding

func NewRoleForManifest

func NewRoleForManifest(namespace, name string, rules ...rbacv1.PolicyRule) *rbacv1.Role

func NewServiceAccount

func NewServiceAccount(namespace, name string) (*unstructured.Unstructured, schema.GroupVersionResource)

func NewWorkPatch added in v0.15.0

func NewWorkPatch(old, new *workapiv1.ManifestWork) ([]byte, error)

func PrepareSpokeAgentNamespace

func PrepareSpokeAgentNamespace(kubeClient kubernetes.Interface, namespace string) error

func RemoveConfigmapFinalizers

func RemoveConfigmapFinalizers(kubeClient kubernetes.Interface, namespace string, names ...string) error

func RunMQTTBroker added in v0.15.0

func RunMQTTBroker() error

func StopMQTTBroker added in v0.15.0

func StopMQTTBroker() error

func SyncBootstrapKubeConfigFilesToSecret added in v0.14.0

func SyncBootstrapKubeConfigFilesToSecret(
	filePath, secretNS, secretName string,
	kubeClient kubernetes.Interface) error

func SyncBootstrapKubeConfigSecretToFiles added in v0.14.0

func SyncBootstrapKubeConfigSecretToFiles(
	filePath, secretNS, secretName string,
	kubeClient kubernetes.Interface) error

func ToManifest

func ToManifest(object runtime.Object) workapiv1.Manifest

Types

type IntegrationTestEventRecorder

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

func (*IntegrationTestEventRecorder) ComponentName

func (r *IntegrationTestEventRecorder) ComponentName() string

func (*IntegrationTestEventRecorder) Event

func (r *IntegrationTestEventRecorder) Event(reason, message string)

func (*IntegrationTestEventRecorder) Eventf

func (r *IntegrationTestEventRecorder) Eventf(reason, messageFmt string, args ...interface{})

func (*IntegrationTestEventRecorder) ForComponent

func (*IntegrationTestEventRecorder) Shutdown

func (r *IntegrationTestEventRecorder) Shutdown()

func (*IntegrationTestEventRecorder) Warning

func (r *IntegrationTestEventRecorder) Warning(reason, message string)

func (*IntegrationTestEventRecorder) Warningf

func (r *IntegrationTestEventRecorder) Warningf(reason, messageFmt string, args ...interface{})

func (*IntegrationTestEventRecorder) WithComponentSuffix

func (r *IntegrationTestEventRecorder) WithComponentSuffix(suffix string) events.Recorder

func (*IntegrationTestEventRecorder) WithContext

type ProxyServer added in v0.12.0

type ProxyServer struct {
	HTTPProxyURL string

	HTTPSProxyURL string
	// contains filtered or unexported fields
}

ProxyServer is a simple proxy server that supports http tunnel

func NewProxyServer added in v0.12.0

func NewProxyServer(certData, keyData []byte) *ProxyServer

func (*ProxyServer) Start added in v0.12.0

func (ps *ProxyServer) Start(ctx context.Context, timeout time.Duration) error

type TestAuthn

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

func NewTestAuthn

func NewTestAuthn(caFile, caKeyFile string) *TestAuthn

func (*TestAuthn) AddUser

func (t *TestAuthn) AddUser(user envtest.User, baseCfg *rest.Config) (*rest.Config, error)

AddUser provisions a user, returning a copy of the given base rest.Config configured to authenticate as that users.

May only be called while the authenticator is "running".

func (*TestAuthn) ApproveCSR

func (t *TestAuthn) ApproveCSR(kubeClient kubernetes.Interface, csr *certificates.CertificateSigningRequest, notBefore, notAfter time.Time) error

func (*TestAuthn) ApproveSpokeClusterCSR

func (t *TestAuthn) ApproveSpokeClusterCSR(kubeClient kubernetes.Interface, spokeClusterName string, certAge time.Duration) error

func (*TestAuthn) ApproveSpokeClusterCSRWithExpiredCert

func (t *TestAuthn) ApproveSpokeClusterCSRWithExpiredCert(kubeClient kubernetes.Interface, spokeClusterName string) error

func (*TestAuthn) Configure

func (t *TestAuthn) Configure(workDir string, args *envtest.Arguments) error

func (*TestAuthn) CreateBootstrapKubeConfig

func (t *TestAuthn) CreateBootstrapKubeConfig(configFileName, serverCertFile, securePort, bootstrapUser string,
	certAge time.Duration, contextCluster string) error

func (*TestAuthn) CreateBootstrapKubeConfigWithCertAge

func (t *TestAuthn) CreateBootstrapKubeConfigWithCertAge(configFileName, serverCertFile, securePort string,
	certAge time.Duration, contextCluster ...string) error

func (*TestAuthn) CreateBootstrapKubeConfigWithProxy added in v0.12.0

func (t *TestAuthn) CreateBootstrapKubeConfigWithProxy(configFileName, serverCertFile, securePort, proxyURL string, proxyServerCertData []byte) error

func (*TestAuthn) CreateBootstrapKubeConfigWithUser

func (t *TestAuthn) CreateBootstrapKubeConfigWithUser(configFileName, serverCertFile, securePort, bootstrapUser string) error

func (*TestAuthn) FillCertificateToApprovedCSR

func (t *TestAuthn) FillCertificateToApprovedCSR(kubeClient kubernetes.Interface,
	csr *certificates.CertificateSigningRequest, notBefore, notAfter time.Time) error

func (*TestAuthn) SignServerCert added in v0.12.0

func (t *TestAuthn) SignServerCert(commonName string, maxAge time.Duration) ([]byte, []byte, error)

func (*TestAuthn) Start

func (t *TestAuthn) Start() error

Start runs this authenticator. Will be called just before API server start.

Must be called after Configure.

func (*TestAuthn) Stop

func (t *TestAuthn) Stop() error

Stop shuts down this authenticator.

Jump to

Keyboard shortcuts

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