123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package kube
- import (
- "errors"
- "regexp"
- "strings"
- )
- type annotations struct {
- SubnetKubeManaged string
- BackendData string
- BackendType string
- BackendPublicIP string
- BackendPublicIPOverwrite string
- }
- func newAnnotations(prefix string) (annotations, error) {
- slashCnt := strings.Count(prefix, "/")
- if slashCnt > 1 {
- return annotations{}, errors.New("subnet/kube: prefix can contain at most single slash")
- }
- if slashCnt == 0 {
- prefix += "/"
- }
- if !strings.HasSuffix(prefix, "/") && !strings.HasSuffix(prefix, "-") {
- prefix += "-"
- }
- matches, err := regexp.MatchString(`(?:[a-z0-9_-]+\.)+[a-z0-9_-]+/(?:[a-z0-9_-]+-)?$`, prefix)
- if err != nil {
- panic(err)
- }
- if !matches {
- return annotations{}, errors.New("subnet/kube: prefix must be in a format: fqdn/[0-9a-z-_]*")
- }
- a := annotations{
- SubnetKubeManaged: prefix + "kube-subnet-manager",
- BackendData: prefix + "backend-data",
- BackendType: prefix + "backend-type",
- BackendPublicIP: prefix + "public-ip",
- BackendPublicIPOverwrite: prefix + "public-ip-overwrite",
- }
- return a, nil
- }
|