Skip to content

Commit

Permalink
Drop AnyKubernetesAPIResource in favour of UnstructuredResource
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab committed Jan 25, 2023
1 parent 3f40e3e commit 282f132
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 595 deletions.
22 changes: 0 additions & 22 deletions Sources/Model/AnyKubernetesAPIResource+Listable.swift

This file was deleted.

385 changes: 0 additions & 385 deletions Sources/Model/AnyKubernetesAPIResource.swift

This file was deleted.

27 changes: 0 additions & 27 deletions Sources/Model/CodingUserInfo+AnyKubernetesAPIResource.swift

This file was deleted.

18 changes: 15 additions & 3 deletions Sources/Model/UnstructuredResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@ import Foundation

// MARK: - UnstructuredResource

///
/// Unstructured allows objects that do not have registered `KubernetesAPIResource`s to
/// be manipulated generically. This can be used to deal with the API objects from a plug-in.
/// Unstructured objects still have functioning TypeMeta features-- kind, version, etc.
///
@dynamicMemberLookup
public struct UnstructuredResource: KubernetesAPIResource {
public struct UnstructuredResource: KubernetesAPIResource, ListableResource {

///
/// ListableResource.List associated type
///
public typealias List = UnstructuredResourceList

private var properties = [String: Any]()
///
/// Dictionary holding this resource's unstructured representation
///
public let properties: Dictionary<String, Any>

/// Constructs an unstructured instance of a resource given a Dictionary representation.
///
/// - Parameter properties: A dictionary representation of the resource to construct.
public init(properties: Dictionary<String, Any>) {
self.properties = properties
}
Expand All @@ -41,7 +53,7 @@ public struct UnstructuredResource: KubernetesAPIResource {
properties["kind"] as? String ?? ""
}

/// This associated `metadata` of this resource.
/// This resource's `metadata`.
public var metadata: meta.v1.ObjectMeta? {
properties["metadata"] as? meta.v1.ObjectMeta
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
// limitations under the License.
//

///
/// Generated by Swiftkube:ModelGen
/// Kubernetes v1.18.9
///

import Foundation

// MARK: - UnstructuredResource

///
/// A type-erased `KubernetesResourceList` that holds type-erased `AnyKubernetesAPIResource` instances.
/// UnstructuredResourceList is a collection of UnstructuredResources.
///
public struct AnyKubernetesAPIResourceList: KubernetesResourceList {
public struct UnstructuredResourceList: KubernetesResourceList {

private enum CodingKeys: String, CodingKey {
case apiVersion
Expand All @@ -42,24 +39,24 @@ public struct AnyKubernetesAPIResourceList: KubernetesResourceList {
/// This resource list's `meta.v1.ListMeta` object.
public var metadata: meta.v1.ListMeta?

/// A list of type-erased `AnyKubernetesAPIResource` instances.
public var items: [AnyKubernetesAPIResource]
/// A list of `UnstructuredResource` instances.
public var items: [UnstructuredResource]

/// Creates a new type-erased `AnyKubernetesAPIResourceList` instance wrapping the given resources.
/// Creates a new type-erased `UnstructuredResourceList` instance wrapping the given resources.
///
/// The passed items must be of the same type as the provided `apiVersion` and `kind` arguments.
/// This initializer doesn't ensure/enforce this requirement which may lead to unexpected behaviour if not fulfilled.
///
/// - Parameters:
/// - apiVersion: The `apiVerison` of the type-erased list.
/// - apiVersion: The `apiVersion` of the type-erased list.
/// - kind: The `kind` of the type-erased list.
/// - metadata: The `metadata` of the type-erased list.
/// - items: A list of type-erased resources.
public init(
apiVersion: String,
kind: String,
metadata: meta.v1.ListMeta?,
items: [AnyKubernetesAPIResource]
items: [UnstructuredResource]
) {
self.apiVersion = apiVersion
self.kind = kind
Expand All @@ -72,7 +69,7 @@ public struct AnyKubernetesAPIResourceList: KubernetesResourceList {
let apiVersion = try container.decode(String.self, forKey: .apiVersion)
let kind = try container.decode(String.self, forKey: .kind)
let metadata = try container.decodeIfPresent(meta.v1.ListMeta.self, forKey: .metadata)
let items = try container.decode([AnyKubernetesAPIResource].self, forKey: CodingKeys.items)
let items = try container.decode([UnstructuredResource].self, forKey: CodingKeys.items)

self.init(apiVersion: apiVersion, kind: kind, metadata: metadata, items: items)
}
Expand Down
73 changes: 0 additions & 73 deletions Tests/SwiftkubeModelTests/AnyKubernetesAPIResourceListTests.swift

This file was deleted.

63 changes: 0 additions & 63 deletions Tests/SwiftkubeModelTests/AnyKubernetesAPIResourceTests.swift

This file was deleted.

9 changes: 0 additions & 9 deletions Tests/SwiftkubeModelTests/GroupVersionKindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ final class GroupVersionKindTests: XCTestCase {
XCTAssertEqual(gvk?.kind, "Deployment")
}

func testInitByAnyResourceInstance() {
let resource = AnyKubernetesAPIResource(apps.v1.Deployment())
let gvk = GroupVersionKind(of: resource)

XCTAssertEqual(gvk?.group, "apps")
XCTAssertEqual(gvk?.version, "v1")
XCTAssertEqual(gvk?.kind, "Deployment")
}

func testInitByString() {
let apiVersion = "v1"
let kind = "Pod"
Expand Down
Loading

0 comments on commit 282f132

Please sign in to comment.