Skip to content

Commit

Permalink
Use env vars for ArgoCD client config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oded-B committed Apr 18, 2024
1 parent c8992f0 commit 12536e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
9 changes: 7 additions & 2 deletions internal/pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"

cmdutil "github.com/argoproj/argo-cd/v2/cmd/util"
"github.com/argoproj/argo-cd/v2/controller"
Expand Down Expand Up @@ -263,10 +264,14 @@ func getEnv(key, fallback string) string {
}

func createArgoCdClient() (apiclient.Client, error) {
argoCdClientConfigPath := getEnv("ARGOCD_CLIENT_CONFIG_PATH", "argocd-client-config.yaml")
plaintext, _ := strconv.ParseBool(getEnv("ARGOCD_PLAINTEXT", "false"))
insecure, _ := strconv.ParseBool(getEnv("ARGOCD_INSECURE", "false"))

opts := &apiclient.ClientOptions{
ConfigPath: argoCdClientConfigPath,
ServerAddr: getEnv("ARGOCD_SERVER_ADDR", "localhost:8080"),
AuthToken: getEnv("ARGOCD_TOKEN", ""),
PlainText: plaintext,
Insecure: insecure,
}

clientset, err := apiclient.NewClient(opts)
Expand Down
20 changes: 12 additions & 8 deletions internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,19 @@ func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPr
if err != nil {
prHandleError = err
ghPrClientDetails.PrLogger.Errorf("Failed to get ArgoCD diff information: err=%s\n", err)
} else if noDiffsAndErrorsPR {
prLables, resp, err := ghPrClientDetails.GhClientPair.v3Client.Issues.AddLabelsToIssue(ghPrClientDetails.Ctx, ghPrClientDetails.Owner, ghPrClientDetails.Repo, *eventPayload.PullRequest.Number, []string{"noop"})
prom.InstrumentGhCall(resp)
if err != nil {
ghPrClientDetails.PrLogger.Errorf("Could not label GitHub PR: err=%s\n%v\n", err, resp)
} else {
ghPrClientDetails.PrLogger.Debugf("PR %v labeled\n%+v", *eventPayload.PullRequest.Number, prLables)
} else {
ghPrClientDetails.PrLogger.Debugf("Successfully got ArgoCD diff\n")
if noDiffsAndErrorsPR {
ghPrClientDetails.PrLogger.Debugf("ArgoCD diff is empty, this PR will not change cluster state\n")
prLables, resp, err := ghPrClientDetails.GhClientPair.v3Client.Issues.AddLabelsToIssue(ghPrClientDetails.Ctx, ghPrClientDetails.Owner, ghPrClientDetails.Repo, *eventPayload.PullRequest.Number, []string{"noop"})
prom.InstrumentGhCall(resp)
if err != nil {
ghPrClientDetails.PrLogger.Errorf("Could not label GitHub PR: err=%s\n%v\n", err, resp)
} else {
ghPrClientDetails.PrLogger.Debugf("PR %v labeled\n%+v", *eventPayload.PullRequest.Number, prLables)
}
// TODO Auto-merge PRs with no changes(optional)
}
// TODO Auto-merge PRs with no changes(optional)
}

err, templateOutput := executeTemplate(ghPrClientDetails.PrLogger, "argoCdDiff", "argoCD-diff-pr-comment.gotmpl", diffOfChangedComponents)
Expand Down

0 comments on commit 12536e9

Please sign in to comment.