Showing with 899 additions and 103 deletions.
  1. +8 −1 CHANGELOG.md
  2. +30 −0 README.md
  3. +146 −1 REFERENCE.md
  4. +6 −5 lib/puppet/provider/sensu_asset/sensuctl.rb
  5. +6 −5 lib/puppet/provider/sensu_check/sensuctl.rb
  6. +6 −5 lib/puppet/provider/sensu_entity/sensuctl.rb
  7. +6 −5 lib/puppet/provider/sensu_filter/sensuctl.rb
  8. +6 −5 lib/puppet/provider/sensu_handler/sensuctl.rb
  9. +6 −5 lib/puppet/provider/sensu_hook/sensuctl.rb
  10. +6 −5 lib/puppet/provider/sensu_mutator/sensuctl.rb
  11. +6 −5 lib/puppet/provider/sensu_role/sensuctl.rb
  12. +6 −5 lib/puppet/provider/sensu_role_binding/sensuctl.rb
  13. +5 −1 lib/puppet/provider/sensuctl.rb
  14. +40 −2 lib/puppet/type/sensu_asset.rb
  15. +41 −2 lib/puppet/type/sensu_check.rb
  16. +39 −3 lib/puppet/type/sensu_entity.rb
  17. +39 −2 lib/puppet/type/sensu_filter.rb
  18. +39 −2 lib/puppet/type/sensu_handler.rb
  19. +38 −2 lib/puppet/type/sensu_hook.rb
  20. +38 −2 lib/puppet/type/sensu_mutator.rb
  21. +42 −2 lib/puppet/type/sensu_role.rb
  22. +46 −2 lib/puppet/type/sensu_role_binding.rb
  23. +1 −1 metadata.json
  24. +15 −0 spec/acceptance/sensu_check_spec.rb
  25. +2 −2 spec/unit/provider/sensu_asset/sensuctl_spec.rb
  26. +2 −2 spec/unit/provider/sensu_check/sensuctl_spec.rb
  27. +2 −2 spec/unit/provider/sensu_entity/sensuctl_spec.rb
  28. +2 −2 spec/unit/provider/sensu_filter/sensuctl_spec.rb
  29. +2 −2 spec/unit/provider/sensu_handler/sensuctl_spec.rb
  30. +2 −2 spec/unit/provider/sensu_hook/sensuctl_spec.rb
  31. +2 −2 spec/unit/provider/sensu_mutator/sensuctl_spec.rb
  32. +2 −2 spec/unit/provider/sensu_role/sensuctl_spec.rb
  33. +2 −2 spec/unit/provider/sensu_role_binding/sensuctl_spec.rb
  34. +28 −1 spec/unit/sensu_asset_spec.rb
  35. +30 −3 spec/unit/sensu_check_spec.rb
  36. +28 −1 spec/unit/sensu_entity_spec.rb
  37. +28 −1 spec/unit/sensu_filter_spec.rb
  38. +34 −7 spec/unit/sensu_handler_spec.rb
  39. +28 −1 spec/unit/sensu_hook_spec.rb
  40. +28 −1 spec/unit/sensu_mutator_spec.rb
  41. +28 −1 spec/unit/sensu_role_binding_spec.rb
  42. +28 −1 spec/unit/sensu_role_spec.rb
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log

## [v3.5.0](https://github.com/sensu/sensu-puppet/tree/v3.5.0) (2019-07-21)
## [v3.6.0](https://github.com/sensu/sensu-puppet/tree/v3.6.0) (2019-08-16)
[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v3.5.0...v3.6.0)

**Merged pull requests:**

