Skip to content

Commit

Permalink
feat: allow setting default subnet for custom vpc (#4171)
Browse files Browse the repository at this point in the history
* feat: allow setting default subnet for custom vpc

Signed-off-by: Karol Szwaj <[email protected]>

* set default subnet in custom vpc

Signed-off-by: Karol Szwaj <[email protected]>

* add ns annotation to enable default pod subnet in custom vpc

Signed-off-by: Karol Szwaj <[email protected]>

* update crd

Signed-off-by: Karol Szwaj <[email protected]>

* fix ns check

Signed-off-by: Karol Szwaj <[email protected]>

* fix namespace condition

Signed-off-by: Karol Szwaj <[email protected]>

* review update

Signed-off-by: Karol Szwaj <[email protected]>

* review update

Signed-off-by: Karol Szwaj <[email protected]>

* reuse logical_switch namespace annotation instead introducing a new one

Signed-off-by: Karol Szwaj <[email protected]>

* add comment

Signed-off-by: Karol Szwaj <[email protected]>

* reuse defaultLogicalSwitch status field instead of new one

Signed-off-by: Karol Szwaj <[email protected]>

---------

Signed-off-by: Karol Szwaj <[email protected]>
  • Loading branch information
cnvergence authored Aug 23, 2024
1 parent c1a367b commit 6f669c7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions charts/kube-ovn/templates/kube-ovn-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1603,12 +1603,17 @@ spec:
- jsonPath: .spec.namespaces
name: Namespaces
type: string
- jsonPath: .status.defaultLogicalSwitch
name: DefaultSubnet
type: string
name: v1
schema:
openAPIV3Schema:
properties:
spec:
properties:
defaultSubnet:
type: string
enableExternal:
type: boolean
enableBfd:
Expand Down
19 changes: 12 additions & 7 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1846,12 +1846,17 @@ spec:
- jsonPath: .spec.namespaces
name: Namespaces
type: string
- jsonPath: .status.defaultLogicalSwitch
name: DefaultSubnet
type: string
name: v1
schema:
openAPIV3Schema:
properties:
spec:
properties:
defaultSubnet:
type: string
enableExternal:
type: boolean
enableBfd:
Expand Down Expand Up @@ -3144,11 +3149,11 @@ rules:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- apiGroups:
- "certificates.k8s.io"
resources:
resources:
- "certificatesigningrequests"
verbs:
verbs:
- "get"
- "list"
- "watch"
Expand Down Expand Up @@ -3277,12 +3282,12 @@ rules:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- apiGroups:
- "certificates.k8s.io"
resources:
resources:
- "certificatesigningrequests"
verbs:
- "create"
verbs:
- "create"
- "get"
- "list"
- "watch"
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ type Vpc struct {
}

type VpcSpec struct {
DefaultSubnet string `json:"defaultSubnet,omitempty"`
Namespaces []string `json:"namespaces,omitempty"`
StaticRoutes []*StaticRoute `json:"staticRoutes,omitempty"`
PolicyRoutes []*PolicyRoute `json:"policyRoutes,omitempty"`
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ func (c *Controller) handleAddNamespace(key string) error {
break
}
}
// check if subnet is in custom vpc with configured defaultSubnet, then annotate the namespace with this subnet
if s.Spec.Vpc != "" && s.Spec.Vpc != c.config.ClusterRouter {
vpc, err := c.vpcsLister.Get(s.Spec.Vpc)
if err != nil {
klog.Errorf("failed to get custom vpc %v", err)
return err
}
if s.Name == vpc.Spec.DefaultSubnet {
lss = []string{s.Name}
}
}
}

for _, p := range ippools {
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,10 @@ func (c *Controller) getVpcSubnets(vpc *kubeovnv1.Vpc) (subnets []string, defaul
if subnet.Spec.Default {
defaultSubnet = subnet.Name
}

if vpc.Name != util.DefaultVpc && vpc.Spec.DefaultSubnet != "" && vpc.Spec.DefaultSubnet == subnet.Name {
defaultSubnet = vpc.Spec.DefaultSubnet
}
}
return
}
Expand Down

0 comments on commit 6f669c7

Please sign in to comment.