Skip to content

Commit

Permalink
Fix UnstructuredResource's metadata encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab committed Jan 29, 2023
1 parent d961d40 commit 7f748ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.7.1

- Fix UnstructuredResource's `metadata` encoding

## 0.7.0

- Drop `AnyKubernetesAPIResource` in favour of `UnstructuredResource`
Expand Down
5 changes: 4 additions & 1 deletion Sources/Model/UnstructuredResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ extension UnstructuredResource: Codable {
var encodingContainer = encoder.container(keyedBy: JSONCodingKeys.self)

try properties.forEach { key, value in
try encodingContainer.encodeAny(value, forKey: JSONCodingKeys(stringValue: key)!)
switch key {
case "metadata": try encodingContainer.encodeIfPresent(value as? meta.v1.ObjectMeta, forKey: JSONCodingKeys(stringValue: key)!)
default: try encodingContainer.encodeAny(value, forKey: JSONCodingKeys(stringValue: key)!)
}
}
}
}
5 changes: 1 addition & 4 deletions Tests/SwiftkubeModelTests/UnstructureResourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ final class UnstructuredResourceTests: XCTestCase {
let cron = UnstructuredResource(properties: [
"apiVersion": "stable.example.com/v1",
"kind": "CronTab",
"metadata": [
"name": "my-new-cron-object",
"namespace": "default"
],
"metadata": meta.v1.ObjectMeta(name: "my-new-cron-object", namespace: "default"),
"spec": [
"cronSpec": "* * * * */5",
"image": "my-awesome-cron-image"
Expand Down

0 comments on commit 7f748ae

Please sign in to comment.