diff --git a/README.md b/README.md index d42a2d10..8e8cbd60 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,12 @@ This is how this warning looks in the PR: +### ArgoCD integration + +Telefonistka can compare manifests in PR brances to live objects in the clusters and comment the difference in PRs + +It can also automtically merge PRs that would not incure any change to cluster. + ### Artifact version bumping from CLI If your IaC repo deploys software you maintain internally you probably want to automate artifact version bumping. diff --git a/docs/installation.md b/docs/installation.md index 143aca81..61260565 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -87,6 +87,14 @@ Environment variables for the webhook process: `TEMPLATES_PATH` Telefonistka uses Go templates to format GitHub PR comments, the variable override the default templates path("templates/"), useful for environments where the container workdir is overridden(like GitHub Actions) or when custom templates are desired. +`ARGOCD_SERVER_ADDR` Hostname and port of the ArgoCD API endpoint, like `argocd-server.argocd.svc.cluster.local:443`, default is `localhost:8080"` + +`ARGOCD_TOKEN` ArgoCD authentication token. + +`ARGOCD_PLAINTEXT` Allows disabeling TLS on ArgoCD API calls. + +`ARGOCD_INSECURE` Allow disabeling server certificate validation. + Behavior of the bot is configured by YAML files **in the target repo**: ## Repo Configuration diff --git a/internal/pkg/githubapi/promotion.go b/internal/pkg/githubapi/promotion.go index 708a4733..22239dc4 100644 --- a/internal/pkg/githubapi/promotion.go +++ b/internal/pkg/githubapi/promotion.go @@ -110,6 +110,7 @@ func getComponentConfig(ghPrClientDetails GhPrClientDetails, componentPath strin } func generateListOfRelevantComponents(ghPrClientDetails GhPrClientDetails, config *cfg.Config) map[relevantComponent]bool { + // This function generates a list of "components" that where changed in the PR and are relevant for promotion) relevantComponents := map[relevantComponent]bool{} prFiles, resp, err := ghPrClientDetails.GhClientPair.v3Client.PullRequests.ListFiles(ghPrClientDetails.Ctx, ghPrClientDetails.Owner, ghPrClientDetails.Repo, ghPrClientDetails.PrNumber, &github.ListOptions{}) @@ -154,6 +155,7 @@ type relevantComponent struct { } func generateListOfChangedComponentPaths(ghPrClientDetails GhPrClientDetails, config *cfg.Config) []string { + // Turns the map with struct keys into a list of strings changedComponentPaths := []string{} relevantComponents := generateListOfRelevantComponents(ghPrClientDetails, config) for component := range relevantComponents { @@ -162,14 +164,11 @@ func generateListOfChangedComponentPaths(ghPrClientDetails GhPrClientDetails, co return changedComponentPaths } -func GeneratePromotionPlan(ghPrClientDetails GhPrClientDetails, config *cfg.Config, configBranch string) (map[string]PromotionInstance, error) { - promotions := make(map[string]PromotionInstance) +func generatePlanBasedOnChangeddComponent(ghPrClientDetails GhPrClientDetails, config *cfg.Config, relevantComponents map[relevantComponent]bool, configBranch string) (map[string]PromotionInstance, error) { + // This function generates a promotion plan based on the list of relevant components that where "touched" and the in-repo telefonitka configuration - //first we build a **unique** list of relevant directories - // - relevantComponents := generateListOfRelevantComponents(ghPrClientDetails, config) - - // then we iterate over the list of relevant directories and generate a plan based on the configuration + promotions := make(map[string]PromotionInstance) + // Iterate over the list of relevant directories and generate a plan based on the configuration for componentToPromote := range relevantComponents { componentConfig, err := getComponentConfig(ghPrClientDetails, componentToPromote.SourcePath+componentToPromote.ComponentName, configBranch) if err != nil { @@ -236,6 +235,12 @@ func GeneratePromotionPlan(ghPrClientDetails GhPrClientDetails, config *cfg.Conf } } } - return promotions, nil } + +func GeneratePromotionPlan(ghPrClientDetails GhPrClientDetails, config *cfg.Config, configBranch string) (map[string]PromotionInstance, error) { + // TODO refactor tests to use the two functions below instead of this one + relevantComponents := generateListOfRelevantComponents(ghPrClientDetails, config) + promotions, err := generatePlanBasedOnChangeddComponent(ghPrClientDetails, config, relevantComponents, configBranch) + return promotions, err +}