pfab 0.58.22 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/pfab/cli.rb +2 -2
 - data/lib/pfab/templates/base.rb +152 -2
 - data/lib/pfab/templates/cron.rb +1 -0
 - data/lib/pfab/templates/daemon.rb +1 -0
 - data/lib/pfab/templates/job.rb +1 -0
 - data/lib/pfab/templates/web.rb +1 -0
 - data/lib/pfab/version.rb +2 -2
 - data/pfab.gemspec +3 -3
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 15668736ef7c25f6740964b891ed462e9525438cad02ac4a31f6675fa8a86d8a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: cd649c6f885dff4abd50e56c14c20ec7541909e7938abcaf99eefdd46871d5dd
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: be5e0fc796dee5c98edf48277cc6869c7897e384b1a762743ac8c3845e9988f24d54596d5de64da2dac053c1ab221c83421bab5f6e8d51c43052ae63922e5273
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d1c8b6dd4acf30cacd32704f37076da3fc1190be000b08d1718cc02306c1b3d784819ac9a9547393ee015033346c3bbbae99a16cbf08bb9565fbdf667d3fbf6b
         
     | 
    
        data/lib/pfab/cli.rb
    CHANGED
    
    | 
         @@ -526,8 +526,8 @@ module Pfab 
     | 
|
| 
       526 
526 
     | 
    
         
             
                end
         
     | 
| 
       527 
527 
     | 
    
         | 
| 
       528 
528 
     | 
    
         
             
                def docker_container_driver_available?
         
     | 
| 
       529 
     | 
    
         
            -
                  output = `docker buildx  
     | 
| 
       530 
     | 
    
         
            -
                  output.lines.any? { |line| line.match( 
     | 
| 
      
 529 
     | 
    
         
            +
                  output = `docker buildx inspect 2>/dev/null`
         
     | 
| 
      
 530 
     | 
    
         
            +
                  output.lines.any? { |line| line.match(/^Driver:\s+docker-container/) }
         
     | 
| 
       531 
531 
     | 
    
         
             
                end
         
     | 
| 
       532 
532 
     | 
    
         | 
| 
       533 
533 
     | 
    
         
             
                def should_use_registry_cache?
         
     | 
    
        data/lib/pfab/templates/base.rb
    CHANGED
    
    | 
         @@ -26,9 +26,9 @@ module Pfab 
     | 
|
| 
       26 
26 
     | 
    
         
             
                  def get_command()
         
     | 
| 
       27 
27 
     | 
    
         
             
                    cmd = get("command")
         
     | 
| 
       28 
28 
     | 
    
         
             
                    if cmd.kind_of?(Array)
         
     | 
| 
       29 
     | 
    
         
            -
                      return cmd
         
     | 
| 
      
 29 
     | 
    
         
            +
                      return clean_command_array(cmd)
         
     | 
| 
       30 
30 
     | 
    
         
             
                    end
         
     | 
| 
       31 
     | 
    
         
            -
                    return cmd.split(" ")
         
     | 
| 
      
 31 
     | 
    
         
            +
                    return clean_command_array(cmd.split(" "))
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                  def cpu(req_type)
         
     | 
| 
         @@ -164,6 +164,156 @@ module Pfab 
     | 
|
| 
       164 
164 
     | 
    
         
             
                    return ports
         
     | 
| 
       165 
165 
     | 
    
         
             
                  end
         
     | 
| 
       166 
166 
     | 
    
         | 
| 
      
 167 
     | 
    
         
            +
                  def sidecars
         
     | 
| 
      
 168 
     | 
    
         
            +
                    get("sidecars") || []
         
     | 
| 
      
 169 
     | 
    
         
            +
                  end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
                  def build_sidecar_resources(sidecar)
         
     | 
| 
      
 172 
     | 
    
         
            +
                    return nil unless sidecar["resources"]
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                    resources = {}
         
     | 
| 
      
 175 
     | 
    
         
            +
                    if sidecar["resources"]["requests"]
         
     | 
| 
      
 176 
     | 
    
         
            +
                      resources[:requests] = {}
         
     | 
| 
      
 177 
     | 
    
         
            +
                      resources[:requests][:cpu] = sidecar["resources"]["requests"]["cpu"] if sidecar["resources"]["requests"]["cpu"]
         
     | 
| 
      
 178 
     | 
    
         
            +
                      resources[:requests][:memory] = sidecar["resources"]["requests"]["memory"] if sidecar["resources"]["requests"]["memory"]
         
     | 
| 
      
 179 
     | 
    
         
            +
                    end
         
     | 
| 
      
 180 
     | 
    
         
            +
                    if sidecar["resources"]["limits"]
         
     | 
| 
      
 181 
     | 
    
         
            +
                      resources[:limits] = {}
         
     | 
| 
      
 182 
     | 
    
         
            +
                      resources[:limits][:cpu] = sidecar["resources"]["limits"]["cpu"] if sidecar["resources"]["limits"]["cpu"]
         
     | 
| 
      
 183 
     | 
    
         
            +
                      resources[:limits][:memory] = sidecar["resources"]["limits"]["memory"] if sidecar["resources"]["limits"]["memory"]
         
     | 
| 
      
 184 
     | 
    
         
            +
                    end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
                    resources.empty? ? nil : resources
         
     | 
| 
      
 187 
     | 
    
         
            +
                  end
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
                  def build_sidecar_env(sidecar)
         
     | 
| 
      
 190 
     | 
    
         
            +
                    # Start with base environment variables that all containers get
         
     | 
| 
      
 191 
     | 
    
         
            +
                    base_env = env_vars.dup
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                    # If sidecar has additional env vars, merge them in (allowing overrides)
         
     | 
| 
      
 194 
     | 
    
         
            +
                    if sidecar["env"]
         
     | 
| 
      
 195 
     | 
    
         
            +
                      sidecar_env = sidecar["env"].map do |env_var|
         
     | 
| 
      
 196 
     | 
    
         
            +
                        if env_var.is_a?(Hash)
         
     | 
| 
      
 197 
     | 
    
         
            +
                          env_var.transform_keys(&:to_sym)
         
     | 
| 
      
 198 
     | 
    
         
            +
                        elsif env_var.is_a?(String)
         
     | 
| 
      
 199 
     | 
    
         
            +
                          # Handle simple string format like "KEY=value" or just "KEY"
         
     | 
| 
      
 200 
     | 
    
         
            +
                          if env_var.include?("=")
         
     | 
| 
      
 201 
     | 
    
         
            +
                            key, value = env_var.split("=", 2)
         
     | 
| 
      
 202 
     | 
    
         
            +
                            { name: key, value: value }
         
     | 
| 
      
 203 
     | 
    
         
            +
                          else
         
     | 
| 
      
 204 
     | 
    
         
            +
                            { name: env_var }
         
     | 
| 
      
 205 
     | 
    
         
            +
                          end
         
     | 
| 
      
 206 
     | 
    
         
            +
                        end
         
     | 
| 
      
 207 
     | 
    
         
            +
                      end.compact
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
                      # Merge sidecar env vars, allowing them to override base vars
         
     | 
| 
      
 210 
     | 
    
         
            +
                      env_hash = {}
         
     | 
| 
      
 211 
     | 
    
         
            +
                      base_env.each { |e| env_hash[e[:name]] = e }
         
     | 
| 
      
 212 
     | 
    
         
            +
                      sidecar_env.each { |e| env_hash[e[:name]] = e }
         
     | 
| 
      
 213 
     | 
    
         
            +
                      env_hash.values
         
     | 
| 
      
 214 
     | 
    
         
            +
                    else
         
     | 
| 
      
 215 
     | 
    
         
            +
                      base_env
         
     | 
| 
      
 216 
     | 
    
         
            +
                    end
         
     | 
| 
      
 217 
     | 
    
         
            +
                  end
         
     | 
| 
      
 218 
     | 
    
         
            +
             
     | 
| 
      
 219 
     | 
    
         
            +
                  def build_sidecar_ports(sidecar)
         
     | 
| 
      
 220 
     | 
    
         
            +
                    return nil unless sidecar["ports"]
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
                    sidecar["ports"].map do |port|
         
     | 
| 
      
 223 
     | 
    
         
            +
                      if port.is_a?(Hash)
         
     | 
| 
      
 224 
     | 
    
         
            +
                        result = {}
         
     | 
| 
      
 225 
     | 
    
         
            +
                        result[:name] = port["name"] if port["name"]
         
     | 
| 
      
 226 
     | 
    
         
            +
                        result[:containerPort] = port["containerPort"] if port["containerPort"]
         
     | 
| 
      
 227 
     | 
    
         
            +
                        result[:protocol] = port["protocol"] if port["protocol"]
         
     | 
| 
      
 228 
     | 
    
         
            +
                        result
         
     | 
| 
      
 229 
     | 
    
         
            +
                      elsif port.is_a?(Integer)
         
     | 
| 
      
 230 
     | 
    
         
            +
                        { containerPort: port }
         
     | 
| 
      
 231 
     | 
    
         
            +
                      end
         
     | 
| 
      
 232 
     | 
    
         
            +
                    end.compact
         
     | 
| 
      
 233 
     | 
    
         
            +
                  end
         
     | 
| 
      
 234 
     | 
    
         
            +
             
     | 
| 
      
 235 
     | 
    
         
            +
                  def build_sidecar_volume_mounts(sidecar)
         
     | 
| 
      
 236 
     | 
    
         
            +
                    return nil unless sidecar["volumeMounts"]
         
     | 
| 
      
 237 
     | 
    
         
            +
             
     | 
| 
      
 238 
     | 
    
         
            +
                    sidecar["volumeMounts"].map do |mount|
         
     | 
| 
      
 239 
     | 
    
         
            +
                      result = {}
         
     | 
| 
      
 240 
     | 
    
         
            +
                      result[:name] = mount["name"] if mount["name"]
         
     | 
| 
      
 241 
     | 
    
         
            +
                      result[:mountPath] = mount["mountPath"] if mount["mountPath"]
         
     | 
| 
      
 242 
     | 
    
         
            +
                      result[:readOnly] = mount["readOnly"] if mount.key?("readOnly")
         
     | 
| 
      
 243 
     | 
    
         
            +
                      result[:subPath] = mount["subPath"] if mount["subPath"]
         
     | 
| 
      
 244 
     | 
    
         
            +
                      result
         
     | 
| 
      
 245 
     | 
    
         
            +
                    end
         
     | 
| 
      
 246 
     | 
    
         
            +
                  end
         
     | 
| 
      
 247 
     | 
    
         
            +
             
     | 
| 
      
 248 
     | 
    
         
            +
                  def build_env_hash_for_expansion
         
     | 
| 
      
 249 
     | 
    
         
            +
                    # Build hash of all environment variables with same precedence as env_vars
         
     | 
| 
      
 250 
     | 
    
         
            +
                    env_hash = {}
         
     | 
| 
      
 251 
     | 
    
         
            +
             
     | 
| 
      
 252 
     | 
    
         
            +
                    # Load in order of precedence (later values override earlier)
         
     | 
| 
      
 253 
     | 
    
         
            +
                    [
         
     | 
| 
      
 254 
     | 
    
         
            +
                      @data.dig("application_yaml", :environment),
         
     | 
| 
      
 255 
     | 
    
         
            +
                      @data.dig("application_yaml", @data["env"], :environment),
         
     | 
| 
      
 256 
     | 
    
         
            +
                      app_vars[:environment],
         
     | 
| 
      
 257 
     | 
    
         
            +
                      app_vars.dig(@data["env"], :environment)
         
     | 
| 
      
 258 
     | 
    
         
            +
                    ].each do |env_vars|
         
     | 
| 
      
 259 
     | 
    
         
            +
                      next unless env_vars
         
     | 
| 
      
 260 
     | 
    
         
            +
                      env_vars.each do |key, value|
         
     | 
| 
      
 261 
     | 
    
         
            +
                        # Skip special field/ and configmap/ references
         
     | 
| 
      
 262 
     | 
    
         
            +
                        unless value.to_s.start_with?("field/", "configmap/")
         
     | 
| 
      
 263 
     | 
    
         
            +
                          env_hash[key.to_s] = value.to_s
         
     | 
| 
      
 264 
     | 
    
         
            +
                        end
         
     | 
| 
      
 265 
     | 
    
         
            +
                      end
         
     | 
| 
      
 266 
     | 
    
         
            +
                    end
         
     | 
| 
      
 267 
     | 
    
         
            +
             
     | 
| 
      
 268 
     | 
    
         
            +
                    env_hash
         
     | 
| 
      
 269 
     | 
    
         
            +
                  end
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
      
 271 
     | 
    
         
            +
                  def expand_variables(str)
         
     | 
| 
      
 272 
     | 
    
         
            +
                    return str unless str.is_a?(String)
         
     | 
| 
      
 273 
     | 
    
         
            +
             
     | 
| 
      
 274 
     | 
    
         
            +
                    env_hash = build_env_hash_for_expansion
         
     | 
| 
      
 275 
     | 
    
         
            +
             
     | 
| 
      
 276 
     | 
    
         
            +
                    # Support both $(VAR) and ${VAR} syntax
         
     | 
| 
      
 277 
     | 
    
         
            +
                    str.gsub(/\$\{([^}]+)\}|\$\(([^)]+)\)/) do
         
     | 
| 
      
 278 
     | 
    
         
            +
                      var_name = $1 || $2
         
     | 
| 
      
 279 
     | 
    
         
            +
                      env_hash[var_name] || "$#{$1 ? "{#{var_name}}" : "(#{var_name})"}"
         
     | 
| 
      
 280 
     | 
    
         
            +
                    end
         
     | 
| 
      
 281 
     | 
    
         
            +
                  end
         
     | 
| 
      
 282 
     | 
    
         
            +
             
     | 
| 
      
 283 
     | 
    
         
            +
                  def clean_command_array(array)
         
     | 
| 
      
 284 
     | 
    
         
            +
                    return nil unless array
         
     | 
| 
      
 285 
     | 
    
         
            +
             
     | 
| 
      
 286 
     | 
    
         
            +
                    array.map do |item|
         
     | 
| 
      
 287 
     | 
    
         
            +
                      if item.is_a?(String)
         
     | 
| 
      
 288 
     | 
    
         
            +
                        expand_variables(item.strip)
         
     | 
| 
      
 289 
     | 
    
         
            +
                      else
         
     | 
| 
      
 290 
     | 
    
         
            +
                        item
         
     | 
| 
      
 291 
     | 
    
         
            +
                      end
         
     | 
| 
      
 292 
     | 
    
         
            +
                    end
         
     | 
| 
      
 293 
     | 
    
         
            +
                  end
         
     | 
| 
      
 294 
     | 
    
         
            +
             
     | 
| 
      
 295 
     | 
    
         
            +
                  def sidecar_containers
         
     | 
| 
      
 296 
     | 
    
         
            +
                    sidecars.map do |sidecar|
         
     | 
| 
      
 297 
     | 
    
         
            +
                      container = {
         
     | 
| 
      
 298 
     | 
    
         
            +
                        name: sidecar["name"],
         
     | 
| 
      
 299 
     | 
    
         
            +
                        image: sidecar["image"],
         
     | 
| 
      
 300 
     | 
    
         
            +
                        restartPolicy: "Always"  # Native sidecar support (K8s 1.28+)
         
     | 
| 
      
 301 
     | 
    
         
            +
                      }
         
     | 
| 
      
 302 
     | 
    
         
            +
             
     | 
| 
      
 303 
     | 
    
         
            +
                      container[:command] = clean_command_array(sidecar["command"])
         
     | 
| 
      
 304 
     | 
    
         
            +
                      container[:args] = clean_command_array(sidecar["args"])
         
     | 
| 
      
 305 
     | 
    
         
            +
                      container[:env] = build_sidecar_env(sidecar)
         
     | 
| 
      
 306 
     | 
    
         
            +
                      container[:envFrom] = env_from  # Inherit ConfigMap/Secret references
         
     | 
| 
      
 307 
     | 
    
         
            +
                      container[:resources] = build_sidecar_resources(sidecar)
         
     | 
| 
      
 308 
     | 
    
         
            +
                      container[:ports] = build_sidecar_ports(sidecar)
         
     | 
| 
      
 309 
     | 
    
         
            +
                      container[:volumeMounts] = build_sidecar_volume_mounts(sidecar)
         
     | 
| 
      
 310 
     | 
    
         
            +
                      container[:imagePullPolicy] = sidecar["imagePullPolicy"] if sidecar["imagePullPolicy"]
         
     | 
| 
      
 311 
     | 
    
         
            +
                      container[:securityContext] = sidecar["securityContext"].transform_keys(&:to_sym) if sidecar["securityContext"]
         
     | 
| 
      
 312 
     | 
    
         
            +
             
     | 
| 
      
 313 
     | 
    
         
            +
                      container.compact
         
     | 
| 
      
 314 
     | 
    
         
            +
                    end
         
     | 
| 
      
 315 
     | 
    
         
            +
                  end
         
     | 
| 
      
 316 
     | 
    
         
            +
             
     | 
| 
       167 
317 
     | 
    
         
             
                  def base_labels
         
     | 
| 
       168 
318 
     | 
    
         
             
                    {
         
     | 
| 
       169 
319 
     | 
    
         
             
                      application: @data['application'],
         
     | 
    
        data/lib/pfab/templates/cron.rb
    CHANGED
    
    
    
        data/lib/pfab/templates/job.rb
    CHANGED
    
    
    
        data/lib/pfab/templates/web.rb
    CHANGED
    
    | 
         @@ -282,6 +282,7 @@ module Pfab 
     | 
|
| 
       282 
282 
     | 
    
         
             
                          spec: {
         
     | 
| 
       283 
283 
     | 
    
         
             
                            serviceAccountName: get('serviceAccountName'),
         
     | 
| 
       284 
284 
     | 
    
         
             
                            terminationGracePeriodSeconds: get("terminationGracePeriodSeconds") || 30,
         
     | 
| 
      
 285 
     | 
    
         
            +
                            initContainers: sidecar_containers.empty? ? nil : sidecar_containers,
         
     | 
| 
       285 
286 
     | 
    
         
             
                            containers: [
         
     | 
| 
       286 
287 
     | 
    
         
             
                              {
         
     | 
| 
       287 
288 
     | 
    
         
             
                                image: image_name,
         
     | 
    
        data/lib/pfab/version.rb
    CHANGED
    
    
    
        data/pfab.gemspec
    CHANGED
    
    | 
         @@ -2,16 +2,16 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            # DO NOT EDIT THIS FILE DIRECTLY
         
     | 
| 
       3 
3 
     | 
    
         
             
            # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
         
     | 
| 
       4 
4 
     | 
    
         
             
            # -*- encoding: utf-8 -*-
         
     | 
| 
       5 
     | 
    
         
            -
            # stub: pfab 0. 
     | 
| 
      
 5 
     | 
    
         
            +
            # stub: pfab 0.59.0 ruby lib
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       8 
8 
     | 
    
         
             
              s.name = "pfab".freeze
         
     | 
| 
       9 
     | 
    
         
            -
              s.version = "0. 
     | 
| 
      
 9 
     | 
    
         
            +
              s.version = "0.59.0".freeze
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
         
     | 
| 
       12 
12 
     | 
    
         
             
              s.require_paths = ["lib".freeze]
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.authors = ["Jeff Dwyer".freeze]
         
     | 
| 
       14 
     | 
    
         
            -
              s.date = "2025- 
     | 
| 
      
 14 
     | 
    
         
            +
              s.date = "2025-10-28"
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.description = "k8s helper".freeze
         
     | 
| 
       16 
16 
     | 
    
         
             
              s.email = "jdwyer@prefab.cloud".freeze
         
     | 
| 
       17 
17 
     | 
    
         
             
              s.executables = ["pfab".freeze]
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: pfab
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.59.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jeff Dwyer
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2025- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2025-10-28 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: commander
         
     |