Skip to content

Commit

Permalink
move initDefaultVpc into initOVN (#4344)
Browse files Browse the repository at this point in the history
Signed-off-by: oilbeater <[email protected]>
  • Loading branch information
oilbeater authored and bobz965 committed Aug 13, 2024
1 parent de94d6f commit f5460f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
4 changes: 0 additions & 4 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,6 @@ func (c *Controller) Run(ctx context.Context) {
util.LogFatalAndExit(err, "failed to initialize ovn resources")
}

if err := c.InitDefaultVpc(); err != nil {
util.LogFatalAndExit(err, "failed to initialize default vpc")
}

// sync ip crd before initIPAM since ip crd will be used to restore vm and statefulset pod in initIPAM
if err := c.syncIPCR(); err != nil {
util.LogFatalAndExit(err, "failed to sync crd ips")
Expand Down
37 changes: 18 additions & 19 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import (
func (c *Controller) InitOVN() error {
var err error

if err := c.InitDefaultVpc(); err != nil {
klog.Errorf("init default vpc failed: %v", err)
return err
}

if err = c.initClusterRouter(); err != nil {
klog.Errorf("init cluster router failed: %v", err)
return err
Expand Down Expand Up @@ -61,39 +66,33 @@ func (c *Controller) InitOVN() error {

func (c *Controller) InitDefaultVpc() error {
cachedVpc, err := c.vpcsLister.Get(c.config.ClusterRouter)
if err != nil {
cachedVpc = &kubeovnv1.Vpc{}
cachedVpc.Name = c.config.ClusterRouter
cachedVpc, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Create(context.Background(), cachedVpc, metav1.CreateOptions{})
if !k8serrors.IsNotFound(err) {
klog.Errorf("get default vpc %s failed: %v", c.config.DefaultLogicalSwitch, err)
return err
}

if k8serrors.IsNotFound(err) {
vpc := &kubeovnv1.Vpc{
ObjectMeta: metav1.ObjectMeta{Name: c.config.ClusterRouter},
}
cachedVpc, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Create(context.Background(), vpc, metav1.CreateOptions{})
if err != nil {
klog.Errorf("init default vpc failed: %v", err)
return err
}
}

vpc := cachedVpc.DeepCopy()
vpc.Status.DefaultLogicalSwitch = c.config.DefaultLogicalSwitch
vpc.Status.Router = c.config.ClusterRouter
if c.config.EnableLb {
vpc.Status.TCPLoadBalancer = c.config.ClusterTCPLoadBalancer
vpc.Status.TCPSessionLoadBalancer = c.config.ClusterTCPSessionLoadBalancer
vpc.Status.UDPLoadBalancer = c.config.ClusterUDPLoadBalancer
vpc.Status.UDPSessionLoadBalancer = c.config.ClusterUDPSessionLoadBalancer
vpc.Status.SctpLoadBalancer = c.config.ClusterSctpLoadBalancer
vpc.Status.SctpSessionLoadBalancer = c.config.ClusterSctpSessionLoadBalancer
}
vpc.Status.Standby = true
vpc.Status.Default = true

bytes, err := vpc.Status.Bytes()
if err != nil {
klog.Error(err)
return err
}
_, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Patch(context.Background(), vpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status")
if err != nil {
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().UpdateStatus(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
klog.Errorf("init default vpc failed: %v", err)
return err
}

return nil
}

Expand Down

0 comments on commit f5460f0

Please sign in to comment.