Rename Add/Delete to *Reference

This commit is contained in:
wojtekt 2018-05-09 18:14:50 +02:00
parent 8e55220523
commit 52713cd837
3 changed files with 21 additions and 21 deletions

View File

@ -83,10 +83,10 @@ func isSecretOlder(newSecret, oldSecret *v1.Secret) bool {
return newVersion < oldVersion
}
func (s *secretStore) Add(namespace, name string) {
func (s *secretStore) AddReference(namespace, name string) {
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.
// Then Get() is responsible for fetching if needed.
s.lock.Lock()
@ -105,7 +105,7 @@ func (s *secretStore) Add(namespace, name string) {
item.secret = nil
}
func (s *secretStore) Delete(namespace, name string) {
func (s *secretStore) DeleteReference(namespace, name string) {
key := objectKey{namespace: namespace, name: name}
s.lock.Lock()

View File

@ -53,13 +53,13 @@ func noObjectTTL() (time.Duration, bool) {
func TestSecretStore(t *testing.T) {
fakeClient := &fake.Clientset{}
store := newSecretStore(fakeClient, clock.RealClock{}, noObjectTTL, 0)
store.Add("ns1", "name1")
store.Add("ns2", "name2")
store.Add("ns1", "name1")
store.Add("ns1", "name1")
store.Delete("ns1", "name1")
store.Delete("ns2", "name2")
store.Add("ns3", "name3")
store.AddReference("ns1", "name1")
store.AddReference("ns2", "name2")
store.AddReference("ns1", "name1")
store.AddReference("ns1", "name1")
store.DeleteReference("ns1", "name1")
store.DeleteReference("ns2", "name2")
store.AddReference("ns3", "name3")
// Adds don't issue Get requests.
actions := fakeClient.Actions()
@ -87,7 +87,7 @@ func TestSecretStore(t *testing.T) {
func TestSecretStoreDeletingSecret(t *testing.T) {
fakeClient := &fake.Clientset{}
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"}}
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)
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()
@ -146,7 +146,7 @@ func TestSecretStoreGetNeverRefresh(t *testing.T) {
store := newSecretStore(fakeClient, fakeClock, noObjectTTL, time.Minute)
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()
@ -175,7 +175,7 @@ func TestCustomTTL(t *testing.T) {
fakeClock := clock.NewFakeClock(time.Time{})
store := newSecretStore(fakeClient, fakeClock, customTTL, time.Minute)
store.Add("ns", "name")
store.AddReference("ns", "name")
store.Get("ns", "name")
fakeClient.ClearActions()

View File

@ -70,15 +70,15 @@ func (s *simpleSecretManager) UnregisterPod(pod *v1.Pod) {
// store is the interface for a secrets cache that
// can be used by cacheBasedSecretManager.
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
// in the implementations and effectively treated as refcounted.
Add(namespace, name string)
// Delete a secret from the store.
AddReference(namespace, name string)
// DeleteReference deletes reference to the secret from the store.
// Note that secret should be deleted only when there was a
// corresponding Delete call for each of Add calls (effectively
// when refcount was reduced to zero).
Delete(namespace, name string)
DeleteReference(namespace, name string)
// Get a secret from a store.
Get(namespace, name string) (*v1.Secret, error)
}
@ -119,7 +119,7 @@ func (c *cacheBasedSecretManager) RegisterPod(pod *v1.Pod) {
c.lock.Lock()
defer c.lock.Unlock()
for name := range names {
c.secretStore.Add(pod.Namespace, name)
c.secretStore.AddReference(pod.Namespace, name)
}
var prev *v1.Pod
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
// are only in prev need to be completely removed. This unconditional
// 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)
if prev != nil {
for name := range getSecretNames(prev) {
c.secretStore.Delete(prev.Namespace, name)
c.secretStore.DeleteReference(prev.Namespace, name)
}
}
}