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

Introduction to RUDDER Language

Rudder
February 04, 2020

Introduction to RUDDER Language

🎥 https://www.youtube.com/watch?v=A6klC0dwjhU
🧑 Benoît Peccate
📅 Configuration Management Camp 2020

RUDDER is a graphical configuration management tool, which is quite an unusual approach in this domain. This talk is about the why and how we are now introducing a new DSL for RUDDER. If you had never considered RUDDER because he didn't have a DSL, or if you want to discuss language with us, now is the right time to attend this talk!

Rudder

February 04, 2020
Tweet

More Decks by Rudder

Other Decks in Programming

Transcript

  1. Why ? More than one engine ▪ We currently support

    CFEngine ▪ We currently support DSC ▪ We want more (mgmt ? puppet ? ansible ?) 3
  2. Why ? Less code ? ▪ NCF doesn’t map directly

    to CFEngine and DSC ▪ We need a lot of extra code to make it NCF ▪ We could put this code into a generator 4
  3. Why ? New features ▪ NCF contains a lot of

    methods ▪ Adding a single feature may require to touch each one a. Ex: change logging ▪ We could add the feature quickly in the generator 5
  4. Why ? New features 6 F1 F2 F3 F4 M1

    x x x x M2 x x x x M3 x x x x F1 F2 F3 F4 M1 M2 M3 Compiler x x x x x x x
  5. Why ? Higher level language ▪ Be more descriptive ▪

    Be less prescriptive (less logic) ▪ Be more expressive (less code) 7
  6. Why ? Compiler ▪ Be stricter ▪ Have compile time

    errors ▪ Have higher level checks ▪ Have type checking 8
  7. Why ? Existing languages ▪ Compile time warning and errors

    - Be strict ▪ Separate compiler from interpreter ▪ We can add things to the language through the compiler ▪ Do not depend on the quirks of a given agent 10
  8. Why ? New DSL ! ▪ Yes and ▪ It’s

    better than poor data format ▪ Everyone should have his own DSL 11
  9. How ? Define a language ▪ Concepts ▪ Syntax ▪

    Document design decisions ▪ Try to rewrite existing code 13
  10. How ? Build a compiler ▪ In rust we trust

    ▪ Parse with nom ▪ Create new language structure in memory ▪ Check for sanity ▪ Generate for target engine language 14
  11. How ? Build a compiler ▪ Nom ▪ Parser combinator

    ▪ Easy development of parser ▪ Less easy error reporting 15
  12. How ? Build a translator ▪ To transparently keep existing

    code ▪ In rust we trust ▪ Convert to json and read this ▪ Convert what is obvious ▪ Have heuristics and guesses for new concepts ▪ Fail in case we don’t know and let the user fix it 17
  13. How ? Integrate it transparently ▪ Have the translator and

    compiler work in parallel with existing editor ▪ Make them report error when they see some ▪ Do not block the user ▪ When ready, translate existing code and start from there 18
  14. What ? First aim for techniques ▪ We want the

    language to be everywhere ▪ But let’s be incremental ▪ Target a language subset for creating techniques ▪ Nothing really new 20
  15. What ? Language concepts ▪ The resource ▪ Identified by

    parameters ▪ No parameter means it is single instance ▪ Identical instance parameter mean instance equality 22
  16. What ? Language concepts ▪ The state ▪ Applies on

    a resource ▪ Specified by parameters ▪ Either of a ‘present’ kind or ‘absent’ ▪ States are mutually exclusive except identical states 23
  17. What ? Example 24 resource File(path) File state content(bytes) {

    ... } resource OpenNTP() OpenNTP state configured() { File(“/etc/ntpd.conf”).content(“blah”) }
  18. What ? Language concepts ▪ The universe ▪ The only

    resource that is automatically instantiated with a state ▪ Has a main state that you must define 25
  19. What ? Language concepts ▪ Metadata ▪ Just key /

    values ▪ Starts with a ‘@’ ▪ Does not change the language ▪ Change how things are compiled for a given target 26
  20. What ? Technique metadata example 27 @name="Configure NTP" @description="NTP test

    technique" @version="1.0" @parameters=[ “server_name ]
  21. What ? Language concepts ▪ Classic types: dict, array, string,

    integer, boolean ▪ A parameter can have a type and a default value ▪ Default type is “string” ▪ Or detected from default value 28
  22. What ? Language concepts ▪ Type: dict ▪ A JSON

    like object - dict in python - Hashmap - ... 29
  23. What ? Language concepts ▪ Type: Enum ▪ One of

    many (C / rust enum without data) ▪ Can be inferred from other enum ▪ Ex: we can infer a. debian from debian-9 b. OK from success 31
  24. What ? Enum example 32 enum outcome { kept, repaired,

    error } global enum os { ubuntu, debian } enum os ~> family { ubuntu -> debian, debian -> debian }
  25. What ? Language concepts ▪ Case: Enum ▪ We can

    check that all cases are handled ▪ A case must have all cases or a default ▪ Accept complex boolean expression base on enum ▪ Having a default that does nothing is acceptable as long as it is explicit 33
  26. What ? Enum example 34 case { ubuntu => File("/tmp").permissions("root",

    "root", "g+w"), os:debian | centos => File("/tmp").permissions("user", "user", "g+w") default => error(“BUG”) } case { outvar =~ repaired => log(“repaired”) default => noop }
  27. What ? Mapping with existing concepts ▪ Generic method :

    state (all … until next step) ▪ Method category : resource ▪ Technique : resource with a state ▪ Outcome, conditions, classes : enum ▪ Hardclasses : global enum ▪ Report component : metadata 35
  28. What ? Full technique example 36 @format=0 @name="Configure NTP" @description="test"

    @version="1.0" @parameters=[] resource Configure_NTP() Configure_NTP state technique() { @component = "Package present" package("ntp").present() as ntp_present }
  29. When ? First release when it’s ready ▪ Rudder 6.1

    ▪ But let’s be incremental ▪ Target a language subset to create techniques 38
  30. When ? Can still be changed ▪ Language definition still

    open ▪ First version is for testing applicability ▪ Your input can improve things 39
  31. When ? Next, target the rest ▪ Generic methods writing

    in rudder-lang ▪ Everything in rudder-lang ? ▪ New language elements ▪ Key value store ? 40
  32. When ? Language concepts ▪ Function ▪ Takes an input

    and gives matching output ▪ Output for a given input should not change ▪ Can be a combination of functions 41
  33. When ? Language concepts ▪ Measure ▪ Do not modify

    a resource ▪ Get information that may change or not ▪ Can be a combination of measures and functions 42
  34. When ? Language concepts ▪ Action ▪ Modifies the state

    of a resource ▪ Can be a combinations of actions, functions, and measures 43
  35. When ? Language concepts ▪ State ▪ Define a resource

    state ▪ Do not change things that don’t need ▪ Update things that need ▪ Can be a combination of states and functions 44
  36. When ? Language concepts ▪ Unsafe ▪ Allows things that

    should not usually be allowed ▪ Allows an action to be used in a state a. Ex: restart a service after a file change ▪ Allows an external command to be used in a measure a. Ex: shell command 45
  37. When ? Language concepts ▪ Templating ▪ Integrate template parsing

    in the language ▪ Detect template error and missing variables at compile time 47