Skip to content

Commit

Permalink
Add ddns updater (#40)
Browse files Browse the repository at this point in the history
* add ddns-updater

* 2 validators

* first providers

* fix

* fix hc

* cf

* more tests

* some questions

* 2 more

* fix

* make it easier to expand

* rename

* fix

* all providers

* moer

* fix

* fix

* more test and fixes

* tests

* namecom

* rest

* extra

* fix

* fix

* fix gcp

* update lib

* clean

* provider list

* common opts

* some ui

* rest

* update lib

* update lib

* update lib

* update lib

* update lib

* update lib

* lint

* update lib

* update lib

* update lib

* update lib

* update lib

* adapt to lib changes

* update lib

* adapt to lib changes

* update lib

* adapt to lib changes

* update lib

* update lib

* update lib

* ix_values

* update lib

* update readme
  • Loading branch information
stavros-k authored Aug 1, 2024
1 parent f679e0d commit ad9f9ae
Show file tree
Hide file tree
Showing 74 changed files with 6,105 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Thank you for your understanding.
| clamav | community | - | - |
| cloudflared | community | - | - |
| dashy | community || - |
| ddns-updater | community | - | - |
| ddns-updater | community | | - |
| deluge | community | - | - |
| distribution | community | - | - |
| drawio | community | - | - |
Expand Down
56 changes: 55 additions & 1 deletion cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
words:
- audiobook
- autobrr
- bazarr
- cifs
- consts
Expand All @@ -9,13 +10,48 @@ words:
- htpasswd
- ipaddr
- dockge
- autobrr
- cooldown
- ddns
- aliyun
- allinkl
- changeip
- ddnss
- desec
- dnsomatic
- dnspod
- Dominio
- dondominio
- dreamhost
- duckdns
- dynu
- dynv
- easydns
- freedns
- gandi
- godaddy
- goip
- goipde
- healtcheck
- hetzner
- icanhazip
- Inkl
- inwx
- ionos
- ipify
- ipinfo
- ipleak
- isready
- jellyfin
- lidarr
- logsearch
- mebibytes
- luadns
- minio
- namecheap
- namecom
- netcup
- njalla
- nnev
- nocopy
- pihole
- plexinc
Expand All @@ -28,7 +64,25 @@ words:
- syncthing
- tailscale
- tailscaled
- noip
- nowdns
- opendns
- porkbun
- proxied
- publicip
- publicipv
- seeip
- selfhost
- selfhost.de
- selfhostde
- servercow
- shoutrrr
- spdyn
- strato
- tmpfs
- tracebacklimit
- truenas
- userspace
- variomedia
- wtfismyip
- zoneedit
3 changes: 3 additions & 0 deletions ix-dev/community/ddns-updater/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DDNS Updater

[DDNS Updater](https://github.com/qdm12/ddns-updater) is a lightweight universal DDNS Updater with web UI
33 changes: 33 additions & 0 deletions ix-dev/community/ddns-updater/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
app_version: 2.7.0
capabilities: []
categories:
- network
description: Lightweight universal DDNS Updater with web UI
home: https://github.com/qdm12/ddns-updater
host_mounts: []
icon: https://media.sys.truenas.net/apps/ddns-updater/icons/icon.svg
keywords:
- ddns-updater
- ddns
lib_version: 1.0.0
lib_version_hash: 66c98111180da566a3bcc9ee1d1be4f673356f453b5d97ee7c784c9a38ee9999
maintainers:
- email: dev@ixsystems.com
name: truenas
url: https://www.truenas.com/
name: ddns-updater
run_as_context:
- description: DDNS Updater runs as any non-root user.
gid: 568
group_name: ddns-updater
uid: 568
user_name: ddns-updater
screenshots:
- https://media.sys.truenas.net/apps/ddns-updater/screenshots/screenshot1.png
sources:
- https://github.com/qdm12/ddns-updater
- https://github.com/truenas/charts/tree/master/community/ddns-updater
- https://hub.docker.com/r/qmcgaw/ddns-updater
title: DDNS Updater
train: community
version: 1.0.0
8 changes: 8 additions & 0 deletions ix-dev/community/ddns-updater/item.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
categories:
- network
icon_url: https://media.sys.truenas.net/apps/ddns-updater/icons/icon.svg
screenshots:
- https://media.sys.truenas.net/apps/ddns-updater/screenshots/screenshot1.png
tags:
- ddns-updater
- ddns
9 changes: 9 additions & 0 deletions ix-dev/community/ddns-updater/ix_values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
images:
image:
repository: qmcgaw/ddns-updater
tag: v2.7.0

consts:
ddns_container_name: ddns
perms_container_name: permissions
data_path: /updater/data
Empty file.
27 changes: 27 additions & 0 deletions ix-dev/community/ddns-updater/migrations/migration_helpers/cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import math
import re
import os

CPU_COUNT = os.cpu_count()

NUMBER_REGEX = re.compile(r"^[1-9][0-9]$")
FLOAT_REGEX = re.compile(r"^[0-9]+\.[0-9]+$")
MILI_CPU_REGEX = re.compile(r"^[0-9]+m$")


def transform_cpu(cpu) -> int:
result = 2
if NUMBER_REGEX.match(cpu):
result = int(cpu)
elif FLOAT_REGEX.match(cpu):
result = int(math.ceil(float(cpu)))
elif MILI_CPU_REGEX.match(cpu):
num = int(cpu[:-1])
num = num / 1000
result = int(math.ceil(num))

if CPU_COUNT is not None:
# Do not exceed the actual CPU count
result = min(result, CPU_COUNT)

return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def migrate_dns_config(dns_config):
if not dns_config:
return []

dns_opts = []
for opt in dns_config.get("options", []):
dns_opts.append(f"{opt['name']}:{opt['value']}")

return dns_opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def get_value_from_secret(secrets={}, secret_name="", key=""):
if not secrets or not secret_name or not key:
raise ValueError("Expected [secrets], [secret_name] and [key] to be set")
for secret in secrets.items():
curr_secret_name = secret[0]
curr_data = secret[1]

if curr_secret_name.endswith(secret_name):
if not curr_data.get(key, None):
raise ValueError(
f"Expected [{key}] to be set in secret [{curr_secret_name}]"
)
return curr_data[key]

raise ValueError(f"Secret [{secret_name}] not found")
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import re
import math
import psutil

TOTAL_MEM = psutil.virtual_memory().total

SINGLE_SUFFIX_REGEX = re.compile(r"^[1-9][0-9]*([EPTGMK])$")
DOUBLE_SUFFIX_REGEX = re.compile(r"^[1-9][0-9]*([EPTGMK])i$")
BYTES_INTEGER_REGEX = re.compile(r"^[1-9][0-9]*$")
EXPONENT_REGEX = re.compile(r"^[1-9][0-9]*e[0-9]+$")

SUFFIX_MULTIPLIERS = {
"K": 10**3,
"M": 10**6,
"G": 10**9,
"T": 10**12,
"P": 10**15,
"E": 10**18,
}

DOUBLE_SUFFIX_MULTIPLIERS = {
"Ki": 2**10,
"Mi": 2**20,
"Gi": 2**30,
"Ti": 2**40,
"Pi": 2**50,
"Ei": 2**60,
}


def transform_memory(memory):
result = 4096 # Default to 4GB

if re.match(SINGLE_SUFFIX_REGEX, memory):
suffix = memory[-1]
result = int(memory[:-1]) * SUFFIX_MULTIPLIERS[suffix]
elif re.match(DOUBLE_SUFFIX_REGEX, memory):
suffix = memory[-2:]
result = int(memory[:-2]) * DOUBLE_SUFFIX_MULTIPLIERS[suffix]
elif re.match(BYTES_INTEGER_REGEX, memory):
result = int(memory)
elif re.match(EXPONENT_REGEX, memory):
result = int(float(memory))

result = math.ceil(result)
result = min(result, TOTAL_MEM)
# Convert to Megabytes
result = result / 1024 / 1024
return int(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from .memory import transform_memory, TOTAL_MEM
from .cpu import transform_cpu, CPU_COUNT


def migrate_resources(resources, gpus=None, system_gpus=None):
gpus = gpus or {}
system_gpus = system_gpus or []

result = {
"limits": {
"cpus": (CPU_COUNT or 2) / 2,
"memory": {TOTAL_MEM / 1024 / 1024},
}
}

if resources.get("limits", {}).get("cpu", ""):
result["limits"].update(
{"cpus": transform_cpu(resources.get("limits", {}).get("cpu", ""))}
)
if resources.get("limits", {}).get("memory", ""):
result["limits"].update(
{"memory": transform_memory(resources.get("limits", {}).get("memory", ""))}
)

gpus_result = {}
for gpu in gpus.items() if gpus else []:
kind = gpu[0].lower() # Kind of gpu (amd, nvidia, intel)
count = gpu[1] # Number of gpus user requested

if count == 0:
continue

if "amd" in kind or "intel" in kind:
gpus_result.update({"use_all_gpus": True})
elif "nvidia" in kind:
sys_gpus = [
gpu_item
for gpu_item in system_gpus
if gpu_item.get("error") is None
and gpu_item.get("vendor", None) is not None
and gpu_item.get("vendor", "").upper() == "NVIDIA"
]
for sys_gpu in sys_gpus:
if count == 0: # We passed # of gpus that user previously requested
break
guid = sys_gpu.get("vendor_specific_config", {}).get("uuid", "")
pci_slot = sys_gpu.get("pci_slot", "")
if not guid or not pci_slot:
continue

gpus_result.update(
{"nvidia_gpu_selection": {pci_slot: {"uuid": guid, "use_gpu": True}}}
)
count -= 1

if gpus_result:
result.update({"gpus": gpus_result})

return result
Loading

0 comments on commit ad9f9ae

Please sign in to comment.