Skip to content

Commit

Permalink
Add neighbor switch specs to the agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed Nov 14, 2023
1 parent 2ecdd07 commit d9f794b
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 11 deletions.
23 changes: 12 additions & 11 deletions api/agent/v1alpha2/agent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ import (

// AgentSpec defines the desired state of Agent
type AgentSpec struct {
Role wiringapi.SwitchRole `json:"role,omitempty"`
Description string `json:"description,omitempty"`
Config AgentSpecConfig `json:"config,omitempty"`
Version AgentVersion `json:"version,omitempty"`
Users []UserCreds `json:"users,omitempty"`
Switch wiringapi.SwitchSpec `json:"switch,omitempty"`
Connections []ConnectionInfo `json:"connections,omitempty"`
VPCs []vpcapi.VPCSummarySpec `json:"vpcs,omitempty"`
VPCVLANRange string `json:"vpcVLANRange,omitempty"`
NAT vpcapi.NATSpec `json:"nat,omitempty"`
PortChannels map[string]uint16 `json:"portChannels,omitempty"`
Role wiringapi.SwitchRole `json:"role,omitempty"`
Description string `json:"description,omitempty"`
Config AgentSpecConfig `json:"config,omitempty"`
Version AgentVersion `json:"version,omitempty"`
Users []UserCreds `json:"users,omitempty"`
Switch wiringapi.SwitchSpec `json:"switch,omitempty"`
Switches map[string]wiringapi.SwitchSpec `json:"switches,omitempty"`
Connections []ConnectionInfo `json:"connections,omitempty"`
VPCs []vpcapi.VPCSummarySpec `json:"vpcs,omitempty"`
VPCVLANRange string `json:"vpcVLANRange,omitempty"`
NAT vpcapi.NATSpec `json:"nat,omitempty"`
PortChannels map[string]uint16 `json:"portChannels,omitempty"`

Reinstall string `json:"reinstall,omitempty"` // set to InstallID to reinstall NOS
Reboot string `json:"reboot,omitempty"` // set to RunID to reboot
Expand Down
8 changes: 8 additions & 0 deletions api/agent/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions config/crd/bases/agent.githedgehog.com_agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,63 @@ spec:
vtepIP:
type: string
type: object
switches:
additionalProperties:
description: SwitchSpec defines the desired state of Switch
properties:
asn:
format: int32
type: integer
description:
type: string
ip:
type: string
location:
description: Location defines the geopraphical position of the
device in a datacenter
properties:
aisle:
type: string
location:
type: string
rack:
type: string
row:
type: string
slot:
type: string
type: object
locationSig:
description: LocationSig contains signatures for the location
UUID as well as the device location itself
properties:
sig:
type: string
uuidSig:
type: string
type: object
portBreakouts:
additionalProperties:
type: string
type: object
portGroupSpeeds:
additionalProperties:
type: string
type: object
profile:
type: string
protocolIP:
type: string
role:
enum:
- spine
- server-leaf
- border-leaf
type: string
vtepIP:
type: string
type: object
type: object
users:
items:
properties:
Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ _Appears in:_
| `version` _[AgentVersion](#agentversion)_ | |
| `users` _[UserCreds](#usercreds) array_ | |
| `switch` _[SwitchSpec](#switchspec)_ | |
| `switches` _object (keys:string, values:[SwitchSpec](#switchspec))_ | |
| `connections` _[ConnectionInfo](#connectioninfo) array_ | |
| `vpcs` _[VPCSummarySpec](#vpcsummaryspec) array_ | |
| `vpcVLANRange` _string_ | |
Expand Down
24 changes: 24 additions & 0 deletions pkg/ctrl/agent/agent_ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (r *AgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return ctrl.Result{}, errors.Wrapf(err, "error getting switch connections")
}

neighborSwitches := map[string]bool{}
mclagPeerName := ""
conns := []agentapi.ConnectionInfo{}
for _, conn := range connList.Items {
Expand All @@ -182,6 +183,14 @@ func (r *AgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
Spec: conn.Spec,
})

sws, _, _, err := conn.Spec.Endpoints()
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "error getting endpoints for connection %s", conn.Name)
}
for _, sw := range sws {
neighborSwitches[sw] = true
}

statusUpdates = appendUpdate(statusUpdates, &conn)

if conn.Spec.MCLAGDomain != nil {
Expand All @@ -199,6 +208,20 @@ func (r *AgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return conns[i].Name < conns[j].Name
})

switchList := &wiringapi.SwitchList{}
err = r.List(ctx, switchList, client.InNamespace(sw.Namespace))
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "error getting switches")
}

switches := map[string]wiringapi.SwitchSpec{}
for _, sw := range switchList.Items {
if !neighborSwitches[sw.Name] {
continue
}
switches[sw.Name] = sw.Spec
}

// TODO always provision all VPCs to all switches
vpcs := []vpcapi.VPCSummarySpec{}
vpcSummaries := &vpcapi.VPCSummaryList{}
Expand Down Expand Up @@ -251,6 +274,7 @@ func (r *AgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
agent.Spec.Description = sw.Spec.Description
agent.Spec.Config.ControlVIP = r.Cfg.ControlVIP
agent.Spec.Switch = sw.Spec
agent.Spec.Switches = switches
agent.Spec.Connections = conns
agent.Spec.VPCs = vpcs
agent.Spec.VPCVLANRange = fmt.Sprintf("%d..%d", r.Cfg.VPCVLANRange.Min, r.Cfg.VPCVLANRange.Max)
Expand Down

0 comments on commit d9f794b

Please sign in to comment.