Skip to content

Commit

Permalink
Cluster: Adding parameter KeepDownedNodesInCluster to control whether…
Browse files Browse the repository at this point in the history
… or not to remove nodes in downed state (#272)
  • Loading branch information
nickgw authored Jun 11, 2022
1 parent 9908405 commit 5c81cde
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

## [Unreleased]

### Changed
- Cluster
- New parameter KeepDownedNodesInCluster controls whether or not to evict nodes in a down state from the cluster.
- FailoverClusterDsc
- Update pipeline files to the latest from the Sampler project.
- Move somme documentation from README-md to the GitHub repository Wiki.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ The resource examples are also available in the [FailoverClusterDsc Wiki](https:
Full Control over the Cluster Name Object in Active Directory.
* Otherwise the Computer Account must have been granted Full Control
over the Cluster Name Object in Active Directory.
* **`[Boolean]` KeepDownedNodesInCluster** _(Write)_: Switch controlling whether or not
to evict cluster nodes in a down state from the cluster. Default value is 'false'.


#### Examples for Cluster
Expand Down
44 changes: 38 additions & 6 deletions source/DSCResources/DSC_Cluster/DSC_Cluster.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
.PARAMETER DomainAdministratorCredential
Credential used to create the failover cluster in Active Directory.
.PARAMETER KeepDownedNodesInCluster
Switch used to determine whether or not to evict cluster nodes in a
downed state. Defaults to $false
#>
function Get-TargetResource
{
Expand All @@ -45,7 +49,11 @@ function Get-TargetResource

[Parameter()]
[System.Management.Automation.PSCredential]
$DomainAdministratorCredential
$DomainAdministratorCredential,

[Parameter()]
[System.Boolean]
$KeepDownedNodesInCluster = $false
)

Write-Verbose -Message ($script:localizedData.GetClusterInformation -f $Name)
Expand Down Expand Up @@ -115,6 +123,10 @@ function Get-TargetResource
.PARAMETER DomainAdministratorCredential
Credential used to create the failover cluster in Active Directory.
.PARAMETER KeepDownedNodesInCluster
Switch used to determine whether or not to evict cluster nodes in a
downed state. Defaults to $false
.NOTES
If the cluster does not exist, it will be created in the domain and the
static IP address will be assigned to the cluster.
Expand Down Expand Up @@ -142,7 +154,11 @@ function Set-TargetResource

[Parameter()]
[System.Management.Automation.PSCredential]
$DomainAdministratorCredential
$DomainAdministratorCredential,

[Parameter()]
[System.Boolean]
$KeepDownedNodesInCluster = $false
)

$bCreate = $true
Expand Down Expand Up @@ -231,13 +247,21 @@ function Set-TargetResource
{
if ($node.State -eq 'Down')
{
Write-Verbose -Message ($script:localizedData.RemoveOfflineNodeFromCluster -f $targetNodeName, $Name)

Remove-ClusterNode -Name $targetNodeName -Cluster $Name -Force
if ($KeepDownedNodesInCluster)
{
Write-Verbose -Message ($script:localizedData.KeepDownedNodesInCluster -f $targetNodeName, $Name)
}
else
{
Write-Verbose -Message ($script:localizedData.RemoveOfflineNodeFromCluster -f $targetNodeName, $Name)

Remove-ClusterNode -Name $targetNodeName -Cluster $Name -Force
}
}
}
}


Add-ClusterNode -Name $targetNodeName -Cluster $Name -NoStorage

Write-Verbose -Message ($script:localizedData.AddNodeToClusterSuccessful -f $targetNodeName, $Name)
Expand Down Expand Up @@ -281,6 +305,10 @@ function Set-TargetResource
.PARAMETER DomainAdministratorCredential
Credential used to create the failover cluster in Active Directory.
.PARAMETER KeepDownedNodesInCluster
Switch used to determine whether or not to evict cluster nodes in a
downed state. Defaults to $false
.NOTES
The code will check the following in order:
Expand Down Expand Up @@ -312,7 +340,11 @@ function Test-TargetResource

[Parameter()]
[System.Management.Automation.PSCredential]
$DomainAdministratorCredential
$DomainAdministratorCredential,

[Parameter()]
[System.Boolean]
$KeepDownedNodesInCluster = $false
)

