Skip to content

Commit

Permalink
gitops - handle app file does not exists in repo (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed May 22, 2020
1 parent 56f2eba commit c780635
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions kotsadm/pkg/gitops/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,24 @@ func CreateGitOpsCommit(gitOpsConfig *GitOpsConfig, appSlug string, appName stri
}
}

// if the file has not changed, end now
currentRevision, err := ioutil.ReadFile(filepath.Join(workDir, gitOpsConfig.Path, fmt.Sprintf("%s.yaml", appSlug)))
if err != nil {
return "", errors.Wrap(err, "failed to read current file")
}
if string(currentRevision) == string(out) {
return "", nil
filePath := filepath.Join(workDir, gitOpsConfig.Path, fmt.Sprintf("%s.yaml", appSlug))
_, err = os.Stat(filePath)
if err == nil { // if the file has not changed, end now
currentRevision, err := ioutil.ReadFile(filePath)
if err != nil {
return "", errors.Wrap(err, "failed to read current file")
}
if string(currentRevision) == string(out) {
return "", nil
}
} else if os.IsNotExist(err) { // create subdirectory if not exist
err := os.MkdirAll(filepath.Join(workDir, gitOpsConfig.Path), 0644)
if err != nil {
return "", errors.Wrap(err, "failed to mkdir for file")
}
}

err = ioutil.WriteFile(filepath.Join(workDir, gitOpsConfig.Path, fmt.Sprintf("%s.yaml", appSlug)), out, 0644)
err = ioutil.WriteFile(filePath, out, 0644)
if err != nil {
return "", errors.Wrap(err, "failed to write updated app yaml")
}
Expand Down

0 comments on commit c780635

Please sign in to comment.