mumoshu / helm-x

Treat any Kustomization or K8s manifests directory as a Helm chart
Other
172 stars 13 forks source link

feat: replicated/ship integration #2

Closed mumoshu closed 5 years ago

mumoshu commented 5 years ago

https://github.com/replicatedhq/ship

The integration would basically run ship so that ship runs helm template and kustomize to generate a set of kubernetes manifests, which is then consumed by helm-x as a helm chart

mumoshu commented 5 years ago

ship provides two commands ship inti and ship update, which basically fetches the upstream helm chart, run helm template, generate kustomization.yaml files, run kustomize build to produce a rendered.yaml to be applied later.

The file tree after ship init looks like:

$ tree .
.
├── base
│   ├── deployment.yaml
│   ├── kustomization.yaml
│   ├── pvc.yaml
│   ├── secrets.yaml
│   ├── svc.yaml
│   └── tests
│       ├── test-configmap.yaml
│       └── test.yaml
├── overlays
│   └── ship
│       └── kustomization.yaml
└── rendered.yaml

4 directories, 9 files

What helm-x would need here is the part of ship that runs helm fetch, and helm template, kustomize build, so that helm-x can instlal the kustomize output as a helm chart.

mumoshu commented 5 years ago

...and we won't need rendered.yaml in helm-x.

mumoshu commented 5 years ago

Generated kustomization.yamls are:

$ cat base/kustomization.yaml
kind: ""
apiversion: ""
resources:
- deployment.yaml
- pvc.yaml
- secrets.yaml
- svc.yaml
- tests/test-configmap.yaml
- tests/test.yaml

$ cat overlays/ship/kustomization.yaml
kind: ""
apiversion: ""
bases:
- ../../base
mumoshu commented 5 years ago

So can we just add --kustomize-patches-json6902 extensions/v1beta1/Ingress/myingress=myjsonpatch.yaml or --kustomize-patches-strategic-merge patch.yaml to helm-x?

Kustomize JSON pathes: https://github.com/kubernetes-sigs/kustomize/blob/master/examples/jsonpatch.md

Kustomize Strategic-merge patches: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/wordpress

mumoshu commented 5 years ago

An useful extension in helm-x would be that extensions/v1beta1/Ingress/myingress=myjsonpatch.yaml can be replaced with a single yaml file containing:

# "target" syntax borrowed from kustomize
target:
    group: extensions
    version: v1beta1
    kind: Ingress
    name: my-ingress
# Single RFC6902 JSON Patch document = A sequence of JSON Patch "operations"
# https://triple-underscore.github.io/RFC6902-ja.html
patch:
- op: replace
  path: /spec/rules/0/host
  value: foo.bar.io
- op: add
  path: /spec/rules/0/http/paths/-
  value:
    path: '/test'
    backend:
      serviceName: my-test
      servicePort: 8081

#Or externalize the `patch` section by:
patchFile: myjsonpatch.yaml
mumoshu commented 5 years ago

Added --json-patch FILE and --strategic-merge-patch FILE flags via #8. Probably we won't need this in short term. Feel free to reopen if anyone wants this!