Skip to content

Commit

Permalink
Estimating the size of list when its possible to reduce memory usage …
Browse files Browse the repository at this point in the history
…and improve performance
  • Loading branch information
SoulKyu committed May 24, 2024
1 parent cfe7579 commit 8ff7628
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/k8s/parse_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func NewService(cfg config.Config, pod *corev1.Pod) *ParserService {
}

func (s *ParserService) GetPodDbConfig() (*podDbConfig, error) {
var dbConfigurations []DbConfiguration
estimatedSize := len(s.pod.Annotations)
dbConfigurations := make([]DbConfiguration, 0, estimatedSize)
vaultDbPath, ok := s.pod.Annotations[ANNOTATION_VAULT_DB_PATH]
if !ok || vaultDbPath == "" {
vaultDbPath = s.cfg.DefaultEngine
Expand Down
4 changes: 3 additions & 1 deletion pkg/k8s/pod_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func (p *podServiceImpl) GetAllPodAndNamespace(ctx context.Context) ([]PodInform
return nil, errors.Newf("no pods found in the cluster")
}

var podInfos []PodInformations
estimatedSize := len(pods.Items)
podInfos := make([]PodInformations, 0, estimatedSize)

for _, pod := range pods.Items {
if uuid, exists := pod.GetAnnotations()[ANNOTATION_VAULT_POD_UUID]; exists {
podInfos = append(podInfos, PodInformations{
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8smutator/k8smutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func generateUUID(logger log.Logger) string {

func handlePodConfiguration(ctx context.Context, cfg *config.Config, dbConfs *[]k8s.DbConfiguration, logger log.Logger, vaultDbPath, tok string, pod *corev1.Pod) (*corev1.Pod, string, []string, error) {
if len(*dbConfs) > 0 {
var podUuids []string
podUuids := make([]string, 0, len(*dbConfs))
for _, dbConf := range *dbConfs {
// Configure vault connection using serviceAccount token
err := checkConfiguration(dbConf)
Expand Down

0 comments on commit 8ff7628

Please sign in to comment.