module Kubes::Compiler::Dsl::Syntax class Deployment < Resource fields :container, # "matchLabels:hash", # :sidecar, # :sidecar_name, # :sidecar_image, # :templateMetadata, # :templateSpec # # kubectl explain deployment.spec fields :minReadySeconds, # :paused, # :progressDeadlineSeconds, # :replicas, # :revisionHistoryLimit, # :selector, # -required- :strategy, # :template # -required- # kubectl explain deployment.spec.strategy.rollingUpdate fields :maxSurge, # :maxUnavailable # # kubectl explain deploy.spec.template.spec fields :activeDeadlineSeconds, # :affinity, # :automountServiceAccountToken, # :containers, # <[]Object> -required- :dnsConfig, # :dnsPolicy, # :enableServiceLinks, # :ephemeralContainers, # <[]Object> :hostAliases, # <[]Object> :hostIPC, # :hostNetwork, # :hostPID, # :hostname, # :imagePullSecrets, # <[]Object> :initContainers, # <[]Object> :nodeName, # :nodeSelector, # :overhead, # :preemptionPolicy, # :priority, # :priorityClassName, # :readinessGates, # <[]Object> :restartPolicy, # :runtimeClassName, # :schedulerName, # :securityContext, # :serviceAccount, # :serviceAccountName, # :shareProcessNamespace, # :subdomain, # :terminationGracePeriodSeconds,# :tolerations, # <[]Object> :topologySpreadConstraints, # <[]Object> :volumes # <[]Object> # kubectl explain deployment.spec.template.spec.containers fields :args, # <[]string> :command, # <[]string> :env, # <[]Object> :envFrom, # <[]Object> :image, # :imagePullPolicy, # :lifecycle, # :livenessProbe, # :containerName, # -required- (originally called name) :ports, # <[]Object> :readinessProbe, # :resources, # :securityContext, # :startupProbe, # :stdin, # :stdinOnce, # :terminationMessagePath, # :terminationMessagePolicy, # :tty, # :volumeDevices, # <[]Object> :volumeMounts, # <[]Object> :workingDir # # kubectl explain deployment.spec.template.spec.containers.ports fields :containerPort, # -required- :hostIP, # :hostPort, # :portName, # (originally called name) :protocol # def default_apiVersion "apps/v1" end def default_spec { minReadySeconds: minReadySeconds, paused: paused, progressDeadlineSeconds: progressDeadlineSeconds, replicas: replicas, revisionHistoryLimit: revisionHistoryLimit, selector: selector, strategy: strategy, template: template, } end def default_replicas 1 end def default_selector { matchLabels: matchLabels } end def default_matchLabels labels end def default_strategy return unless maxUnavailable || maxSurge maxSurge = maxUnavailable if maxUnavailable && !maxSurge maxUnavailable = maxSurge if !maxUnavailable && maxSurge { rollingUpdate: { maxSurge: maxSurge, maxUnavailable: maxUnavailable, }, type: "RollingUpdate", } end def default_template { metadata: templateMetadata, spec: templateSpec, } end def default_templateSpec { activeDeadlineSeconds: activeDeadlineSeconds, affinity: affinity, automountServiceAccountToken: automountServiceAccountToken, containers: containers, dnsConfig: dnsConfig, dnsPolicy: dnsPolicy, enableServiceLinks: enableServiceLinks, ephemeralContainers: ephemeralContainers, hostAliases: hostAliases, hostIPC: hostIPC, hostNetwork: hostNetwork, hostPID: hostPID, hostname: hostname, imagePullSecrets: imagePullSecrets, initContainers: initContainers, nodeName: nodeName, nodeSelector: nodeSelector, overhead: overhead, preemptionPolicy: preemptionPolicy, priority: priority, priorityClassName: priorityClassName, readinessGates: readinessGates, restartPolicy: restartPolicy, runtimeClassName: runtimeClassName, schedulerName: schedulerName, securityContext: securityContext, serviceAccount: serviceAccount, serviceAccountName: serviceAccountName, shareProcessNamespace: shareProcessNamespace, subdomain: subdomain, terminationGracePeriodSeconds: terminationGracePeriodSeconds, tolerations: tolerations, topologySpreadConstraints: topologySpreadConstraints, volumes: volumes, } end def default_templateMetadata { labels: labels } end def default_containers [container, sidecar].compact end def default_sidecar { name: sidecar_name, image: sidecar_image, } end def default_sidecar_name "sidecar" if sidecar_image # othewise will create invalid sidecar field w/o image end def default_container { args: args, command: command, env: env, envFrom: envFrom, image: image, imagePullPolicy: imagePullPolicy, lifecycle: lifecycle, livenessProbe: livenessProbe, name: containerName || name, ports: ports, readinessProbe: readinessProbe, resources: resources, securityContext: securityContext, startupProbe: startupProbe, stdin: stdin, stdinOnce: stdinOnce, terminationMessagePath: terminationMessagePath, terminationMessagePolicy: terminationMessagePolicy, tty: tty, volumeDevices: volumeDevices, volumeMounts: volumeMounts, workingDir: workingDir, } end def default_ports [ containerPort: containerPort, hostIP: hostIP, hostPort: hostPort, name: portName, protocol: protocol, ] end # Override command instead of default_command since we want to change a String to an Array def command_reader @command.is_a?(String) ? @command.split(' ') : @command # else assume Array end end end