forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Kubernetes KV interface to etcd client
Signed-off-by: Marek Siarkowicz <[email protected]>
- Loading branch information
Showing
10 changed files
with
341 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2024 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
||
"go.etcd.io/etcd/api/v3/mvccpb" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
// Interface defines the minimal client-side interface that Kubernetes requires | ||
// to interact with etcd for its reconciliation protocol. Methods below are standard | ||
// etcd operations with semantics adjusted to better suit Kubernetes' needs. | ||
type Interface interface { | ||
// Get retrieves a single key-value pair from etcd. | ||
// | ||
// If opts.Revision is set to a non-zero value, the key-value pair is retrieved at the specified revision. | ||
// If the required revision has been compacted, the request will fail with ErrCompacted. | ||
Get(ctx context.Context, key string, opts GetOptions) (GetResponse, error) | ||
|
||
// List retrieves key-value pairs with the specified prefix. | ||
// | ||
// If opts.Revision is non-zero, the key-value pairs are retrieved at the specified revision. | ||
// If the required revision has been compacted, the request will fail with ErrCompacted. | ||
// If opts.Limit is greater than zero, the number of returned key-value pairs is bounded by the limit. | ||
// If opts.Continue is not empty, the listing will start from the key immediately after the one specified by Continue. | ||
List(ctx context.Context, prefix string, opts ListOptions) (ListResponse, error) | ||
|
||
// Count returns the number of keys with the specified prefix. | ||
Count(ctx context.Context, prefix string) (int64, error) | ||
|
||
// OptimisticPut creates or updates a key-value pair if the key has not been modified or created | ||
// since the revision specified in expectedRevision. Otherwise, it updates the key-value pair | ||
// only if it hasn't been modified since expectedRevision. | ||
// | ||
// If opts.GetOnFailure is true, the modified key-value pair will be returned if the put operation fails due to a revision mismatch. | ||
// If opts.LeaseID is provided, it overrides the lease associated with the key. If not provided, the existing lease is cleared. | ||
OptimisticPut(ctx context.Context, key string, value []byte, expectedRevision int64, opts PutOptions) (PutResponse, error) | ||
|
||
// OptimisticDelete deletes the key-value pair if it hasn't been modified since the revision | ||
// specified in expectedRevision. | ||
// | ||
// If opts.GetOnFailure is true, the modified key-value pair will be returned if the delete operation fails due to a revision mismatch. | ||
OptimisticDelete(ctx context.Context, key string, expectedRevision int64, opts DeleteOptions) (DeleteResponse, error) | ||
} | ||
|
||
type GetOptions struct { | ||
Revision int64 | ||
} | ||
|
||
type ListOptions struct { | ||
Revision int64 | ||
Limit int64 | ||
Continue string | ||
} | ||
|
||
type PutOptions struct { | ||
GetOnFailure bool | ||
// LeaseID | ||
// Deprecated: Should be replaced with TTL when Interface starts using one lease per object. | ||
LeaseID clientv3.LeaseID | ||
} | ||
|
||
type DeleteOptions struct { | ||
GetOnFailure bool | ||
} | ||
|
||
type GetResponse struct { | ||
KV *mvccpb.KeyValue | ||
Revision int64 | ||
} | ||
|
||
type ListResponse struct { | ||
KVs []*mvccpb.KeyValue | ||
Count int64 | ||
Revision int64 | ||
} | ||
|
||
type PutResponse struct { | ||
KV *mvccpb.KeyValue | ||
Succeeded bool | ||
Revision int64 | ||
} | ||
|
||
type DeleteResponse struct { | ||
KV *mvccpb.KeyValue | ||
Succeeded bool | ||
Revision int64 | ||
} |
Oops, something went wrong.