Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory usage for tiller-proxy #1058

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chart/kubeapps/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ tillerProxy:
resources:
limits:
cpu: 250m
memory: 128Mi
memory: 256Mi
requests:
cpu: 25m
memory: 32Mi
Expand Down
40 changes: 32 additions & 8 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package chart

import (
"bytes"
"crypto/sha1"
"crypto/tls"
"crypto/x509"
"encoding/json"
Expand Down Expand Up @@ -45,6 +46,17 @@ const (
defaultTimeoutSeconds = 180
)

type repoIndex struct {
checksum string
index *repo.IndexFile
}

var repoIndexes map[string]*repoIndex

func init() {
repoIndexes = map[string]*repoIndex{}
}

// Details contains the information to retrieve a Chart
type Details struct {
// RepoURL is the URL of the repository. Defaults to stable repo.
Expand Down Expand Up @@ -145,14 +157,26 @@ func readResponseBody(res *http.Response) ([]byte, error) {
return body, nil
}

func parseIndex(data []byte) (*repo.IndexFile, error) {
index := &repo.IndexFile{}
err := yaml.Unmarshal(data, index)
if err != nil {
return index, err
func checksum(data []byte) string {
hasher := sha1.New()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason we want to use sha1 and not sha256?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed it was faster but I guess it's not really needed

hasher.Write(data)
return string(hasher.Sum(nil))
}

func parseIndex(repoURL string, data []byte) (*repo.IndexFile, error) {
sha := checksum(data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the cache check should be part of parseIndex, it would make more sense if we checked the cache in a separate function before parseIndex.

// Cache the result of parsing the repo index since parsing this YAML
// is an expensive operation. See https://github.com/kubeapps/kubeapps/issues/1052
if repoIndexes[repoURL] == nil || repoIndexes[repoURL].checksum != sha {
index := &repo.IndexFile{}
err := yaml.Unmarshal(data, index)
if err != nil {
return index, err
}
index.SortEntries()
repoIndexes[repoURL] = &repoIndex{sha, index}
}
index.SortEntries()
return index, nil
return repoIndexes[repoURL].index, nil
}

// fetchRepoIndex returns a Helm repository
Expand All @@ -171,7 +195,7 @@ func fetchRepoIndex(netClient *HTTPClient, repoURL string, authHeader string) (*
return nil, err
}

return parseIndex(data)
return parseIndex(repoURL, data)
}

func resolveChartURL(index, chart string) (string, error) {
Expand Down