Skip to content

Commit

Permalink
Use cache.SetDefault instead of Set since we're always using default
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob committed Nov 16, 2021
1 parent 287aa20 commit 1193302
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/cloudprovider/aws/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (p *AMIProvider) getAMIID(ctx context.Context, query string) (string, error
return "", fmt.Errorf("getting ssm parameter, %w", err)
}
ami := aws.StringValue(output.Parameter.Value)
p.cache.Set(query, ami, CacheTTL)
p.cache.SetDefault(query, ami)
logging.FromContext(ctx).Debugf("Discovered ami %s for query %s", ami, query)
return ami, nil
}
Expand All @@ -102,7 +102,7 @@ func (p *AMIProvider) kubeServerVersion(ctx context.Context) (string, error) {
return "", err
}
version := fmt.Sprintf("%s.%s", serverVersion.Major, strings.TrimSuffix(serverVersion.Minor, "+"))
p.cache.Set(kubernetesVersionCacheKey, version, CacheTTL)
p.cache.SetDefault(kubernetesVersionCacheKey, version)
logging.FromContext(ctx).Debugf("Discovered kubernetes version %s", version)
return version, nil
}
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (p *LaunchTemplateProvider) ensureLaunchTemplate(ctx context.Context, optio
launchTemplate = output.LaunchTemplates[0]
}
// 4. Save in cache to reduce API calls
p.cache.Set(name, launchTemplate, CacheTTL)
p.cache.SetDefault(name, launchTemplate)
return launchTemplate, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/securitygroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *SecurityGroupProvider) getSecurityGroups(ctx context.Context, filters [
if err != nil {
return nil, fmt.Errorf("describing security groups %+v, %w", filters, err)
}
s.cache.Set(fmt.Sprint(hash), output.SecurityGroups, CacheTTL)
s.cache.SetDefault(fmt.Sprint(hash), output.SecurityGroups)
logging.FromContext(ctx).Debugf("Discovered security groups: %s", s.securityGroupIds(output.SecurityGroups))
return output.SecurityGroups, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *SubnetProvider) Get(ctx context.Context, constraints *v1alpha1.Constrai
if len(output.Subnets) == 0 {
return nil, fmt.Errorf("no subnets matched selector %v", constraints.SubnetSelector)
}
s.cache.Set(fmt.Sprint(hash), output.Subnets, CacheTTL)
s.cache.SetDefault(fmt.Sprint(hash), output.Subnets)
logging.FromContext(ctx).Debugf("Discovered subnets: %s", prettySubnets(output.Subnets))
return output.Subnets, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/allocation/scheduling/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func (p *Preferences) Relax(ctx context.Context, pods []*v1.Pod) {
affinity, ok := p.cache.Get(string(pod.UID))
// Add to cache if we've never seen it before
if !ok {
p.cache.Set(string(pod.UID), pod.Spec.Affinity, ExpirationTTL)
p.cache.SetDefault(string(pod.UID), pod.Spec.Affinity)
continue
}
// Attempt to relax the pod and update the cache
pod.Spec.Affinity = affinity.(*v1.Affinity)
if relaxed := p.relax(ctx, pod); relaxed {
p.cache.Set(string(pod.UID), pod.Spec.Affinity, ExpirationTTL)
p.cache.SetDefault(string(pod.UID), pod.Spec.Affinity)
}
}
}
Expand Down

0 comments on commit 1193302

Please sign in to comment.