Skip to content

Commit

Permalink
[api] add switch group label and fix conn check
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed Apr 15, 2024
1 parent e291056 commit ab6f8bc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api/wiring/v1alpha2/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var (
LabelConnectionType = LabelName("connection-type")
LabelSwitches = LabelName("switches")
LabelServers = LabelName("servers")
LabelGroups = LabelName("groups")
LabelVPC = LabelName("vpc")
ListLabelValue = "true"
ConnectionLabelTypeServer = "server"
Expand Down Expand Up @@ -76,6 +75,10 @@ func ListLabelVLANNamespace(vlanNamespace string) string {
return ListLabel("vlanns", vlanNamespace)
}

func ListLabelSwitchGroup(groupName string) string {
return ListLabel("switchgroup", groupName)
}

func MatchingLabelsForListLabelServer(serverName string) client.MatchingLabels {
return client.MatchingLabels{
ListLabel(ConnectionLabelTypeServer, serverName): ListLabelValue,
Expand All @@ -88,6 +91,12 @@ func MatchingLabelsForListLabelSwitch(switchName string) client.MatchingLabels {
}
}

func MatchingLabelsForSwitchGroup(groupName string) client.MatchingLabels {
return client.MatchingLabels{
ListLabelSwitchGroup(groupName): ListLabelValue,
}
}

// Location defines the geographical position of the device in a datacenter
type Location struct {
Location string `json:"location,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions api/wiring/v1alpha2/switch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ func (sw *Switch) Default() {
sw.Spec.Groups = append(sw.Spec.Groups, sw.Spec.Redundancy.Group)
}

for _, group := range sw.Spec.Groups {
sw.Labels[ListLabelSwitchGroup(group)] = ListLabelValue
}

for _, vlanNs := range sw.Spec.VLANNamespaces {
sw.Labels[ListLabelVLANNamespace(vlanNs)] = ListLabelValue
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/util/apiutil/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ func IsSubnetReachableBetweenVPCs(ctx context.Context, kube client.Client, vpc1N
}

for _, vpcPeering := range vpcPeerings.Items {
if vpcPeering.Spec.Remote != "" {
if err := kube.Get(ctx, client.ObjectKey{
Namespace: metav1.NamespaceDefault,
Name: vpcPeering.Spec.Remote,
}, &wiringapi.SwitchGroup{}); err != nil {
return false, errors.Wrapf(err, "failed to get switch group %s", vpcPeering.Spec.Remote)
}

switches := wiringapi.SwitchList{}
if err := kube.List(ctx, &switches,
client.InNamespace(metav1.NamespaceDefault),
wiringapi.MatchingLabelsForSwitchGroup(vpcPeering.Spec.Remote),
); err != nil {
return false, errors.Wrapf(err, "failed to list switches")
}

if len(switches.Items) == 0 {
return false, nil
}
}

for _, permit := range vpcPeering.Spec.Permit {
vpc1Permit, exist := permit[vpc1Name]
if !exist {
Expand Down

0 comments on commit ab6f8bc

Please sign in to comment.