- Better support for resources in different namespaces [\#1126](https://github.com/sensu/sensu-puppet/pull/1126) ([treydock](https://github.com/treydock))

## [v3.5.0](https://github.com/sensu/sensu-puppet/tree/v3.5.0) (2019-07-22)
[Full Changelog](https://github.com/sensu/sensu-puppet/compare/v3.4.1...v3.5.0)

**Merged pull requests:**
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [Sensu backend cluster](#sensu-backend-cluster)
* [Adding backend members to an existing cluster](#adding-backend-members-to-an-existing-cluster)
* [Large Environment Considerations](#large-environment-considerations)
* [Composite Names for Namespaces](#composite-names-for-namespaces)
4. [Reference](#reference)
* [Facts](#facts)
5. [Limitations - OS compatibility, etc.](#limitations)
Expand Down Expand Up @@ -482,6 +483,35 @@ class { '::sensu::backend':
}
```
### Composite Names for Namespaces
All resources that support having a `namespace` also support a composite name to define the namespace.
For example, the `sensu_check` with name `check-cpu in team1` would be named `check-cpu` and put into the `team1` namespace.
Using composite names is necessary if you wish to have multiple resources with the same name but in different namespaces.
For example to define the same check in two namespaces using the same check name:
```puppet
sensu_check { 'check-cpu in default':
ensure => 'present',
command => 'check-cpu.sh -w 75 -c 90',
interval => 60,
subscriptions => ['linux'],
}
sensu_check { 'check-cpu in team1':
ensure => 'present',
command => 'check-cpu.sh -w 75 -c 90',
interval => 60,
subscriptions => ['linux'],
}
```

The example above would add the `check-cpu` check to both the `default` and `team1` namespaces.

**NOTE:** If you use composite names for namespaces, the `namespace` property takes precedence.

## Reference

### Facts
Expand Down
147 changes: 146 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,17 @@ sensu_asset { 'test':
}
```

##### Create an asset with namespace `dev` in the name

```puppet
sensu_asset { 'test in dev':
ensure => 'present',
url => 'http://example.com/asset/example.tar',
sha512 => '4f926bf4328fbad2b9cac873d117f771914f4b837c9c85584c38ccf55a3ef3c2e8d154812246e5dda4a87450576b2c58ad9ab40c9e2edc31b288d066b195b21b',
filters => ["entity.system.os == 'linux'"],
}
```

#### Properties

The following properties are available in the `sensu_asset` type.
Expand Down Expand Up @@ -957,6 +968,12 @@ The following parameters are available in the `sensu_asset` type.

namevar

The name of the asset.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the asset.

### sensu_check
Expand Down Expand Up @@ -1000,6 +1017,18 @@ sensu_check { 'test':
}
```

##### Create a check with namespace `dev` in the name

```puppet
sensu_check { 'test in dev':
ensure => 'present',
command => 'check-http.rb',
subscriptions => ['demo'],
handlers => ['email'],
interval => 60,
}
```

#### Properties

The following properties are available in the `sensu_check` type.
Expand Down Expand Up @@ -1168,6 +1197,12 @@ The following parameters are available in the `sensu_check` type.

namevar

The name of the check.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the check.

### sensu_cluster_member
Expand Down Expand Up @@ -1437,6 +1472,15 @@ sensu_entity { 'test':
}
```

##### Create an entity with namespace `dev` in the name

```puppet
sensu_entity { 'test in dev':
ensure => 'present',
entity_class => 'proxy',
}
```

#### Properties

The following properties are available in the `sensu_entity` type.
Expand Down Expand Up @@ -1503,7 +1547,13 @@ The following parameters are available in the `sensu_entity` type.

namevar

The unique name of the entity
The name of the entity.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the entity.

### sensu_event

Expand Down Expand Up @@ -1590,6 +1640,16 @@ sensu_filter { 'test':
}
```

##### Create a filter with namespace `dev` in the name

```puppet
sensu_filter { 'test in dev':
ensure => 'present',
action => 'allow',
expressions => ["event.entity.labels.environment == 'production'"],
}
```

#### Properties

The following properties are available in the `sensu_filter` type.
Expand Down Expand Up @@ -1640,6 +1700,12 @@ The following parameters are available in the `sensu_filter` type.

namevar

The name of the filter.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the filter.

### sensu_handler
Expand Down Expand Up @@ -1667,6 +1733,16 @@ sensu_handler { 'test':
}
```

##### Create a handler with namespace `dev` in the name

```puppet
sensu_handler { 'test in dev':
ensure => 'present',
type => 'pipe',
command => 'notify.rb'
}
```

#### Properties

The following properties are available in the `sensu_handler` type.
Expand Down Expand Up @@ -1757,6 +1833,12 @@ The following parameters are available in the `sensu_handler` type.

namevar

The name of the handler.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the handler.

### sensu_hook
Expand All @@ -1779,6 +1861,15 @@ sensu_hook { 'test':
}
```

##### Create a hook with namespace `dev` in the name

```puppet
sensu_hook { 'test in dev':
ensure => 'present',
command => 'ps aux',
}
```

#### Properties

The following properties are available in the `sensu_hook` type.
Expand Down Expand Up @@ -1831,6 +1922,12 @@ The following parameters are available in the `sensu_hook` type.

namevar

The name of the hook.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the hook.

### sensu_ldap_auth
Expand Down Expand Up @@ -1960,6 +2057,15 @@ sensu_mutator { 'example':
}
```

##### Create a mutator with namespace `dev` in the name

```puppet
sensu_mutator { 'example in dev':
ensure => 'present',
command => 'example-mutator.rb',
}
```

#### Properties

The following properties are available in the `sensu_mutator` type.
Expand Down Expand Up @@ -2016,6 +2122,12 @@ The following parameters are available in the `sensu_mutator` type.

namevar

The name of the mutator.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the mutator.

### sensu_namespace
Expand Down Expand Up @@ -2163,6 +2275,15 @@ sensu_role { 'test':
}
```

##### Add a role with namespace `dev` in the name

```puppet
sensu_role { 'test in dev':
ensure => 'present',
rules => [{'verbs' => ['get','list'], 'resources' => ['checks'], 'resource_names' => ['']}],
}
```

#### Properties

The following properties are available in the `sensu_role` type.
Expand Down Expand Up @@ -2193,6 +2314,12 @@ The following parameters are available in the `sensu_role` type.

namevar

The name of the role.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the role.

### sensu_role_binding
Expand Down Expand Up @@ -2220,6 +2347,18 @@ sensu_role_binding { 'test':
}
```

##### Add a role binding with namespace `dev` in the name

```puppet
sensu_role_binding { 'test in dev':
ensure => 'present',
role_ref => 'test-role',
subjects => [
{ 'type' => 'User', 'name' => 'test-user' }
],
}
```

#### Properties

The following properties are available in the `sensu_role_binding` type.
Expand Down Expand Up @@ -2254,6 +2393,12 @@ The following parameters are available in the `sensu_role_binding` type.

namevar

The name of the binding.
The name supports composite names that can define the namespace.
An example composite name to define resource named `test` in namespace `dev`: `test in dev`

##### `resource_name`

The name of the role binding.

### sensu_silenced
Expand Down
11 changes: 6 additions & 5 deletions lib/puppet/provider/sensu_asset/sensuctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def self.instances
data.each do |d|
asset = {}
asset[:ensure] = :present
asset[:name] = d['metadata']['name']
asset[:resource_name] = d['metadata']['name']
asset[:namespace] = d['metadata']['namespace']
asset[:name] = "#{asset[:resource_name]} in #{asset[:namespace]}"
asset[:labels] = d['metadata']['labels']
asset[:annotations] = d['metadata']['annotations']
d.each_pair do |key, value|
Expand All @@ -34,7 +35,7 @@ def self.instances
def self.prefetch(resources)
assets = instances
resources.keys.each do |name|
if provider = assets.find { |c| c.name == name }
if provider = assets.find { |c| c.resource_name == resources[name][:resource_name] && c.namespace == resources[name][:namespace] }
resources[name].provider = provider
end
end
Expand All @@ -58,7 +59,7 @@ def initialize(value = {})
def create
spec = {}
metadata = {}
metadata[:name] = resource[:name]
metadata[:name] = resource[:resource_name]
type_properties.each do |property|
value = resource[property]
next if value.nil?
Expand Down Expand Up @@ -88,7 +89,7 @@ def flush
if !@property_flush.empty?
spec = {}
metadata = {}
metadata[:name] = resource[:name]
metadata[:name] = resource[:resource_name]
type_properties.each do |property|
if @property_flush[property]
value = @property_flush[property]
Expand Down Expand Up @@ -122,7 +123,7 @@ def flush

def destroy
begin
sensuctl_delete('asset', resource[:name])
sensuctl_delete('asset', resource[:resource_name], resource[:namespace])
rescue Exception => e
raise Puppet::Error, "sensuctl delete asset #{resource[:name]} failed\nError message: #{e.message}"
end
Expand Down
Loading