A bunch of broken stuff

This commit is contained in:
2024-07-25 15:23:28 +02:00
parent 64decebb87
commit c9c50df9aa
11 changed files with 169 additions and 181 deletions

View File

@ -7,13 +7,12 @@ import (
"git.badhouseplants.net/allanger/shoebill/pkg/cluster"
"git.badhouseplants.net/allanger/shoebill/pkg/mirror"
"git.badhouseplants.net/allanger/shoebill/pkg/release"
"git.badhouseplants.net/allanger/shoebill/pkg/repository"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
type Config struct {
Repositories repository.Repositories
Repositories Repositories
Releases release.Releases
Clusters cluster.Clusters
Charts chart.Charts

40
pkg/config/repository.go Normal file
View File

@ -0,0 +1,40 @@
package config
import (
"fmt"
)
/*
* Helm repo kinds: default/oci
*/
const (
HELM_REPO_OCI = "oci"
HELM_REPO_DEFAULT = "default"
)
type Repository struct {
Name string
Helm *RepositoryHelm
Git *RepositoryGit
}
type RepositoryHelm struct {
URL string
}
type RepositoryGit struct {
URL string
// Git ref
Ref string
// Path inside a git repo
Path string
}
type Repositories []*Repository
func (r *Repository) ValidateConfig() error {
if r.Helm != nil && r.Git != nil {
return fmt.Errorf("repo %s is invalid, only one repo kind can be specified", r.Name)
}
return nil
}

View File

@ -0,0 +1,56 @@
package config_test
import (
"fmt"
"testing"
"git.badhouseplants.net/allanger/shoebill/pkg/config"
"github.com/stretchr/testify/assert"
)
func TestBothRepoKindsError(t *testing.T) {
repo := &config.Repository{
Name: "test",
Helm: &config.RepositoryHelm{
URL: "test",
},
Git: &config.RepositoryGit{
URL: "test",
Ref: "test",
Path: "test",
},
}
err := repo.ValidateConfig()
assert.ErrorContains(t, err,
"repo test is invalid, only one repo kind can be specified",
fmt.Sprintf("haven't got an unexpected err: %s", err))
}
func TestHelmRepoNoError(t *testing.T) {
repo := &config.Repository{
Name: "test",
Helm: &config.RepositoryHelm{
URL: "test",
},
}
err := repo.ValidateConfig()
assert.NoError(t, err,
fmt.Sprintf("got an unexpected err: %s", err))
}
func TestGitRepoNoError(t *testing.T) {
repo := &config.Repository{
Name: "test",
Git: &config.RepositoryGit{
URL: "test",
Ref: "test",
Path: "test",
},
}
err := repo.ValidateConfig()
assert.NoError(t, err,
fmt.Sprintf("got an unexpected err: %s", err))
}

View File

@ -10,6 +10,7 @@ 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/config"
"git.badhouseplants.net/allanger/shoebill/pkg/lockfile"
"git.badhouseplants.net/allanger/shoebill/pkg/mirror"
"git.badhouseplants.net/allanger/shoebill/pkg/repository"
@ -31,18 +32,18 @@ type Release struct {
Values []string
// Secrets SOPS encrypted
Secrets []string
Mirror string
Mirror string
// Private fields that should be pupulated during the run-time
RepositoryObj *repository.Repository `yaml:"-"`
ChartObj *chart.Chart `yaml:"-"`
ChartObj *chart.Chart `yaml:"-"`
DestValues ValuesHolders `yaml:"-"`
DestSecrets ValuesHolders `yaml:"-"`
}
func (r *Release) ToHelmReleaseData() *helmhelper.ReleaseData {
// valuesData =
// valuesData =
// for _, data := range r.DestValues {
// }
return &helmhelper.ReleaseData{
Name: r.Release,
@ -92,7 +93,7 @@ func (r *Release) MirrorObjFromName(mirrors mirror.Mirrors) error {
if mir.Name == r.Mirror {
r.RepositoryObj = &repository.Repository{
Name: mir.Name,
URL: fmt.Sprintf("%s/%s", mir.OCI.URL, mir.OCI.Prefix),
URL: fmt.Sprintf("%s/%s", mir.OCI.URL, mir.OCI.Prefix),
}
}
}
@ -248,16 +249,16 @@ func (src Releases) Diff(dest Releases) Diff {
return diff
}
func (rs *Releases) PopulateRepositories(repos repository.Repositories, mirrors mirror.Mirrors) error {
func (rs *Releases) PopulateRepositories(repos config.Repositories, mirrors mirror.Mirrors) error {
for _, r := range *rs {
if len(r.Mirror) > 0 {
if err := r.MirrorObjFromName(mirrors); err != nil {
return err
}
} else {
if err := r.RepositoryObjFromName(repos); err != nil {
return err
}
if err := r.RepositoryObjFromName(repos); err != nil {
return err
}
}
}
return nil