mirror of
https://github.com/hanzoai/volume.git
synced 2026-10-01 00:48:00 +00:00
A fork of Rancher's local-path-provisioner at v0.0.36. The behaviour is unchanged and deliberately so — a directory on the node a pod lands on is the right thing for a disk. What changes is identity. The provisioner answers to hanzo.ai/volume rather than rancher.io/local-path. That is not branding: two provisioners sharing one name race for the same claims, and a stock k3s carries the upstream one, so a cluster running both would settle our storage by chance. Data lives at /var/lib/hanzo/volume, so reading a Hanzo cluster does not mean learning another vendor's directory. Apache-2.0 as published, unaltered, with Rancher's attribution in NOTICE. The README says what this is not: durability. A volume here dies with its node. That is hanzoai/replicate's question, one layer up, and keeping the two apart is what lets the disk stay this simple.
101 lines
3.6 KiB
Go
101 lines
3.6 KiB
Go
/*
|
|
Copyright 2014 The Kubernetes 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 cache
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"k8s.io/apimachinery/pkg/api/meta"
|
|
"k8s.io/apimachinery/pkg/util/sets"
|
|
)
|
|
|
|
// Indexer extends Store with multiple indices and restricts each
|
|
// accumulator to simply hold the current object (and be empty after
|
|
// Delete).
|
|
//
|
|
// There are three kinds of strings here:
|
|
// 1. a storage key, as defined in the Store interface,
|
|
// 2. a name of an index, and
|
|
// 3. an "indexed value", which is produced by an IndexFunc and
|
|
// can be a field value or any other string computed from the object.
|
|
type Indexer interface {
|
|
Store
|
|
// Index returns the stored objects whose set of indexed values
|
|
// intersects the set of indexed values of the given object, for
|
|
// the named index
|
|
Index(indexName string, obj interface{}) ([]interface{}, error)
|
|
// IndexKeys returns the storage keys of the stored objects whose
|
|
// set of indexed values for the named index includes the given
|
|
// indexed value
|
|
IndexKeys(indexName, indexedValue string) ([]string, error)
|
|
// ListIndexFuncValues returns all the indexed values of the given index
|
|
ListIndexFuncValues(indexName string) []string
|
|
// ByIndex returns the stored objects whose set of indexed values
|
|
// for the named index includes the given indexed value
|
|
ByIndex(indexName, indexedValue string) ([]interface{}, error)
|
|
// GetIndexers return the indexers
|
|
GetIndexers() Indexers
|
|
|
|
// AddIndexers adds more indexers to this store. This supports adding indexes after the store already has items.
|
|
AddIndexers(newIndexers Indexers) error
|
|
}
|
|
|
|
// IndexFunc knows how to compute the set of indexed values for an object.
|
|
type IndexFunc func(obj interface{}) ([]string, error)
|
|
|
|
// IndexFuncToKeyFuncAdapter adapts an indexFunc to a keyFunc. This is only useful if your index function returns
|
|
// unique values for every object. This conversion can create errors when more than one key is found. You
|
|
// should prefer to make proper key and index functions.
|
|
func IndexFuncToKeyFuncAdapter(indexFunc IndexFunc) KeyFunc {
|
|
return func(obj interface{}) (string, error) {
|
|
indexKeys, err := indexFunc(obj)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if len(indexKeys) > 1 {
|
|
return "", fmt.Errorf("too many keys: %v", indexKeys)
|
|
}
|
|
if len(indexKeys) == 0 {
|
|
return "", fmt.Errorf("unexpected empty indexKeys")
|
|
}
|
|
return indexKeys[0], nil
|
|
}
|
|
}
|
|
|
|
const (
|
|
// NamespaceIndex is the lookup name for the most common index function, which is to index by the namespace field.
|
|
NamespaceIndex string = "namespace"
|
|
)
|
|
|
|
// MetaNamespaceIndexFunc is a default index function that indexes based on an object's namespace
|
|
func MetaNamespaceIndexFunc(obj interface{}) ([]string, error) {
|
|
meta, err := meta.Accessor(obj)
|
|
if err != nil {
|
|
return []string{""}, fmt.Errorf("object has no meta: %v", err)
|
|
}
|
|
return []string{meta.GetNamespace()}, nil
|
|
}
|
|
|
|
// Index maps the indexed value to a set of keys in the store that match on that value
|
|
type Index map[string]sets.String
|
|
|
|
// Indexers maps a name to an IndexFunc
|
|
type Indexers map[string]IndexFunc
|
|
|
|
// Indices maps a name to an Index
|
|
type Indices map[string]Index
|