@@ -42,12 +42,24 @@ import (
4242 tpb "github.com/openconfig/kne/proto/topo"
4343)
4444
45- const (
46- // modelCdnos is a string used in the topology to specify that a cdnos
47- // device instance should be created .
48- modelCdnos string = "CDNOS"
45+ var (
46+ // modelCdnos is a list of model names that should be treated as cdnos devices.
47+ // Accept both CDNOS and MCDNOS (case-insensitive) .
48+ modelCdnos = [] string { "CDNOS" , "MCDNOS" }
4949)
5050
51+ // isModelCdnos returns true if the provided model is one of the supported
52+ // cdnos-family models (cdnos or mcdnos), case-insensitive.
53+ func isModelCdnos (model string ) bool {
54+ upper := strings .ToUpper (model )
55+ for _ , m := range modelCdnos {
56+ if upper == m {
57+ return true
58+ }
59+ }
60+ return false
61+ }
62+
5163// extractNodeSelector extracts nodeSelector from constraints map.
5264// Supports two formats:
5365// - Node selector via key prefix "nodeSelector.<labelKey>" => "<value>"
@@ -133,7 +145,7 @@ func New(nodeImpl *node.Impl) (node.Node, error) {
133145 return nil , fmt .Errorf ("nodeImpl.Proto cannot be nil" )
134146 }
135147
136- if nodeImpl .Proto .Model != modelCdnos {
148+ if ! isModelCdnos ( nodeImpl .Proto .Model ) {
137149 return nil , fmt .Errorf ("unknown model" )
138150 }
139151
@@ -160,7 +172,7 @@ var clientFn = func(c *rest.Config) (clientset.Interface, error) {
160172}
161173
162174func (n * Node ) Create (ctx context.Context ) error {
163- if n .Impl .Proto .Model != modelCdnos {
175+ if ! isModelCdnos ( n .Impl .Proto .Model ) {
164176 return fmt .Errorf ("cannot create an instance of an unknown model" )
165177 }
166178 return n .cdnosCreate (ctx )
@@ -195,11 +207,18 @@ func (n *Node) cdnosCreate(ctx context.Context) error {
195207 }
196208 }
197209
210+ // Add model to labels so the controller can access it
211+ labels := make (map [string ]string )
212+ for k , v := range nodeSpec .Labels {
213+ labels [k ] = v
214+ }
215+ labels ["model" ] = strings .ToUpper (nodeSpec .Model )
216+
198217 dut := & cdnosv1.Cdnos {
199218 ObjectMeta : metav1.ObjectMeta {
200219 Name : nodeSpec .Name ,
201220 Namespace : n .Namespace ,
202- Labels : nodeSpec . Labels ,
221+ Labels : labels ,
203222 },
204223 Spec : cdnosv1.CdnosSpec {
205224 Image : config .Image ,
@@ -240,7 +259,7 @@ func (n *Node) cdnosCreate(ctx context.Context) error {
240259}
241260
242261func (n * Node ) Status (ctx context.Context ) (node.Status , error ) {
243- if n .Impl .Proto .Model != modelCdnos {
262+ if ! isModelCdnos ( n .Impl .Proto .Model ) {
244263 return node .StatusUnknown , fmt .Errorf ("invalid model specified" )
245264 }
246265 return n .cdnosStatus (ctx )
@@ -268,7 +287,7 @@ func (n *Node) cdnosStatus(ctx context.Context) (node.Status, error) {
268287}
269288
270289func (n * Node ) Delete (ctx context.Context ) error {
271- if n .Impl .Proto .Model != modelCdnos {
290+ if ! isModelCdnos ( n .Impl .Proto .Model ) {
272291 return fmt .Errorf ("unknown model" )
273292 }
274293 return n .cdnosDelete (ctx )
0 commit comments