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
327 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,88 @@ | ||
// 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 utilize etcd for reconciliation protocol. Methods below are normal | ||
// etcd operations with their semantics adjusted to better suite Kubernetes. | ||
type Interface interface { | ||
// Get retrieves a single key. | ||
// When GetOptions.Revision sets rev > 0, Get retrieves keys at the given revision; | ||
// if the required revision is compacted, the request will fail with ErrCompacted. | ||
Get(ctx context.Context, key string, opts GetOptions) (GetResponse, error) | ||
// List retrieves keys sharing the same prefix. | ||
// When ListOptions.Revision > 0, List retrieves keys at the given revision; | ||
// if the required revision is compacted, the request will fail with ErrCompacted. | ||
// When ListOptions.Limit > 0 , the number of returned keys is bounded by limit. | ||
// When ListOptions.Continue != 0, List will skip all the preceding keys. | ||
List(ctx context.Context, prefix string, opts ListOptions) (ListResponse, error) | ||
// Count retrieves number of keys sharing the same prefix. | ||
Count(ctx context.Context, prefix string) (int64, error) | ||
OptimisticPut(ctx context.Context, key string, value []byte, opts PutOptions) (PutResponse, error) | ||
OptimisticDelete(ctx context.Context, key string, opts DeleteOptions) (DeleteResponse, error) | ||
} | ||
|
||
type GetOptions struct { | ||
Revision int64 | ||
} | ||
|
||
type ListOptions struct { | ||
Revision int64 | ||
Limit int64 | ||
Continue string | ||
} | ||
|
||
type PutOptions struct { | ||
ExpectedRevision int64 | ||
GetOnFailure bool | ||
// LeaseID | ||
// Deprecated: Should be replaced with TTL when Interface starts using one lease per object. | ||
LeaseID clientv3.LeaseID | ||
} | ||
|
||
type DeleteOptions struct { | ||
ExpectedRevision int64 | ||
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.