Skip to content

Commit

Permalink
fix: init default vpc
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed Aug 22, 2024
1 parent 6bfbfe8 commit d984cb0
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,37 @@ func (c *Controller) InitOVN() error {

func (c *Controller) InitDefaultVpc() error {
cachedVpc, err := c.vpcsLister.Get(c.config.ClusterRouter)
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)
if err != nil {
if !k8serrors.IsNotFound(err) {
klog.Errorf("failed to get default vpc %q: %v", c.config.ClusterRouter, 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("failed to create default vpc %q: %v", c.config.ClusterRouter, err)
return err
}
}
}

vpc := cachedVpc.DeepCopy()
vpc.Status.DefaultLogicalSwitch = c.config.DefaultLogicalSwitch
vpc.Status.Router = c.config.ClusterRouter
vpc.Status.Standby = true
vpc.Status.Default = true

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
if !vpc.Status.Default || !vpc.Status.Standby ||
vpc.Status.Router != c.config.ClusterRouter ||
vpc.Status.DefaultLogicalSwitch != c.config.DefaultLogicalSwitch {
vpc.Status.Standby = true
vpc.Status.Default = true
vpc.Status.Router = c.config.ClusterRouter
vpc.Status.DefaultLogicalSwitch = c.config.DefaultLogicalSwitch

if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().UpdateStatus(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
klog.Errorf("failed to update default vpc %q: %v", c.config.ClusterRouter, err)
return err
}
}

return nil
Expand Down

0 comments on commit d984cb0

Please sign in to comment.