func NewNginx(kc kubernetes.Interface, namespace string, options ...NginxOpts) (*Nginx, error) {
	name := fmt.Sprintf("nginx-%s", utilrand.String(5))
	n := &Nginx{
		Namespace: namespace,
		Name:      name,
		podSelector: &metav1.LabelSelector{
			MatchLabels: map[string]string{"app": name}},
		nodeSelector: &metav1.LabelSelector{
			MatchLabels: map[string]string{},
		},
		pingPodSelector: &metav1.LabelSelector{
			MatchLabels: map[string]string{},
		},
		client: kc,
	}
	for _, option := range options {
		if err := option(n); err != nil {
			return nil, fmt.Errorf("error invalid options: %v", err)
		}
	}
	var err error
	defer func() {
		if err != nil {
			n.Delete()
		}
	}()
	if err = n.newNginxDeployment(); err != nil {
		return nil, fmt.Errorf("error creating deployment %s: %v", n.Name, err)
	}
	if err = n.newNginxService(); err != nil {
		return nil, fmt.Errorf("error creating service %s: %v", n.Name, err)
	}
	if err = wait.PollImmediate(PollIntervalForNginx, PollTimeoutForNginx, func() (bool, error) {
		d, err := kc.ExtensionsV1beta1().Deployments(n.Namespace).Get(context.TODO(), n.Name, metav1.GetOptions{})
		if err != nil {
			glog.Errorf("Error getting deployment %s: %v", n.Name, err)
			return false, nil
		}
		if d.Status.UpdatedReplicas != d.Status.AvailableReplicas && d.Status.UnavailableReplicas != 0 {
			return false, nil
		}
		pl, err := kc.CoreV1().Pods(n.Namespace).List(context.TODO(), metav1.ListOptions{
			LabelSelector: metav1.FormatLabelSelector(n.podSelector),
		})
		if err != nil {
			glog.Errorf("Error getting pods for deployment %s: %v", n.Name, err)
			return false, nil
		}
		if len(pl.Items) == 0 {
			return false, nil
		}
		var pods []*v1.Pod
		for i := range pl.Items {
			p := &pl.Items[i]
			if p.Status.Phase != v1.PodRunning {
				return false, nil
			}
			pods = append(pods, p)
		}
		n.Pods = pods
		return true, nil
	}); err != nil {
		return nil, fmt.Errorf("deployment %s is not ready: %v", n.Name, err)
	}
	return n, nil
}
NewNginx create this nginx deployment/service pair.
It waits until all the pods in the deployment are running.
package testworkload
import (
	"context"
	"fmt"
	"time"
	"github.com/golang/glog"
	batchv1 "k8s.io/api/batch/v1"
	"k8s.io/api/core/v1"
	extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/intstr"
	utilrand "k8s.io/apimachinery/pkg/util/rand"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/client-go/kubernetes"
)
var (
	PollTimeoutForNginx = 10 * time.Minute
	PollIntervalForNginx = 10 * time.Second
)
type Nginx struct {
	Namespace string
	Name      string
	Pods []*v1.Pod
	client          kubernetes.Interface
	podSelector     *metav1.LabelSelector
	nodeSelector    *metav1.LabelSelector
	pingPodSelector *metav1.LabelSelector
}
type NginxOpts func(*Nginx) error