diff --git a/config/crd/bases/l2sm.l2sm.k8s.local_overlays.yaml b/config/crd/bases/l2sm.l2sm.k8s.local_overlays.yaml index e2c5e8508943ddfca9e725952e5cbae98cb694ea..810e9698559cc9103f22a1dd3266ba29fe198629 100644 --- a/config/crd/bases/l2sm.l2sm.k8s.local_overlays.yaml +++ b/config/crd/bases/l2sm.l2sm.k8s.local_overlays.yaml @@ -53,26 +53,11 @@ spec: spec: description: OverlaySpec defines the desired state of Overlay properties: - neighbors: - description: Field exclusive to the multi-domain overlay type. If - specified in other types of overlays, the reosurce will launch - an error and won't be created. - items: - properties: - domain: - description: |- - Domain where the neighbor's NED switch can be reached at. Must be a valid IP Address or Domain name, reachable from the node the NED - is going to be deployed at. - type: string - node: - description: Name of the cluster the link is going to be made - upon. - type: string - required: - - domain - - node - type: object - type: array + interfaceNumber: + default: 10 + description: Interface number specifies how many interfaces the switch + should have predefined (if used with multus) + type: integer networkController: description: The SDN Controller that manages the overlay network. Must specify a domain and a name. diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 50d41643b8ddebc996fadac42bd4ad5885ab1d99..16e53559fd46a81c72bc43457c9373ef64fe201f 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -56,6 +56,18 @@ rules: - get - patch - update +- apiGroups: + - k8s.cni.cncf.io + resources: + - network-attachment-definitions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - l2sm.l2sm.k8s.local resources: diff --git a/go.sum b/go.sum index 97080749ab21c6d30ac0c3405bac199fa96f1ce1..cd71baf91f862749d9eff4739042a0da5556aa80 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ -github.com/Networks-it-uc3m/l2sm-switch v1.0.0 h1:SQ2hFmObffhNV2jVSeSpqVGCm2/d6HZuQ02YzeCI+x0= -github.com/Networks-it-uc3m/l2sm-switch v1.0.0/go.mod h1:zcfUyOLAiCEQza5QRTJoQsrOYdu+WQf/6rQNmhGb4WQ= -github.com/Networks-it-uc3m/l2sm-switch v1.0.1 h1:nMvK0K13UGloG+S/33/DhEvc+U5MvcBWKL/qqgEmylI= -github.com/Networks-it-uc3m/l2sm-switch v1.0.1/go.mod h1:zcfUyOLAiCEQza5QRTJoQsrOYdu+WQf/6rQNmhGb4WQ= +github.com/Networks-it-uc3m/l2sm-switch v1.0.2 h1:P4gVqfcO6LgKVxWI4aDfQnbYnRi+8+nc5+K1wq9sIEU= +github.com/Networks-it-uc3m/l2sm-switch v1.0.2/go.mod h1:zcfUyOLAiCEQza5QRTJoQsrOYdu+WQf/6rQNmhGb4WQ= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= diff --git a/internal/controller/overlay_controller.go b/internal/controller/overlay_controller.go index ebff2453a3e5c5749d18f4f76aac5671cc6a476f..abacbab8e3e64fcc5757e9e892130d5b175bdc7b 100644 --- a/internal/controller/overlay_controller.go +++ b/internal/controller/overlay_controller.go @@ -43,6 +43,7 @@ type OverlayReconciler struct { var replicaSetOwnerKeyOverlay = ".metadata.controller.overlay" +// +kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=configmaps,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=configmaps,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=services,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=replicasets,verbs=get;list;watch;create;update;patch;delete @@ -50,6 +51,7 @@ var replicaSetOwnerKeyOverlay = ".metadata.controller.overlay" //+kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=overlays,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=overlays/status,verbs=get;update;patch //+kubebuilder:rbac:groups=l2sm.l2sm.k8s.local,resources=overlays/finalizers,verbs=update +// +kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch;create;update;patch;delete // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. @@ -92,11 +94,11 @@ func (r *OverlayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct // The object is being deleted if controllerutil.ContainsFinalizer(overlay, l2smFinalizer) { // our finalizer is present, so lets handle any external dependency - // if err := r.deleteExternalResources(ctx, overlay); err != nil { - // // if fail to delete the external dependency here, return with error - // // so that it can be retried. - // return ctrl.Result{}, err - // } + if err := r.deleteExternalResources(ctx, overlay); err != nil { + // if fail to delete the external dependency here, return with error + // so that it can be retried. + return ctrl.Result{}, err + } // remove our finalizer from the list and update it. controllerutil.RemoveFinalizer(overlay, l2smFinalizer) @@ -158,10 +160,14 @@ func (r *OverlayReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -// func (r *OverlayReconciler) deleteExternalResources(ctx context.Context, overlay *l2smv1.Overlay) error { - -// return nil -// } +func (r *OverlayReconciler) deleteExternalResources(ctx context.Context, overlay *l2smv1.Overlay) error { + opts := []client.DeleteAllOfOption{ + client.InNamespace(overlay.Namespace), + client.MatchingLabels{"overlay": overlay.Name}, + } + r.Client.DeleteAllOf(ctx, &nettypes.NetworkAttachmentDefinition{}, opts...) + return nil +} type OverlayConfigJson struct { ControllerIp string `json:"ControllerIp"` @@ -311,7 +317,7 @@ func (r *OverlayReconciler) createExternalResources(ctx context.Context, overlay ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-veth%d", overlay.Name, i), Namespace: overlay.Namespace, - Labels: map[string]string{"app": "l2sm"}, + Labels: map[string]string{"app": "l2sm", "overlay": overlay.Name}, }, Spec: nettypes.NetworkAttachmentDefinitionSpec{ Config: fmt.Sprintf(`{