Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

feat(#729): initialize tenant when GET call is received and don't wait for POST #742

Closed

Conversation

MatousJobanek
Copy link
Contributor

@MatousJobanek MatousJobanek commented Jan 29, 2019

  • tenant initializes namespaces (and creates DB records) not only for POST call but also for GET call that is received with a user token.
  • checks for the existence of all namespaces - in other words - when one namespace is missing for a particular tenant, then it initializes it

Fixes: #729

@MatousJobanek
Copy link
Contributor Author

[test]

@codecov
Copy link

codecov bot commented Jan 29, 2019

Codecov Report

Merging #742 into master will decrease coverage by 0.44%.
The diff coverage is 52.32%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
openshift/types.go 92.18% <100%> (ø) ⬆️
openshift/service.go 72.63% <100%> (ø) ⬆️
cluster/service.go 79.38% <100%> (ø) ⬆️
controller/tenant.go 68.29% <48.75%> (-3.64%) ⬇️
update/update.go 80.37% <0%> (-1.87%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c2ea27...a326890. Read the comment docs.

@MatousJobanek MatousJobanek changed the title WIP feat(#729): initialize tenant when GET call is received and don't wait for POST feat(#729): initialize tenant when GET call is received and don't wait for POST Feb 5, 2019
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)
Copy link
Contributor

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))

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

in https://github.com/fabric8-services/fabric8-tenant/pull/742/files#diff-f9e0701950f6288288104f0f34160817

}

func (c *TenantController) createNamespaces(ctx context.Context, envTypes []environment.Type, user *auth.User, dbTenant *tenant.Tenant) error {
clusterNsMapping, err := c.clusterService.GetUserClusterForType(ctx, user)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

@MatousJobanek MatousJobanek changed the base branch from develop to master February 6, 2019 14:40
@MatousJobanek
Copy link
Contributor Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants