Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Chart Λ Unit Test ͢Δ Kubernetes Meetup Tokyo #42 LT
Slide 2
Slide 2 text
I work for @ponde_m @d-kuro
Slide 3
Slide 3 text
Summary • Helm Chart ͷ Test ʹ͍ͭͯ • Helm Chart Λ Unit Test ͢ΔͨΊͷϥΠϒϥϦΛ࣮ͨ͠ • ࣮ͷৄࡉ • “k8s.io” ϥΠϒϥϦΛͬͨ Tips ͷհ
Slide 4
Slide 4 text
Testing Helm Charts --set autoscaling.enabled=false --set replicaCount=3
Slide 5
Slide 5 text
Testing Helm Charts • Helm ʹςετػߏ͕ଘࡏ͢Δ • “helm.sh/hook: test” annotation Λ༩ͨ͠ Pod ఆٛΛ༻ҙ͢Δ • “/templates/tests/“ ʹஔ͢Δ • “helm install” ͨ͋͠ͱʹ “helm test” Λ࣮ߦ͢Δ • Pod ͕ exit 0 Ͱऴྃ͢Εςετ͕ޭͨ͠ͱΈͳ͞ΕΔ
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
Testing Helm Charts • ͜ͷςετػߏͲͪΒ͔ͱ͍͑ Integration Test • values.yaml ʹఆٛͨ͠ Option ͕ҙਤͨ͠௨Γʹػೳ͢Δ͔ Ͳ͏͔ͳͲͷ Unit Test Ϩϕϧͷ֬ೝ͕͔ͨͬͨ͠
Slide 9
Slide 9 text
Unit Testing Helm Charts • Go Ͱ Helm Chart Λ Unit Test ͢Δ • “helm.sh/helm/v3” Λ import ͯ͠ “helm template” ίϚϯυͰ༻͍ͯ͠ΔؔΛݺͼग़͢ • ϨϯμϦϯά͞Εͨ YAML ͕ string Ͱ͑ΔͷͰ ͍͍ײ͡ʹൺֱ͢Δ
Slide 10
Slide 10 text
Unit Testing Helm Charts • ࡞ͨ͠ϥΠϒϥϦ • github.com/d-kuro/helmut • “helm template” ίϚϯυ૬ͷॲཧΛ࣮ߦ͢ΔϥΠϒϥϦ • Assert ༻ͷؔΛఏڙ • github.com/google/go-cmp Λ༻ͨ͠ diff Λදࣔ͢Δ
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
Unit Testing Helm Charts • ྨࣅͷϥΠϒϥϦ • github.com/gruntwork-io/terratest/modules/helm • ෦Ͱ “helm tempalte —show-only” ίϚϯυΛ࣮ߦ͍ͯ͠Δ • github.com/Waterdrips/helmunit • Helm ͷύοέʔδΛ import ͢Δಉ༷ͷΞϓϩʔν • Assert ؔͳͲͳ͍
Slide 15
Slide 15 text
Architecture map[ObjectKey]runtime.Object Rendered Manifests Exec helm template Render Convert Get User
Slide 16
Slide 16 text
Exec helm template
Slide 17
Slide 17 text
No content
Slide 18
Slide 18 text
Split Manifests
Slide 19
Slide 19 text
No content
Slide 20
Slide 20 text
Convert from Raw Manifest to runtime.Object
Slide 21
Slide 21 text
No content
Slide 22
Slide 22 text
Assert • ݱࡏ Contains ͔࣮͍ؔͯ͠͠ͳ͍ • Contains ؔʹ͞Εͨ Object Λ map ͔Β Get ͯ͠ google/go-cmp Ͱൺֱͯ͠ߏମͷ diff Λදࣔ͢Δ • runtime.Object Λ͢ํ๏ͱ YAML or JSON ͷ Manifest Λ͢ํ๏ͷ 2 ͭΛఏڙ • ͢ runtime.Object ͷ TypeMeta ۭͳΒಈతʹઃఆ
Slide 23
Slide 23 text
TypeMeta ͷهड़͕ෆཁʹͳΔ
Slide 24
Slide 24 text
Get GVK from runtime.Object
Slide 25
Slide 25 text
No content
Slide 26
Slide 26 text
Assert • Helm ʹΑ͘ΘΕΔ label annotation ͳͲͷ ࠩΛແࢹ͢ΔͨΊͷ Option Λఏڙ
Slide 27
Slide 27 text
Omit Metadata
Slide 28
Slide 28 text
No content
Slide 29
Slide 29 text
Conclude • Helm Chart Λ Unit Test ͢ΔͨΊͷϥΠϒϥϦΛ࡞ͬͨ • github.com/d-kuro/helmut • ྑ͚Ε͍ͬͯͩ͘͞
Slide 30
Slide 30 text
Thank You for Listening