From a19407c0e9db3d0d5e613c5b21a61d4e4c7f9f75 Mon Sep 17 00:00:00 2001 From: Bernie White Date: Mon, 10 Feb 2020 23:40:57 +1000 Subject: [PATCH] Use qualified target names #36 (#37) - Use qualified target names #36 - Use pre-release PSRule version to fix POSIX issue. --- CHANGELOG.md | 3 +++ build.ps1 | 2 +- pipeline.build.ps1 | 8 ++++--- .../rules/Baseline.Rule.yaml | 2 ++ .../Kubernetes.AKS.Tests.ps1 | 4 ++-- .../Kubernetes.API.Tests.ps1 | 4 ++-- .../Kubernetes.Metadata.Tests.ps1 | 4 ++-- .../Kubernetes.Pod.Tests.ps1 | 24 +++++++++---------- 8 files changed, 29 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91027e1..23d57c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- **Breaking change**: Use qualified target names. [#36](https://github.com/Microsoft/PSRule.Rules.Kubernetes/issues/36) + - If using suppression, update suppressed target name with qualified name. + ## v0.1.0 - Initial release. diff --git a/build.ps1 b/build.ps1 index e1bacb2..0d1f51b 100644 --- a/build.ps1 +++ b/build.ps1 @@ -7,4 +7,4 @@ . ./.azure-pipelines/pipeline-deps.ps1 Invoke-Build Test -AssertStyle Client -Write-Host "If no build errors occured. The module has been saved to out/modules/PSRule.Rules.Kubernetes" +Write-Host "If no build errors occurred. The module has been saved to out/modules/PSRule.Rules.Kubernetes" diff --git a/pipeline.build.ps1 b/pipeline.build.ps1 index 7931ead..bf2a813 100644 --- a/pipeline.build.ps1 +++ b/pipeline.build.ps1 @@ -22,11 +22,13 @@ param ( [String]$AssertStyle = 'AzurePipelines' ) +Write-Host -Object "[Pipeline] -- PowerShell: v$($PSVersionTable.PSVersion.ToString())" -ForegroundColor Green; Write-Host -Object "[Pipeline] -- PWD: $PWD" -ForegroundColor Green; Write-Host -Object "[Pipeline] -- ArtifactPath: $ArtifactPath" -ForegroundColor Green; Write-Host -Object "[Pipeline] -- BuildNumber: $($Env:BUILD_BUILDNUMBER)" -ForegroundColor Green; Write-Host -Object "[Pipeline] -- SourceBranch: $($Env:BUILD_SOURCEBRANCH)" -ForegroundColor Green; Write-Host -Object "[Pipeline] -- SourceBranchName: $($Env:BUILD_SOURCEBRANCHNAME)" -ForegroundColor Green; +Write-Host -Object "[Pipeline] -- Culture: $((Get-Culture).Name), $((Get-Culture).Parent)" -ForegroundColor Green; if ($Env:SYSTEM_DEBUG -eq 'true') { $VerbosePreference = 'Continue'; @@ -143,7 +145,7 @@ task VersionModule ModuleDependencies, { $manifest = Test-ModuleManifest -Path $manifestPath; $requiredModules = $manifest.RequiredModules | ForEach-Object -Process { if ($_.Name -eq 'PSRule' -and $Configuration -eq 'Release') { - @{ ModuleName = 'PSRule'; ModuleVersion = '0.13.0' } + @{ ModuleName = 'PSRule'; ModuleVersion = '0.14.0' } } else { @{ ModuleName = $_.Name; ModuleVersion = $_.Version } @@ -193,8 +195,8 @@ task PSScriptAnalyzer NuGet, { # Synopsis: Install PSRule task PSRule NuGet, { - if ($Null -eq (Get-InstalledModule -Name PSRule -MinimumVersion 0.13.0 -ErrorAction Ignore)) { - Install-Module -Name PSRule -MinimumVersion 0.13.0 -Scope CurrentUser -Force; + if ($Null -eq (Get-InstalledModule -Name PSRule -MinimumVersion '0.15.0-B2002012' -AllowPrerelease -ErrorAction Ignore)) { + Install-Module -Name PSRule -MinimumVersion '0.15.0-B2002012' -AllowPrerelease -Scope CurrentUser -Force; } Import-Module -Name PSRule -Verbose:$False; } diff --git a/src/PSRule.Rules.Kubernetes/rules/Baseline.Rule.yaml b/src/PSRule.Rules.Kubernetes/rules/Baseline.Rule.yaml index fe1d144..56b2ab3 100644 --- a/src/PSRule.Rules.Kubernetes/rules/Baseline.Rule.yaml +++ b/src/PSRule.Rules.Kubernetes/rules/Baseline.Rule.yaml @@ -12,6 +12,7 @@ spec: - kind field: namespace: [ 'metadata.namespace' ] + useQualifiedName: true rule: tag: group: core @@ -29,6 +30,7 @@ spec: - kind field: namespace: [ 'metadata.namespace' ] + useQualifiedName: true rule: tag: group: [ 'core', 'AKS' ] diff --git a/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.AKS.Tests.ps1 b/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.AKS.Tests.ps1 index 73ea06a..101af23 100644 --- a/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.AKS.Tests.ps1 +++ b/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.AKS.Tests.ps1 @@ -38,13 +38,13 @@ Describe 'Kubernetes.AKS' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'service-B'; + $ruleResult.TargetName | Should -Be 'service/service-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 2; - $ruleResult.TargetName | Should -BeIn 'service-A', 'service-C'; + $ruleResult.TargetName | Should -BeIn 'service/service-A', 'service/service-C'; } } } diff --git a/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.API.Tests.ps1 b/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.API.Tests.ps1 index 8d0b048..82133be 100644 --- a/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.API.Tests.ps1 +++ b/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.API.Tests.ps1 @@ -38,13 +38,13 @@ Describe 'Kubernetes.API.Removal' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-B'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-A'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-A'; } } } diff --git a/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.Metadata.Tests.ps1 b/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.Metadata.Tests.ps1 index 62c58df..3c55388 100644 --- a/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.Metadata.Tests.ps1 +++ b/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.Metadata.Tests.ps1 @@ -38,13 +38,13 @@ Describe 'Kubernetes.Metadata' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 2; - $ruleResult.TargetName | Should -BeIn 'deployment-B', 'service-B'; + $ruleResult.TargetName | Should -BeIn 'deployment/deployment-B', 'service/service-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 2; - $ruleResult.TargetName | Should -BeIn 'deployment-A', 'service-A'; + $ruleResult.TargetName | Should -BeIn 'deployment/deployment-A', 'service/service-A'; } } } diff --git a/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.Pod.Tests.ps1 b/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.Pod.Tests.ps1 index ad95e38..9d04aad 100644 --- a/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.Pod.Tests.ps1 +++ b/tests/PSRule.Rules.Kubernetes.Tests/Kubernetes.Pod.Tests.ps1 @@ -38,13 +38,13 @@ Describe 'Kubernetes.Pod' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-B'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-A'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-A'; } It 'Kubernetes.Pod.Latest' { @@ -54,13 +54,13 @@ Describe 'Kubernetes.Pod' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-B'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-A'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-A'; } It 'Kubernetes.Pod.Secrets' { @@ -70,13 +70,13 @@ Describe 'Kubernetes.Pod' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-B'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-A'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-A'; } } @@ -88,13 +88,13 @@ Describe 'Kubernetes.Pod' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-B'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-A'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-A'; } } @@ -106,13 +106,13 @@ Describe 'Kubernetes.Pod' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-B'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-A'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-A'; } It 'Kubernetes.Pod.Replicas' { @@ -122,13 +122,13 @@ Describe 'Kubernetes.Pod' { $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-B'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-B'; # Pass $ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' }); $ruleResult | Should -Not -BeNullOrEmpty; $ruleResult.Length | Should -Be 1; - $ruleResult.TargetName | Should -Be 'deployment-A'; + $ruleResult.TargetName | Should -Be 'deployment/deployment-A'; } } }