github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/pkg/labels/selectable.go (about) 1 package labels 2 3 import "gopkg.in/yaml.v3" 4 5 var ( 6 _ IDLabels = (*Selectable)(nil) 7 selectable = InternalSelectableProp{Selectable: "yes"} 8 ) 9 10 type Selectable struct { 11 model InternalSelectable 12 base *Name 13 } 14 15 type InternalSelectableProp struct { 16 Selectable string `yaml:"orbos.ch/selectable"` 17 } 18 19 type InternalSelectable struct { 20 InternalSelectableProp `yaml:",inline"` 21 InternalName `yaml:",inline"` 22 } 23 24 func AsSelectable(l *Name) *Selectable { 25 return &Selectable{ 26 base: l, 27 model: InternalSelectable{ 28 InternalName: l.model, 29 InternalSelectableProp: selectable, 30 }, 31 } 32 } 33 34 func (l *Selectable) UnmarshalYAML(node *yaml.Node) error { 35 if err := node.Decode(&l.model); err != nil { 36 return err 37 } 38 l.base = &Name{} 39 return node.Decode(l.base) 40 } 41 42 /* 43 func (l *Selectable) Major() int8 { 44 return l.base.Major() 45 } 46 */ 47 48 func (l *Selectable) Name() string { 49 return l.base.Name() 50 } 51 52 func (l *Selectable) Equal(r comparable) bool { 53 if right, ok := r.(*Selectable); ok { 54 return l.model == right.model 55 } 56 return false 57 } 58 59 func (l *Selectable) MarshalYAML() (interface{}, error) { 60 return l.model, nil 61 } 62 63 func MustForNameK8SMap(l *Component, name string) map[string]string { 64 return MustK8sMap(MustForName(l, name)) 65 }