-
Notifications
You must be signed in to change notification settings - Fork 20
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
Implement the reconciler for SubnetConnectionBindingMap #901
base: main
Are you sure you want to change the base?
Conversation
7991d8d
to
d80d3d9
Compare
d80d3d9
to
346923e
Compare
// Try to delete stale NSX SubnetConnectionBindingMaps if exists | ||
if err := r.SubnetBindingService.DeleteSubnetConnectionBindingMapsByCRName(req.Name, req.Namespace); err != nil { | ||
log.Error(err, "Failed to delete NSX SubnetConnectionBindingMap", "SubnetConnectionBindingMap", req.NamespacedName) | ||
return ResultRequeue, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns nil
in Reconcile function even if an error happened because we want to use the ResultRequeue to control the delay to re-queue the request rather than the framework's default value. Otherwise, it may print such logs.
2024-11-19 08:16:55.803 INFO controller/controller.go:314 Warning: Reconciler returned both a non-zero result and a non-nil error. The result will always be ignored if the error is non-nil and the non-nil error causes reqeueuing with exponential backoff. For more details, see: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile#Reconciler {"controller": "subnetconnectionbindingmap", "controllerGroup": "crd.nsx.vmware.com", "controllerKind": "SubnetConnectionBindingMap", "SubnetConnectionBindingMap": {"name":"binding1","namespace":"svc-tkg-domain-c10"}, "namespace": "svc-tkg-domain-c10", "name": "binding1", "reconcileID": "b504bdcb-9a6b-4009-bc02-f00db6a9dfd1"}
2024-11-19 08:16:55.803 ERROR controller/controller.go:316 Reconciler error {"controller": "subnetconnectionbindingmap", "controllerGroup": "crd.nsx.vmware.com", "controllerKind": "SubnetConnectionBindingMap", "SubnetConnectionBindingMap": {"name":"binding1","namespace":"svc-tkg-domain-c10"}, "namespace": "svc-tkg-domain-c10", "name": "binding1", "reconcileID": "b504bdcb-9a6b-4009-bc02-f00db6a9dfd1", "error": "no existing NSX VpcSubnet created by SubnetSet CR 'svc-tkg-domain-c10/pod-default'"}
0a603b9
to
15795be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not finished.
if !IsObjectReady(newBindingMap.Status.Conditions) { | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved before line 78 to return earlier with less checks in some cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we shall support two cases with readiness change: 1) unready->ready, 2) ready->unready.
I use it here is to support the third case that binding map is ready, but its spec has changed.
CreateFunc: func(e event.CreateEvent) bool { | ||
return false | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one and GenericFunc can be removed, the default is false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having checked the code in the library used by nsx-operator, the default return value is true
if we don't explicitly provide the functions.
if msg != "" { | ||
newConditions[0].Message = msg | ||
} | ||
if reason != "" { | ||
newConditions[0].Reason = reason | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it's ok to assign directly without checking since the default value of string is "", it won't impact the final result if we assign it when msg and reason are empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the empty will overwrite the default values in line 290-296.
) | ||
|
||
func requeueSubnetByBindingMapUpdate(ctx context.Context, c client.Client, objOld client.Object, objNew client.Object, q workqueue.TypedRateLimitingInterface[reconcile.Request]) { | ||
bindingMap := objNew.(*v1alpha1.SubnetConnectionBindingMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bindingMap := objNew.(*v1alpha1.SubnetConnectionBindingMap) | |
newBM := objNew.(*v1alpha1.SubnetConnectionBindingMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
reasonDependencyNotReady = "DependencyNotReady" | ||
reasonConfigureFailure = "ConfigureFailed" | ||
msgGetSubnetCR = "Unable to get Subnet CR %s" | ||
msgGetSubnetSetCR = "Unable to get SubnetSet CR %s" | ||
msgGetNSXSubnetsBySubnet = "Subnet CR %s is not realized on NSX" | ||
msgGetNSXSubnetsBySubnetSet = "SubnetSet CR %s is not realized on NSX" | ||
msgChildWorkAsParent = "Subnet CR %s is working as target by %s" | ||
msgParentWorkAsChild = "Target Subnet CR %s is attached by %s" | ||
msgRealizeSubnetBinding = "Failed to realize SubnetConnectionBindingMap %s on NSX" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, please check if it's necessary to define these in global variables.
I would avoid define them here if it's used once in one function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, although I prefer to place such CR condition messages/reasons together to help quickly understand what conditions may exist for this CR.
|
||
var ( | ||
log = &logger.Log | ||
MetricResTypeSubnetConnectionBindingMap = common.MetricResTypeSubnetConnectionBindingMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this assignment needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I learned from other nsx services in nsx-operator.
15795be
to
137f6d7
Compare
1. Implement the reconciler for SubnetConnectionBindingMap, it may update the SubnetConnectionBindingMap status with condition ready is false if its dependent Subnet or SubnetSet is not ready (or realized) or it hits errors when realizing NSX SubnetConnectionBindingMaps. It updates the status with ready condition as true if it is successfully realized on NSX. The reconciler also watches the Subnet/SubnetSet CR events to sync the connection binding maps. 2. The change also modifies the Subnet/SubnetSet reconciler to watch SubnetConnectionBindingMap CR events. If a Subnet/SubnetSet is used by a SubnetConnectionBindingMap, a finalizer is added on the corresponding Subnet/SubnetSet CR, and the finalizer is removed automatically if the CR is not used by any SubnetConnectionBindingMaps.
137f6d7
to
000adf5
Compare
Test Done:
A child Subnet CR and a SubnetConnectionBindingMap CR are prepared,
After the SubnetConnectionBindingMap is successfully realized, its ready condition is updated as true
SubnetInUse
SubnetSet scale-out and scale-in.
After scale-out the target SubnetSet, the number of generated NSX SubnetConnectionBindingMaps is increased from 1 to 2.
After scale-in the target SubnetSet, the number of generated NSX SubnetConnectionBindingMaps is decreased from 2 to 1,
No changes was updated to SubnetConnectionBindingMap CR unless errors occurred.
If the dependent SubnetSet has no NSX SubnetPort, and all NSX VpcSubnets are gc, the SubnetConnectionBindingMap CR status is changed to not-ready.