Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new handler for being able to map eth0 to management interfaces and #558

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/multivendor/multivendor.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ nodes: {
config: {
file: "ceos.cfg"
}
interfaces: {
key: "eth0"
value: {
name: "Management1"
}
}
}
nodes: {
name: "ncptx"
vendor: JUNIPER
config: {
image: "ncptx:ga"
file: "ncptx.cfg"
}
interfaces: {
Expand Down
4 changes: 2 additions & 2 deletions exec/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ func (c *Command) Run() error {
call.Optional = r.Optional

if c.stdout != nil && r.Stdout != "" {
fmt.Fprintf(c.stdout, r.Stdout)
fmt.Fprint(c.stdout, r.Stdout)
}
if c.stderr != nil && r.Stderr != "" {
fmt.Fprintf(c.stderr, r.Stderr)
fmt.Fprint(c.stderr, r.Stderr)
}
switch e := r.Err.(type) {
case string:
Expand Down
6 changes: 5 additions & 1 deletion topo/node/arista/arista.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func (n *Node) CreateCRD(ctx context.Context) error {
log.Infof("Creating new CEosLabDevice CRD for node: %v", n.Name())
proto := n.GetProto()
config := proto.GetConfig()
links, err := node.GetNodeLinks(proto)
if err != nil {
return err
}
device := &ceos.CEosLabDevice{
TypeMeta: metav1.TypeMeta{
APIVersion: "ceoslab.arista.com/v1alpha1",
Expand All @@ -179,7 +183,7 @@ func (n *Node) CreateCRD(ctx context.Context) error {
InitContainerImage: config.GetInitImage(),
Args: config.GetArgs(),
Resources: proto.GetConstraints(),
NumInterfaces: int32(len(proto.GetInterfaces())),
NumInterfaces: int32(len(links)),
Sleep: int32(config.GetSleep()),
},
}
Expand Down
12 changes: 10 additions & 2 deletions topo/node/arista/arista_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,18 @@ func TestCRD(t *testing.T) {
Version: "version-test",
Os: "os-test",
Interfaces: map[string]*topopb.Interface{
"eth0": {
Name: "Management1",
},
"eth1": {
Name: "Ethernet1/1",
Name: "Ethernet1/1",
PeerIntName: "eth1",
PeerName: "foo",
},
"eth2": {
Name: "Ethernet1/2",
Name: "Ethernet1/2",
PeerIntName: "eth2",
PeerName: "foo",
},
},
},
Expand Down Expand Up @@ -423,6 +430,7 @@ func TestCRD(t *testing.T) {
}},
},
IntfMapping: map[string]string{
"eth0": "Management1",
"eth1": "Ethernet1/1",
"eth2": "Ethernet1/2",
},
Expand Down
54 changes: 34 additions & 20 deletions topo/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,32 +172,17 @@ func (n *Impl) String() string {
}

func (n *Impl) TopologySpecs(context.Context) ([]*topologyv1.Topology, error) {
proto := n.GetProto()

var links []topologyv1.Link
for ifcName, ifc := range proto.Interfaces {
if ifc.PeerIntName == "" {
return nil, fmt.Errorf("interface %q PeerIntName canot be empty", ifcName)
}
if ifc.PeerName == "" {
return nil, fmt.Errorf("interface %q PeerName canot be empty", ifcName)
}
links = append(links, topologyv1.Link{
UID: int(ifc.Uid),
LocalIntf: ifcName,
PeerIntf: ifc.PeerIntName,
PeerPod: ifc.PeerName,
LocalIP: "",
PeerIP: "",
})
links, err := GetNodeLinks(n.Proto)
if err != nil {
return nil, err
}

// by default each node will result in exactly one topology resource
// with multiple links
return []*topologyv1.Topology{
{
ObjectMeta: metav1.ObjectMeta{
Name: proto.Name,
Name: n.Proto.Name,
},
Spec: topologyv1.TopologySpec{
Links: links,
Expand Down Expand Up @@ -393,6 +378,10 @@ func (n *Impl) CreateConfig(ctx context.Context) (*corev1.Volume, error) {
// CreatePod creates a Pod for the Node based on the underlying proto.
func (n *Impl) CreatePod(ctx context.Context) error {
pb := n.Proto
links, err := GetNodeLinks(pb)
if err != nil {
return err
}
log.Infof("Creating Pod:\n %+v", pb)
initContainerImage := pb.Config.InitImage
if initContainerImage == "" {
Expand All @@ -411,7 +400,7 @@ func (n *Impl) CreatePod(ctx context.Context) error {
Name: fmt.Sprintf("init-%s", pb.Name),
Image: initContainerImage,
Args: []string{
fmt.Sprintf("%d", len(n.Proto.Interfaces)+1),
fmt.Sprintf("%d", len(links)+1),
fmt.Sprintf("%d", pb.Config.Sleep),
},
ImagePullPolicy: "IfNotPresent",
Expand Down Expand Up @@ -753,3 +742,28 @@ func (n *Impl) GetCLIConn(platform string, opts []scrapliutil.Option) (*scraplin
func (n *Impl) BackToBackLoop() bool {
return false
}

func GetNodeLinks(n *tpb.Node) ([]topologyv1.Link, error) {
var links []topologyv1.Link
for ifcName, ifc := range n.Interfaces {
if ifcName == "eth0" {
log.Infof("Found mgmt interface ignoring for Meshnet: %q", ifcName)
continue
}
if ifc.PeerIntName == "" {
return nil, fmt.Errorf("interface %q PeerIntName canot be empty", ifcName)
}
if ifc.PeerName == "" {
return nil, fmt.Errorf("interface %q PeerName canot be empty", ifcName)
}
links = append(links, topologyv1.Link{
UID: int(ifc.Uid),
LocalIntf: ifcName,
PeerIntf: ifc.PeerIntName,
PeerPod: ifc.PeerName,
LocalIP: "",
PeerIP: "",
})
}
return links, nil
}
4 changes: 2 additions & 2 deletions topo/topo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type resettable struct {

func (r *resettable) ResetCfg(_ context.Context) error {
if r.rErr != "" {
return fmt.Errorf(r.rErr)
return fmt.Errorf("%s", r.rErr)
}
return nil
}
Expand All @@ -144,7 +144,7 @@ func (c *certable) GetProto() *tpb.Node {

func (c *certable) GenerateSelfSigned(_ context.Context) error {
if c.gErr != "" {
return fmt.Errorf(c.gErr)
return fmt.Errorf("%s", c.gErr)
}
return nil
}
Expand Down
Loading