Skip to content

Commit

Permalink
append add cidr and excludeIps annotation for namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Feb 16, 2022
1 parent e04eaf7 commit 0869e62
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/controller/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *Controller) handleAddNamespace(key string) error {
}

var ls string
var lss []string
var lss, cidrs, excludeIps []string
subnets, err := c.subnetsLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list subnets %v", err)
Expand All @@ -135,6 +135,9 @@ func (c *Controller) handleAddNamespace(key string) error {
for _, ns := range s.Spec.Namespaces {
if ns == key {
lss = append(lss, s.Name)
cidrs = append(cidrs, s.Spec.CIDRBlock)
excludeIps = append(excludeIps, strings.Join(s.Spec.ExcludeIps, ","))
break
}
}
}
Expand Down Expand Up @@ -169,6 +172,8 @@ func (c *Controller) handleAddNamespace(key string) error {
return err
}
lss = append(lss, subnet.Name)
cidrs = append(cidrs, subnet.Spec.CIDRBlock)
excludeIps = append(excludeIps, strings.Join(subnet.Spec.ExcludeIps, ","))
}

op := "replace"
Expand All @@ -181,6 +186,8 @@ func (c *Controller) handleAddNamespace(key string) error {
}
}
namespace.Annotations[util.LogicalSwitchAnnotation] = strings.Join(lss, ",")
namespace.Annotations[util.CidrAnnotation] = strings.Join(cidrs, ";")
namespace.Annotations[util.ExcludeIpsAnnotation] = strings.Join(excludeIps, ";")

if _, err = c.config.KubeClient.CoreV1().Namespaces().Patch(context.Background(), key, types.JSONPatchType, generatePatchPayload(namespace.Annotations, op), metav1.PatchOptions{}, ""); err != nil {
klog.Errorf("patch namespace %s failed %v", key, err)
Expand Down

0 comments on commit 0869e62

Please sign in to comment.