Skip to content

Commit

Permalink
Some documentation and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Oded-B committed Apr 19, 2024
1 parent 12536e9 commit c574377
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ This is how this warning looks in the PR:
<img src="https://user-images.githubusercontent.com/1616153/219383563-8b833c17-7701-45b6-9471-d937d03142f4.png" width="50%" height="50%">
<!-- markdownlint-enable MD033 -->

### ArgoCD integration

Telefonistka can compare manifests in PR brances to live objects in the clusters and comment the difference in PRs <!-- TODO: add image -->

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.
Expand Down
8 changes: 8 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions internal/pkg/githubapi/promotion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit c574377

Please sign in to comment.