Skip to content

Commit

Permalink
Release 2.0.0 (#72)
Browse files Browse the repository at this point in the history
Compatible release of operator for Netris Controller v3.1
  • Loading branch information
pogossian authored Aug 19, 2022
1 parent 2a088b6 commit 219b4b7
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 425 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Netris Operator managing resources samples are available in the `samples/` [fold
| Operator version | Controller version |
| -----------------| -------------------|
| `v0.X` | `v2.9.X` |
| `v1.X` | `v3.X` |
| `v1.X` | `v3.0.X` |
| `v2.X` | `v3.1.X` |


## Features
* Managing Netris Controller via CRD
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/vnet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type VNetSpec struct {

GuestTenants []string `json:"guestTenants"`
Sites []VNetSite `json:"sites"`
VlanID string `json:"vlanId,omitempty"`
}

// VNetSite .
Expand Down
16 changes: 7 additions & 9 deletions api/v1alpha1/vnetmeta_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type VNetMetaSpec struct {
VaMode bool `json:"vaMode"`
VaNativeVLAN int `json:"vaNativeVlan"`
VaVLANs string `json:"vaVlans"`
VlanID string `json:"vlanid"`
}

// VNetMetaSite .
Expand All @@ -51,15 +52,12 @@ type VNetMetaSite struct {

// VNetMetaMember .
type VNetMetaMember struct {
ChildPort int `json:"childPort"`
LACP string `json:"lacp"`
MemberState string `json:"member_state"`
ParentPort int `json:"parentPort"`
PortIsUntagged bool `json:"portIsUntagged"`
PortID int `json:"port_id"`
PortName string `json:"port_name"`
TenantID int `json:"tenant_id"`
VLANID int `json:"vlan_id"`
Name string `json:"name"`
Access bool `json:"access"`
ID int `json:"id"`
Lacp string `json:"lacp"`
State string `json:"state"`
Vlan string `json:"vlan"`
}

// VNetMetaGateway .
Expand Down
36 changes: 15 additions & 21 deletions config/crd/bases/k8s.netris.ai_vnetmeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,25 @@ spec:
items:
description: VNetMetaMember .
properties:
childPort:
access:
type: boolean
id:
type: integer
lacp:
type: string
member_state:
name:
type: string
parentPort:
type: integer
port_id:
type: integer
port_name:
state:
type: string
vlan:
type: string
portIsUntagged:
type: boolean
tenant_id:
type: integer
vlan_id:
type: integer
required:
- childPort
- access
- id
- lacp
- member_state
- parentPort
- portIsUntagged
- port_id
- port_name
- tenant_id
- vlan_id
- name
- state
- vlan
type: object
type: array
name:
Expand Down Expand Up @@ -125,6 +116,8 @@ spec:
type: integer
vaVlans:
type: string
vlanid:
type: string
vnetGeneration:
format: int64
type: integer
Expand All @@ -145,6 +138,7 @@ spec:
- vaMode
- vaNativeVlan
- vaVlans
- vlanid
- vnetGeneration
- vnetName
type: object
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/k8s.netris.ai_vnets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ spec:
- active
- disabled
type: string
vlanId:
type: string
required:
- guestTenants
- ownerTenant
Expand Down
2 changes: 1 addition & 1 deletion controllers/allocation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (r *AllocationReconciler) deleteAllocation(allocation *k8sv1alpha1.Allocati
if err != nil {
return ctrl.Result{}, err
}
if !resp.IsSuccess && resp.Meta.StatusCode != 400 {
if !resp.IsSuccess && resp.Meta.StatusCode != 404 {
return ctrl.Result{}, fmt.Errorf("{deleteAllocation} %s", fmt.Errorf(resp.Message))
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/allocationmeta_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (r *AllocationMetaReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
}
logger.Info("Allocation Created")
} else {
if apiAllocation, ok := r.NStorage.SubnetsStorage.FindByID(allocationMeta.Spec.ID); ok {
if apiAllocation, ok := r.NStorage.SubnetsStorage.FindByID(allocationMeta.Spec.ID, "allocation"); ok {

debugLogger.Info("Comparing AllocationMeta with Netris Allocation")
if ok := compareAllocationMetaAPIEAllocation(allocationMeta, apiAllocation, u); ok {
Expand Down
46 changes: 18 additions & 28 deletions controllers/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package controllers

import (
"fmt"
"strconv"
"time"

k8sv1alpha1 "github.com/netrisai/netris-operator/api/v1alpha1"
"github.com/netrisai/netris-operator/configloader"
"github.com/netrisai/netris-operator/netrisstorage"
"github.com/netrisai/netriswebapi/v1/types/vnet"
"github.com/netrisai/netriswebapi/v2/types/vnet"
)

func init() {
Expand All @@ -35,15 +36,11 @@ func init() {

func (r *VNetReconciler) getPortsMeta(portNames []k8sv1alpha1.VNetSwitchPort) ([]k8sv1alpha1.VNetMetaMember, error) {
members := []k8sv1alpha1.VNetMetaMember{}
hwPorts := make(map[string]*vnet.VNetMember)
portIsUntagged := false
hwPorts := make(map[string]*vnet.VNetAddPort)
for _, port := range portNames {
vlanID := 1
if port.VlanID > 0 {
vlanID = port.VlanID
}
if vlanID == 1 {
portIsUntagged = true
vlanID := "1"
if port.VlanID > 1 {
vlanID = strconv.Itoa(port.VlanID)
}

state := "active"
Expand All @@ -53,37 +50,30 @@ func (r *VNetReconciler) getPortsMeta(portNames []k8sv1alpha1.VNetSwitchPort) ([
}
}

hwPorts[port.Name] = &vnet.VNetMember{
VLANID: vlanID,
PortIsUntagged: portIsUntagged,
MemberState: state,
hwPorts[port.Name] = &vnet.VNetAddPort{
Vlan: vlanID,
Lacp: "off",
State: state,
}

}
for portName := range hwPorts {
if port, yes := r.NStorage.PortsStorage.FindByName(portName); yes {
hwPorts[portName].PortID = port.ID
hwPorts[portName].PortName = portName
hwPorts[portName].TenantID = port.Tenant.ID
hwPorts[portName].LACP = "off"
hwPorts[portName].ParentPort = port.ParentPort
// hwPorts[portName].Name = port.SlavePortName
hwPorts[portName].ID = port.ID
hwPorts[portName].Name = portName
hwPorts[portName].Lacp = "off"
} else {
return members, fmt.Errorf("port '%s' not found", portName)
}
}

for _, member := range hwPorts {
members = append(members, k8sv1alpha1.VNetMetaMember{
ChildPort: member.ChildPort,
LACP: member.LACP,
MemberState: member.MemberState,
ParentPort: member.ParentPort,
PortIsUntagged: member.PortIsUntagged,
PortID: member.PortID,
PortName: member.PortName,
TenantID: member.TenantID,
VLANID: member.VLANID,
Name: member.Name,
Lacp: member.Lacp,
State: member.State,
ID: member.ID,
Vlan: member.Vlan,
})
}
return members, nil
Expand Down
2 changes: 1 addition & 1 deletion controllers/controller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (r *ControllerReconciler) deleteController(controller *k8sv1alpha1.Controll
if err != nil {
return ctrl.Result{}, err
}
if !resp.IsSuccess && resp.Meta.StatusCode != 400 {
if !resp.IsSuccess && resp.Meta.StatusCode != 404 {
return ctrl.Result{}, fmt.Errorf("{deleteController} %s", fmt.Errorf(resp.Message))
}
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/l4lb_translations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"strings"

k8sv1alpha1 "github.com/netrisai/netris-operator/api/v1alpha1"
"github.com/netrisai/netriswebapi/v1/types/l4lb"
"github.com/netrisai/netriswebapi/v2/types/ipam"
"github.com/netrisai/netriswebapi/v2/types/l4lb"
"github.com/r3labs/diff/v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -324,7 +324,6 @@ func L4LBMetaToNetrisUpdate(l4lbMeta *k8sv1alpha1.L4LBMeta) (*l4lb.LoadBalancerU
}

l4lbUpdate := &l4lb.LoadBalancerUpdate{
ID: l4lbMeta.Spec.ID,
Name: l4lbMeta.Spec.L4LBName,
TenantID: l4lbMeta.Spec.Tenant,
SiteID: l4lbMeta.Spec.SiteID,
Expand Down
8 changes: 4 additions & 4 deletions controllers/l4lbmeta_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
k8sv1alpha1 "github.com/netrisai/netris-operator/api/v1alpha1"
"github.com/netrisai/netris-operator/netrisstorage"
"github.com/netrisai/netriswebapi/http"
"github.com/netrisai/netriswebapi/v1/types/l4lb"
api "github.com/netrisai/netriswebapi/v2"
"github.com/netrisai/netriswebapi/v2/types/l4lb"
)

// L4LBMetaReconciler reconciles a L4LBMeta object
Expand Down Expand Up @@ -151,7 +151,7 @@ func (r *L4LBMetaReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
logger.Error(fmt.Errorf("{VnetMetaToNetrisUpdate} %s", err), "")
return u.patchL4LBStatus(l4lbCR, "Failure", err.Error())
}
if _, err, errMsg := r.updateL4LB(l4lbUpdate); err != nil {
if _, err, errMsg := r.updateL4LB(l4lbMeta.Spec.ID, l4lbUpdate); err != nil {
logger.Error(fmt.Errorf("{updateL4LB} %s", err), "")
return u.patchL4LBStatus(l4lbCR, "Failure", errMsg.Error())
}
Expand Down Expand Up @@ -225,8 +225,8 @@ func (r *L4LBMetaReconciler) createL4LB(l4lbMeta *k8sv1alpha1.L4LBMeta) (ctrl.Re
return ctrl.Result{}, nil, nil
}

func (r *L4LBMetaReconciler) updateL4LB(l4lb *l4lb.LoadBalancerUpdate) (ctrl.Result, error, error) {
reply, err := r.Cred.L4LB().Update(l4lb)
func (r *L4LBMetaReconciler) updateL4LB(id int, l4lb *l4lb.LoadBalancerUpdate) (ctrl.Result, error, error) {
reply, err := r.Cred.L4LB().Update(id, l4lb)
if err != nil {
return ctrl.Result{}, fmt.Errorf("{updateL4LB} %s", err), err
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/site_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (r *SiteReconciler) deleteSite(site *k8sv1alpha1.Site, siteMeta *k8sv1alpha
if err != nil {
return ctrl.Result{}, err
}
if !resp.IsSuccess {
if !resp.IsSuccess && resp.Meta.StatusCode != 404 {
return ctrl.Result{}, fmt.Errorf("{deleteSite} %s", fmt.Errorf(resp.Message))
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/softgate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (r *SoftgateReconciler) deleteSoftgate(softgate *k8sv1alpha1.Softgate, soft
if err != nil {
return ctrl.Result{}, err
}
if !resp.IsSuccess && resp.Meta.StatusCode != 400 {
if !resp.IsSuccess && resp.Meta.StatusCode != 404 {
return ctrl.Result{}, fmt.Errorf("{deleteSoftgate} %s", fmt.Errorf(resp.Message))
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/subnet_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (r *SubnetReconciler) deleteSubnet(subnet *k8sv1alpha1.Subnet, subnetMeta *
if err != nil {
return ctrl.Result{}, err
}
if !resp.IsSuccess && resp.Meta.StatusCode != 400 {
if !resp.IsSuccess && resp.Meta.StatusCode != 404 {
return ctrl.Result{}, fmt.Errorf("{deleteSubnet} %s", fmt.Errorf(resp.Message))
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/subnetmeta_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r *SubnetMetaReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
}
logger.Info("Subnet Created")
} else {
if apiSubnet, ok := r.NStorage.SubnetsStorage.FindByID(subnetMeta.Spec.ID); ok {
if apiSubnet, ok := r.NStorage.SubnetsStorage.FindByID(subnetMeta.Spec.ID, "subnet"); ok {
debugLogger.Info("Comparing SubnetMeta with Netris Subnet")
if ok := compareSubnetMetaAPIESubnet(subnetMeta, apiSubnet, u); ok {
debugLogger.Info("Nothing Changed")
Expand Down
2 changes: 1 addition & 1 deletion controllers/switch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (r *SwitchReconciler) deleteSwitch(switchH *k8sv1alpha1.Switch, switchMeta
if err != nil {
return ctrl.Result{}, err
}
if !resp.IsSuccess && resp.Meta.StatusCode != 400 {
if !resp.IsSuccess && resp.Meta.StatusCode != 404 {
return ctrl.Result{}, fmt.Errorf("{deleteSwitch} %s", fmt.Errorf(resp.Message))
}
}
Expand Down
Loading

0 comments on commit 219b4b7

Please sign in to comment.