Improve uniqueness of ClusterControlPlane name#1386
Improve uniqueness of ClusterControlPlane name#1386Atish-iaf wants to merge 1 commit intovmware-tanzu:mainfrom
Conversation
|
Can one of the admins verify this patch? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1386 +/- ##
=======================================
Coverage 76.76% 76.76%
=======================================
Files 151 151
Lines 21313 21315 +2
=======================================
+ Hits 16360 16362 +2
Misses 3784 3784
Partials 1169 1169
🚀 New features to boost your workflow:
|
0fe343c to
cc434c2
Compare
|
Hi @edwardbadboy @liu4480 |
627c567 to
5a56192
Compare
5a56192 to
905a145
Compare
| NSXClient: &nsx.Client{ | ||
| NsxConfig: &config.NSXOperatorConfig{ | ||
| CoeConfig: &config.CoeConfig{ | ||
| Cluster: "k8scl-one:test", |
There was a problem hiding this comment.
@edwardbadboy I just recalled that we replaced ":" with "_" in normalized name, this might lead to misunderstanding as well, shall we use other character to replace it, for example "--" or "__"
There was a problem hiding this comment.
Does : ever exist in NSXConfig.CoeConfig.Cluster ? It is supervisor_id so it seems no.
So, while normalizing cluster name, the cluster name wouldn't have : and therefore no need to replace : because it won't exists ?
There was a problem hiding this comment.
util.NormalizeId coverts ":" to "_". Specific to our use case, today supervisor cluster id is a UUID, it doesn't has any ":". Namespace and cluster names cannot have ":", so this is fine.
Besides, if you want to get a conflict, you have to control both part of the names. For example, before this patch, if namespace and cluster names are connected by "-", you can do
- aaa-bbb + ccc -> aaa-bbb-ccc
- aaa + bbb-ccc -> aaa-bbb-ccc
You have to construct both namespace name and cluster names.
Supervisor ID is auto generated, not controlled by the customer, so this is fine. For example, you cannot do:
- SV ID = aaa:bbb , namespace = ccc -> aaa_bbb_ccc
- SV ID = aaa, namespace = bbb-ccc -> aaa_bbb_ccc
This is because customer have no control on SV IDs. If a SV ID has ":", then all SV IDs should have ":" in the same place.
util.NormalizeId coverts ":" to "_" may because the SV name (not ID) can be like "domain-c10:uuid". Maybe in previous releases, WCP once configured NCP ConfigMap with this name.
| func (s *NSXServiceAccountService) DeleteNSXServiceAccount(ctx context.Context, namespacedName types.NamespacedName, uid types.UID) error { | ||
| isDeleteSecret := false | ||
| nsxsa := &v1alpha1.NSXServiceAccount{} | ||
| if err := s.Client.Get(ctx, namespacedName, nsxsa); err != nil { |
There was a problem hiding this comment.
If DeleteNSXServiceAccount is called by NSXServiceAccountReconciler.garbageCollector, the NSXServiceAccount object with the namespacedName may not exist. Here I estimate that it will hit this err != nil code path and *nsxsa may be still a zero value (v1alpha1.NSXServiceAccount{}) after this Client.Get call.
The later s.getClusterName(nsxsa) call should be prepared for this situation.
This situation should not happen in usual case, because the nsx-operator adds a finalizer to NSXSA. NSXSA CR should not be deleted without deregistering. This may happen when NSX is backup-restored. NSXSA was created, NSX was backed up, then NSXSA was deleted, and NSX is restored. During garbage collection, the operator will see that cluster-control-plane resource exists but NSXSA doesn't exist. Then DeleteNSXServiceAccount is called with a namespacedName pointing to this non-existent NSXSA.
There was a problem hiding this comment.
Thanks @edwardbadboy , updated to handle this situation, please help to review again.
| NSXClient: &nsx.Client{ | ||
| NsxConfig: &config.NSXOperatorConfig{ | ||
| CoeConfig: &config.CoeConfig{ | ||
| Cluster: "k8scl-one:test", |
There was a problem hiding this comment.
util.NormalizeId coverts ":" to "_". Specific to our use case, today supervisor cluster id is a UUID, it doesn't has any ":". Namespace and cluster names cannot have ":", so this is fine.
Besides, if you want to get a conflict, you have to control both part of the names. For example, before this patch, if namespace and cluster names are connected by "-", you can do
- aaa-bbb + ccc -> aaa-bbb-ccc
- aaa + bbb-ccc -> aaa-bbb-ccc
You have to construct both namespace name and cluster names.
Supervisor ID is auto generated, not controlled by the customer, so this is fine. For example, you cannot do:
- SV ID = aaa:bbb , namespace = ccc -> aaa_bbb_ccc
- SV ID = aaa, namespace = bbb-ccc -> aaa_bbb_ccc
This is because customer have no control on SV IDs. If a SV ID has ":", then all SV IDs should have ":" in the same place.
util.NormalizeId coverts ":" to "_" may because the SV name (not ID) can be like "domain-c10:uuid". Maybe in previous releases, WCP once configured NCP ConfigMap with this name.
edwardbadboy
left a comment
There was a problem hiding this comment.
There is a typo in PR title and commit message title: ClusterClontrolPlane -> ClusterControlPlane
Signed-off-by: Kumar Atish <kumar.atish@broadcom.com>
905a145 to
33063fe
Compare
nsx-operator uses the following name pattern when generating cluster-control-plane names.
fmt.Sprintf("%s-%s-%s", s.NSXConfig.CoeConfig.Cluster, namespace, name)The following two different namespaces and clusters will be in the same name.
namespace: xx, cluster: yy-zz, result: xx-yy-zz
namespace: xx-yy, cluster: zz, result: xx-yy-zz
A solution would be using underscore instead of "-" as delimiter. K8s doesn't allow namespace names to include underscore (ref)
No need to change existing NSXServiceAccount cluster-control-plane node IDs and names. This new name pattern should only apply to new NSXServiceAccount CRs created after this new name pattern is enabled in nsx-operator.
Test summary
Doesn't change
status.clusterNamein existing NSXServiceAccount CRFor new NSXServiceAccount CR, it uses the new pattern
_to join namespace and name instead of-when generating clusterName so that it is unique.