|
| 1 | +Cache Options |
| 2 | +=================== |
| 3 | + |
| 4 | +This document describes how we imagine the cache options to look like in |
| 5 | +the future. |
| 6 | + |
| 7 | +## Goals |
| 8 | + |
| 9 | +* Align everyone on what settings on the cache we want to support and |
| 10 | + their configuration surface |
| 11 | +* Ensure that we support both complicated cache setups and provide an |
| 12 | + intuitive configuration UX |
| 13 | + |
| 14 | +## Non-Goals |
| 15 | + |
| 16 | +* Line out how the actual implementation of the cache itself will look like. |
| 17 | + The assumption is that the most granular level we will end up with is |
| 18 | + "per object multiple namespaces with distinct selectors" and that this |
| 19 | + can be implemented using a "meta cache" that delegates per object and by |
| 20 | + extending the current multi-namespace cache |
| 21 | +* Outline any kind of timeline for when these settings will be implemented. |
| 22 | + Implementation will happen gradually over time whenever someone steps up |
| 23 | + to do the actual work |
| 24 | + |
| 25 | +## Proposal |
| 26 | + |
| 27 | + |
| 28 | +``` |
| 29 | +type CacheSetting struct { |
| 30 | + // LabelSelector specifies a label selector. A nil value allows to |
| 31 | + // default this. |
| 32 | + LabelSelector labels.Selector |
| 33 | +
|
| 34 | + // FieldSelector specifics a field selector. A nil value allows to |
| 35 | + // default this. |
| 36 | + FieldSelector fields.Selector |
| 37 | +
|
| 38 | + // Transform specifies a transform func. A nil value allows to default |
| 39 | + // this. |
| 40 | + Transform toolscache.TransformFunc |
| 41 | +
|
| 42 | + // UnsafeDisableDeepCopy specifies if List and Get requests against the |
| 43 | + // cache should not DeepCopy. A nil value allows to default this. |
| 44 | + UnsafeDisableDeepCopy *bool |
| 45 | +} |
| 46 | +
|
| 47 | +
|
| 48 | +type ByObject struct { |
| 49 | + // Namespaces maps a namespace name to cache setting. If set, only the |
| 50 | + // namespaces in this map will be cached. |
| 51 | + // |
| 52 | + // A nil value in this map means "fall through to the ByObject CacheSetting" |
| 53 | + // |
| 54 | + // An empty value in this map means "No Selectors". |
| 55 | + // |
| 56 | + // It is possible to have specific CacheSettings for just some namespaces |
| 57 | + // but cache all namespaces by using the empty string as map key for |
| 58 | + // "all namespaces". This wil then include all namespaces that do not have |
| 59 | + // a more specific setting. |
| 60 | + // |
| 61 | + // A nil map allows to default this to the caches DefaultNamespaces setting. |
| 62 | + // An empty map prevents this. |
| 63 | + // |
| 64 | + // This must be unset for cluster-scoped objects. |
| 65 | + Namespaces map[string]*CacheSetting |
| 66 | +
|
| 67 | + // CacheSettings will be used if Namespaces is empty or for entries in |
| 68 | + // Namespaces that have a nil value. |
| 69 | + // |
| 70 | + // If nil, this will be defaulted to the caches DefaultLabelSelector, |
| 71 | + // DefaultFieldSelector and DefaultTransform. |
| 72 | + CacheSettings *CacheSetting |
| 73 | +} |
| 74 | +
|
| 75 | +type Options struct { |
| 76 | + // ByObject specifies per-object cache settings. If unset for a given |
| 77 | + // object, this will fall through to Default* settings. |
| 78 | + ByObject map[client.Object]*ByObject |
| 79 | +
|
| 80 | + // DefaultNamespaces maps namespace names to cache settings. If set, it |
| 81 | + // will be usd for all objects that have a nil Namespaces setting. |
| 82 | + // |
| 83 | + // It is possible to have specific CacheSettings for just some namespaces |
| 84 | + // but cache all namespaces by using the empty string as map key for |
| 85 | + // "all namespaces". This wil then include all namespaces that do not have |
| 86 | + // a more specific setting. |
| 87 | + // |
| 88 | + // If CacheSetting is nil, DefaultLabelSelector, DefaultFieldSelector |
| 89 | + // and DefaultTransform will be used if set. |
| 90 | + DefaultNamespaces map[string]*CacheSetting |
| 91 | +
|
| 92 | + // DefaultLabelSelector is the label selector that will be used as |
| 93 | + // the default field label selector for everything that doesn't |
| 94 | + // have one configured. |
| 95 | + DefaultLabelSelector labels.Selector |
| 96 | +
|
| 97 | + // DefaultFieldSelector is the field selector that will be used as |
| 98 | + // the default field selector for everything that doesn't have |
| 99 | + // one configured. |
| 100 | + DefaultFieldSelector fields.Selector |
| 101 | +
|
| 102 | + // DefaultUnsafeDisableDeepCopy is the default for UnsafeDisableDeepCopy |
| 103 | + // for everything that doesn't specify this. |
| 104 | + DefaultUnsafeDisableDeepCopy *bool |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | + |
| 109 | +## Example usages |
| 110 | + |
| 111 | +### Cache ConfigMaps in the `public` and `kube-system` namespaces and Secrets in the `operator` Namespace |
| 112 | + |
| 113 | + |
| 114 | +``` |
| 115 | +Options{ |
| 116 | + ByObject: map[client.Object]*cache.ByObject{ |
| 117 | + &corev1.ConfigMap{}: { |
| 118 | + Namespaces: map[string]*cache.CacheSetting{ |
| 119 | + "public": {}, |
| 120 | + "kube-system": {}, |
| 121 | + }, |
| 122 | + }, |
| 123 | + &corev1.Secret{}: {Namespaces: map[string]*CacheSetting: |
| 124 | + "operator": {}, |
| 125 | + }, |
| 126 | + }, |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +### Cache ConfigMaps in all namespaces without selector, but have a selector for the `operator` Namespace |
| 131 | + |
| 132 | +``` |
| 133 | +Options{ |
| 134 | + ByObject: map[client.Object]*cache.ByObject{ |
| 135 | + &corev1.ConfgMap{}: { |
| 136 | + Namespaces: map[string]*cache.CacheSetting{ |
| 137 | + "": {}, // No selector for all namespaces... |
| 138 | + "operator" {LabelSelector: labelSelector}, // except for the operator namespace |
| 139 | + }, |
| 140 | + }, |
| 141 | + }, |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | + |
| 146 | +### Only cache the `operator` namespace except for Deployments |
| 147 | + |
| 148 | +``` |
| 149 | +Options{ |
| 150 | + ByObject: map[client.Object]*cache.ByObject{ |
| 151 | + &appsv1.Deployment: {Namespaces: map[string]*cacheSetting: |
| 152 | + "": {}, |
| 153 | + }, |
| 154 | + }, |
| 155 | + DefaultNamespaces: map[string]*cache.CacheSetting{ |
| 156 | + "operator": {}, |
| 157 | + }, |
| 158 | +} |
| 159 | +``` |
| 160 | + |
| 161 | +### Use a LabelSelector for everything except Nodes |
| 162 | + |
| 163 | +``` |
| 164 | +Options{ |
| 165 | + ByObject: map[client.Object]*cache.ByObject{ |
| 166 | + &corev1.Node: {}, |
| 167 | + }, |
| 168 | + DefaultLabelSelector: myLabelSelector, |
| 169 | +} |
| 170 | +``` |
0 commit comments