mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Rename Add/Delete to *Reference
This commit is contained in:
parent
8e55220523
commit
52713cd837
@ -83,10 +83,10 @@ func isSecretOlder(newSecret, oldSecret *v1.Secret) bool {
|
|||||||
return newVersion < oldVersion
|
return newVersion < oldVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *secretStore) Add(namespace, name string) {
|
func (s *secretStore) AddReference(namespace, name string) {
|
||||||
key := objectKey{namespace: namespace, name: name}
|
key := objectKey{namespace: namespace, name: name}
|
||||||
|
|
||||||
// Add is called from RegisterPod, thus it needs to be efficient.
|
// AddReference is called from RegisterPod, thus it needs to be efficient.
|
||||||
// Thus Add() is only increasing refCount and generation of a given secret.
|
// Thus Add() is only increasing refCount and generation of a given secret.
|
||||||
// Then Get() is responsible for fetching if needed.
|
// Then Get() is responsible for fetching if needed.
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
@ -105,7 +105,7 @@ func (s *secretStore) Add(namespace, name string) {
|
|||||||
item.secret = nil
|
item.secret = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *secretStore) Delete(namespace, name string) {
|
func (s *secretStore) DeleteReference(namespace, name string) {
|
||||||
key := objectKey{namespace: namespace, name: name}
|
key := objectKey{namespace: namespace, name: name}
|
||||||
|
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
|
@ -53,13 +53,13 @@ func noObjectTTL() (time.Duration, bool) {
|
|||||||
func TestSecretStore(t *testing.T) {
|
func TestSecretStore(t *testing.T) {
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
store := newSecretStore(fakeClient, clock.RealClock{}, noObjectTTL, 0)
|
store := newSecretStore(fakeClient, clock.RealClock{}, noObjectTTL, 0)
|
||||||
store.Add("ns1", "name1")
|
store.AddReference("ns1", "name1")
|
||||||
store.Add("ns2", "name2")
|
store.AddReference("ns2", "name2")
|
||||||
store.Add("ns1", "name1")
|
store.AddReference("ns1", "name1")
|
||||||
store.Add("ns1", "name1")
|
store.AddReference("ns1", "name1")
|
||||||
store.Delete("ns1", "name1")
|
store.DeleteReference("ns1", "name1")
|
||||||
store.Delete("ns2", "name2")
|
store.DeleteReference("ns2", "name2")
|
||||||
store.Add("ns3", "name3")
|
store.AddReference("ns3", "name3")
|
||||||
|
|
||||||
// Adds don't issue Get requests.
|
// Adds don't issue Get requests.
|
||||||
actions := fakeClient.Actions()
|
actions := fakeClient.Actions()
|
||||||
@ -87,7 +87,7 @@ func TestSecretStore(t *testing.T) {
|
|||||||
func TestSecretStoreDeletingSecret(t *testing.T) {
|
func TestSecretStoreDeletingSecret(t *testing.T) {
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
store := newSecretStore(fakeClient, clock.RealClock{}, noObjectTTL, 0)
|
store := newSecretStore(fakeClient, clock.RealClock{}, noObjectTTL, 0)
|
||||||
store.Add("ns", "name")
|
store.AddReference("ns", "name")
|
||||||
|
|
||||||
result := &v1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "name", ResourceVersion: "10"}}
|
result := &v1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "name", ResourceVersion: "10"}}
|
||||||
fakeClient.AddReactor("get", "secrets", func(action core.Action) (bool, runtime.Object, error) {
|
fakeClient.AddReactor("get", "secrets", func(action core.Action) (bool, runtime.Object, error) {
|
||||||
@ -119,7 +119,7 @@ func TestSecretStoreGetAlwaysRefresh(t *testing.T) {
|
|||||||
store := newSecretStore(fakeClient, fakeClock, noObjectTTL, 0)
|
store := newSecretStore(fakeClient, fakeClock, noObjectTTL, 0)
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
store.Add(fmt.Sprintf("ns-%d", i), fmt.Sprintf("name-%d", i))
|
store.AddReference(fmt.Sprintf("ns-%d", i), fmt.Sprintf("name-%d", i))
|
||||||
}
|
}
|
||||||
fakeClient.ClearActions()
|
fakeClient.ClearActions()
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ func TestSecretStoreGetNeverRefresh(t *testing.T) {
|
|||||||
store := newSecretStore(fakeClient, fakeClock, noObjectTTL, time.Minute)
|
store := newSecretStore(fakeClient, fakeClock, noObjectTTL, time.Minute)
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
store.Add(fmt.Sprintf("ns-%d", i), fmt.Sprintf("name-%d", i))
|
store.AddReference(fmt.Sprintf("ns-%d", i), fmt.Sprintf("name-%d", i))
|
||||||
}
|
}
|
||||||
fakeClient.ClearActions()
|
fakeClient.ClearActions()
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ func TestCustomTTL(t *testing.T) {
|
|||||||
fakeClock := clock.NewFakeClock(time.Time{})
|
fakeClock := clock.NewFakeClock(time.Time{})
|
||||||
store := newSecretStore(fakeClient, fakeClock, customTTL, time.Minute)
|
store := newSecretStore(fakeClient, fakeClock, customTTL, time.Minute)
|
||||||
|
|
||||||
store.Add("ns", "name")
|
store.AddReference("ns", "name")
|
||||||
store.Get("ns", "name")
|
store.Get("ns", "name")
|
||||||
fakeClient.ClearActions()
|
fakeClient.ClearActions()
|
||||||
|
|
||||||
|
@ -70,15 +70,15 @@ func (s *simpleSecretManager) UnregisterPod(pod *v1.Pod) {
|
|||||||
// store is the interface for a secrets cache that
|
// store is the interface for a secrets cache that
|
||||||
// can be used by cacheBasedSecretManager.
|
// can be used by cacheBasedSecretManager.
|
||||||
type store interface {
|
type store interface {
|
||||||
// Add a secret to the store.
|
// AddReference adds a reference to the secret to the store.
|
||||||
// Note that multiple additions to the store has to be allowed
|
// Note that multiple additions to the store has to be allowed
|
||||||
// in the implementations and effectively treated as refcounted.
|
// in the implementations and effectively treated as refcounted.
|
||||||
Add(namespace, name string)
|
AddReference(namespace, name string)
|
||||||
// Delete a secret from the store.
|
// DeleteReference deletes reference to the secret from the store.
|
||||||
// Note that secret should be deleted only when there was a
|
// Note that secret should be deleted only when there was a
|
||||||
// corresponding Delete call for each of Add calls (effectively
|
// corresponding Delete call for each of Add calls (effectively
|
||||||
// when refcount was reduced to zero).
|
// when refcount was reduced to zero).
|
||||||
Delete(namespace, name string)
|
DeleteReference(namespace, name string)
|
||||||
// Get a secret from a store.
|
// Get a secret from a store.
|
||||||
Get(namespace, name string) (*v1.Secret, error)
|
Get(namespace, name string) (*v1.Secret, error)
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func (c *cacheBasedSecretManager) RegisterPod(pod *v1.Pod) {
|
|||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
for name := range names {
|
for name := range names {
|
||||||
c.secretStore.Add(pod.Namespace, name)
|
c.secretStore.AddReference(pod.Namespace, name)
|
||||||
}
|
}
|
||||||
var prev *v1.Pod
|
var prev *v1.Pod
|
||||||
key := objectKey{namespace: pod.Namespace, name: pod.Name}
|
key := objectKey{namespace: pod.Namespace, name: pod.Name}
|
||||||
@ -132,7 +132,7 @@ func (c *cacheBasedSecretManager) RegisterPod(pod *v1.Pod) {
|
|||||||
// names and prev need to have their ref counts decremented. Any that
|
// names and prev need to have their ref counts decremented. Any that
|
||||||
// are only in prev need to be completely removed. This unconditional
|
// are only in prev need to be completely removed. This unconditional
|
||||||
// call takes care of both cases.
|
// call takes care of both cases.
|
||||||
c.secretStore.Delete(prev.Namespace, name)
|
c.secretStore.DeleteReference(prev.Namespace, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ func (c *cacheBasedSecretManager) UnregisterPod(pod *v1.Pod) {
|
|||||||
delete(c.registeredPods, key)
|
delete(c.registeredPods, key)
|
||||||
if prev != nil {
|
if prev != nil {
|
||||||
for name := range getSecretNames(prev) {
|
for name := range getSecretNames(prev) {
|
||||||
c.secretStore.Delete(prev.Namespace, name)
|
c.secretStore.DeleteReference(prev.Namespace, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user