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

Cookbook Reusability

someara
October 02, 2014

Cookbook Reusability

Chef Summit 2014

someara

October 02, 2014
Tweet

More Decks by someara

Other Decks in Technology

Transcript

  1. Cookbook Reusability!
    Chef Community Summit
    2014

    View full-size slide

  2. A Year in Review

    View full-size slide

  3. Diversification

    View full-size slide

  4. 7zip!
    apache2!
    ark!
    application*!
    couchdb!
    Imagemagick!
    java

    View full-size slide

  5. logrotate!
    mercurial!
    munin!
    nagios!
    nginx!
    ntp!
    openvpn

    View full-size slide

  6. pacman!
    postgresql!
    python!
    reprepro!
    rabbitmq!
    runit!
    supervisor

    View full-size slide

  7. selinux!
    tmux!
    varnish !
    wordpress!

    View full-size slide

  8. Supermarket
    https://www.flickr.com/photos/mobilestreetlife/10885044043

    View full-size slide

  9. • Escaped the tyranny of JIRA!
    • Moved to Github Issues!
    • Automated CLA checking!
    • OSS Artifact Repository

    View full-size slide

  10. 2009
    0.5.2
    Chef
    Vagrant
    ChefSpec
    0.1.0
    0.0.2
    Minitest-Chef
    Berkshelf
    Test Kitchen
    2010
    0.9.0
    2011
    0.10.0
    2012
    10.12.0
    1.0.0
    0.2.0
    1.0.0
    0.7.0
    1.0.0
    2013 2014
    1.0.0
    2.0.0
    1.0.0
    2.0.0
    1.4.0
    11.0.0 12.0.0
    1.6.5
    3.0.0
    3.0.0
    1.2.2
    ServerSpec
    ChefDK
    0.0.1 2.0.0
    0.2.2
    TDI Capability
    0.8.0

    View full-size slide

  11. yum!
    yum-*!
    jenkins!
    mysql!
    httpd

    View full-size slide

  12. The Evolution of a Chef
    Cookbook

    View full-size slide

  13. Stage 1 - Paradise
    https://www.flickr.com/photos/nattu/1385100375/

    View full-size slide

  14. test / repair
    test / repair
    test / repair

    View full-size slide

  15. Easy to read

    Easy to grok

    Easy to test
    }

    View full-size slide

  16. Stage 2 - if statements

    View full-size slide

  17. logic
    compiled into
    resource collection

    View full-size slide

  18. Resource
    DSL
    }
    Just
    Ruby
    }

    View full-size slide

  19. Resource
    DSL
    }
    Just
    Ruby
    } }Chef

    View full-size slide

  20. Stage 3 - Crazytown
    https://www.flickr.com/photos/kwl/4595324641

    View full-size slide

  21. Reusable is useful

    View full-size slide

  22. Cross-platform is useful

    View full-size slide

  23. We desire useful things

    View full-size slide

  24. Platform idioms are hard

    View full-size slide

  25. Keeping the Dream Alive
    https://www.flickr.com/photos/kalexanderson/7014655351/

    View full-size slide

  26. Most people just write their
    own cookbooks from
    scratch

    View full-size slide

  27. I really really really want
    reusable cross-platform
    cookbooks

    View full-size slide

  28. Lessons Learned

    View full-size slide

  29. Attributes are routinely
    abused
    https://www.flickr.com/photos/jabberwocky381/2828863789

    View full-size slide

  30. Attributes are an
    interface

    View full-size slide

  31. Attributes are tunable
    knobs

    View full-size slide

  32. You probably just want a
    variable

    View full-size slide

  33. Or even a method

    View full-size slide

  34. Using an attribute to track
    state during a Chef run
    causes tears and sorrow

    View full-size slide

  35. Prefer resource parameters

    View full-size slide

  36. Primitives are more useful
    than opinionated policy

    View full-size slide

  37. “They’re Just Resources”!
    !
    LWRP is Googleable

    View full-size slide

  38. Zoom out a level!
    !
    Think about services and
    runtimes, not files and processes

    View full-size slide

  39. Singleton resources are good but
    confusing. Possibly even
    dangerous.!
    !
    Multiple instance support is better!
    !
    Cross-platform resources are best

    View full-size slide

  40. BDD / TDD yields high
    quality cookbooks
    https://www.flickr.com/photos/glenirah/4376553184

    View full-size slide

  41. Test Kitchen!
    ServerSpec / Minitest / Bats!
    ChefSpec

    View full-size slide

  42. 2009
    0.5.2
    Chef
    Vagrant
    ChefSpec
    0.1.0
    0.0.2
    Minitest-Chef
    Berkshelf
    Test Kitchen
    2010
    0.9.0
    2011
    0.10.0
    2012
    10.12.0
    1.0.0
    0.2.0
    1.0.0
    0.7.0
    1.0.0
    2013 2014
    1.0.0
    2.0.0
    1.0.0
    2.0.0
    1.4.0
    11.0.0 12.0.0
    1.6.5
    3.0.0
    3.0.0
    1.2.2
    ServerSpec
    ChefDK
    0.0.1 2.0.0
    0.2.2
    This Slide Again
    0.8.0

    View full-size slide

  43. Full test coverage is tedious

    View full-size slide

  44. Full test coverage is totally
    worth it

    View full-size slide

  45. Let users bring their own
    configurations

    View full-size slide

  46. It is better to add to a
    resource_collection than to
    monkey patch it

    View full-size slide

  47. Configuration files are the
    brains of a service

    View full-size slide

  48. Manage minimal
    configuration to get a service
    running

    View full-size slide

  49. Offload further configuration
    to the user

    View full-size slide

  50. conf.d is your friend

    View full-size slide

  51. Hide everything else
    inside a resource

    View full-size slide

  52. Add resource parameters
    when appropriate

    View full-size slide

  53. Cross-platform cookbooks
    are hard
    https://www.flickr.com/photos/glenirah/4376553184

    View full-size slide

  54. Cross-platform resources
    are even harder

    View full-size slide

  55. They can be done!

    View full-size slide

  56. Create a resource

    View full-size slide

  57. Create a provider

    View full-size slide

  58. Subclass platform providers

    View full-size slide

  59. Set provider default for
    platforms

    View full-size slide

  60. Do Repeat Yourself

    View full-size slide

  61. Some resources are often
    the duplicated across
    providers

    View full-size slide

  62. That’s fine. It’s the pattern
    as a whole that’s important

    View full-size slide

  63. Maximize for grokability

    View full-size slide

  64. People will be reading your
    code for the first time
    during operations work

    View full-size slide

  65. Init systems are annoying

    View full-size slide

  66. Using a service resource
    usually requires file or
    template resources in
    addition to
    service[thingd]

    View full-size slide

  67. Debconf!
    Docker!
    LaunchD!
    Runit!
    SMF!
    Simple!
    SystemD!
    Sysvinit!
    Upstart!
    Windows Services

    View full-size slide

  68. Subclassing is awesome

    View full-size slide

  69. Customize before recipe
    compilation

    View full-size slide

  70. Going Forward

    View full-size slide

  71. Cookbooks that ship
    resource primitives

    View full-size slide

  72. More examples to copy

    View full-size slide

  73. More breaking backwards
    compatibility (sorry)

    View full-size slide

  74. Providers implemented
    with Docker containers
    (why not?)

    View full-size slide

  75. Tell me what you think

    View full-size slide

  76. Please don’t hurt me =)

    View full-size slide