kapicorp/kapitan-reference

Error creating a cronjob resource

Moep90 opened this issue · 2 comments

When trying to create cronjob resource with the following config:

parameters:
  postgres-backup:
    image: moep1990/pgbackup:latest
    component: database
  
  persistence:
    backup:
      storageclass: ${storageclass}
      accessModes: ["ReadWriteOnce"]
      size: 10Gi

  components:
    postgres-backup:
      type: job
      schedule: "0 */6 * * *"
      image: ${postgres-backup:image}
      env:
        PGDATABASE: ${database:name}
        PGHOST: ${database:host}
        PGPASSWORD: "xyz"
        PGPORT: ${database:port}
        PGUSER: ${database:user}
      # Persistence
      volume_mounts:
        backup:
          mountPath: /var/postgres
          subPath: postgres
      volume_claims:
        backup:
          spec:
            accessModes: ${persistence:backup:accessModes}
            storageClassName: ${persistence:backup:storageclass}
            resources:
              requests:
                storage: ${persistence:backup:size}

I get the following error:

$ ./kapitan compile -t artifactory
Unknown (Non-Kapitan) Error occurred
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/multiprocessing/pool.py", line 121, in worker
    result = (True, func(*args, **kwds))
  File "/opt/venv/lib/python3.7/site-packages/kapitan/targets.py", line 466, in compile_target
    input_compiler.compile_obj(comp_obj, ext_vars, **kwargs)
  File "/opt/venv/lib/python3.7/site-packages/kapitan/inputs/base.py", line 55, in compile_obj
    self.compile_input_path(input_path, comp_obj, ext_vars, **kwargs)
  File "/opt/venv/lib/python3.7/site-packages/kapitan/inputs/base.py", line 77, in compile_input_path
    **kwargs,
  File "/opt/venv/lib/python3.7/site-packages/kapitan/inputs/kadet.py", line 120, in compile_file
    output_obj = kadet_module.main(input_params).to_dict()
  File "/src/components/generators/kubernetes/__init__.py", line 908, in main
    return globals()[function](input_params)
  File "/src/components/generators/kubernetes/__init__.py", line 841, in generate_manifests
    workload.add_volumes_for_objects(configs)
AttributeError: 'CronJob' object has no attribute 'add_volumes_for_objects'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.7/site-packages/kapitan/targets.py", line 136, in compile_targets
    [p.get() for p in pool.imap_unordered(worker, target_objs) if p]
  File "/opt/venv/lib/python3.7/site-packages/kapitan/targets.py", line 136, in <listcomp>
    [p.get() for p in pool.imap_unordered(worker, target_objs) if p]
  File "/usr/local/lib/python3.7/multiprocessing/pool.py", line 748, in next
    raise value
AttributeError: 'CronJob' object has no attribute 'add_volumes_for_objects'


'CronJob' object has no attribute 'add_volumes_for_objects'

Potentially fixed by #84

Fixed Thx @ademariag !

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  annotations:
    manifests.kapicorp.com/generated: 'true'
[...]
spec:
  jobTemplate:
    spec:
      backoffLimit: 1
      completions: 1
      parallelism: 1
[...]
  schedule: 0 */6 * * *
  template:
    spec:
      volumes:
        - configMap:
            defaultMode: 420
            name: postgres-backup
          name: config