$returnValue = $false
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/DSC_Cluster/DSC_Cluster.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class DSC_Cluster : OMI_BaseResource
[Write, Description("StaticIPAddress of the Cluster")] String StaticIPAddress;
[Write, EmbeddedInstance("MSFT_Credential"), Description("Credential to create the cluster")] String DomainAdministratorCredential;
[Write, Description("One or more networks to ignore when creating the cluster. Only networks using Static IP can be ignored, networks that are assigned an IP address through DHCP cannot be ignored, and are added for cluster communication. To remove networks assigned an IP address through DHCP use the resource ClusterNetwork to change the role of the network. This parameter is only used during the creation of the cluster and is not monitored after.")] String IgnoreNetwork[];
[Write, Description("Remove nodes in down state from cluster.")] Boolean KeepDownedNodesInCluster;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ ConvertFrom-StringData @'
UnableToImpersonateUser = Can't logon as user {0}.
UnableToCloseToken = Can't close impersonation token {0}.
GetClusterInformation = Retrieving information for cluster {0}.
KeepDownedNodesInCluster = Cluster node {0} is in a down state and will not be removed from the cluster {1}.
'@
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<#PSScriptInfo
.VERSION 1.0.0
.GUID 593e1540-3778-4260-9389-1deceb419c8c
.AUTHOR DSC Community
.COMPANYNAME DSC Community
.COPYRIGHT DSC Community contributors. All rights reserved.
.TAGS DSCConfiguration
.LICENSEURI https://github.com/dsccommunity/FailoverClusterDsc/blob/main/LICENSE
.PROJECTURI https://github.com/dsccommunity/FailoverClusterDsc
.ICONURI https://dsccommunity.org/images/DSC_Logo_300p.png
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
First version.
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core
#>

#Requires -Module FailoverClusterDsc

<#
.DESCRIPTION
This example shows how to add an additional node to the failover cluster without evicting cluster nodes in a down state.
#>

Configuration Cluster_JoinAdditionalNodeToFailoverClusterConfigAndDontEvictDownedNodes
{
param
(
[Parameter(Mandatory = $true)]
[PSCredential]
$ActiveDirectoryAdministratorCredential
)

Import-DscResource -ModuleName FailoverClusterDsc

Node localhost
{
WindowsFeature AddFailoverFeature
{
Ensure = 'Present'
Name = 'Failover-clustering'
}

WindowsFeature AddRemoteServerAdministrationToolsClusteringPowerShellFeature
{
Ensure = 'Present'
Name = 'RSAT-Clustering-PowerShell'
DependsOn = '[WindowsFeature]AddFailoverFeature'
}

WindowsFeature AddRemoteServerAdministrationToolsClusteringCmdInterfaceFeature
{
Ensure = 'Present'
Name = 'RSAT-Clustering-CmdInterface'
DependsOn = '[WindowsFeature]AddRemoteServerAdministrationToolsClusteringPowerShellFeature'
}

WaitForCluster WaitForCluster
{
Name = 'Cluster01'
RetryIntervalSec = 10
RetryCount = 60
DependsOn = '[WindowsFeature]AddRemoteServerAdministrationToolsClusteringCmdInterfaceFeature'
}

Cluster JoinSecondNodeToCluster
{
Name = 'Cluster01'
StaticIPAddress = '192.168.100.20/24'
DomainAdministratorCredential = $ActiveDirectoryAdministratorCredential
KeepDownedNodesInCluster = $True
DependsOn = '[WaitForCluster]WaitForCluster'
}
}
}
12 changes: 12 additions & 0 deletions tests/Unit/DSC_Cluster.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ foreach ($moduleVersion in @('2012', '2016'))
Assert-MockCalled -CommandName Remove-ClusterNode -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Add-ClusterNode -Exactly -Times 1 -Scope It
}

It 'Should not call Remove-ClusterNode when KeepDownedNodesInCluster is True' {
Mock -CommandName Get-Cluster -MockWith $mockGetCluster -ParameterFilter $mockGetCluster_ParameterFilter

$mockDefaultParametersKeepDownedNodes = $mockDefaultParameters + @{'KeepDownedNodesInCluster' = $True}

{ Set-TargetResource @mockDefaultParametersKeepDownedNodes } | Should -Not -Throw

Assert-MockCalled -CommandName New-Cluster -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Remove-ClusterNode -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Add-ClusterNode -Exactly -Times 1 -Scope It
}
}
}

Expand Down

0 comments on commit 5c81cde

Please sign in to comment.