Skip to content

Commit

Permalink
Allow cluster volume overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaldrip committed Jun 29, 2019
1 parent 37c0333 commit 9eb2eb0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion shard.yml
@@ -1,5 +1,5 @@
name: psykube
version: 2.16.0
version: 2.17.0
crystal: 0.26.0

authors:
Expand Down
9 changes: 9 additions & 0 deletions src/psykube/generator.cr
Expand Up @@ -53,6 +53,15 @@ abstract class Psykube::Generator
manifest_secrets.merge(cluster_secrets)
end

private def combined_volumes
case (c = cluster)
when Psykube::V2::Manifest::Shared::Cluster
manifest.volumes.merge(c.volumes)
else
manifest.volumes
end
end

private def manifest_secrets
case manifest.secrets
when true, false, nil
Expand Down
13 changes: 8 additions & 5 deletions src/psykube/v2/generator/concerns/pod_helper.cr
Expand Up @@ -30,7 +30,7 @@ module Psykube::V2::Generator::Concerns::PodHelper
private def generate_pod_spec
Pyrite::Api::Core::V1::PodSpec.new(
restart_policy: manifest.restart_policy,
volumes: generate_volumes(manifest.volumes),
volumes: generate_volumes(combined_volumes),
containers: generate_containers,
init_containers: generate_init_containers(manifest.init_containers),
security_context: generate_security_context,
Expand Down Expand Up @@ -137,10 +137,6 @@ module Psykube::V2::Generator::Concerns::PodHelper
end unless volumes.empty?
end

private def generate_volumes(any)
nil
end

private def generate_volume(volume_name : String, size : String)
Pyrite::Api::Core::V1::Volume.new(
name: volume_name,
Expand All @@ -150,6 +146,13 @@ module Psykube::V2::Generator::Concerns::PodHelper
)
end

private def generate_volume(volume_name : String, size : Nil)
Pyrite::Api::Core::V1::Volume.new(
name: volume_name,
empty_dir: Pyrite::Api::Core::V1::EmptyDirVolumeSource.new
)
end

private def generate_volume(volume_name : String, volume_alias : Manifest::Volume::Alias)
Pyrite::Api::Core::V1::Volume.new(
name: volume_name,
Expand Down
2 changes: 1 addition & 1 deletion src/psykube/v2/generator/persistent_volume_claims.cr
Expand Up @@ -3,7 +3,7 @@ class Psykube::V2::Generator::PersistentVolumeClaims < ::Psykube::Generator
cast_manifest Manifest

protected def result
generate_persistent_volume_claims(manifest.volumes)
generate_persistent_volume_claims(combined_volumes)
end

private def volume_is_claim?(volume : String | Manifest::Volume::Claim)
Expand Down
2 changes: 1 addition & 1 deletion src/psykube/v2/manifest.cr
Expand Up @@ -155,7 +155,7 @@ abstract class Psykube::V2::Manifest
termination_grace_period: {type: Int32, optional: true},
tolerations: {type: Array(Pyrite::Api::Core::V1::Toleration), optional: true},
clusters: {type: ClusterMap, default: ClusterMap.new },
volumes: {type: VolumeMap, optional: true},
volumes: {type: VolumeMap, default: VolumeMap.new},
security_context: {type: Shared::SecurityContext, optional: true},
{% if service %}
ingress: {type: Manifest::Ingress, optional: true},
Expand Down
1 change: 1 addition & 0 deletions src/psykube/v2/manifest/shared/cluster.cr
Expand Up @@ -16,6 +16,7 @@ class Psykube::V2::Manifest::Shared::Cluster
secrets: {type: StringMap | Bool, optional: true},
autoscale: {type: Manifest::Autoscale, optional: true},
container_overrides: {type: ContainerOverides, default: ContainerOverides.new},
volumes: {type: VolumeMap, default: VolumeMap.new},
})

def initialize(@context : String? = nil)
Expand Down

0 comments on commit 9eb2eb0

Please sign in to comment.