Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit allows to manage in a simpler way the NamespaceMap lifecycle.
- Loading branch information
1 parent
3c09091
commit c85ce9d
Showing
10 changed files
with
496 additions
and
736 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...liqo-controller-manager/virtualNode-controller/manage_virtualnode_controller_finalizer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package virtualnodectrl | ||
|
||
import ( | ||
"context" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/klog" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
ctrlutils "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
func (r *VirtualNodeReconciler) checkVirtualNodeFinalizerPresence(ctx context.Context, n *corev1.Node) error { | ||
if !ctrlutils.ContainsFinalizer(n, virtualNodeControllerFinalizer) { | ||
original := n.DeepCopy() | ||
ctrlutils.AddFinalizer(n, virtualNodeControllerFinalizer) | ||
if err := r.Patch(ctx, n, client.MergeFrom(original)); err != nil { | ||
klog.Errorf("%s --> Unable to add finalizer to the virtual-node '%s'", err, n.GetName()) | ||
return err | ||
} | ||
klog.Infof("Finalizer correctly added on the virtual-node '%s'", n.GetName()) | ||
} | ||
return nil | ||
} | ||
|
||
func (r *VirtualNodeReconciler) removeVirtualNodeFinalizer(ctx context.Context, n *corev1.Node) error { | ||
original := n.DeepCopy() | ||
ctrlutils.RemoveFinalizer(n, virtualNodeControllerFinalizer) | ||
if err := r.Patch(ctx, n, client.MergeFrom(original)); err != nil { | ||
klog.Errorf("%s --> Unable to remove finalizer from the virtual-node '%s'", err, n.GetName()) | ||
return err | ||
} | ||
klog.Infof("Finalizer is correctly removed from the virtual-node '%s'", n.GetName()) | ||
return nil | ||
} |
56 changes: 56 additions & 0 deletions
56
pkg/liqo-controller-manager/virtualNode-controller/namespaceMap_creation.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package virtualnodectrl | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/klog" | ||
ctrlutils "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
|
||
mapsv1alpha1 "github.com/liqotech/liqo/apis/virtualKubelet/v1alpha1" | ||
liqoconst "github.com/liqotech/liqo/pkg/consts" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// create a new NamespaceMap with OwnerReference. | ||
func (r *VirtualNodeReconciler) createNamespaceMap(ctx context.Context, n *corev1.Node) error { | ||
nm := &mapsv1alpha1.NamespaceMap{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: fmt.Sprintf("%s-", n.GetAnnotations()[liqoconst.RemoteClusterID]), | ||
Namespace: liqoconst.TechnicalNamespace, | ||
Labels: map[string]string{ | ||
liqoconst.RemoteClusterID: n.GetAnnotations()[liqoconst.RemoteClusterID], | ||
}, | ||
}, | ||
} | ||
|
||
if err := ctrlutils.SetControllerReference(n, nm, r.Scheme); err != nil { | ||
return err | ||
} | ||
|
||
if err := r.Create(ctx, nm); err != nil { | ||
klog.Errorf("%s --> Problems in NamespaceMap creation for the virtual node '%s'", err, n.GetName()) | ||
return err | ||
} | ||
klog.Infof(" Create the NamespaceMap '%s' for the virtual node '%s'", nm.GetName(), n.GetName()) | ||
return nil | ||
} | ||
|
||
// This function manages NamespaceMaps Lifecycle on the basis of NamespaceMaps' number. | ||
func (r *VirtualNodeReconciler) checkNamespaceMapPresence(ctx context.Context, n *corev1.Node) error { | ||
nms := &mapsv1alpha1.NamespaceMapList{} | ||
if err := r.List(ctx, nms, client.InNamespace(liqoconst.TechnicalNamespace), | ||
client.MatchingLabels{liqoconst.RemoteClusterID: n.GetAnnotations()[liqoconst.RemoteClusterID]}); err != nil { | ||
klog.Errorf("%s --> Unable to List NamespaceMaps of virtual-node '%s'", err, n.GetName()) | ||
return err | ||
} | ||
|
||
if len(nms.Items) == 0 { | ||
return r.createNamespaceMap(ctx, n) | ||
} | ||
|
||
return nil | ||
} |
153 changes: 0 additions & 153 deletions
153
pkg/liqo-controller-manager/virtualNode-controller/namespaceMap_lifecycle.go
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.