Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

tenant-controller: add namespace/rbac sync on update of tenant #12

Merged
merged 1 commit into from
Apr 12, 2019

Conversation

easeway
Copy link
Contributor

@easeway easeway commented Apr 11, 2019

Refactor the code and add the functionality to:

  • synchronize namespaces when Tenant object is updated, including namespace deletion/creation;
  • synchronize RBAC inside namespaces when Tenant object is updated, for tenant admins;
  • add OwnerReferences to be managed by garbage collector.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 11, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: easeway

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 11, 2019
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 11, 2019

func (c *Controller) ensureNamespaceExists(tenant *tenantsapi.Tenant, nsName string) error {
// TODO Add later ... sanity checks to ensure namespaces being requested are valid and not already assigned to another tenant
if err := newKubeCtl().addObjects(&corev1.Namespace{
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor comment: In the same file we now have calls using k8sclient as well as newKubeCtl() ... we should discuss whether to make it consistent and use the same approach everywhere or whether it is okay to use different approaches. The separate k8sclient approach was taken to natch the example in the sample-controller repo.

// TODO sync namespace
// TODO sync RBAC inside namespace
func (c *Controller) createNamespaceForTenant(tenant *tenantsapi.Tenant, nsReq *tenantsapi.TenantNamespace) error {
if err := c.ensureNamespaceExists(tenant, nsReq.Name); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor comment: The names of the functions ensureNamespaceExists and syncNamespaceForTenant are slightly misleading. The first one is not ensuring but actually creating the namespace (maybe a name like createNamespaceForTenant is something to consider ?). The second one is attaching rbac for this namespace (so maybe a name like syncRbacForTenant or syncPropertiesForTenant could be considered ?). Anyway its a minor comment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants