k3s/vendor/github.com/k3s-io/kine/pkg/server/create.go
Jacob Blain Christen 36230daa86
[migration k3s-io] update kine dependency (#2568)
rancher/kine ➡️ k3s-io/kine

Part of https://github.com/rancher/k3s/issues/2189

Signed-off-by: Jacob Blain Christen <jacob@rancher.com>
2020-11-30 16:45:22 -07:00

55 lines
1.3 KiB
Go

package server
import (
"context"
"go.etcd.io/etcd/etcdserver/etcdserverpb"
)
func isCreate(txn *etcdserverpb.TxnRequest) *etcdserverpb.PutRequest {
if len(txn.Compare) == 1 &&
txn.Compare[0].Target == etcdserverpb.Compare_MOD &&
txn.Compare[0].Result == etcdserverpb.Compare_EQUAL &&
txn.Compare[0].GetModRevision() == 0 &&
len(txn.Failure) == 0 &&
len(txn.Success) == 1 &&
txn.Success[0].GetRequestPut() != nil {
return txn.Success[0].GetRequestPut()
}
return nil
}
func (l *LimitedServer) create(ctx context.Context, put *etcdserverpb.PutRequest, txn *etcdserverpb.TxnRequest) (*etcdserverpb.TxnResponse, error) {
if put.IgnoreLease {
return nil, unsupported("ignoreLease")
} else if put.IgnoreValue {
return nil, unsupported("ignoreValue")
} else if put.PrevKv {
return nil, unsupported("prevKv")
}
rev, err := l.backend.Create(ctx, string(put.Key), put.Value, put.Lease)
if err == ErrKeyExists {
return &etcdserverpb.TxnResponse{
Header: txnHeader(rev),
Succeeded: false,
}, nil
} else if err != nil {
return nil, err
}
return &etcdserverpb.TxnResponse{
Header: txnHeader(rev),
Responses: []*etcdserverpb.ResponseOp{
{
Response: &etcdserverpb.ResponseOp_ResponsePut{
ResponsePut: &etcdserverpb.PutResponse{
Header: txnHeader(rev),
},
},
},
},
Succeeded: true,
}, nil
}