Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Helm Chart を Unit Test する / Unit Testing Helm C...

d-kuro
June 24, 2021

Helm Chart を Unit Test する / Unit Testing Helm Chart

Kubernetes Meetup Tokyo #42 で発表したスライドです
https://k8sjp.connpass.com/event/214286/

d-kuro

June 24, 2021
Tweet

More Decks by d-kuro

Other Decks in Programming

Transcript

  1. Summary • Helm Chart ͷ Test ʹ͍ͭͯ • Helm Chart

    Λ Unit Test ͢ΔͨΊͷϥΠϒϥϦΛ࣮૷ͨ͠࿩ • ࣮૷ͷৄࡉ • “k8s.io” ϥΠϒϥϦΛ࢖ͬͨ Tips ͷ঺հ
  2. Testing Helm Charts • Helm ʹ͸ςετػߏ͕ଘࡏ͢Δ • “helm.sh/hook: test” annotation

    Λ෇༩ͨ͠ Pod ఆٛΛ༻ҙ͢Δ • “<chart-name>/templates/tests/“ ʹ഑ஔ͢Δ • “helm install” ͨ͋͠ͱʹ “helm test” Λ࣮ߦ͢Δ • Pod ͕ exit 0 Ͱऴྃ͢Ε͹ςετ͕੒ޭͨ͠ͱΈͳ͞ΕΔ
  3. Testing Helm Charts • ͜ͷςετػߏ͸ͲͪΒ͔ͱ͍͑͹ Integration Test • values.yaml ʹఆٛͨ͠

    Option ͕ҙਤͨ͠௨Γʹػೳ͢Δ͔ 
 Ͳ͏͔ͳͲͷ Unit Test Ϩϕϧͷ֬ೝ͕͔ͨͬͨ͠
  4. Unit Testing Helm Charts • Go Ͱ Helm Chart Λ

    Unit Test ͢Δ • “helm.sh/helm/v3” Λ import ͯ͠ 
 “helm template” ίϚϯυͰ࢖༻͍ͯ͠Δؔ਺Λݺͼग़͢ • ϨϯμϦϯά͞Εͨ YAML ͕ string Ͱ໯͑ΔͷͰ 
 ͍͍ײ͡ʹൺֱ͢Δ
  5. Unit Testing Helm Charts • ࡞੒ͨ͠ϥΠϒϥϦ • github.com/d-kuro/helmut • “helm

    template” ίϚϯυ૬౰ͷॲཧΛ࣮ߦ͢ΔϥΠϒϥϦ • Assert ༻ͷؔ਺Λఏڙ • github.com/google/go-cmp Λ࢖༻ͨ͠ diff Λදࣔ͢Δ
  6. Unit Testing Helm Charts • ྨࣅͷϥΠϒϥϦ • github.com/gruntwork-io/terratest/modules/helm • ಺෦Ͱ

    “helm tempalte —show-only” ίϚϯυΛ࣮ߦ͍ͯ͠Δ • github.com/Waterdrips/helmunit • Helm ͷύοέʔδΛ import ͢Δಉ༷ͷΞϓϩʔν • Assert ؔ਺ͳͲ͸ͳ͍
  7. Assert • ݱࡏ͸ Contains ؔ਺͔࣮͠૷͍ͯ͠ͳ͍ • Contains ؔ਺ʹ౉͞Εͨ Object Λ

    map ͔Β Get ͯ͠ 
 google/go-cmp Ͱൺֱͯ͠ߏ଄ମͷ diff Λදࣔ͢Δ • runtime.Object Λ௚઀౉͢ํ๏ͱ 
 YAML or JSON ͷ Manifest Λ౉͢ํ๏ͷ 2 ͭΛఏڙ • ౉͢ runtime.Object ͷ TypeMeta ͸ۭͳΒಈతʹઃఆ