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