Add mirrors
This commit is contained in:
@ -9,7 +9,9 @@ import (
|
||||
|
||||
"git.badhouseplants.net/allanger/shoebill/internal/utils/helmhelper"
|
||||
"git.badhouseplants.net/allanger/shoebill/internal/utils/sopshelper"
|
||||
"git.badhouseplants.net/allanger/shoebill/pkg/chart"
|
||||
"git.badhouseplants.net/allanger/shoebill/pkg/lockfile"
|
||||
"git.badhouseplants.net/allanger/shoebill/pkg/mirror"
|
||||
"git.badhouseplants.net/allanger/shoebill/pkg/repository"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -29,8 +31,11 @@ type Release struct {
|
||||
Values []string
|
||||
// Secrets SOPS encrypted
|
||||
Secrets []string
|
||||
Mirror string
|
||||
// Private fields that should be pupulated during the run-time
|
||||
RepositoryObj *repository.Repository `yaml:"-"`
|
||||
ChartObj *chart.Chart `yaml:"-"`
|
||||
MirrorObj *mirror.Mirror `yaml:"-"`
|
||||
DestValues ValuesHolders `yaml:"-"`
|
||||
DestSecrets ValuesHolders `yaml:"-"`
|
||||
}
|
||||
@ -82,28 +87,39 @@ func (r *Release) RepositoryObjFromName(repos repository.Repositories) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RepositoryObjFromName gather the whole repository object by its name
|
||||
func (r *Release) MirrorObjFromName(mirrors mirror.Mirrors) error {
|
||||
for _, mir := range mirrors {
|
||||
if mir.Name == r.Mirror {
|
||||
r.RepositoryObj = &repository.Repository{
|
||||
Name: mir.Name,
|
||||
URL: fmt.Sprintf("%s/%s", mir.OCI.URL, mir.OCI.Prefix),
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.RepositoryObj == nil {
|
||||
return fmt.Errorf("couldn't gather the RepositoryObj for %s", r.Repository)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Release) ChartObjFromName(chs chart.Charts) error {
|
||||
for _, ch := range chs {
|
||||
if ch.Name == r.Chart {
|
||||
r.ChartObj = ch
|
||||
}
|
||||
}
|
||||
if r.ChartObj == nil {
|
||||
return fmt.Errorf("couldn't gather the ChartObj for %s", r.Chart)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Possible version placeholders
|
||||
const (
|
||||
VERSION_LATEST = "latest"
|
||||
)
|
||||
|
||||
// Replace the version placeholder with the fixed version
|
||||
func (r *Release) VersionHandler(dir string, hh helmhelper.Helmhelper) error {
|
||||
if len(r.Version) == 0 {
|
||||
r.Version = VERSION_LATEST
|
||||
}
|
||||
switch r.Version {
|
||||
case VERSION_LATEST:
|
||||
version, err := hh.FindLatestVersion(dir, r.ToHelmReleaseData())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.Version = version
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Release) ValuesHandler(dir string) error {
|
||||
for i := range r.Values {
|
||||
r.Values[i] = fmt.Sprintf("%s/%s", dir, strings.ReplaceAll(r.Values[i], "./", ""))
|
||||
@ -241,3 +257,12 @@ func (rs *Releases) PopulateRepositories(repos repository.Repositories) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rs *Releases) PopulateCharts(chs chart.Charts) error {
|
||||
for _, r := range *rs {
|
||||
if err := r.ChartObjFromName(chs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user