This repository has been archived on 2023-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
kreaper/reaper/types.go

44 lines
669 B
Go
Raw Normal View History

2022-04-13 12:34:27 +00:00
package reaper
import (
"errors"
"flag"
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var ErrNotAVAlidTarget = errors.New("not a valid target")
var _ flag.Value = (*Target)(nil)
type Target string
func (t Target) Selector() (*metav1.LabelSelector, error) {
s := string(t)
if s == "" {
return nil, ErrNotAVAlidTarget
}
key, val, found := strings.Cut(s, "=")
if !found {
return nil, ErrNotAVAlidTarget
}
return &metav1.LabelSelector{
MatchLabels: map[string]string{
key: val,
},
}, nil
}
func (t Target) String() string {
return string(t)
}
func (t *Target) Set(s string) error {
val := (*string)(t)
*val = s
return nil
}