diff --git a/PSKubectl/PSKubectl.psd1 b/PSKubectl/PSKubectl.psd1 index a3e087c..4dad413 100644 --- a/PSKubectl/PSKubectl.psd1 +++ b/PSKubectl/PSKubectl.psd1 @@ -102,7 +102,7 @@ 'Get-KubeResourceKinds', 'Remove-KubePod', 'Set-KubeConfig', - 'Update-KubeResource', + 'Publish-KubeResource', 'Use-KubeContext' ) diff --git a/README.md b/README.md index dc3b5ba..1be15be 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ There are also specialised cmdlets for common kinds like `Get-KubePod` and `Get- Equivalent to `kubectl logs`. Pass `-Follow` to stream logs. The cmdlet accepts pipeline input from `Get-KubePod`. -#### `Update-KubeResource` +#### `Publish-KubeResource` Equivalent to `kubectl apply`. Takes Kubernetes objects or YAML file paths as pipeline or parameter input and sends them to the server to apply the difference. @@ -56,8 +56,8 @@ Pass `-Force` to resolve the conflict in these cases. Example: ```powershell -Update-KubeResource *.yml -Get-ChildItem *.yml -Recurse | Update-KubeResource +Publish-KubeResource *.yml +Get-ChildItem *.yml -Recurse | Publish-KubeResource ``` Editing a field before updating: @@ -67,7 +67,7 @@ Get-ChildItem *.Deployment.yml -Recurse | Get-Content -Raw | ConvertFrom-KubeYaml | ForEach-Object { $_.Spec.Template.Spec.Containers[0].Image = $newImage; $_ } | - Update-KubeResource + Publish-KubeResource ``` #### `ConvertFrom-KubeYaml` @@ -80,7 +80,7 @@ Other cmdlets take these objects as input. Compare two Kubernetes objects and output a JSON Patch. -Example that replicates the logic of `Update-KubeResource`: +Example that replicates the logic of `Publish-KubeResource`: ```powershell $modified = Get-Content -Raw deployment.yml | ConvertFrom-KubeYaml diff --git a/Tests/PSKubectl.Tests.ps1 b/Tests/PSKubectl.Tests.ps1 index e4b1ede..2fa0b91 100644 --- a/Tests/PSKubectl.Tests.ps1 +++ b/Tests/PSKubectl.Tests.ps1 @@ -121,7 +121,7 @@ Describe Get-KubeNamespace { } } -Describe Update-KubeResource { +Describe Publish-KubeResource { BeforeAll { Initialize-TestNamespace } BeforeEach { # Delete everything for each test to make sure field managers are not messed up. @@ -178,7 +178,7 @@ Describe Update-KubeResource { } } } - $result = $modified | Update-KubeResource + $result = $modified | Publish-KubeResource $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType KubeClient.Models.DeploymentV1 $result.Metadata.Annotations['hello'] | Should -Be 'changed' @@ -189,7 +189,7 @@ Describe Update-KubeResource { It 'Should update the resource from a path to a YAML file' { $before = (Invoke-Executable { kubectl get deploy -n pskubectltest -o json } | ConvertFrom-Json).Items $before.Metadata.Annotations.hello | Should -Be 'world' - $result = Update-KubeResource -Path $PSScriptRoot/modified.Deployment.yml + $result = Publish-KubeResource -Path $PSScriptRoot/modified.Deployment.yml $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType KubeClient.Models.DeploymentV1 $result.Metadata.Annotations['hello'] | Should -Be 'changed' @@ -205,7 +205,7 @@ Describe Update-KubeResource { It 'Should fail with a Conflict error if it was with kubectl create or client-side apply before' { Invoke-Executable { kubectl create -f $PSScriptRoot/test.Deployment.yml } Invoke-Executable { kubectl rollout status --namespace pskubectltest deploy/hello-world } | Out-Stream -SuccessTarget 6 - { Update-KubeResource -Path $PSScriptRoot/modified.Deployment.yml } | Should -Throw "Conflict" + { Publish-KubeResource -Path $PSScriptRoot/modified.Deployment.yml } | Should -Throw "Conflict" } It 'Should update the resource if it was updated before with kubectl create or client-side apply and -Force was given' { @@ -215,7 +215,7 @@ Describe Update-KubeResource { $before = (Invoke-Executable { kubectl get deploy -n pskubectltest -o json } | ConvertFrom-Json).Items $before.Metadata.Annotations.hello | Should -Be 'world' - $result = Update-KubeResource -Path $PSScriptRoot/modified.Deployment.yml -Force + $result = Publish-KubeResource -Path $PSScriptRoot/modified.Deployment.yml -Force $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType KubeClient.Models.DeploymentV1 $result.Metadata.Annotations.hello | Should -Be 'changed' @@ -231,7 +231,7 @@ Describe Update-KubeResource { $before = (Invoke-Executable { kubectl get deploy -n pskubectltest -o json } | ConvertFrom-Json).Items $before | Should -BeNullOrEmpty - $result = Update-KubeResource -Path $PSScriptRoot/test.Deployment.yml + $result = Publish-KubeResource -Path $PSScriptRoot/test.Deployment.yml $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType KubeClient.Models.DeploymentV1 diff --git a/src/Cmdlets/UpdateKubeResourceCmdlet.cs b/src/Cmdlets/DeployKubeResourceCmdlet.cs similarity index 97% rename from src/Cmdlets/UpdateKubeResourceCmdlet.cs rename to src/Cmdlets/DeployKubeResourceCmdlet.cs index cef2b31..c70d678 100644 --- a/src/Cmdlets/UpdateKubeResourceCmdlet.cs +++ b/src/Cmdlets/DeployKubeResourceCmdlet.cs @@ -8,9 +8,9 @@ using Microsoft.Extensions.Logging; namespace Kubectl.Cmdlets { - [Cmdlet(VerbsData.Update, "KubeResource", SupportsShouldProcess = true)] + [Cmdlet(VerbsData.Publish, "KubeResource", SupportsShouldProcess = true)] [OutputType(new[] { typeof(KubeResourceV1) })] - public sealed class UpdateKubeResourceCmdlet : KubeApiCmdlet { + public sealed class DeployKubeResourceCmdlet : KubeApiCmdlet { private static readonly string fieldManager = "kubectl"; [Parameter(Mandatory = true, Position = 0, ParameterSetName = "Path", ValueFromPipelineByPropertyName = true)]