Fix: nil s3Client of attachment api

Signed-off-by: LiHui <andrewli@yunify.com>

format code

Signed-off-by: LiHui <andrewli@yunify.com>

Fix: delete helmRelease on host when delete member cluster

Signed-off-by: LiHui <andrewli@yunify.com>

Fix: modify repo credential

Signed-off-by: LiHui <andrewli@yunify.com>

remove not exitsts charts from helm repo

Signed-off-by: LiHui <andrewli@yunify.com>
This commit is contained in:
LiHui
2021-03-14 15:31:31 +08:00
parent 686b180f3f
commit dd8429c542
17 changed files with 406 additions and 319 deletions

View File

@@ -63,7 +63,7 @@ func LoadRepoIndex(ctx context.Context, u string, cred *v1alpha1.HelmRepoCredent
// This will fail if API Version is not set (ErrNoAPIVersion) or if the unmarshal fails.
func loadIndex(data []byte) (*helmrepo.IndexFile, error) {
i := &helmrepo.IndexFile{}
if err := yaml.UnmarshalStrict(data, i); err != nil {
if err := yaml.Unmarshal(data, i); err != nil {
return i, err
}
i.SortEntries()
@@ -73,6 +73,8 @@ func loadIndex(data []byte) (*helmrepo.IndexFile, error) {
return i, nil
}
var empty = struct{}{}
// merge new index with index from crd
func MergeRepoIndex(index *helmrepo.IndexFile, existsSavedIndex *SavedIndex) *SavedIndex {
saved := &SavedIndex{}
@@ -92,7 +94,7 @@ func MergeRepoIndex(index *helmrepo.IndexFile, existsSavedIndex *SavedIndex) *Sa
saved.Generated = index.Generated
saved.PublicKeys = index.PublicKeys
allNames := make(map[string]bool, len(index.Entries))
allAppNames := make(map[string]struct{}, len(index.Entries))
for name, versions := range index.Entries {
// add new applications
if application, exists := saved.Applications[name]; !exists {
@@ -112,6 +114,7 @@ func MergeRepoIndex(index *helmrepo.IndexFile, existsSavedIndex *SavedIndex) *Sa
}
charts = append(charts, chart)
}
application.Charts = charts
saved.Applications[name] = application
} else {
@@ -121,6 +124,7 @@ func MergeRepoIndex(index *helmrepo.IndexFile, existsSavedIndex *SavedIndex) *Sa
savedChartVersion[ver.Version] = struct{}{}
}
charts := application.Charts
var newVersion = make(map[string]struct{}, len(versions))
for _, ver := range versions {
// add new chart version
if _, exists := savedChartVersion[ver.Version]; !exists {
@@ -131,15 +135,34 @@ func MergeRepoIndex(index *helmrepo.IndexFile, existsSavedIndex *SavedIndex) *Sa
}
charts = append(charts, chart)
}
application.Charts = charts
saved.Applications[name] = application
newVersion[ver.Version] = empty
}
// delete not exists chart version
for last, curr := 0, 0; curr < len(charts); {
chart := charts[curr]
version := chart.Version
if _, exists := newVersion[version]; !exists {
// version not exists, check next one
curr++
} else {
// If last and curr point to the same place, there is nothing to do, just move to next.
if last != curr {
charts[last] = charts[curr]
}
last++
curr++
}
}
application.Charts = charts[:len(newVersion)]
saved.Applications[name] = application
}
allNames[name] = true
allAppNames[name] = empty
}
for name := range saved.Applications {
if _, exists := allNames[name]; !exists {
if _, exists := allAppNames[name]; !exists {
delete(saved.Applications, name)
}
}