mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
36230daa86
rancher/kine ➡️ k3s-io/kine Part of https://github.com/rancher/k3s/issues/2189 Signed-off-by: Jacob Blain Christen <jacob@rancher.com>
55 lines
1.3 KiB
Go
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
|
|
}
|