Skip to content

Commit

Permalink
Create scripts for bootstrapping the env (#42)
Browse files Browse the repository at this point in the history
* Create scripts for bootstrapping the env

* Shellcheck the scripts and add shellcheck to pre-commit

* Add shell-format to pre-commit

* Add action for shell checking

* Add action for shell checking

* Finalize scripts

* Paremetrize argocd version

* Script login against local argocd. Update readme

* Use jsonpath instead of piping cut

Co-authored-by: Sebastien Le Digabel <[email protected]>

* Open login page

Co-authored-by: Sebastien Le Digabel <[email protected]>
  • Loading branch information
nebojsa-prodana and sledigabel authored Mar 15, 2021
1 parent ebe96b3 commit 7b89c36
Show file tree
Hide file tree
Showing 19 changed files with 510 additions and 26 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/shell-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Shell Lint

on:
push:
tags:
- v*
branches:
- main
pull_request:

jobs:
shellcheck:
name: shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: shellcheck
run: |
pip install shellcheck-py
GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt
shellcheck -x **/*.sh
$(go env GOPATH)/bin/shfmt -l -d .
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ Temporary Items
# End of https://www.toptal.com/developers/gitignore/api/osx,intellij,go

.idea
bin
bin

# Ignore all hack marker files
hack/.hack.*

# Ignore .env files
.env.local
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ repos:
- id: helm-docs
args:
- --chart-search-root=charts
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.7.1.1
hooks:
- id: shellcheck
args:
- -x
- repo: local
hooks:
- id: shell-format
name: shell-format
entry: shfmt -l -d -w .
language: system
types: [shell]
pass_filenames: false
58 changes: 54 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,61 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md)

### Local development with Kubebuilder

1. Install `pre-commit`: see <https://pre-commit.com/#install>
1. Install `kubebuilder`: see <https://book.kubebuilder.io/quick-start.html#installation>
1. Install `ArgoCD Application` API pkg: see `hack/install-argocd-application.sh`
To get the controller running against the configured Kubernetes cluster in ~/.kube/config, run:

### Update ArgoCD Application API package
```
make install
make run
```

### Setting up dev environment

To facilitate local debugging and testing against real clusters, you may run:

```
bash hack/install-dev-deps.sh
bash hack/setup-dev.sh [argocd-version] [appset-version]
make install
make deploy
```

this will install all the dependencies (`pre-commit`, `kubebuilder`, `argocd`, `kind`) and it will install the correct version of ArgoCD Application API package for you. If you omit `argocd-version` and/or `appset-version` it will default to the latest stable/tested versions of ArgoCD and Appset controller.

After running the script, you will have 3 kind clusters created locally:
- `kind-argocd-control-plane` - cluster hosting the argocd installation and the progressive rollout operator. This cluster is also registered with Argo so that we can simulate using the same process for deploying to control cluster as well
- `kind-prc-cluster-1` and `kind-prc-cluster-2` - are the target clusters for deploying the apps to.

This gives us a total of 3 clusters allowing us to play with multiple stages of deploying. It will also log you in argocd cli. You can find additional login details in `.env.local` file that will be generated for your convenience.

#### Regenerating your access

In case that your access to the local argocd has become broken, you can regenerate it by running

```
bash hack/login-argocd-local.sh
```
This will create a socat link in kind docker network allowing you to access argocd server UI through your localhost.
The exact port will be outputted after the command has been run. Running this command will also update the values in `.env.local`.
#### Registering additional clusters
If you want to create additional clusters, you can do so by running
```
bash hack/add-cluster <cluster-name> <recreate>
```
This will spin up another kind cluster and register it against ArgoCD running in `kind-argocd-control-plane`
#### Deploying a test appset
You can deploy a test appset to the default 3 clusters by running the following:
```
bash hack/deploy-test-appset.sh
```
Feel free to extend the cluster generation section of the appset spec if you want to deploy it clusters that you have manually created.
#### Update ArgoCD Application API package
Because of [https://github.com/argoproj/argo-cd/issues/4055](https://github.com/argoproj/argo-cd/issues/4055) we can't just run `go get github.com/argoproj/argo-cd`.
Expand Down
33 changes: 18 additions & 15 deletions go-mod-hack.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/bin/sh
#!/bin/bash
# See https://github.com/argoproj/argo-cd/issues/4055
set -euo pipefail

VERSION=${1#"v"}
if [ -z "$VERSION" ]; then
echo "Must specify version!"
exit 1
if [[ -z "$VERSION" ]]; then
echo "Must specify version!"
exit 1
fi
MODS=($(
curl -sS https://raw.githubusercontent.com/kubernetes/kubernetes/v${VERSION}/go.mod |
sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p'
))
for MOD in "${MODS[@]}"; do
V=$(
go mod download -json "${MOD}@kubernetes-${VERSION}" |
sed -n 's|.*"Version": "\(.*\)".*|\1|p'
)
go mod edit "-replace=${MOD}=${MOD}@${V}"
done

FILES=$(
curl -sS https://raw.githubusercontent.com/kubernetes/kubernetes/v"${VERSION}"/go.mod |
sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p'
)

while read -r MOD; do
V=$(
go mod download -json "${MOD}@kubernetes-${VERSION}" |
sed -n 's|.*"Version": "\(.*\)".*|\1|p'
)
go mod edit "-replace=${MOD}=${MOD}@${V}"
done <<<"$FILES"

go get "k8s.io/kubernetes@v${VERSION}"
13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module github.com/Skyscanner/argocd-progressive-rollout
go 1.15

require (
github.com/argoproj/argo-cd v0.8.1-0.20210218202601-6de3cf44a4cb
github.com/argoproj/argo-cd v0.8.1-0.20210218100039-a4ee25b59d8d
github.com/argoproj/gitops-engine v0.2.1-0.20210129183711-c5b7114c501f
github.com/go-logr/logr v0.3.0
github.com/kr/pretty v0.2.1 // indirect
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.3
k8s.io/api v0.20.1
Expand All @@ -30,15 +31,15 @@ replace k8s.io/cloud-provider => k8s.io/cloud-provider v0.20.1

replace k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.20.1

replace k8s.io/code-generator => k8s.io/code-generator v0.20.4-rc.0
replace k8s.io/code-generator => k8s.io/code-generator v0.20.5-rc.0

replace k8s.io/component-base => k8s.io/component-base v0.20.1

replace k8s.io/component-helpers => k8s.io/component-helpers v0.20.1

replace k8s.io/controller-manager => k8s.io/controller-manager v0.20.1

replace k8s.io/cri-api => k8s.io/cri-api v0.20.4-rc.0
replace k8s.io/cri-api => k8s.io/cri-api v0.20.5-rc.0

replace k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.20.1

Expand All @@ -58,6 +59,10 @@ replace k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.20.1

replace k8s.io/metrics => k8s.io/metrics v0.20.1

replace k8s.io/mount-utils => k8s.io/mount-utils v0.20.4-rc.0
replace k8s.io/mount-utils => k8s.io/mount-utils v0.20.5-rc.0

replace k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.20.1

replace k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.20.1

replace k8s.io/sample-controller => k8s.io/sample-controller v0.20.1
Loading

0 comments on commit 7b89c36

Please sign in to comment.