wip: Some changes
This commit is contained in:
parent
6b9a401c97
commit
e04443922b
@ -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)
|
||||
|
@ -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 {
|
||||
if err := os.RemoveAll(secretsPath); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
if err := os.Mkdir(secretsPath, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -134,25 +134,44 @@ 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")
|
||||
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
|
||||
}
|
||||
if _, err := file.Write(manifest); err != nil {
|
||||
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 := os.WriteFile(dstFilePath, manifest, os.ModeExclusive); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := gh.AddAllAndCommit(path, "Update the root kustomization"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user