karmab / kcli

Management tool for virtualization and kubernetes platforms
https://kcli.readthedocs.io/en/latest/
Apache License 2.0
505 stars 138 forks source link

my old plan doesn't seem to work anymore. #716

Closed kundeng closed 1 month ago

kundeng commented 1 month ago

I'm getting the following error when trying to apply it:

INFO Ignition-Configs created in: /home/kundeng/.kcli/clusters/devk and /home/kundeng/.kcli/clusters/devk/auth 
Using keepalived virtual_router_id 180
Using 192.168.123.200 for api vip....
Traceback (most recent call last):
  File "/usr/bin/kcli", line 33, in <module>
    sys.exit(load_entry_point('kcli==99.0', 'console_scripts', 'kcli')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/kvirt/cli.py", line 5543, in cli
    args.func(args)
  File "/usr/lib/python3/dist-packages/kvirt/cli.py", line 2205, in create_plan
    result = config.plan(plan, ansible=ansible, url=url, path=path, container=container, inputfile=inputfile,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/kvirt/config.py", line 1961, in plan
    result = currentconfig.create_kube(plan, kubetype, overrides=kube_overrides)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/kvirt/config.py", line 2681, in create_kube
    result = self.create_kube_openshift(cluster, overrides=overrides)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/kvirt/config.py", line 2769, in create_kube_openshift
    return openshift.create(self, plandir, cluster, overrides, dnsconfig=dnsconfig)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/kvirt/cluster/openshift/__init__.py", line 1629, in create
    backup_paramfile(config.client, installparam, clusterdir, cluster, plan, image, dnsconfig)
  File "/usr/lib/python3/dist-packages/kvirt/cluster/openshift/__init__.py", line 219, in backup_paramfile
    safe_dump(installparam, p, default_flow_style=False, encoding='utf-8', allow_unicode=True)
  File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 269, in safe_dump
    return dump_all([data], stream, Dumper=SafeDumper, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 241, in dump_all
    dumper.represent(data)
  File "/usr/lib/python3/dist-packages/yaml/representer.py", line 27, in represent
    node = self.represent_data(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/yaml/representer.py", line 58, in represent_data
    node = self.yaml_representers[None](self, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/yaml/representer.py", line 231, in represent_undefined
    raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', environ({'SHELL': '/bin/bash', 'TERM_PROGRAM_VERSION': '3.4', 'TMUX': '/tmp/tmux-1000/default,27349,0', 'PWD': '/home/kundeng/devk', 'LOGNAME': 'kundeng', 'XDG_SESSION_TYPE': 'tty', 'HOME': '/home/kundeng', 'LANG': 'en_US.UTF-8', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:', 'SSH_CONNECTION': '192.168.1.67 60043 192.168.1.141 22', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'XDG_SESSION_CLASS': 'user', 'TERM': 'tmux-256color', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'LIBVIRT_DEFAULT_URI': 'qemu:///system', 'USER': 'kundeng', 'TMUX_PANE': '%0', 'SHLVL': '2', 'XDG_SESSION_ID': '1132', 'XDG_RUNTIME_DIR': '/run/user/1000', 'SSH_CLIENT': '192.168.1.67 60043 22', 'DEBUGINFOD_URLS': 'https://debuginfod.ubuntu.com ', 'XDG_DATA_DIRS': '/usr/share/gnome:/home/kundeng/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop', 'PATH': '/home/kundeng/devk:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/kundeng/devk', 'DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus', 'SSH_TTY': '/dev/pts/0', 'OLDPWD': '/mnt/Dropbox/config/homelab_ser_k/infra/devk', 'TERM_PROGRAM': 'tmux', '_': '/usr/bin/kcli', 'KUBECONFIG': '/home/kundeng/.kcli/clusters/devk/auth/kubeconfig'}))
kundeng commented 1 month ago

here is the plan that used to work:

parameters:
  cluster: devk
  domain: bayeslearner.org
  #number: 2
  network: devk
  cidr: 192.168.123.0/24

{{ network }}:
  type: network
  cidr: {{ cidr }}

{% set num = 0 %}

{% set api_ip = cidr|network_ip(200 + num ) %}

{% set cluster = 'devk' %}

{{cluster}}:
  cluster: {{cluster}}
  type: cluster
  kubetype: openshift
  domain: {{ domain }}
  ctlplanes: 3
  workers: 0     # single node
  disk_size: 100
  #extra_ctlplane_disks: [50]
  #extra_disks: [50]
  api_ip: {{ api_ip }}
  numcpus: 4
  memory: 20480 
  nfs_sc: True
  network: {{network}}
  apps: 
    - nfs

api-{{cluster}}:
 type: dns
 net: {{ network }}
 ip: {{ api_ip }}
 alias:
 - api.{{ cluster }}.{{ domain }}
 - api-int.{{ cluster }}.{{ domain }}

{% if num == 0 %}
apps-{{cluster}}:
 type: dns
 net: {{ network }}
 ip: {{ api_ip }}
 alias:
 - console-openshift-console.apps.{{ cluster }}.{{ domain }}
 - oauth-openshift.apps.{{ cluster }}.{{ domain }}
 - prometheus-k8s-openshift-monitoring.apps.{{ cluster }}.{{ domain }}
 - canary-openshift-ingress-canary.apps.{{ cluster }}.{{ domain }}
 - multicloud-console.apps.{{ cluster }}.{{ domain }}
{% endif %}
karmab commented 1 month ago

fixed here

(side note: your old plan didnt fully work in the past, because you had the same key used twice. This works now because we allow the same key to be repeated when the type is different)

kundeng commented 1 month ago

What key? key in the env variables or in the kcli plan?

karmab commented 1 month ago

in your example, you set cluster and network variables to both devk. So it means you rendered plan has devk repeated. In such a case, old behaviour was to silently ignore one of the entries (probably the first one), because that's how default yaml parser handles this. But I was asked to change this behaviour since it's fine to reuse the same key when the type is different

karmab commented 1 month ago

Also note I reverted for complete this env functionality. This looked appealing, but I think it's confusing for the user to have all the env variables as extra variables instead of picking selective ones