-
Notifications
You must be signed in to change notification settings - Fork 29
feat(#729): initialize tenant when GET call is received and don't wait for POST #742
feat(#729): initialize tenant when GET call is received and don't wait for POST #742
Conversation
…xtensible and replace oc commands (fabric8-services#673)
* chore: make warn log shorter
…ed and don't wait for POST
[test] |
Codecov Report
@@ Coverage Diff @@
## master #742 +/- ##
==========================================
- Coverage 75.24% 74.79% -0.45%
==========================================
Files 37 37
Lines 3013 3031 +18
==========================================
Hits 2267 2267
- Misses 561 574 +13
- Partials 185 190 +5
Continue to review full report at Codecov.
|
func (c *TenantController) getOrInitTenant(ctx context.Context, user *auth.User) (*tenant.Tenant, error) { | ||
var dbTenant *tenant.Tenant | ||
var err error | ||
tenantRepository := c.tenantService.NewTenantRepository(user.ID) |
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 do you pass the user.ID
in the tenant repository constructor? shouldn't it be user-agnostic (hence, pass the user.ID
as an arg when calling the methods. eg: repository.Exists(user.ID)
)
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.
Because the TenantRepository
is specific for one tenant. In one request I'm dealing with one tenant and this helps me to minimize the number of parameters passed to other methods/objects - I don't have to pass DB service along with the tenant id because it is already contained within the repository: https://github.com/fabric8-services/fabric8-tenant/blob/develop/tenant/repository.go#L138
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.
yes, that's what I understood, but it feels unusual to construct the repository with the tenant associated to it. My point is that it does not follow our pattern for services and repositories.
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.
For me it makes sense - it represents a repository for one tenant entity comparing to the DBService
that represents a service for all other cases (not related to one tenant).
But I'm open to any proposal ;-).
we already had some discussions about it:
#673 (comment)
#732 (comment)
I have a big problem with these namings so I would welcome any help :-)
@@ -246,7 +190,24 @@ func (c *TenantController) Show(ctx *app.ShowTenantContext) error { | |||
return jsonapi.JSONErrorResponse(ctx, err) | |||
} | |||
|
|||
return ctx.OK(&app.TenantSingle{Data: convertTenant(ctx, tenant, namespaces, c.clusterService.GetCluster)}) | |||
// check if any environment type is missing - should be provisioned | |||
missing, _ := filterMissingAndExisting(namespaces) |
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.
do you have a test for this filterMissingAndExisting
func?
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.
only indirect tests - not direct
see:
-
when no namespace exists
TestShowTenantOKWhenNoTenantExists
TestSetupTenantOKWhenNoTenantExists
-
when some namespaces exist
TestShowTenantWhenSomeNamespacesAreMissing
TestSetupTenantOKWhenAlreadyExists
-
when all namespace exist
TestSetupConflictFailure
TestShowTenant
controller/tenant.go
Outdated
} | ||
|
||
func (c *TenantController) createNamespaces(ctx context.Context, envTypes []environment.Type, user *auth.User, dbTenant *tenant.Tenant) error { | ||
clusterNsMapping, err := c.clusterService.GetUserClusterForType(ctx, 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.
why is this method called GetUserClusterForType
? what is the type
here?
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.
https://github.com/fabric8-services/fabric8-tenant/blob/develop/cluster/service.go#L34
I could maybe change it to GetUserClusterForEnvType
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 you only pass the context and user as args here, so why ForType
or ForEnvType
?
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.
it returns a function ForType
that returns cluster for the given environment type. To point here is that it was a preparation for a multi-cluster environment (when one env type can be associated with a different cluster), that's why such a mapping. In this case, it just returns the same cluster (the user cluster) for all env types. This function is then used in a generic way.
Closing this issue as it is not relevant anymore. In addition, as there is a Get call before the first Post call, then it would be too early to start provisioning for the first Get call |
POST
call but also forGET
call that is received with a user token.Fixes: #729