Skip to content

Commit

Permalink
feat(tags): make them optional and propagateAtLaunch (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
portellaa authored Jun 23, 2022
1 parent 33594a1 commit 8625def
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/App/ASG/ASGClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ASGClient<Provider: ASGProvider>: ASGClientRepresentable {
let updatedTags = tags.map {
AutoScaling.Tag(
key: $0.key,
propagateAtLaunch: $0.propagateAtLaunch ?? true,
propagateAtLaunch: $0.propagateAtLaunch,
resourceId: $0.resourceId,
resourceType: $0.resourceType ?? "auto-scaling-group",
value: $0.value)
Expand Down
6 changes: 4 additions & 2 deletions Sources/App/Hulk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ struct Hulk {
let tags = asgNames.reduce([AutoScaling.Tag]()) { finalResult, asg in
guard let nodePool = clusterInfo.nodePools[asg.0] else { return finalResult }

let allTags = clusterInfo.commonTags + nodePool.tags
let allTags = (clusterInfo.commonTags ?? []) + (nodePool.tags ?? [])

logger.debug("tags to add to node \(nodePool.name): \(allTags)")

return finalResult + allTags.flatMap { tag in
asg.1.map { AutoScaling.Tag(key: tag.name, resourceId: $0, value: tag.value) }
asg.1.map {
AutoScaling.Tag(key: tag.name, propagateAtLaunch: tag.propagateAtLaunch, resourceId: $0, value: tag.value)
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/CloudFormation/Codable/Tag+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ extension Tag: Codable {
enum CodingKeys: String, CodingKey {
case name = "Name"
case value = "Value"
case propagateAtLaunch = "PropagateAtLaunch"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.init(
name: try container.decode(String.self, forKey: .name),
value: try container.decode(String.self, forKey: .value)
value: try container.decode(String.self, forKey: .value),
propagateAtLaunch: try container.decode(Bool.self, forKey: .propagateAtLaunch)
)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/ClusterNodesTags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

public struct ClusterNodesTags {
public let clusterName: String
public let commonTags: [Tag]
public let commonTags: [Tag]?
public let nodePools: [NodePool]

public init(clusterName: String, commonTags: [Tag], nodePools: [NodePool]) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/NodePool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

public struct NodePool {
public let name: String
public let tags: [Tag]
public let tags: [Tag]?

public init(name: String, tags: [Tag]) {
self.name = name
Expand Down
4 changes: 3 additions & 1 deletion Sources/Models/Tag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import Foundation
public struct Tag {
public let name: String
public let value: String
public let propagateAtLaunch: Bool

public init(name: String, value: String) {
public init(name: String, value: String, propagateAtLaunch: Bool) {
self.name = name
self.value = value
self.propagateAtLaunch = propagateAtLaunch
}
}

0 comments on commit 8625def

Please sign in to comment.