Ole Michaelis & Sönke Ruempler | Jimdo
Make it SOLID
Software Architecture for System
Administrators
OSDC 2014
Ole Michaelis
“Open Source Rockstar”
@CodeStars
github.com/nesQuick
codestars.eu
OSDC 2014
Sönke
Ruempler
“Chief Trolling Officer”
@s0enke
github.com/s0enke
ruempler.eu
OSDC 2014
Jimdo
OSDC 2014
because infrastructure development is
neither a Jenga game!
S.O.L.I.D
OSDC 2014
a little poll!
http://images.fineartamerica.com/images-medium-large/live-long-mr-spock-tobias-woelki.jpg
OSDC 2014
OSDC 2014
S O L I D
OSDC 2014
A
dev/ops
story
Ole
as
Junior Admin
Sönke
as
Dr. Software
OSDC 2014
the basics
OSDC 2014
configuration management
Idempotent
Declarative
Convergent
Abstract
OSDC 2014
software architecture
VS.
36 years
>2000 years
OSDC 2014
OSDC 2014
node web-1 {
$role = 'web-app-a'
$has_apache = true;
include php5
}
node web-2 {
$role = 'web-app-b'
$has_fcgi=t...
OSDC 2014
class php5 {
if ($::has_fcgi)
package { 'php5-cli' : ensure => installed }
}
if ($::has_apache) {
package { 'php...
OSDC 2014
class php5(
$has_fcgi = false,
$has_apache = false,
$role = undef
) {
if ($has_fcgi)
package { 'php5-cli' : ensu...
OSDC 2014
node 'web-1' {
$role = 'web-app-a'
$has_apache = true
class { 'php5' :
has_apache => true,
role => 'web-app-a'
}...
OSDC 2014
Would you solder a
lamp directly to the
electrical wiring in a
wall?
Dependency
Inversion
OSDC 2014
OSDC 2014
class php5(
$has_fcgi = false,
$has_apache = false,
$role = undef
) {
if ($has_fcgi)
package { 'php5-cli' : ensu...
OSDC 2014
Stuff tends to
get big
Beware of god classes!
OSDC 2014
if ($lighttpd) {
package { 'php5-cgi': }
configdir { '/etc/php5/cgi': require => Package['php5-cgi'] }
configdir...
OSDC 2014
OSDC 2014
?
OSDC 2014
OSDC 2014
rspec-puppet
test-kitchen
OSDC 2014
OSDC 2014
describe :node => 'web-1' do
it { should contain_package ('php5-fcgi') }
end
describe :node => 'web-2' do
it { s...
OSDC 2014
describe :class => 'php5::fcgi' do
it { should contain_package('php5-cli') }
end
describe :class => 'php5::apach...
OSDC 2014
Just because you can,
doesn’t mean you
should!
Single
Responsibility
OSDC 2014
describe :node => 'web-1' do
it { should include_class('php5::fcgi') }
it { should contain_package('php5-fcgi') ...
OSDC 2014
OSDC 2014
“programs […] are changed by adding
new code, rather than by changing
existing code”
Open Close
Principle
OSDC 2014
OSDC 2014
new
requirements...
now web app 1 needs a second
node
node web-1 {
$role = 'web-app-a'
include php5::apache
}
no...
OSDC 2014
OSDC 2014
OSDC 2014
class role::web-app-a {
include php5::apache
}
node web-1 {
include role::web-app-
a
}
node web-1a {
include rol...
OSDC 2014
>
OSDC 2014
OSDC 2014
?
class php5::fcgi($role = undef) {
if ($role == 'web-app-c') {
package { 'php5-web-app-c-special-module' }
file...
OSDC 2014
Don’t call us,
we call you!
Hollywood
Principle
OSDC 2014
class role::web-app-c::special-php-stuff {
package { 'php5-web-app-c-special-module' }
file { '/etc/php5/php.ini...
OSDC 2014
class php5::fcgi($include_after_package_install = undef) {
package { 'php5-fcgi' : ensure => installed }
if ($in...
OSDC 2014
class role::web-app-c {
include php5::apache
class { 'php5::fcgi' :
include_after_package_install => 'profile::w...
OSDC 2014
OSDC 2014
class profile::web-app-c::special-php-stuff {
package { 'php5-web-app-c-special-module' }
file { '/etc/php5/php....
OSDC 2014
define php5::specialconfig(
$ensure = present,
$sapi,
$module,
$key,
$value,
$section = undef,
$path = '/etc/php...
OSDC 2014
OSDC 2014
?
OSDC 2014
“puppet separate code and data”
I’m feeling lucky
OSDC 2014
# /etc/puppet/hieradata/web1.yaml
---
classes:
- profile::web-app-a
# /etc/puppet/hieradata/web1a.yaml
---
class...
OSDC 2014
node default {
hiera_include('classes')
}
node web-1 {
include role::web-app-a
}
node web-1a {
include role::web...
OSDC 2014
hiera
AWS/Cloudformation LDAP
DNS
your selfwritten
stuff
OSDC 2014
OSDC 2014
OSDC 2014
OSDC 2014
What about
I and L
in SOLID?
OSDC 2014
You want me to plug
this in, where?
Interface
Segregation
OSDC 2014
If it looks like a duck,
quacks like a duck, but
need batteries - you
probably have the
wrong abstraction!
Lisko...
OSDC 2014
S O L I D
OSDC 2014
OSDC 2014
Structure your code!Node
ProfileProfilesRole ProfileModules
Resources
OSDC 2014
Puppet forge
puppet module registry
OSDC 2014
Librarian Puppet
r10k
Berkshelf (chef)
OSDC 2014
stdmod
https://github.com/stdmod
OSDC 2014
sandboxed
development
https://github.com/mlafeldt/skeleton-cookbook
https://github.com/Jimdo/puppet-skeleton
OSDC 2014
server spec
http://serverspec.org/
beaker
(puppet)
https://github.com/puppetlabs/beaker
OSDC 2014
Thank you!
OSDC 2014
@CodeStars
ole@jimdo.com
@s0enke
soenke@jimdo.com
Questions?
OSDC 2014
*I ’m just a blank slide*
OSDC 2014
Sources
• http://www.slideshare.net/PuppetLabs/garethrushgrove-puppetconf
• http://www.slideshare.net/PuppetLabs...
Upcoming SlideShare
Loading in...5
×

OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architecture for System Administrators

515

Published on

Starting with Chef or Puppet as a System Administrator will lead you to a problem where you are not sure what’s the best solution of a problem in terms of software architecture.
We will give you a brief overview of general well known and battle tested software patterns, which also applies to infrastructure management code. In addition, we‘ll also show Antipatterns, and best practices.

Published in: Software, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
515
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

OSDC 2014: Ole Michaelis & Sönke Rümpler: Make it SOLID - Software Architecture for System Administrators

  1. 1. Ole Michaelis & Sönke Ruempler | Jimdo Make it SOLID Software Architecture for System Administrators
  2. 2. OSDC 2014 Ole Michaelis “Open Source Rockstar” @CodeStars github.com/nesQuick codestars.eu
  3. 3. OSDC 2014 Sönke Ruempler “Chief Trolling Officer” @s0enke github.com/s0enke ruempler.eu
  4. 4. OSDC 2014 Jimdo
  5. 5. OSDC 2014 because infrastructure development is neither a Jenga game! S.O.L.I.D
  6. 6. OSDC 2014 a little poll! http://images.fineartamerica.com/images-medium-large/live-long-mr-spock-tobias-woelki.jpg
  7. 7. OSDC 2014
  8. 8. OSDC 2014 S O L I D
  9. 9. OSDC 2014 A dev/ops story Ole as Junior Admin Sönke as Dr. Software
  10. 10. OSDC 2014 the basics
  11. 11. OSDC 2014 configuration management Idempotent Declarative Convergent Abstract
  12. 12. OSDC 2014 software architecture VS. 36 years >2000 years
  13. 13. OSDC 2014
  14. 14. OSDC 2014 node web-1 { $role = 'web-app-a' $has_apache = true; include php5 } node web-2 { $role = 'web-app-b' $has_fcgi=true include php5 } # has both enabled, but needs a special config node web-3 { $role = 'web-app-c' $has_fcgi=true $has_apache=true include php5 } Web App 1 Web App 2 Web App 3
  15. 15. OSDC 2014 class php5 { if ($::has_fcgi) package { 'php5-cli' : ensure => installed } } if ($::has_apache) { package { 'php5-apache' : ensure => installed } } if ($::role == 'web-app-c') package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' } } } Global variable! Out of Context! No abstraction
  16. 16. OSDC 2014 class php5( $has_fcgi = false, $has_apache = false, $role = undef ) { if ($has_fcgi) package { 'php5-cli' : ensure => installed } } if ($has_apache) { package { 'php5-apache' : ensure => installed } } if ($role == 'web-app-c') { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c', require => Package[php-fcgi] } }
  17. 17. OSDC 2014 node 'web-1' { $role = 'web-app-a' $has_apache = true class { 'php5' : has_apache => true, role => 'web-app-a' } } node 'web-2' { $role = 'web-app-b' $has_fcgi = true class { 'php5' : has_fcgi => true, role => 'web-app-b' } } Injection! Injection!
  18. 18. OSDC 2014 Would you solder a lamp directly to the electrical wiring in a wall? Dependency Inversion
  19. 19. OSDC 2014
  20. 20. OSDC 2014 class php5( $has_fcgi = false, $has_apache = false, $role = undef ) { if ($has_fcgi) package { 'php5-cli' : ensure => installed } } if ($has_apache) { package { 'php5-apache' : ensure => installed } } if ($role == 'web-app-c') { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' require => Package[php-fcgi] } } }
  21. 21. OSDC 2014 Stuff tends to get big Beware of god classes!
  22. 22. OSDC 2014 if ($lighttpd) { package { 'php5-cgi': } configdir { '/etc/php5/cgi': require => Package['php5-cgi'] } configdir { '/etc/php5/cgi/conf.d': require => Package['php5-cgi'] } if ($testserver) { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini-testserver', require => Package['php5-cgi'] } } else { if ($cms ) { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini-cms', require => Package['php5-cgi'] } } else { if ($mgmt ) { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini-mgmt', require => Package['php5-cgi'] } } else { if ($lc ) { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini-lc. jimdo.com', require => Package['php5-cgi'] } } else { configfile { '/etc/php5/cgi/php.ini': sourcename => 'php5/cgi/php.ini', require => Package['php5-cgi'] } } } } } configfile { '/etc/php5/cgi/conf.d/pdo.ini': sourcename => 'php5/cgi/conf.d/pdo.ini', require => Package['php5-cgi'] } }
  23. 23. OSDC 2014
  24. 24. OSDC 2014 ?
  25. 25. OSDC 2014
  26. 26. OSDC 2014 rspec-puppet test-kitchen
  27. 27. OSDC 2014
  28. 28. OSDC 2014 describe :node => 'web-1' do it { should contain_package ('php5-fcgi') } end describe :node => 'web-2' do it { should contain_package ('php5-apache2' ) } end describe :node => 'web-3' do it { should contain_package ('php5-fcgi') } it { should contain_package ('php5-apache2' ) } end Test php5 class: Install Package ?
  29. 29. OSDC 2014 describe :class => 'php5::fcgi' do it { should contain_package('php5-cli') } end describe :class => 'php5::apache' do it { should contain_package('php5-apache2') } end class php5::fgci { package { 'php5-cgi' : ensure => installed } } class php5::apache { package { 'php5-apache' : ensure => installed } }
  30. 30. OSDC 2014 Just because you can, doesn’t mean you should! Single Responsibility
  31. 31. OSDC 2014 describe :node => 'web-1' do it { should include_class('php5::fcgi') } it { should contain_package('php5-fcgi') } end describe :node => 'web-2' do it { should include_class('php5::apache') } it { should contain_package('php5-apache2') } end node web-1 { include php5::apache } node web-2 { include php5::fcgi } Tests Code
  32. 32. OSDC 2014
  33. 33. OSDC 2014 “programs […] are changed by adding new code, rather than by changing existing code” Open Close Principle
  34. 34. OSDC 2014
  35. 35. OSDC 2014 new requirements... now web app 1 needs a second node node web-1 { $role = 'web-app-a' include php5::apache } node web-1a { $role = 'web-app-a' include php5::apache }
  36. 36. OSDC 2014
  37. 37. OSDC 2014
  38. 38. OSDC 2014 class role::web-app-a { include php5::apache } node web-1 { include role::web-app- a } node web-1a { include role::web-app- a } Our new role! And nodes just include it!
  39. 39. OSDC 2014 >
  40. 40. OSDC 2014
  41. 41. OSDC 2014 ? class php5::fcgi($role = undef) { if ($role == 'web-app-c') { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c', require => Package[php-fcgi] } } }
  42. 42. OSDC 2014 Don’t call us, we call you! Hollywood Principle
  43. 43. OSDC 2014 class role::web-app-c::special-php-stuff { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' } } 1. Split out the special case into its own class.
  44. 44. OSDC 2014 class php5::fcgi($include_after_package_install = undef) { package { 'php5-fcgi' : ensure => installed } if ($include_after_package_install) include $include_after_package_install Package['php5-fcgi'] -> Class[$include_after_package_install] } } 2. Make the special case pluggable and reusable. 2a. And name it abstract.
  45. 45. OSDC 2014 class role::web-app-c { include php5::apache class { 'php5::fcgi' : include_after_package_install => 'profile::web-app-c::special-php-stuff' } } 3. Pass the special case as dependency in our web-app-c.
  46. 46. OSDC 2014
  47. 47. OSDC 2014 class profile::web-app-c::special-php-stuff { package { 'php5-web-app-c-special-module' } file { '/etc/php5/php.ini' : source => 'puppet:///modules/php5/php.ini-web-app-c' } } ?
  48. 48. OSDC 2014 define php5::specialconfig( $ensure = present, $sapi, $module, $key, $value, $section = undef, $path = '/etc/php5/%s/conf.d/%s.ini' ) { ini_setting { $title: ensure => $ensure, path => sprintf($path, $sapi, $module), section => $section, setting => $key, value => $value, require => Package["php5-${sapi}"] } }
  49. 49. OSDC 2014
  50. 50. OSDC 2014 ?
  51. 51. OSDC 2014 “puppet separate code and data” I’m feeling lucky
  52. 52. OSDC 2014 # /etc/puppet/hieradata/web1.yaml --- classes: - profile::web-app-a # /etc/puppet/hieradata/web1a.yaml --- classes: - profile::web-app-a # /etc/puppet/hieradata/web2.yaml --- classes: - profile::web-app-c # /etc/puppet/hieradata/web3.yaml --- classes: - profile::web-app-c puppet-hiera example in YAML
  53. 53. OSDC 2014 node default { hiera_include('classes') } node web-1 { include role::web-app-a } node web-1a { include role::web-app-a } node web-2 { include role::web-app-b } node web-3 { include role::web-app-c }
  54. 54. OSDC 2014 hiera AWS/Cloudformation LDAP DNS your selfwritten stuff
  55. 55. OSDC 2014
  56. 56. OSDC 2014
  57. 57. OSDC 2014
  58. 58. OSDC 2014 What about I and L in SOLID?
  59. 59. OSDC 2014 You want me to plug this in, where? Interface Segregation
  60. 60. OSDC 2014 If it looks like a duck, quacks like a duck, but need batteries - you probably have the wrong abstraction! Liskov Substitution
  61. 61. OSDC 2014 S O L I D
  62. 62. OSDC 2014
  63. 63. OSDC 2014 Structure your code!Node ProfileProfilesRole ProfileModules Resources
  64. 64. OSDC 2014 Puppet forge puppet module registry
  65. 65. OSDC 2014 Librarian Puppet r10k Berkshelf (chef)
  66. 66. OSDC 2014 stdmod https://github.com/stdmod
  67. 67. OSDC 2014 sandboxed development https://github.com/mlafeldt/skeleton-cookbook https://github.com/Jimdo/puppet-skeleton
  68. 68. OSDC 2014 server spec http://serverspec.org/ beaker (puppet) https://github.com/puppetlabs/beaker
  69. 69. OSDC 2014 Thank you!
  70. 70. OSDC 2014 @CodeStars ole@jimdo.com @s0enke soenke@jimdo.com Questions?
  71. 71. OSDC 2014 *I ’m just a blank slide*
  72. 72. OSDC 2014 Sources • http://www.slideshare.net/PuppetLabs/garethrushgrove-puppetconf • http://www.slideshare.net/PuppetLabs/alessandro-franceschi-new • https://github.com/jedi4ever/stop-the-fork • http://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational- pictures/ • https://speakerdeck.com/jfryman/refactoring-puppet • http://www.clker.com/cliparts/e/2/a/d/1206574733930851359Ryan_Taylor_Green_Tick.svg.med. png • http://www.craigdunn.org/2012/05/239/ • http://cdn.slashgear.com/wp-content/uploads/2012/10/google-datacenter-tech-13.jpg • http://deviq.com/Media/Default/Article/Dont-Call-Us-Well-Call-You-Jun-2013.png • http://www.timeshighereducation.co.uk/Pictures/web/g/q/g/copy_paste_keyboard_button_450.jpg • http://sanremo.com.au/wp-content/uploads/2013/05/lasagna.jpg • http://4.bp.blogspot. com/_9kQQgQD35rY/SaV5p8YBGhI/AAAAAAAAAkg/HOvlhIo7yGI/s400/06_Red_Green_Refactor. JPG • http://www.thelolshop.com/wp-content/uploads/2012/11/20121126-101937.jpg •
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×