Skip to content

Commit

Permalink
Merge pull request #30 from martin-helmich/bugfix/increasing-dependen…
Browse files Browse the repository at this point in the history
…cy-list

Fix dependencyMap growing indefinitely with time
  • Loading branch information
Hermsi1337 authored Jan 10, 2020
2 parents 356ded2 + d19ad08 commit 75068fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions replicate/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type replicatorProps struct {
controller cache.Controller
allowAll bool

dependencyMap map[string][]string
dependencyMap map[string]map[string]interface{}
}

// Replicator describes the common interface that the secret and configmap
Expand Down Expand Up @@ -52,8 +52,8 @@ func (r *replicatorProps) isReplicationPermitted(object *metav1.ObjectMeta, sour
annotationAllowedNamespaces, ok := sourceObject.Annotations[ReplicationAllowedNamespaces]
if !ok {
return false, fmt.Errorf(
"source %s/%s does not allow replication in namespace %s. %s will not be replicated",
sourceObject.Namespace, sourceObject.Name, object.Namespace, object.Name)
"source %s/%s does not allow replication (%s annotation missing). %s will not be replicated",
sourceObject.Namespace, sourceObject.Name, ReplicationAllowedNamespaces, object.Name)
}
allowedNamespaces := strings.Split(annotationAllowedNamespaces, ",")
allowed := false
Expand Down
12 changes: 6 additions & 6 deletions replicate/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewConfigMapReplicator(client kubernetes.Interface, resyncPeriod time.Durat
replicatorProps: replicatorProps{
allowAll: allowAll,
client: client,
dependencyMap: make(map[string][]string),
dependencyMap: make(map[string]map[string]interface{}),
},
}

Expand Down Expand Up @@ -96,10 +96,10 @@ func (r *configMapReplicator) ConfigMapAdded(obj interface{}) {
}

if _, ok := r.dependencyMap[val]; !ok {
r.dependencyMap[val] = make([]string, 0, 1)
r.dependencyMap[val] = make(map[string]interface{})
}

r.dependencyMap[val] = append(r.dependencyMap[val], configMapKey)
r.dependencyMap[val][configMapKey] = nil

sourceConfigMap := sourceObject.(*v1.ConfigMap)

Expand Down Expand Up @@ -170,8 +170,8 @@ func (r *configMapReplicator) configMapFromStore(key string) (*v1.ConfigMap, err
return configMap, nil
}

func (r *configMapReplicator) updateDependents(configMap *v1.ConfigMap, dependents []string) error {
for _, dependentKey := range dependents {
func (r *configMapReplicator) updateDependents(configMap *v1.ConfigMap, dependents map[string]interface{}) error {
for dependentKey := range dependents {
log.Printf("updating dependent config map %s/%s -> %s", configMap.Namespace, configMap.Name, dependentKey)

targetObject, exists, err := r.store.GetByKey(dependentKey)
Expand Down Expand Up @@ -201,7 +201,7 @@ func (r *configMapReplicator) ConfigMapDeleted(obj interface{}) {
return
}

for _, dependentKey := range replicas {
for dependentKey := range replicas {
targetConfigMap, err := r.configMapFromStore(dependentKey)
if err != nil {
log.Printf("could not load dependent config map: %s", err)
Expand Down
12 changes: 6 additions & 6 deletions replicate/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewSecretReplicator(client kubernetes.Interface, resyncPeriod time.Duration
replicatorProps: replicatorProps{
allowAll: allowAll,
client: client,
dependencyMap: make(map[string][]string),
dependencyMap: make(map[string]map[string]interface{}),
},
}

Expand Down Expand Up @@ -96,10 +96,10 @@ func (r *secretReplicator) SecretAdded(obj interface{}) {
}

if _, ok := r.dependencyMap[val]; !ok {
r.dependencyMap[val] = make([]string, 0, 1)
r.dependencyMap[val] = make(map[string]interface{})
}

r.dependencyMap[val] = append(r.dependencyMap[val], secretKey)
r.dependencyMap[val][secretKey] = nil

sourceSecret := sourceObject.(*v1.Secret)

Expand Down Expand Up @@ -165,8 +165,8 @@ func (r *secretReplicator) secretFromStore(key string) (*v1.Secret, error) {
return secret, nil
}

func (r *secretReplicator) updateDependents(secret *v1.Secret, dependents []string) error {
for _, dependentKey := range dependents {
func (r *secretReplicator) updateDependents(secret *v1.Secret, dependents map[string]interface{}) error {
for dependentKey := range dependents {
log.Printf("updating dependent secret %s/%s -> %s", secret.Namespace, secret.Name, dependentKey)

targetObject, exists, err := r.store.GetByKey(dependentKey)
Expand Down Expand Up @@ -196,7 +196,7 @@ func (r *secretReplicator) SecretDeleted(obj interface{}) {
return
}

for _, dependentKey := range replicas {
for dependentKey := range replicas {
targetSecret, err := r.secretFromStore(dependentKey)
if err != nil {
log.Printf("could not load dependent secret: %s", err)
Expand Down

0 comments on commit 75068fb

Please sign in to comment.