func (j *TestJig) waitForAvailableEndpoint(timeout time.Duration) error {
	//Wait for endpoints to be created, this may take longer time if service backing pods are taking longer time to run
	endpointSelector := fields.OneTermEqualSelector("metadata.name", j.Name)
	stopCh := make(chan struct{})
	endpointAvailable := false
	var controller cache.Controller
	_, controller = cache.NewInformer(
		&cache.ListWatch{
			ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
				options.FieldSelector = endpointSelector.String()
				obj, err := j.Client.CoreV1().Endpoints(j.Namespace).List(context.TODO(), options)
				return runtime.Object(obj), err
			},
			WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
				options.FieldSelector = endpointSelector.String()
				return j.Client.CoreV1().Endpoints(j.Namespace).Watch(context.TODO(), options)
			},
		},
		&v1.Endpoints{},
		0,
		cache.ResourceEventHandlerFuncs{
			AddFunc: func(obj interface{}) {
				if e, ok := obj.(*v1.Endpoints); ok {
					if len(e.Subsets) > 0 && len(e.Subsets[0].Addresses) > 0 {
						endpointAvailable = true
					}
				}
			},
			UpdateFunc: func(old, cur interface{}) {
				if e, ok := cur.(*v1.Endpoints); ok {
					if len(e.Subsets) > 0 && len(e.Subsets[0].Addresses) > 0 {
						endpointAvailable = true
					}
				}
			},
		},
	)
	defer func() {
		close(stopCh)
	}()

	go controller.Run(stopCh)

	err := wait.Poll(1*time.Second, timeout, func() (bool, error) {
		return endpointAvailable, nil
	})
	if err != nil {
		return fmt.Errorf("no subset of available IP address found for the endpoint %s within timeout %v", j.Name, timeout)
	}
	return nil
}
// waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
// waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
func (j *TestJig) waitForAvailableEndpoint(timeout time.Duration) error {
	endpointSelector := fields.OneTermEqualSelector("metadata.name", j.Name)
	stopCh := make(chan struct{})
	endpointAvailable := false
	var controller cache.Controller
	_, controller = cache.NewInformer(
		&cache.ListWatch{
			ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
				options.FieldSelector = endpointSelector.String()
				obj, err := j.Client.CoreV1().Endpoints(j.Namespace).List(context.TODO(), options)
				return runtime.Object(obj), err
			},
			WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
				options.FieldSelector = endpointSelector.String()
				return j.Client.CoreV1().Endpoints(j.Namespace).Watch(context.TODO(), options)
			},
		},
		&v1.Endpoints{},
		0,
		cache.ResourceEventHandlerFuncs{
			AddFunc: func(obj interface{}) {
				if e, ok := obj.(*v1.Endpoints); ok {
					if len(e.Subsets) > 0 && len(e.Subsets[0].Addresses) > 0 {
						endpointAvailable = true
					}
				}
			},
			UpdateFunc: func(old, cur interface{}) {
				if e, ok := cur.(*v1.Endpoints); ok {
					if len(e.Subsets) > 0 && len(e.Subsets[0].Addresses) > 0 {
						endpointAvailable = true
					}
				}
			},
		},
	)
	defer func() {
		close(stopCh)
	}()
	go controller.Run(stopCh)
	err := wait.Poll(1*time.Second, timeout, func() (bool, error) {
		return endpointAvailable, nil
	})
	if err != nil {
		return fmt.Errorf("no subset of available IP address found for the endpoint %s within timeout %v", j.Name, timeout)
	}
	return nil
}
func ( j * TestJig ) waitForAvailableEndpoint ( timeout time . Duration ) error { endpointSelector := fields . OneTermEqualSelector ( " " , j . Name ) stopCh := make ( chan struct { } ) endpointAvailable := false var controller cache . Controller _ , controller = cache . NewInformer ( & cache . ListWatch { ListFunc : func ( options metav1 . ListOptions ) ( runtime . Object , error ) { options . FieldSelector = endpointSelector . String ( ) obj , err := j . Client . CoreV1 ( ) . Endpoints ( j . Namespace ) . List ( context . TODO ( ) , options ) return runtime . Object ( obj ) , err } , WatchFunc : func ( options metav1 . ListOptions ) ( watch . Interface , error ) { options . FieldSelector = endpointSelector . String ( ) return j . Client . CoreV1 ( ) . Endpoints ( j . Namespace ) . Watch ( context . TODO ( ) , options ) } , } , & v1 . Endpoints { } , 0 , cache . ResourceEventHandlerFuncs { AddFunc : func ( obj interface { } ) { if e , ok := obj . ( * v1 . Endpoints ) ; ok { if len ( e . Subsets ) > 0 && len ( e . Subsets [ 0 ] . Addresses ) > 0 { endpointAvailable = true } } } , UpdateFunc : func ( old , cur interface { } ) { if e , ok := cur . ( * v1 . Endpoints ) ; ok { if len ( e . Subsets ) > 0 && len ( e . Subsets [ 0 ] . Addresses ) > 0 { endpointAvailable = true } } } , } , ) defer func ( ) { close ( stopCh ) } ( ) go controller . Run ( stopCh ) err := wait . Poll ( 1 * time . Second , timeout , func ( ) ( bool , error ) { return endpointAvailable , nil } ) if err != nil { return fmt . Errorf ( " " , j . Name , timeout ) } return nil }
waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
//Wait for endpoints to be created, this may take longer time if service backing pods are taking longer time to run