Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External Network: network webhook and logs fixes #2172

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -606,7 +606,7 @@ func (r *ForeignClusterReconciler) clusterIDEnqueuer(ctx context.Context, obj cl

fc, err := foreignclusterutils.GetForeignClusterByID(ctx, r.Client, clusterID)
if err != nil {
klog.Error(err)
klog.V(6).Info(err) // we only print the event, as the network can be created without the existence of the foreign cluster
return []ctrl.Request{}
}

Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ package networkctrl

import (
"context"
"fmt"
"net"

apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -29,7 +28,6 @@ import (

ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1"
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/ipam"
)

@@ -64,14 +62,6 @@ func (r *NetworkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
return ctrl.Result{}, err
}

// Retrieve the remote cluster ID from the labels.
_, found := nw.Labels[consts.RemoteClusterID] // it should always be present thanks to validating webhook
if !found {
err := fmt.Errorf("missing label %q on Network %q (webhook disabled or misconfigured)", consts.RemoteClusterID, req.NamespacedName)
klog.Error(err)
return ctrl.Result{}, err
}

desiredCIDR = nw.Spec.CIDR

if nw.GetDeletionTimestamp().IsZero() {
15 changes: 5 additions & 10 deletions pkg/liqo-controller-manager/webhooks/network/nw.go
Original file line number Diff line number Diff line change
@@ -77,12 +77,6 @@ func (w *nwwhv) HandleCreate(req *admission.Request) admission.Response {
return admission.Errored(http.StatusBadRequest, err)
}

// Check existence of the remote clusterID label
_, found := nw.Labels[consts.RemoteClusterID]
if !found {
return admission.Denied(fmt.Sprintf("Missing remote clusterID label (%q)", consts.RemoteClusterID))
}

// Check existence of the network CIDR
if nw.Spec.CIDR == "" {
return admission.Denied("Missing CIDR")
@@ -110,10 +104,11 @@ func (w *nwwhv) HandleUpdate(req *admission.Request) admission.Response {
return admission.Errored(http.StatusBadRequest, err)
}

// Check if the remote clusterID label is modified
// We do not check the existence of the label as it should always be present
// thank to the webhook validation of creation requests.
if nwold.Labels[consts.RemoteClusterID] != nwnew.Labels[consts.RemoteClusterID] {
// Check if the remote clusterID label is modified.
// note: the label can only be added or removed, but not modified.
oldClusterID, oldExists := nwold.Labels[consts.RemoteClusterID]
newClusterID, newExists := nwnew.Labels[consts.RemoteClusterID]
if oldExists && newExists && oldClusterID != newClusterID {
return admission.Denied("The remote clusterID label cannot be modified after creation")
}