Skip to content

Commit

Permalink
assets/manifests: sort files list in manifests assets
Browse files Browse the repository at this point in the history
The files lists in the manifests assets need to be sorted to ensure that
the assets are equivalent when read from the state file and from on disk.

Changes for https://jira.coreos.com/browse/CORS-940
  • Loading branch information
staebler committed Feb 1, 2019
1 parent 75ab106 commit ef1bae2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -95,3 +96,8 @@ func isDirEmpty(name string) (bool, error) {
}
return false, err // Either not empty or error, suits both cases
}

// SortFiles sorts the specified files by file name.
func SortFiles(files []*File) {
sort.Slice(files, func(i, j int) bool { return files[i].Filename < files[j].Filename })
}
3 changes: 3 additions & 0 deletions pkg/asset/manifests/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func (o *Openshift) Generate(dependencies asset.Parents) error {
})
}

asset.SortFiles(o.FileList)

return nil
}

Expand All @@ -161,5 +163,6 @@ func (o *Openshift) Load(f asset.FileFetcher) (bool, error) {
return false, err
}
o.FileList = fileList
asset.SortFiles(o.FileList)
return len(fileList) > 0, nil
}
4 changes: 4 additions & 0 deletions pkg/asset/manifests/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (m *Manifests) Generate(dependencies asset.Parents) error {
m.FileList = append(m.FileList, network.Files()...)
m.FileList = append(m.FileList, infra.Files()...)

asset.SortFiles(m.FileList)

return nil
}

Expand Down Expand Up @@ -264,6 +266,8 @@ func (m *Manifests) Load(f asset.FileFetcher) (bool, error) {

m.FileList, m.KubeSysConfig = fileList, kubeSysConfig

asset.SortFiles(m.FileList)

return true, nil
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/asset/store/filefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package store
import (
"io/ioutil"
"path/filepath"
"sort"

"github.com/openshift/installer/pkg/asset"
)
Expand Down Expand Up @@ -46,6 +45,5 @@ func (f *fileFetcher) FetchByPattern(pattern string) (files []*asset.File, err e
})
}

sort.Slice(files, func(i, j int) bool { return files[i].Filename < files[j].Filename })
return files, nil
}

0 comments on commit ef1bae2

Please sign in to comment.