func CreateOrUpdateService(client clientset.Interface, service *corev1.Service) (*corev1.Service, error) {
	var err error
	var existing *corev1.Service
	existing, err = client.Core().Services(service.GetNamespace()).Get(service.GetName(), metav1.GetOptions{})
	if err != nil && apierrors.IsNotFound(err) {
		if existing, err = client.Core().Services(service.GetNamespace()).Create(service); err != nil {
			return nil, err
		}
	} else if err != nil {
		return nil, err
	} else {
		if !reflect.DeepEqual(service.Spec, existing.Spec) {
			existing.Spec.Type = service.Spec.Type
			existing.Spec.Ports = service.Spec.Ports
			if existing, err = client.Core().Services(existing.GetNamespace()).Update(existing); err != nil {
				return nil, fmt.Errorf("unable to update Service: %v", err)
			}
		}
	}
	return existing, nil
}
CreateOrUpdateService creates a Deployment if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.
package client
import (
	"fmt"
	"net/http"
	"reflect"
	"time"
	"github.com/golang/glog"
	batchv1 "k8s.io/api/batch/v1"
	corev1 "k8s.io/api/core/v1"
	netv1 "k8s.io/api/networking/v1"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/wait"
	clientset "k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
)
const (
	pollInterval = 2 * time.Second
	pollTimeout = 5 * time.Minute
)
func CreateOrUpdatePod(client clientset.Interface, service *corev1.Pod) (*corev1.Pod, error) {
	var err error
	var existing *corev1.Pod
	existing, err = client.Core().Pods(service.GetNamespace()).Get(service.GetName(), metav1.GetOptions{})
	if err != nil && apierrors.IsNotFound(err) {
		if existing, err = client.Core().Pods(service.GetNamespace()).Create(service); err != nil {
			return nil, err
		}
	} else if err != nil {
		return nil, err
	} else {
		if !reflect.DeepEqual(service.Spec, existing.Spec) {
			existing.Spec = service.Spec
			if existing, err = client.Core().Pods(existing.GetNamespace()).Update(existing); err != nil {
				return nil, fmt.Errorf("unable to update Pod: %v", err)
			}
		}
	}
	return existing, nil
}
func CreateOrUpdateJob(client clientset.Interface, job *batchv1.Job) (*batchv1.Job, error) {
	var err error
	var existing *batchv1.Job
	existing, err = client.Batch().Jobs(job.GetNamespace()).Get(job.GetName(), metav1.GetOptions{})
	if err != nil && apierrors.IsNotFound(err) {
		if existing, err = client.Batch().Jobs(job.GetNamespace()).Create(job); err != nil {
			return nil, err
		}
	} else if err != nil {
		return nil, err
	} else {
		if !reflect.DeepEqual(job.Spec, existing.Spec) {
			existing.Spec = job.Spec
			if existing, err = client.Batch().Jobs(existing.GetNamespace()).Update(existing); err != nil {
				return nil, fmt.Errorf("unable to update Job: %v", err)
			}
		}
	}
	return existing, nil
}