func (c *EtcdClient) Update(d *model.KVPair) (*model.KVPair, error) {
	options := etcd.SetOptions{PrevExist: etcd.PrevExist}
	if len(d.Revision) != 0 {
		var err error
		if options.PrevIndex, err = strconv.ParseUint(d.Revision, 10, 64); err != nil {
			return nil, err
		}
		log.Debugf("Performing CAS against etcd index: %v\n", options.PrevIndex)
	}
	return c.set(d, &options)
}
Update an existing entry in the datastore.  This errors if the entry does
not exist.
package etcdv2
import (
	goerrors "errors"
	"strconv"
	"strings"
	"time"
	log "github.com/sirupsen/logrus"
	etcd "go.etcd.io/etcd/client"
	"go.etcd.io/etcd/pkg/transport"
	"golang.org/x/net/context"
	apiv1 "github.com/projectcalico/libcalico-go/lib/apis/v1"
	"github.com/projectcalico/libcalico-go/lib/backend/model"
	"github.com/projectcalico/libcalico-go/lib/errors"
)
var (
	etcdApplyOpts        = &etcd.SetOptions{PrevExist: etcd.PrevIgnore}
	etcdGetOpts          = &etcd.GetOptions{Quorum: true}
	etcdListOpts         = &etcd.GetOptions{Quorum: true, Recursive: true, Sort: true}
	etcdListChildrenOpts = &etcd.GetOptions{Quorum: true, Recursive: false, Sort: true}
	clientTimeout        = 30 * time.Second
)
type EtcdClient struct {
	etcdClient  etcd.Client
	etcdKeysAPI etcd.KeysAPI
}
func NewEtcdClient(config *apiv1.EtcdConfig) (*EtcdClient, error) {
	var etcdLocation []string
	if config.EtcdAuthority != "" {
		etcdLocation = []string{config.EtcdScheme + "://" + config.EtcdAuthority}
	}
	if config.EtcdEndpoints != "" {
		etcdLocation = strings.Split(config.EtcdEndpoints, ",")
	}
	if len(etcdLocation) == 0 {
		return nil, goerrors.New("no etcd authority or endpoints specified")
	}
	tls := transport.TLSInfo{
		TrustedCAFile: config.EtcdCACertFile,
		CertFile:      config.EtcdCertFile,
		KeyFile:       config.EtcdKeyFile,
	}
	t, err := transport.NewTransport(tls, clientTimeout)
	if err != nil {
		return nil, err
	}
	cfg := etcd.Config{
		Endpoints:               etcdLocation,
		Transport:               t,
		HeaderTimeoutPerRequest: clientTimeout,
	}
	if config.EtcdUsername != "" && config.EtcdPassword != "" {
		cfg.Username = config.EtcdUsername
		cfg.Password = config.EtcdPassword
	}
	client, err := etcd.New(cfg)
	if err != nil {
		return nil, err
	}
	keys := etcd.NewKeysAPI(client)
	return &EtcdClient{etcdClient: client, etcdKeysAPI: keys}, nil
}