-
Notifications
You must be signed in to change notification settings - Fork 29
fix(#674): introduce nsUsername used as base-name for namespace names #675
fix(#674): introduce nsUsername used as base-name for namespace names #675
Conversation
… namespace names If there is a tenant or namespace with such a base-name, then it appends number starting with number 2 - eg. johny2
@@ -0,0 +1,2 @@ | |||
ALTER TABLE tenants | |||
ADD COLUMN ns_username TEXT; |
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.
Index?
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.
Maybe add a migration to add the basename of the existing users. Using the namespace.name where type=user should work..
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.
index added: a1914bc
is it fine that it is in the same file? or did you expect another migration file?
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.
Maybe add a migration to add the basename of the existing users. Using the namespace.name where type=user should work.
Do you mean something like this:
UPDATE tenants t SET t.ns_username = (SELECT name FROM namespaces n WHERE t.id = n.tenant_id AND t.type = 'user')
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.
Actually, it's good idea - with this we could easily find those tenants that are not properly provisioned - have no user
namespace
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.
Yeah, easy to find anyway, but probably about 20 at this point I think
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.
added the migration command here: 139d178
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.
there was a bug in the SQL command - the correct is:
UPDATE tenants SET ns_base_name = (SELECT name FROM namespaces n WHERE tenants.id = n.tenant_id AND n.type = 'user')
fixed as part of ec19689
Codecov Report
@@ Coverage Diff @@
## master #675 +/- ##
==========================================
+ Coverage 52.34% 52.68% +0.34%
==========================================
Files 28 28
Lines 2050 2105 +55
==========================================
+ Hits 1073 1109 +36
- Misses 859 878 +19
Partials 118 118
Continue to review full report at Codecov.
|
5f9f190
to
a1914bc
Compare
controller/tenant.go
Outdated
// create openshift config | ||
openshiftConfig := openshift.NewConfig(c.config, user.UserData, cluster.User, cluster.Token, cluster.APIURL) | ||
tenant := &tenant.Tenant{ | ||
ID: ttoken.Subject(), | ||
Email: ttoken.Email(), | ||
OSUsername: user.OpenShiftUsername, | ||
NsUsername: username, |
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.
Can we maybe call it NsNamePrefix or NsBaseName or something like this? The fact that we use a username as a base for that prefix is implementation detail and we can change it in the future. Also it would make it less confusing why this "nsusername" does not always match username.
So, I would like to make it clear across the code that we have clear names for these two concepts here. Username (actual username) and a base-name or prefix which is currently constructed from a username and an index.
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 called it ns_username
because there in the templates it is used as:
namespace: ${USER_NAME}-che
so, I wanted to make it consitent. Unfortunatelly, the fact that we also have OSUsername that is stored in the table as username
make the stuff more complicated.
So, I would like to make it clear across the code that we have clear names for these two concepts here. Username (actual username) and a base-name or prefix which is currently constructed from a username and an index.
The actual username
is/was used only for the namespaces - there is no other usage of it (if I'm not mistaken). We only use OSUsername. In other words, the username
is only our artificial thingy (implementation detail) that is retrieved from the real OSUsername. Unfortunately, we used this name of the variable also in the templates - which makes sense in case of user namespace.
So, I'll call it NsBaseName
and when this PR is merged I'll change also the variables in all templates from ${USER_NAME}
to ${NS_BASE_NAME}
to make it consistent, if you are fine with it.
Why is naming always so hard? :-/
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.
changed in ec19689
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.
“There are only two hard things in Computer Science: cache invalidation and naming things.”
:)
tenant/repository.go
Outdated
if err != nil { | ||
return false | ||
} | ||
return true |
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.
Check if the error is NotFoundError. If yes then return false. Otherwise return the error. Otherwise if there is some problem with the query or DB different than expected Not Found then you will 1) get an infinite loop when constructing an unique name 2) miss opportunity to catch/log some problem with DB.
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.
Good point - I blindly copied the approach from the Exists method that was already there and I didn't realize these cases.
I'll send another PR to fix the Exists
method as well.
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.
Done in 39cbe2f
tenant/repository.go
Outdated
if err != nil { | ||
return false | ||
} | ||
return true |
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.
Check if the error is NotFoundError. If yes then return false. Otherwise return the error.
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.
done in 39cbe2f
varUserName: userName, | ||
varProjectUser: user, | ||
varProjectRequestingUser: user, | ||
varUserName: nsBaseName, |
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.
Depending on how this is used but the naming looks odd.. username != basename
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.
never mind.. {USER_NAME}-che
This PR introduces
nsUsername
intenant
table. It is used as a base-name (eg.johny
) for namespace names. When a new tenant is being created, then it checks if there is some tenant or namespace that the same base-name already uses. If there is some, then it appends a number to the name starting with number 2 (eg.johny2
) and checks for any conflict again.