@@ -45,12 +45,24 @@ import (
4545 tpb "github.com/openconfig/kne/proto/topo"
4646)
4747
48- const (
49- // modelCdnos is a string used in the topology to specify that a cdnos
50- // device instance should be created .
51- modelCdnos string = "CDNOS"
48+ var (
49+ // modelCdnos is a list of model names that should be treated as cdnos devices.
50+ // Accept both CDNOS and MCDNOS (case-insensitive) .
51+ modelCdnos = [] string { "CDNOS" , "MCDNOS" }
5252)
5353
54+ // isModelCdnos returns true if the provided model is one of the supported
55+ // cdnos-family models (cdnos or mcdnos), case-insensitive.
56+ func isModelCdnos (model string ) bool {
57+ upper := strings .ToUpper (model )
58+ for _ , m := range modelCdnos {
59+ if upper == m {
60+ return true
61+ }
62+ }
63+ return false
64+ }
65+
5466// extractNodeSelector extracts nodeSelector from constraints map.
5567// Supports two formats:
5668// - Node selector via key prefix "nodeSelector.<labelKey>" => "<value>"
@@ -136,7 +148,7 @@ func New(nodeImpl *node.Impl) (node.Node, error) {
136148 return nil , fmt .Errorf ("nodeImpl.Proto cannot be nil" )
137149 }
138150
139- if nodeImpl .Proto .Model != modelCdnos {
151+ if ! isModelCdnos ( nodeImpl .Proto .Model ) {
140152 return nil , fmt .Errorf ("unknown model" )
141153 }
142154
@@ -163,7 +175,7 @@ var clientFn = func(c *rest.Config) (clientset.Interface, error) {
163175}
164176
165177func (n * Node ) Create (ctx context.Context ) error {
166- if n .Impl .Proto .Model != modelCdnos {
178+ if ! isModelCdnos ( n .Impl .Proto .Model ) {
167179 return fmt .Errorf ("cannot create an instance of an unknown model" )
168180 }
169181 return n .cdnosCreate (ctx )
@@ -198,11 +210,18 @@ func (n *Node) cdnosCreate(ctx context.Context) error {
198210 }
199211 }
200212
213+ // Add model to labels so the controller can access it
214+ labels := make (map [string ]string )
215+ for k , v := range nodeSpec .Labels {
216+ labels [k ] = v
217+ }
218+ labels ["model" ] = strings .ToUpper (nodeSpec .Model )
219+
201220 dut := & cdnosv1.Cdnos {
202221 ObjectMeta : metav1.ObjectMeta {
203222 Name : nodeSpec .Name ,
204223 Namespace : n .Namespace ,
205- Labels : nodeSpec . Labels ,
224+ Labels : labels ,
206225 },
207226 Spec : cdnosv1.CdnosSpec {
208227 Image : config .Image ,
@@ -342,7 +361,7 @@ func (n *Node) annotateCdnosService(ctx context.Context) error {
342361}
343362
344363func (n * Node ) Status (ctx context.Context ) (node.Status , error ) {
345- if n .Impl .Proto .Model != modelCdnos {
364+ if ! isModelCdnos ( n .Impl .Proto .Model ) {
346365 return node .StatusUnknown , fmt .Errorf ("invalid model specified" )
347366 }
348367 return n .cdnosStatus (ctx )
@@ -370,7 +389,7 @@ func (n *Node) cdnosStatus(ctx context.Context) (node.Status, error) {
370389}
371390
372391func (n * Node ) Delete (ctx context.Context ) error {
373- if n .Impl .Proto .Model != modelCdnos {
392+ if ! isModelCdnos ( n .Impl .Proto .Model ) {
374393 return fmt .Errorf ("unknown model" )
375394 }
376395 return n .cdnosDelete (ctx )
0 commit comments