diff --git a/internal/config/release/release.go b/internal/config/release/release.go index 83f406b..32f100e 100644 --- a/internal/config/release/release.go +++ b/internal/config/release/release.go @@ -105,19 +105,21 @@ func FindReleaseByNames(releases []string, releasesObj Releases) Releases { func ReleasesFromLockfile(lockfile lockfile.LockFile, repos repository.Repositories) (Releases, error) { releases := Releases{} for _, releaseLocked := range lockfile { - // repoName, err := repos.NameByUrl(releaseLocked.RepoUrl) - repoName := releaseLocked.RepoName - // if err != nil { - // return releases, err - // } release := &Release{ - Repository: repoName, + Repository: releaseLocked.RepoName, Release: releaseLocked.Release, Chart: releaseLocked.Chart, Version: releaseLocked.Version, Namespace: releaseLocked.Namespace, + RepositoryObj: &repository.Repository{ + Name: releaseLocked.RepoName, + URL: releaseLocked.RepoUrl, + }, } - if err := release.RepositoryObjFromName(repos); err != nil { + if err := release.RepositoryObj.ValidateURL(); err != nil { + return nil, err + } + if err := release.RepositoryObj.KindFromUrl(); err != nil { return nil, err } releases = append(releases, release) diff --git a/internal/providers/flux.go b/internal/providers/flux.go index 3cfed37..0c893fc 100644 --- a/internal/providers/flux.go +++ b/internal/providers/flux.go @@ -38,6 +38,14 @@ func (f *Flux) SyncState(diff diff.Diff) error { srcPath := fmt.Sprintf("%s/src", f.path) filePath := fmt.Sprintf("%s/%s-", srcPath, entity) + if err := os.RemoveAll(srcPath); err != nil { + return err + } + + if err := os.Mkdir(srcPath, os.ModePerm); err != nil { + return err + } + for _, repo := range diff.DeletedRepositories { if err := os.Remove(filePath + repo.Name + ".yaml"); err != nil { return err @@ -259,12 +267,7 @@ func SyncValues(release *release.Release, path string) error { for _, valueFile := range release.Values { // Prepare a dir for values valuesPath := fmt.Sprintf("%s/%s", path, "values") - if _, err := os.Stat(valuesPath); errors.Is(err, os.ErrNotExist) { - err := os.Mkdir(valuesPath, os.ModePerm) - if err != nil { - return err - } - } else if err != nil { + if err := os.Mkdir(valuesPath, os.ModePerm); err != nil { return err } @@ -308,12 +311,10 @@ func SyncValues(release *release.Release, path string) error { func SyncSecrets(release *release.Release, destPath, path, sopsBin string) error { secretsPath := fmt.Sprintf("%s/%s", destPath, "secrets") // Prepare a dir for secrets - if _, err := os.Stat(secretsPath); errors.Is(err, os.ErrNotExist) { - err := os.Mkdir(secretsPath, os.ModePerm) - if err != nil { - return err - } - } else if err != nil { + if err := os.RemoveAll(secretsPath); err != nil { + return err + } + if err := os.Mkdir(secretsPath, os.ModePerm); err != nil { return err } diff --git a/internal/utils/diff/diff.go b/internal/utils/diff/diff.go index 255c69f..b381f56 100644 --- a/internal/utils/diff/diff.go +++ b/internal/utils/diff/diff.go @@ -121,13 +121,11 @@ func (diff *Diff) Resolve(repositories repository.Repositories, path string) (lo // Delete the } else { reposWished[i] = repoWished - logrus.Infof("%v -- %v", repoExisting, repoWished) i++ } } reposWished = reposWished[:i] if !found { - logrus.Infof("HERE I AM: %s", repoExisting) diff.DeletedRepositories = append(diff.DeletedRepositories, repoExisting) } } diff --git a/internal/utils/kustomize/kustomize.go b/internal/utils/kustomize/kustomize.go index 3db7bac..d175d0a 100644 --- a/internal/utils/kustomize/kustomize.go +++ b/internal/utils/kustomize/kustomize.go @@ -134,23 +134,42 @@ func Generate(path string, gh githelper.Githelper) error { }, ConfigMapGenerator: kustomize.CmGeneratorFromFiles(), } + if len(kustomize.Secrets) > 0 { kustomization.Generators = []string{"sec-generator.yaml"} if err := kustomize.SecGeneratorCreate(path); err != nil { return err } - + } else { + if err := os.RemoveAll(fmt.Sprintf("%s/sec-generator.yaml", path)); err != nil { + return err + } } + manifest, err := yaml.Marshal(kustomization) if err != nil { return err } - file, err := os.Create(path + "/kustomization.yaml") - if err != nil { + dstFilePath := path + "/kustomization.yaml" + var dstFile *os.File + if _, err = os.Stat(dstFilePath); err == nil { + dstFile, err = os.Open(dstFilePath) + if err != nil { + return err + } + defer dstFile.Close() + } else if errors.Is(err, os.ErrNotExist) { + dstFile, err = os.Create(dstFilePath) + if err != nil { + return nil + } + defer dstFile.Close() + } else { return err } - if _, err := file.Write(manifest); err != nil { - return err + + if err := os.WriteFile(dstFilePath, manifest, os.ModeExclusive); err != nil { + return nil } if err := gh.AddAllAndCommit(path, "Update the root kustomization"); err != nil { diff --git a/shoebill.yaml b/shoebill.yaml index e73888d..9cd02c7 100644 --- a/shoebill.yaml +++ b/shoebill.yaml @@ -42,8 +42,6 @@ releases: repository: metrics-server chart: metrics-server version: 3.11.0 - values: - - common/values.metrics-server.yaml installed: true namespace: kube-system createNamespace: false