Files
egress-proxies-operator/internal/provider/kvm2/id.go
T
kacerrandClaude Fable 5.1 95768281be kvm2: config block, constructor registration, IDs, state mapping and classify
The kvm2 block reuses KVMConfig; validateKVM gains a block-name variant so
messages say kvm2. The package skeleton has a non-dialing New, strict
providerID parsing, the state table and a 34-row classify test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 16:38:48 +00:00

29 lines
987 B
Go

package kvm2
import (
"strings"
)
// The providerID is hosts/<host>/domains/<name>. Host names are validated at
// config load to contain no slash, and domain names come from NameFromUID,
// so a strict four-segment split is enough to parse it.
const (
idHostsSegment = "hosts"
idDomainsSegment = "domains"
)
func formatProviderID(host, name string) string {
return idHostsSegment + "/" + host + "/" + idDomainsSegment + "/" + name
}
// parseProviderID splits an ID back into host and domain name. Anything
// that is not exactly hosts/<host>/domains/<name> with both non-empty is
// ErrPermanent: no retry will make it resolve.
func parseProviderID(id string) (host, name string, err error) {
parts := strings.Split(id, "/")
if len(parts) != 4 || parts[0] != idHostsSegment || parts[2] != idDomainsSegment || parts[1] == "" || parts[3] == "" {
return "", "", permanentf("malformed providerID %q: want hosts/<host>/domains/<name>", id)
}
return parts[1], parts[3], nil
}