Skip to content

Commit

Permalink
feat: IS-3260: Helmfile dependency check (#58)
Browse files Browse the repository at this point in the history
* initial commit

* refactoring

* changed export

* fixed some pathing

* removed nock and unecessary files

* more intuitive function naming

* add upstream dependency checking

* removed staleness state

* added comment

* updated readme

* Update helmfile-dependency-check/action.yml

Co-authored-by: Marcin Dobosz <[email protected]>

Co-authored-by: Marcin Dobosz <[email protected]>
  • Loading branch information
dlongeuay and marcind authored Nov 19, 2020
1 parent 33f7530 commit 35307d4
Show file tree
Hide file tree
Showing 21 changed files with 6,174 additions and 413 deletions.
39 changes: 39 additions & 0 deletions helmfile-dependency-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# helmfile-dependency-check

Simple action to check if there are updates available for charts defined in a `helmfile.yaml`

Helmfile Lock States:

- `missing` - helmfile.lock is missing (helmfile.yaml had repositories to check against)
- `update_available` - Chart updates were found in upstream repos
- `fresh` - Charts are all up to date

## Optional Inputs

```yaml
inputs:
working_directory:
description: "The directory to run all the commands in"
required: false
default: "."
```
## Outputs
```yaml
outputs:
helmfile-lock-state:
description: "State of the helmfile lock. [missing, fresh, update_available]"
value: ${{ steps.main.outputs.helmfile-lock-state }}
helmfile-lock-updates:
description: "JSON list of available updates."
value: ${{ steps.main.outputs.helmfile-lock-updates }}
```
## Example
```yaml
- uses: iStreamPlanet/github-actions/helmfile-dependency-check@main
with:
working_directory: .
```
74 changes: 74 additions & 0 deletions helmfile-dependency-check/__test__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as core from "@actions/core"
import * as path from "path"
import * as nock from "nock"
import { readFileSync } from "fs"
import { helmfileDepCheck } from "../helmfileDepCheck"

const baseDir = "helmfile-dependency-check/__test__/test-data/"

beforeEach(() => {
jest.resetModules()

// index.yaml will be returned for all https GET requests
const helmfilePath = path.join(baseDir, "index.yaml")
const helmfileContent = readFileSync(helmfilePath, "utf-8")
nock(/.*/).persist().get(/.*index.yaml/).reply(200, helmfileContent)
})

afterEach(() => {
delete process.env["INPUT_WORKING-DIR"]
})

describe("helmfile-dep-update", () => {
it("helmfile missing", async () => {
process.env["INPUT_WORKING-DIR"] = path.join(baseDir, "helmfile-missing")
const setOutputMock = jest.spyOn(core, "setOutput")

await helmfileDepCheck()

expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-state", "fresh")
expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-updates", [])
})
it("helmfile missing repositories", async () => {
process.env["INPUT_WORKING-DIR"] = path.join(baseDir, "helmfile-no-repository")
const setOutputMock = jest.spyOn(core, "setOutput")

await helmfileDepCheck()

expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-state", "fresh")
expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-updates", [])
})
it("helmfile lock fresh", async () => {
process.env["INPUT_WORKING-DIR"] = path.join(baseDir, "helmfile-lock-fresh")
const setOutputMock = jest.spyOn(core, "setOutput")

await helmfileDepCheck()

expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-state", "fresh")
expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-updates", [])
})
it("helmfile lock update", async () => {
process.env["INPUT_WORKING-DIR"] = path.join(baseDir, "helmfile-lock-update")
const setOutputMock = jest.spyOn(core, "setOutput")

await helmfileDepCheck()

const updateData = {
name: "datadog",
repository: "https://helm.datadoghq.com/index.yaml",
currentVer: "2.4.39",
latestVer: "2.5.1"
}
expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-state", "update_available")
expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-updates", [updateData])
})
it("helmfile lock missing", async () => {
process.env["INPUT_WORKING-DIR"] = path.join(baseDir, "helmfile-lock-missing")
const setOutputMock = jest.spyOn(core, "setOutput")

await helmfileDepCheck()

expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-state", "missing")
expect(setOutputMock).toHaveBeenCalledWith("helmfile-lock-updates", [])
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: v0.125.0
dependencies:
- name: datadog
repository: https://helm.datadoghq.com
version: 2.5.1
- name: external-dns
repository: https://charts.bitnami.com/bitnami
version: 2.24.1
- name: kube-state-metrics
repository: https://charts.helm.sh/stable
version: 2.9.2
- name: metrics-server
repository: https://charts.helm.sh/stable
version: 2.11.2
- name: spotinst-kubernetes-cluster-controller
repository: https://spotinst.github.io/spotinst-kubernetes-helm-charts
version: 1.0.78
digest: sha256:aa71df80f65944a2281269415dc193943f50d9d7bf2763017ee1d9d9539ac116
generated: "2020-11-06T15:12:37.407096-08:00"
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
repositories:
- name: stable
url: https://charts.helm.sh/stable
- name: spotinst
url: https://spotinst.github.io/spotinst-kubernetes-helm-charts
- name: bitnami
url: https://charts.bitnami.com/bitnami
- name: datadog
url: https://helm.datadoghq.com

releases:
- name: external-dns
namespace: kube-system
chart: bitnami/external-dns
version: ^2.0.0
values:
- helm_values/external-dns.yaml.gotmpl

- name: datadog
namespace: kube-system
chart: datadog/datadog
version: ~2.4.35
values:
- helm_values/datadog.yaml.gotmpl

- name: spotinst-kubernetes-cluster-controller
namespace: kube-system
chart: spotinst/spotinst-kubernetes-cluster-controller
version: ^1.0.54
values:
- helm_values/spotinst.yaml.gotmpl

- name: metrics-server
namespace: kube-system
chart: stable/metrics-server
version: ~2.11.2
values:
- helm_values/metrics-server.yaml

- name: kube-state-metrics
namespace: kube-system
chart: stable/kube-state-metrics
version: ~2.9.2

- name: cloudhealth
namespace: default
chart: ../../../../charts/cloudhealth
values:
- ../../common/helm_values/cloudhealth.yaml
- cloudhealth:
clusterName: infra-prod-usw2-a

environments:
default:
values:
- cluster.yaml
secrets:
- secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
repositories:
- name: stable
url: https://charts.helm.sh/stable
- name: spotinst
url: https://spotinst.github.io/spotinst-kubernetes-helm-charts
- name: bitnami
url: https://charts.bitnami.com/bitnami
- name: datadog
url: https://helm.datadoghq.com

releases:
- name: external-dns
namespace: kube-system
chart: bitnami/external-dns
version: ^2.0.0
values:
- helm_values/external-dns.yaml.gotmpl

- name: datadog
namespace: kube-system
chart: datadog/datadog
version: ~2.4.35
values:
- helm_values/datadog.yaml.gotmpl

- name: spotinst-kubernetes-cluster-controller
namespace: kube-system
chart: spotinst/spotinst-kubernetes-cluster-controller
version: ^1.0.54
values:
- helm_values/spotinst.yaml.gotmpl

- name: metrics-server
namespace: kube-system
chart: stable/metrics-server
version: ~2.11.2
values:
- helm_values/metrics-server.yaml

- name: kube-state-metrics
namespace: kube-system
chart: stable/kube-state-metrics
version: ~2.9.2

- name: cloudhealth
namespace: default
chart: ../../../../charts/cloudhealth
values:
- ../../common/helm_values/cloudhealth.yaml
- cloudhealth:
clusterName: infra-prod-usw2-a

environments:
default:
values:
- cluster.yaml
secrets:
- secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: v0.125.0
dependencies:
- name: datadog
repository: https://helm.datadoghq.com
version: 2.4.39
- name: external-dns
repository: https://charts.bitnami.com/bitnami
version: 2.24.1
- name: kube-state-metrics
repository: https://charts.helm.sh/stable
version: 2.9.2
- name: metrics-server
repository: https://charts.helm.sh/stable
version: 2.11.2
- name: spotinst-kubernetes-cluster-controller
repository: https://spotinst.github.io/spotinst-kubernetes-helm-charts
version: 1.0.78
digest: sha256:aa71df80f65944a2281269415dc193943f50d9d7bf2763017ee1d9d9539ac116
generated: "2019-11-06T15:12:37.407096-08:00"
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
repositories:
- name: stable
url: https://charts.helm.sh/stable
- name: spotinst
url: https://spotinst.github.io/spotinst-kubernetes-helm-charts
- name: bitnami
url: https://charts.bitnami.com/bitnami
- name: datadog
url: https://helm.datadoghq.com

releases:
- name: external-dns
namespace: kube-system
chart: bitnami/external-dns
version: ^2.0.0
values:
- helm_values/external-dns.yaml.gotmpl

- name: datadog
namespace: kube-system
chart: datadog/datadog
version: ~2.4.35
values:
- helm_values/datadog.yaml.gotmpl

- name: spotinst-kubernetes-cluster-controller
namespace: kube-system
chart: spotinst/spotinst-kubernetes-cluster-controller
version: ^1.0.54
values:
- helm_values/spotinst.yaml.gotmpl

- name: metrics-server
namespace: kube-system
chart: stable/metrics-server
version: ~2.11.2
values:
- helm_values/metrics-server.yaml

- name: kube-state-metrics
namespace: kube-system
chart: stable/kube-state-metrics
version: ~2.9.2

- name: cloudhealth
namespace: default
chart: ../../../../charts/cloudhealth
values:
- ../../common/helm_values/cloudhealth.yaml
- cloudhealth:
clusterName: infra-prod-usw2-a

environments:
default:
values:
- cluster.yaml
secrets:
- secrets.yaml
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
helmfiles:
- path: ../../applications/origin-dev/helmfile.yaml
values:
- cluster.yaml
- { { toYaml .Values | nindent 8 } }

environments:
default:
secrets:
- secrets.yaml
Loading

0 comments on commit 35307d4

Please sign in to comment.