From a759d9d8044d8e24c57905e42e85878a9901fbe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Krupa=20=28paulfantom=29?= Date: Fri, 25 Feb 2022 13:59:59 +0100 Subject: [PATCH] metal: update k3s cluster and cleanup ansible code --- metal/01_system.yml | 5 -- metal/group_vars/k3s.yml | 3 +- metal/inventory | 3 - metal/roles/fans/files/fan.py | 96 ---------------------- metal/roles/fans/files/fan.service | 13 --- metal/roles/fans/handlers/main.yml | 7 -- metal/roles/fans/tasks/main.yml | 16 ---- metal/roles/k3s-download/defaults/main.yml | 2 +- metal/roles/k3s-download/tasks/main.yml | 4 +- metal/roles/k3s-node/handlers/main.yml | 7 ++ metal/roles/k3s-node/tasks/main.yml | 8 +- metal/roles/requirements.yml | 4 - 12 files changed, 13 insertions(+), 155 deletions(-) delete mode 100755 metal/roles/fans/files/fan.py delete mode 100644 metal/roles/fans/files/fan.service delete mode 100644 metal/roles/fans/handlers/main.yml delete mode 100644 metal/roles/fans/tasks/main.yml create mode 100644 metal/roles/k3s-node/handlers/main.yml diff --git a/metal/01_system.yml b/metal/01_system.yml index 6a18f3080..f637c0ba3 100644 --- a/metal/01_system.yml +++ b/metal/01_system.yml @@ -49,8 +49,3 @@ any_errors_fatal: true roles: - paulfantom.raspberry - -- hosts: fancontroler - become: true - roles: - - fans diff --git a/metal/group_vars/k3s.yml b/metal/group_vars/k3s.yml index 29d57114e..5d9bee01b 100644 --- a/metal/group_vars/k3s.yml +++ b/metal/group_vars/k3s.yml @@ -1,12 +1,11 @@ --- -k3s_version: v1.22.3+k3s1 +k3s_version: v1.23.4+k3s1 k3s_master_ip: "{{ hostvars[groups['k3s-master'][0]]['ansible_default_ipv4']['address'] }}" k3s_extra_server_args: >- --disable servicelb --disable traefik --disable local-storage --disable-cloud-controller - --node-taint node-role.kubernetes.io/control-plane=true:NoSchedule --kubelet-arg system-reserved=cpu=100m,memory=200Mi --kubelet-arg kube-reserved=cpu=100m,memory=300Mi --kube-controller-manager-arg address={{ k3s_master_ip }} diff --git a/metal/inventory b/metal/inventory index 3637ff677..548b98e3a 100644 --- a/metal/inventory +++ b/metal/inventory @@ -10,9 +10,6 @@ node02 ansible_user=ubuntu ansible_host=192.168.2.32 network=fast k3s_local_st #node04 ansible_user=ubuntu ansible_host=192.168.2.34 metal01 ansible_user=ubuntu ansible_host=192.168.2.40 network=fast k3s_local_storage_device=/dev/ubuntu-vg/k3s-local-storage enable_smartmon=true -[fancontroler] -master01 - [raspberry] master01 node0[1:2] diff --git a/metal/roles/fans/files/fan.py b/metal/roles/fans/files/fan.py deleted file mode 100755 index c04a68307..000000000 --- a/metal/roles/fans/files/fan.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env python3 - -# Original code in https://github.com/bk4nt/pi-fan-pwm - -import time -import signal -import sys -import RPi.GPIO as GPIO - -FAN_PWM = 18 # PWM input pin -FAN_TACH = 23 # Fan's tachometer output pin -FAN_PULSES = 2 # Noctua fans puts out two pluses per revolution -FAN_FREQ = 100 # Shall be 25kHz. See README.md - -INTERVAL = 1 -MIN_DUTY = 22 # Shouldn't be less than 20 -MAX_DUTY = 50 # Shouldn't be less than MIN_DUTY -MAX_TEMP = 75 - -TEMP_OFFSET = -6 - -TEMP_SOURCE = '/sys/class/thermal/thermal_zone0/temp' -METRICS_FILE = "/var/lib/node_exporter/fans.prom" - - -def signal_handler(sig, frame): - tFile.close() - fan.ChangeDutyCycle(100) # Fan at full speed on exit - GPIO.cleanup() - sys.exit(0) - - -signal.signal(signal.SIGINT, signal_handler) -signal.signal(signal.SIGTERM, signal_handler) - -GPIO.setmode(GPIO.BCM) - -GPIO.setup(18, GPIO.OUT) -fan = GPIO.PWM(FAN_PWM, FAN_FREQ) -fan.start(100) # Start at full fan speed - -GPIO.setup(FAN_TACH, GPIO.IN, pull_up_down=GPIO.PUD_UP) -t = time.time() -pulses = 0 - - -# Count pulses on FAN_TACH pin -def fell(n): - global t - global pulses - if time.time() - t > 0.005: # Eliminate any spurious pulses - pulses += 1 - t = time.time() - - -GPIO.add_event_detect(FAN_TACH, GPIO.FALLING, fell) - -dc = 0 - -# Calculate ratio (min temp - 38C) -ratio = (100 - MIN_DUTY) / (MAX_TEMP - 38.0) -print("Startup parameters: ratio - %f, max_temp - %d, min_duty - %f" % (ratio, MAX_TEMP, MIN_DUTY)) - -while True: - start = time.time() - with open(TEMP_SOURCE) as tFile: - temp = float(tFile.read()) - tempC = temp/1000.0 - - # This should be handled by getting metrics from prometheus and using highest one - tempC = tempC + TEMP_OFFSET - - # Tweak here minimal dc (PWM Duty Cycle), temp threshold and ratio - dc = MIN_DUTY + max(0, int((tempC - 38) * ratio)) - dc = min(dc, MAX_DUTY) - fan.ChangeDutyCycle(dc) - - rpm = pulses * 60 / (FAN_PULSES * INTERVAL) - pulses = 0 - - metrics = """# HELP fans_rpm Fan RPM -# TYPE fans_rpm gauge -fans_rpm %d -# HELP fans_duty_cycle Current duty cycle for PWM fan control -# TYPE fans_duty_cycle gauge -fans_duty_cycle %d -# HELP fans_temperature Detected temperature used as source for fan speed control -# TYPE fans_temperature gauge -fans_temperature %f -""" % (rpm, dc, tempC) - - with open(METRICS_FILE, 'w') as outFile: - outFile.write(metrics) - - diff = time.time() - start - time.sleep(INTERVAL - diff) diff --git a/metal/roles/fans/files/fan.service b/metal/roles/fans/files/fan.service deleted file mode 100644 index 35d067e2a..000000000 --- a/metal/roles/fans/files/fan.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Fan controller - -[Service] -ExecStart=/usr/bin/python3 /usr/local/bin/fan.py -Environment=PYTHONUNBUFFERED=1 -Restart=on-failure -User=root -Nice=-5 - -[Install] -WantedBy=default.target - diff --git a/metal/roles/fans/handlers/main.yml b/metal/roles/fans/handlers/main.yml deleted file mode 100644 index 241ae43a7..000000000 --- a/metal/roles/fans/handlers/main.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: restart fan service - systemd: - name: fan.service - state: restarted - enabled: true - daemon_reload: true diff --git a/metal/roles/fans/tasks/main.yml b/metal/roles/fans/tasks/main.yml deleted file mode 100644 index 008acb99b..000000000 --- a/metal/roles/fans/tasks/main.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: Install required packages - package: - name: "python3-rpi.gpio" - state: present - -- name: Copy fan controller script and systemd service - copy: - src: "{{ item.src }}" - dest: "{{ item.dst }}" - with_items: - - src: "fan.py" - dst: "/usr/local/bin/fan.py" - - src: "fan.service" - dst: "/etc/systemd/system/fan.service" - notify: restart fan service diff --git a/metal/roles/k3s-download/defaults/main.yml b/metal/roles/k3s-download/defaults/main.yml index 145e7b7af..01b0961e6 100644 --- a/metal/roles/k3s-download/defaults/main.yml +++ b/metal/roles/k3s-download/defaults/main.yml @@ -1,2 +1,2 @@ --- -k3s_version: "v1.17.4+k3s1" +k3s_version: "v1.23.4+k3s1" diff --git a/metal/roles/k3s-download/tasks/main.yml b/metal/roles/k3s-download/tasks/main.yml index 8da7d51fd..9f4e920d5 100644 --- a/metal/roles/k3s-download/tasks/main.yml +++ b/metal/roles/k3s-download/tasks/main.yml @@ -7,12 +7,14 @@ - name: Check current k3s version command: /usr/local/bin/k3s --version register: _k3s_local_version_string + check_mode: no when: _k3s_binary.stat.exists - name: Extract current version set_fact: _k3s_local_version: "{{ _k3s_local_version_string.stdout.split(' ')[2] }}" - when: _k3s_binary.stat.exists + check_mode: no + when: _k3s_binary.stat.exists and (_k3s_local_version_string is defined) - name: Download k3s binary get_url: diff --git a/metal/roles/k3s-node/handlers/main.yml b/metal/roles/k3s-node/handlers/main.yml new file mode 100644 index 000000000..b43fe1396 --- /dev/null +++ b/metal/roles/k3s-node/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart k3s + systemd: + name: k3s + daemon_reload: yes + state: restarted + enabled: yes \ No newline at end of file diff --git a/metal/roles/k3s-node/tasks/main.yml b/metal/roles/k3s-node/tasks/main.yml index a13009124..d97c50d87 100644 --- a/metal/roles/k3s-node/tasks/main.yml +++ b/metal/roles/k3s-node/tasks/main.yml @@ -6,10 +6,4 @@ owner: root group: root mode: 0755 - -- name: Enable and check K3s service - systemd: - name: k3s-node - daemon_reload: yes - state: restarted - enabled: yes + notify: restart k3s diff --git a/metal/roles/requirements.yml b/metal/roles/requirements.yml index 1246579b0..dd8e81f1c 100644 --- a/metal/roles/requirements.yml +++ b/metal/roles/requirements.yml @@ -1,12 +1,8 @@ --- -- name: cloudalchemy.node_exporter - name: cloudalchemy.systemd_exporter - name: oefenweb.locales version: v1.0.49 - name: jnv.unattended-upgrades version: v1.12.1 - name: dev-sec.ssh-hardening -#- name: geerlingguy.nfs # conflicts with current ZFS setup - name: paulfantom.raspberry -#- name: bertvv.samba -# version: v2.7.1