{"modulePath":"github.com/dockerstack/kubernetes","version":"v0.20.1-0.20150627061651-1c0b765df6da","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package tools\n\nPackage tools implements types which help work with etcd which depend on the api package. TODO: move this package to an etcd specific utility package.\n\n## Constants\n\n```go\nconst (\n\tEtcdCreate = \"create\"\n\tEtcdGet    = \"get\"\n\tEtcdSet    = \"set\"\n\tEtcdCAS    = \"compareAndSwap\"\n\tEtcdDelete = \"delete\"\n)\n```\nEtcd watch event actions\n\n```go\nconst (\n\tEtcdErrorCodeNotFound      = 100\n\tEtcdErrorCodeTestFailed    = 101\n\tEtcdErrorCodeNodeExist     = 105\n\tEtcdErrorCodeValueRequired = 200\n)\n```\n\n## Variables\n\n```go\nvar (\n\tEtcdErrorNotFound      = \u0026etcd.EtcdError{ErrorCode: EtcdErrorCodeNotFound}\n\tEtcdErrorTestFailed    = \u0026etcd.EtcdError{ErrorCode: EtcdErrorCodeTestFailed}\n\tEtcdErrorNodeExist     = \u0026etcd.EtcdError{ErrorCode: EtcdErrorCodeNodeExist}\n\tEtcdErrorValueRequired = \u0026etcd.EtcdError{ErrorCode: EtcdErrorCodeValueRequired}\n)\n```\n\n## Functions\n\n```go\nfunc EtcdHealthCheck(data []byte) error\n```\n\n```go\nfunc Everything(runtime.Object) bool\n```\nEverything is a FilterFunc which accepts all objects.\n\n```go\nfunc GetEtcdVersion(host string) (string, error)\n```\nGetEtcdVersion performs a version check against the provided Etcd server, returning the string response, and error (if any).\n\n```go\nfunc IsEtcdNodeExist(err error) bool\n```\nIsEtcdNodeExist returns true iff err is an etcd node aleady exist error.\n\n```go\nfunc IsEtcdNotFound(err error) bool\n```\nIsEtcdNotFound returns true iff err is an etcd not found error.\n\n```go\nfunc IsEtcdTestFailed(err error) bool\n```\nIsEtcdTestFailed returns true iff err is an etcd write conflict.\n\n```go\nfunc IsEtcdWatchStoppedByUser(err error) bool\n```\nIsEtcdWatchStoppedByUser returns true iff err is a client triggered stop.\n\n```go\nfunc ParseWatchResourceVersion(resourceVersion, kind string) (uint64, error)\n```\nParseWatchResourceVersion takes a resource version argument and converts it to the etcd version we should pass to helper.Watch(). Because resourceVersion is an opaque value, the default watch behavior for non-zero watch is to watch the next value (if you pass \"1\", you will see updates from \"2\" onwards).\n\n## Types\n\n```go\ntype APIObjectVersioner struct{}\n```\nAPIObjectVersioner implements versioning and extracting etcd node information for objects that have an embedded ObjectMeta or ListMeta field.\n\n```go\nfunc (a APIObjectVersioner) ObjectResourceVersion(obj runtime.Object) (uint64, error)\n```\nObjectResourceVersion implements EtcdVersioner\n\n```go\nfunc (a APIObjectVersioner) UpdateList(obj runtime.Object, resourceVersion uint64) error\n```\nUpdateList implements EtcdVersioner\n\n```go\nfunc (a APIObjectVersioner) UpdateObject(obj runtime.Object, expiration *time.Time, resourceVersion uint64) error\n```\nUpdateObject implements EtcdVersioner\n\n```go\ntype EtcdClient interface {\n\tGetCluster() []string\n\tAddChild(key, data string, ttl uint64) (*etcd.Response, error)\n\tGet(key string, sort, recursive bool) (*etcd.Response, error)\n\tSet(key, value string, ttl uint64) (*etcd.Response, error)\n\tCreate(key, value string, ttl uint64) (*etcd.Response, error)\n\tCompareAndSwap(key, value string, ttl uint64, prevValue string, prevIndex uint64) (*etcd.Response, error)\n\tDelete(key string, recursive bool) (*etcd.Response, error)\n\t// I'd like to use directional channels here (e.g. \u003c-chan) but this interface mimics\n\t// the etcd client interface which doesn't, and it doesn't seem worth it to wrap the api.\n\tWatch(prefix string, waitIndex uint64, recursive bool, receiver chan *etcd.Response, stop chan bool) (*etcd.Response, error)\n}\n```\nEtcdClient is an injectable interface for testing.\n\n```go\nfunc NewEtcdClientStartServerIfNecessary(server string) (EtcdClient, error)\n```\n\n```go\ntype EtcdGetSet interface {\n\tGetCluster() []string\n\tGet(key string, sort, recursive bool) (*etcd.Response, error)\n\tSet(key, value string, ttl uint64) (*etcd.Response, error)\n\tCreate(key, value string, ttl uint64) (*etcd.Response, error)\n\tDelete(key string, recursive bool) (*etcd.Response, error)\n\tCompareAndSwap(key, value string, ttl uint64, prevValue string, prevIndex uint64) (*etcd.Response, error)\n\tWatch(prefix string, waitIndex uint64, recursive bool, receiver chan *etcd.Response, stop chan bool) (*etcd.Response, error)\n}\n```\nEtcdGetSet interface exposes only the etcd operations needed by EtcdHelper.\n\n```go\ntype EtcdHelper struct {\n\tClient EtcdGetSet\n\tCodec  runtime.Codec\n\tCopier runtime.ObjectCopier\n\t// optional, no atomic operations can be performed without this interface\n\tVersioner EtcdVersioner\n\t// prefix for all etcd keys\n\tPathPrefix string\n\t// contains filtered or unexported fields\n}\n```\nEtcdHelper offers common object marshalling/unmarshalling operations on an etcd client.\n\n```go\nfunc NewEtcdHelper(client EtcdGetSet, codec runtime.Codec, prefix string) EtcdHelper\n```\nNewEtcdHelper creates a helper that works against objects that use the internal Kubernetes API objects. TODO: Refactor to take a runtiem.ObjectCopier\n\n```go\nfunc (h *EtcdHelper) CreateObj(key string, obj, out runtime.Object, ttl uint64) error\n```\nCreateObj adds a new object at a key unless it already exists. 'ttl' is time-to-live in seconds, and 0 means forever. If no error is returned and out is not nil, out will be set to the read value from etcd.\n\n```go\nfunc (h *EtcdHelper) Delete(key string, recursive bool) error\n```\nDelete removes the specified key.\n\n```go\nfunc (h *EtcdHelper) DeleteObj(key string, out runtime.Object) error\n```\nDeleteObj removes the specified key and returns the value that existed at that spot.\n\n```go\nfunc (h *EtcdHelper) ExtractObj(key string, objPtr runtime.Object, ignoreNotFound bool) error\n```\nExtractObj unmarshals json found at key into objPtr. On a not found error, will either return a zero object of the requested type, or an error, depending on ignoreNotFound. Treats empty responses and nil response nodes exactly like a not found error.\n\n```go\nfunc (h *EtcdHelper) ExtractObjToList(key string, listObj runtime.Object) error\n```\nExtractObjToList unmarshals json found at key and opaques it into a \\*List api object (an object that satisfies the runtime.IsList definition).\n\n```go\nfunc (h *EtcdHelper) ExtractToList(key string, listObj runtime.Object) error\n```\nExtractToList works on a \\*List api object (an object that satisfies the runtime.IsList definition) and extracts a go object per etcd node into a slice with the resource version.\n\n```go\nfunc (h *EtcdHelper) GuaranteedUpdate(key string, ptrToType runtime.Object, ignoreNotFound bool, tryUpdate EtcdUpdateFunc) error\n```\nGuaranteedUpdate calls \"tryUpdate()\" to update key \"key\" that is of type \"ptrToType\". It keeps calling tryUpdate() and retrying the update until success if there is etcd index conflict. Note that object passed to tryUpdate() may change across invocations of tryUpdate() if other writers are simultaneously updating it, so tryUpdate() needs to take into account the current contents of the object when deciding how the updated object (that it returns) should look.\n\nExample:\n\nh := \u0026util.EtcdHelper{client, encoding, versioning}\n\n\terr := h.GuaranteedUpdate(\"myKey\", \u0026MyType{}, true, func(input runtime.Object, res ResponseMeta) (runtime.Object, *uint64, error) {\n\t\t// Before each invocation of the user-defined function, \"input\" is reset to etcd's current contents for \"myKey\".\n\n\t\tcur := input.(*MyType) // Guaranteed to succeed.\n\n\t\t// Make a *modification*.\n\t\tcur.Counter++\n\n\t\t// Return the modified object. Return an error to stop iterating. Return a uint64 to alter\n\t     // the TTL on the object, or nil to keep it the same value.\n\t\treturn cur, nil, nil\n\t})\n\n```go\nfunc (h *EtcdHelper) MigrateKeys(oldPathPrefix string) error\n```\nCopies the key-value pairs from their old location to a new location based on this helper's etcd prefix. All old keys without the prefix are then deleted.\n\n```go\nfunc (h *EtcdHelper) PrefixEtcdKey(key string) string\n```\n\n```go\nfunc (h *EtcdHelper) SetObj(key string, obj, out runtime.Object, ttl uint64) error\n```\nSetObj marshals obj via json, and stores under key. Will do an atomic update if obj's ResourceVersion field is set. 'ttl' is time-to-live in seconds, and 0 means forever. If no error is returned and out is not nil, out will be set to the read value from etcd.\n\n```go\nfunc (h *EtcdHelper) Watch(key string, resourceVersion uint64, filter FilterFunc) (watch.Interface, error)\n```\nWatch begins watching the specified key. Events are decoded into API objects and sent down the returned watch.Interface. Errors will be sent down the channel.\n\n```go\nfunc (h *EtcdHelper) WatchAndTransform(key string, resourceVersion uint64, transform TransformFunc) watch.Interface\n```\nWatchAndTransform begins watching the specified key. Events are decoded into API objects and sent down the returned watch.Interface. If the transform function is provided, the value decoded from etcd will be passed to the function prior to being returned.\n\nThe transform function can be used to populate data not available to etcd, or to change or wrap the serialized etcd object.\n\n\tstartTime := time.Now()\n\thelper.WatchAndTransform(key, version, func(input runtime.Object) (runtime.Object, error) {\n\t  value := input.(TimeAwareValue)\n\t  value.Since = startTime\n\t  return value, nil\n\t})\n\nErrors will be sent down the channel.\n\n```go\nfunc (h *EtcdHelper) WatchList(key string, resourceVersion uint64, filter FilterFunc) (watch.Interface, error)\n```\nWatchList begins watching the specified key's items. Items are decoded into API objects, and any items passing 'filter' are sent down the returned watch.Interface. resourceVersion may be used to specify what version to begin watching (e.g., for reconnecting without missing any updates).\n\n```go\ntype EtcdResponseWithError struct {\n\tR *etcd.Response\n\tE error\n\t// if N is non-null, it will be assigned into the map after this response is used for an operation\n\tN *EtcdResponseWithError\n}\n```\n\n```go\ntype EtcdUpdateFunc func(input runtime.Object, res ResponseMeta) (output runtime.Object, ttl *uint64, err error)\n```\nPass an EtcdUpdateFunc to EtcdHelper.GuaranteedUpdate to make an etcd update that is guaranteed to succeed. See the comment for GuaranteedUpdate for more detail.\n\n```go\nfunc SimpleUpdate(fn SimpleEtcdUpdateFunc) EtcdUpdateFunc\n```\nSimpleUpdateFunc converts SimpleEtcdUpdateFunc into EtcdUpdateFunc\n\n```go\ntype EtcdVersioner interface {\n\t// UpdateObject sets etcd storage metadata into an API object. Returns an error if the object\n\t// cannot be updated correctly. May return nil if the requested object does not need metadata\n\t// from etcd.\n\tUpdateObject(obj runtime.Object, expiration *time.Time, resourceVersion uint64) error\n\t// UpdateList sets the resource version into an API list object. Returns an error if the object\n\t// cannot be updated correctly. May return nil if the requested object does not need metadata\n\t// from etcd.\n\tUpdateList(obj runtime.Object, resourceVersion uint64) error\n\t// ObjectResourceVersion returns the resource version (for persistence) of the specified object.\n\t// Should return an error if the specified object does not have a persistable version.\n\tObjectResourceVersion(obj runtime.Object) (uint64, error)\n}\n```\nEtcdVersioner abstracts setting and retrieving fields from the etcd response onto the object or list.\n\n```go\ntype FakeEtcdClient struct {\n\tData        map[string]EtcdResponseWithError\n\tDeletedKeys []string\n\n\tsync.Mutex\n\tErr    error\n\tCasErr error\n\n\tIx          int\n\tTestIndex   bool\n\tChangeIndex uint64\n\tLastSetTTL  uint64\n\tMachines    []string\n\n\t// Will become valid after Watch is called; tester may write to it. Tester may\n\t// also read from it to verify that it's closed after injecting an error.\n\tWatchResponse chan *etcd.Response\n\tWatchIndex    uint64\n\t// Write to this to prematurely stop a Watch that is running in a goroutine.\n\tWatchInjectError chan\u003c- error\n\tWatchStop        chan\u003c- bool\n\t// If non-nil, will be returned immediately when Watch is called.\n\tWatchImmediateError error\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewFakeEtcdClient(t TestLogger) *FakeEtcdClient\n```\n\n```go\nfunc (f *FakeEtcdClient) AddChild(key, data string, ttl uint64) (*etcd.Response, error)\n```\n\n```go\nfunc (f *FakeEtcdClient) CompareAndSwap(key, value string, ttl uint64, prevValue string, prevIndex uint64) (*etcd.Response, error)\n```\n\n```go\nfunc (f *FakeEtcdClient) Create(key, value string, ttl uint64) (*etcd.Response, error)\n```\n\n```go\nfunc (f *FakeEtcdClient) Delete(key string, recursive bool) (*etcd.Response, error)\n```\n\n```go\nfunc (f *FakeEtcdClient) ExpectNotFoundGet(key string)\n```\n\n```go\nfunc (f *FakeEtcdClient) Get(key string, sort, recursive bool) (*etcd.Response, error)\n```\n\n```go\nfunc (f *FakeEtcdClient) GetCluster() []string\n```\n\n```go\nfunc (f *FakeEtcdClient) NewError(code int) *etcd.EtcdError\n```\n\n```go\nfunc (f *FakeEtcdClient) Set(key, value string, ttl uint64) (*etcd.Response, error)\n```\n\n```go\nfunc (f *FakeEtcdClient) SetError(err error)\n```\n\n```go\nfunc (f *FakeEtcdClient) WaitForWatchCompletion()\n```\n\n```go\nfunc (f *FakeEtcdClient) Watch(prefix string, waitIndex uint64, recursive bool, receiver chan *etcd.Response, stop chan bool) (*etcd.Response, error)\n```\n\n```go\ntype FilterFunc func(obj runtime.Object) bool\n```\nFilterFunc is a predicate which takes an API object and returns true iff the object should remain in the set.\n\n```go\ntype ResponseMeta struct {\n\t// TTL is the time to live of the node that contained the returned object. It may be\n\t// zero or negative in some cases (objects may be expired after the requested\n\t// expiration time due to server lag).\n\tTTL int64\n\t// Expiration is the time at which the node that contained the returned object will expire and be deleted.\n\t// This can be nil if there is no expiration time set for the node.\n\tExpiration *time.Time\n\t// The resource version of the node that contained the returned object.\n\tResourceVersion uint64\n}\n```\nResponseMeta contains information about the etcd metadata that is associated with an object. It abstracts the actual underlying objects to prevent coupling with etcd and to improve testability.\n\n```go\ntype SimpleEtcdUpdateFunc func(runtime.Object) (runtime.Object, error)\n```\n\n```go\ntype TestLogger interface {\n\tFatalf(format string, args ...interface{})\n\tErrorf(format string, args ...interface{})\n\tLogf(format string, args ...interface{})\n}\n```\nTestLogger is a type passed to Test functions to support formatted test logs.\n\n```go\ntype TransformFunc func(runtime.Object) (runtime.Object, error)\n```\nTransformFunc attempts to convert an object to another object for use with a watcher.\n\n","path":"github.com/dockerstack/kubernetes/pkg/tools","name":"tools","synopsis":"Package tools implements types which help work with etcd which depend on the api package.","isRedistributable":true}
