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) {
|
func ReleasesFromLockfile(lockfile lockfile.LockFile, repos repository.Repositories) (Releases, error) {
|
||||||
releases := Releases{}
|
releases := Releases{}
|
||||||
for _, releaseLocked := range lockfile {
|
for _, releaseLocked := range lockfile {
|
||||||
// repoName, err := repos.NameByUrl(releaseLocked.RepoUrl)
|
|
||||||
repoName := releaseLocked.RepoName
|
|
||||||
// if err != nil {
|
|
||||||
// return releases, err
|
|
||||||
// }
|
|
||||||
release := &Release{
|
release := &Release{
|
||||||
Repository: repoName,
|
Repository: releaseLocked.RepoName,
|
||||||
Release: releaseLocked.Release,
|
Release: releaseLocked.Release,
|
||||||
Chart: releaseLocked.Chart,
|
Chart: releaseLocked.Chart,
|
||||||
Version: releaseLocked.Version,
|
Version: releaseLocked.Version,
|
||||||
Namespace: releaseLocked.Namespace,
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
releases = append(releases, release)
|
releases = append(releases, release)
|
||||||
|
@ -38,6 +38,14 @@ func (f *Flux) SyncState(diff diff.Diff) error {
|
|||||||
srcPath := fmt.Sprintf("%s/src", f.path)
|
srcPath := fmt.Sprintf("%s/src", f.path)
|
||||||
filePath := fmt.Sprintf("%s/%s-", srcPath, entity)
|
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 {
|
for _, repo := range diff.DeletedRepositories {
|
||||||
if err := os.Remove(filePath + repo.Name + ".yaml"); err != nil {
|
if err := os.Remove(filePath + repo.Name + ".yaml"); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -259,12 +267,7 @@ func SyncValues(release *release.Release, path string) error {
|
|||||||
for _, valueFile := range release.Values {
|
for _, valueFile := range release.Values {
|
||||||
// Prepare a dir for values
|
// Prepare a dir for values
|
||||||
valuesPath := fmt.Sprintf("%s/%s", path, "values")
|
valuesPath := fmt.Sprintf("%s/%s", path, "values")
|
||||||
if _, err := os.Stat(valuesPath); errors.Is(err, os.ErrNotExist) {
|
if err := os.Mkdir(valuesPath, os.ModePerm); err != nil {
|
||||||
err := os.Mkdir(valuesPath, os.ModePerm)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,12 +311,10 @@ func SyncValues(release *release.Release, path string) error {
|
|||||||
func SyncSecrets(release *release.Release, destPath, path, sopsBin string) error {
|
func SyncSecrets(release *release.Release, destPath, path, sopsBin string) error {
|
||||||
secretsPath := fmt.Sprintf("%s/%s", destPath, "secrets")
|
secretsPath := fmt.Sprintf("%s/%s", destPath, "secrets")
|
||||||
// Prepare a dir for secrets
|
// Prepare a dir for secrets
|
||||||
if _, err := os.Stat(secretsPath); errors.Is(err, os.ErrNotExist) {
|
if err := os.RemoveAll(secretsPath); err != nil {
|
||||||
err := os.Mkdir(secretsPath, os.ModePerm)
|
return err
|
||||||
if err != nil {
|
}
|
||||||
return err
|
if err := os.Mkdir(secretsPath, os.ModePerm); err != nil {
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,13 +121,11 @@ func (diff *Diff) Resolve(repositories repository.Repositories, path string) (lo
|
|||||||
// Delete the
|
// Delete the
|
||||||
} else {
|
} else {
|
||||||
reposWished[i] = repoWished
|
reposWished[i] = repoWished
|
||||||
logrus.Infof("%v -- %v", repoExisting, repoWished)
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reposWished = reposWished[:i]
|
reposWished = reposWished[:i]
|
||||||
if !found {
|
if !found {
|
||||||
logrus.Infof("HERE I AM: %s", repoExisting)
|
|
||||||
diff.DeletedRepositories = append(diff.DeletedRepositories, repoExisting)
|
diff.DeletedRepositories = append(diff.DeletedRepositories, repoExisting)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,23 +134,42 @@ func Generate(path string, gh githelper.Githelper) error {
|
|||||||
},
|
},
|
||||||
ConfigMapGenerator: kustomize.CmGeneratorFromFiles(),
|
ConfigMapGenerator: kustomize.CmGeneratorFromFiles(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(kustomize.Secrets) > 0 {
|
if len(kustomize.Secrets) > 0 {
|
||||||
kustomization.Generators = []string{"sec-generator.yaml"}
|
kustomization.Generators = []string{"sec-generator.yaml"}
|
||||||
if err := kustomize.SecGeneratorCreate(path); err != nil {
|
if err := kustomize.SecGeneratorCreate(path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if err := os.RemoveAll(fmt.Sprintf("%s/sec-generator.yaml", path)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest, err := yaml.Marshal(kustomization)
|
manifest, err := yaml.Marshal(kustomization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
file, err := os.Create(path + "/kustomization.yaml")
|
dstFilePath := path + "/kustomization.yaml"
|
||||||
if err != nil {
|
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
|
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 {
|
if err := gh.AddAllAndCommit(path, "Update the root kustomization"); err != nil {
|
||||||
|
@ -42,8 +42,6 @@ releases:
|
|||||||
repository: metrics-server
|
repository: metrics-server
|
||||||
chart: metrics-server
|
chart: metrics-server
|
||||||
version: 3.11.0
|
version: 3.11.0
|
||||||
values:
|
|
||||||
- common/values.metrics-server.yaml
|
|
||||||
installed: true
|
installed: true
|
||||||
namespace: kube-system
|
namespace: kube-system
|
||||||
createNamespace: false
|
createNamespace: false
|
||||||
|
Loading…
Reference in New Issue
Block a user