WIP: Trying to implement diff

This commit is contained in:
Nikolai Rodionov
2023-10-20 13:31:30 +02:00
parent 93ad3389b2
commit ed3d45a7c4
15 changed files with 197 additions and 136 deletions

View File

@ -24,7 +24,14 @@ func ReadTheConfig(path string) (*config.Config, error) {
return conf, nil
}
func Sync(definedWorkdirPath, sshKeyPath string, conf *config.Config, dry, diffArg bool) error {
// func cloneSnapshoot(gh githelper.Githelper, snapshotDir, snapshotBranch string) error {
// if err := gh.CloneRepo(snapshotBranch, snapshotUrl, false); err != nil {
// return err
// }
// return nil
// }
func Sync(definedWorkdirPath, sshKeyPath string, conf *config.Config, dry bool, diffArg string) error {
// Start by creating a directory where everything should be happening
configPath := filepath.Dir(conf.ConfigPath)
workdirPath, err := workdir.CreateWorkdir(definedWorkdirPath)
@ -41,6 +48,10 @@ func Sync(definedWorkdirPath, sshKeyPath string, conf *config.Config, dry, diffA
// Configure a git client
gh := githelper.NewGit(sshKeyPath)
// if len(diffArg) > 0 {
// snapshotDir := fmt.Sprint("%s/.snapshot", workdirPath)
// cloneSnapshoot(gh, snapshotDir, diffArg)
// }
// The main logic starts here
for _, cluster := range conf.Clusters {
@ -88,12 +99,15 @@ func Sync(definedWorkdirPath, sshKeyPath string, conf *config.Config, dry, diffA
return err
}
if diffArg {
_, err := hh.PullChart(workdirPath, *release.RepositoryObj, release.Chart, release.Version)
if len(diffArg) > 0 {
_, err := hh.PullChart(workdirPath, release.ToHelmReleaseData())
if err != nil {
return err
}
hh.RenderChart(workdirPath, *release.RepositoryObj, release.Chart, release.Version)
if err := hh.RenderChart(workdirPath, release.ToHelmReleaseData()); err != nil {
return err
}
}
if err := release.ValuesHandler(configPath); err != nil {
@ -113,9 +127,9 @@ func Sync(definedWorkdirPath, sshKeyPath string, conf *config.Config, dry, diffA
return err
}
if diffArg {
if len(diffArg) > 0 {
for _, releaseCurrent := range releasesCurrent {
hh.PullChart(workdirPath, *releaseCurrent.RepositoryObj, releaseCurrent.Chart, releaseCurrent.Version)
hh.PullChart(workdirPath, releaseCurrent.ToHelmReleaseData())
}
}
@ -130,7 +144,8 @@ func Sync(definedWorkdirPath, sshKeyPath string, conf *config.Config, dry, diffA
return err
}
if err := provider.SyncState(diffReleases, diffRepos); err != nil {
hashesPerRelease, err := provider.SyncState(diffReleases, diffRepos)
if err != nil {
return err
}
@ -138,10 +153,12 @@ func Sync(definedWorkdirPath, sshKeyPath string, conf *config.Config, dry, diffA
return err
}
lockfile.AddHashes(hashesPerRelease)
if err := lockfile.WriteToFile(clusterWorkdirPath); err != nil {
return err
}
if err := gh.AddAllAndCommit(clusterWorkdirPath, "Update the lockfile"); err != nil {
if _, err := gh.AddAllAndCommit(clusterWorkdirPath, "Update the lockfile"); err != nil {
return err
}
if !dry {