Package: gordian
GordianGordian applies transformations to files in github repositories and create PRs for the owners of the repositories to review and merge them.This project grew from a need to keep various kubernetes services consistent and roll out changes at scale. The main use case for this tool is to make changes to configuration files across multiple repositories simultaneously.UsageSearch and ReplaceYou can use the docker image to search and replace various strings across repositories. It supports simple and complex search/replace strings operations.docker run --rm -it argoprojlabs/gordian:latest -h
usage: gordian [-h] [-c CONFIG_FILE] [-g GITHUB_API] --pr PR_MESSAGE [-v] [-d]
               [-b BRANCH] [-t TARGET_BRANCH] [-l PR_LABELS [PR_LABELS ...]]
               [-M | -m | -p]
               [--description DESCRIPTION | --description-file DESCRIPTION_FILE]
               [--force-changelog FORCE_CHANGELOG] -s SEARCH -r REPLACE

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG_FILE, --config CONFIG_FILE
                        Config file path. (default: config.yaml)
  -g GITHUB_API, --github-api GITHUB_API
                        Github API URL (default: None)
  --pr PR_MESSAGE       Pull request name. (default: None)
  -v, --verbose
  -d, --dry-run         Enable dry run mode (default: False)
  -b BRANCH, --branch BRANCH
                        Branch name to use (default: None)
  -t TARGET_BRANCH, --target-branch TARGET_BRANCH
                        Target branch (default: master)
  -l PR_LABELS [PR_LABELS ...], --labels PR_LABELS [PR_LABELS ...]
                        List of space separated label names you wish to add to
                        your pull request(s) (default: [])
  -F FILE, --file FILE
                        File to change, currently only supported with
                        PlainTextUpdater. (default: None)
  -M, --major           Bump the major version. (default: None)
  -m, --minor           Bump the minor version. (default: None)
  -p, --patch           Bump the patch version. (default: None)
  --description DESCRIPTION
                        Description to be passed to the PR. (default: )
  --description-file DESCRIPTION_FILE
                        Local file path for the description to be passed to
                        the PR. (default: None)
  --force-changelog FORCE_CHANGELOG
                        Fail if changelog does not exist or cannot be parsed
                        (default: None)
  -s SEARCH, --search SEARCH
                        The string to search for in config files. (default:
                        None)
  -r REPLACE, --replace REPLACE
                        The string that will replace instances of the searched
                        string. (default: None)Simple transformationsYou can use the command line interface to make simple changes across various JSON and YAML files, as shown in this example that modifies a kubernetes API Version.The following command will update the repositories listed in the default config fileconfig.yamlby making a new pull request to the targetmasterbranch
using a new origin branchupdate_k8s_apiversionby updating all files that containsapiVersion: apps/v1beta2to replace it withapiVersion: apps/v1.
The new PR will have the labelsk8s.1.16andsupportassigned to it and theminorversion will be bumped.dockerrun--rm-itargoprojlabs/gordian:latest-b"update_k8s_apiversion"--pr"update_k8s_apiversion"-s"apiVersion: apps/v1beta2"-r"apiVersion: apps/v1"-lk8s.1.16-v-mComplex transformationsYou can use the python script interface to make complex changes across various JSON and YAML files, as shown in this example that modifies a kubernetes resource. You can see more examples in theexamplesdirectory.importsysfromgordian.gordianimportget_basic_parser,apply_transformationsfromgordian.transformationsimportTransformationclassPreScale(Transformation):def__init__(self,args,repo):super().__init__(args,repo)self.environments=args.environmentsdefrun(self):forenvinself.environments:objects=self.repo.get_objects(f'overlays/{env}/envconfig-values.yaml')min_replicas=Noneforobjinobjects:ifobj['kind']!='HorizontalPodAutoscaler':continueifobj['spec']['minReplicas']!=obj['spec']['maxReplicas']:min_replicas=obj['spec']['minReplicas']obj['spec']['maxReplicas']=min_replicasifmin_replicasisnotNone:objects.save(f'Setting maxRelicas = minReplicas ={min_replicas}',self.dry_run)self.repo.changelog.added('Set max replicas equal to min replicas','TICKET-1234')self.repo.changelog.save('Update changelog',self.dry_run)if__name__=='__main__':parser=get_basic_parser()parser.add_argument('-e','--environments',required=False,dest='environments',default=['prd'],action='append',help='Environments to update.')args=parser.parse_args(sys.argv[1:])apply_transformations(args,[PreScale])Dependenciesconfig.yaml(required) - list of repositories you wish to modifyGIT_USERNAME(optional) - your Github usernameGIT_PASSWORD(optional) - your Github password or Personal Access TokenGIT_TOKEN(optional) - Github Personal Access Token that grants write access to the specified repositoriesAuthenticationTwo methods of authentication are available:Using a Personal Access TokenUsing a Github Username & PasswordA Github Personal Access Token, Github Username and Github Password can also be passed in via thetoken=,username=andpassword=named parameters. The passed value will always take precedence over any environment variable. (Added in3.5.0)Authentication - Personal Access TokenA Personal Access Token can be used in two ways:Setting theGIT_TOKENenvironment variablePassing thetoken=named parameterThe Personal Access Token must havewriteaccess to any specified repositories you wish to submit changes to.Authentication - Github Username & PasswordA Github Username and Password combination can be used in two ways:Setting theGIT_USERNAMEandGIT_PASSWORDenvironment variablesPassing theusername=andpassword=parametersThe user must havewriteaccess to any specified repositories you wish to submit changes to.TheGIT_PASSWORDorpassword=may also contain a Personal Access Token instead of the account password.DevelopmentThe simplest way to hit the ground running if you want to contribute with code is using docker.Launch a python containerlocalhost$dockerrun--rm-it-v$(pwd):$(pwd)-w$(pwd)python:3.7-stretchbashInstall the project and test dependencies in developer modecontainer#pipinstall-e.[test]Run the testscontainer#pytest===========================================testsessionstarts============================================platformlinux--Python3.7.1,pytest-4.5.0,py-1.8.0,pluggy-0.11.0
rootdir:/Users/user/git/argoproj-labs
plugins:requests-mock-1.6.0,cov-2.7.1
collected33items

....==================================33passed,2warningsin1.73seconds===================================SupportCreatorsRene MartinJonathan NevelsonCorey CaverlySara BluminContributorsJeremy ChavezEtienne GrignonAnshul Vohra