Files
homelab/ci/images/kuma-sync/internal/controller/mapping.go
claude-botandClaude Opus 5.5 7f29ebb878
review-bot reviewed: comment
ci/woodpecker/pr/ci-scripts-test Pipeline was successful
ci/woodpecker/pr/review-bot-test Pipeline was successful
ci/woodpecker/pr/ci-manifests-test Pipeline was successful
chore: follow homelab to konairius/homelab
Flux source URL, flux-git rotator verify repo, review-bot REPOS, pipeline API,
clone and push URLs, the heating-can source label and the review-bot and
kuma-sync Go module paths. Merge right after the transfer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:43:23 +02:00

70 lines
1.7 KiB
Go

package controller
import (
"maps"
"slices"
v1 "gitea.renner.uno/konairius/homelab/kuma-sync/api/v1alpha1"
"gitea.renner.uno/konairius/homelab/kuma-sync/internal/kumaclient"
)
// defaultMaxRedirects is Kuma's default for a monitor with no explicit value.
const defaultMaxRedirects = 10
// OwnerKey is the value of the kuma-sync tag for a resource.
func OwnerKey(km *v1.KumaMonitor) string {
return km.Namespace + "/" + km.Name
}
// Desired maps a spec to the monitor Kuma should hold. Parent is resolved by
// the reconciler.
func Desired(km *v1.KumaMonitor) kumaclient.Monitor {
s := km.Spec
m := kumaclient.Monitor{
Type: s.Type,
Name: s.DisplayName,
Description: s.Description,
Active: !s.Paused,
Interval: s.Interval,
RetryInterval: s.RetryInterval,
MaxRetries: s.MaxRetries,
OwnerKey: OwnerKey(km),
}
if s.Timeout != nil {
m.Timeout = *s.Timeout
}
if h := s.HTTP; h != nil {
m.URL = h.URL
m.Method = h.Method
m.AcceptedStatusCodes = slices.Clone(h.AcceptedStatusCodes)
m.Headers = maps.Clone(h.Headers)
m.Body = h.Body
m.MaxRedirects = defaultMaxRedirects
if h.MaxRedirects != nil {
m.MaxRedirects = *h.MaxRedirects
}
m.IgnoreTLS = h.IgnoreTLS
m.ExpiryNotification = h.ExpiryNotification
}
if k := s.Keyword; k != nil {
m.Keyword = k.Keyword
m.InvertKeyword = k.Invert
}
if q := s.JSONQuery; q != nil {
m.JSONPath = q.Expression
m.JSONPathOperator = q.Operator
m.ExpectedValue = q.Expected
}
if d := s.DNS; d != nil {
m.Hostname = d.Hostname
m.DNSResolveType = d.ResolveType
m.DNSResolveServer = d.ResolveServer
m.Port = d.Port
}
if p := s.Port; p != nil {
m.Hostname = p.Hostname
m.Port = p.Port
}
return m
}