Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.6] Populate backing namespace field for projects #532

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

JonCrowther
Copy link
Contributor

Issue:

Builds on rancher/rancher#47723

@JonCrowther JonCrowther self-assigned this Oct 30, 2024
@JonCrowther JonCrowther requested a review from a team as a code owner October 30, 2024 14:51
@JonCrowther JonCrowther changed the title Populate backing namespace field for projects [v0.6] Populate backing namespace field for projects Oct 30, 2024
nflynt
nflynt previously approved these changes Oct 30, 2024
@@ -4,6 +4,9 @@

ClusterName must be equal to the namespace, and must refer to an existing `management.cattle.io/v3.Cluster` object. In addition, users cannot update the field after creation.

### BackingNamespace validation
The BackingNamespace field cannot be changed once set. Projects without the BackingNamespace field can have it added.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The BackingNamespace field cannot be changed once set. Projects without the BackingNamespace field can have it added.
The `BackingNamespace` field cannot be changed once set. Projects without the `BackingNamespace` field can have it added.

@@ -31,4 +34,13 @@ If `field.cattle.io/no-creator-rbac` annotation is set, `field.cattle.io/creator

### On create

Populates the BackingNamespace field by concatenating `Project.ClusterName` and `Project.Name`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Populates the BackingNamespace field by concatenating `Project.ClusterName` and `Project.Name`.
Populates the `BackingNamespace` field by concatenating `Project.ClusterName` and `Project.Name`.

Populates the BackingNamespace field by concatenating `Project.ClusterName` and `Project.Name`.

If the project is using a generated name (ie `GenerateName` is not empty), the generation happens within the mutating webhook.
The reason for this is that the BackingNamespace is made up of the `Project.Name`, and name generation happens after mutating webhooks and before validating webhooks.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The reason for this is that the BackingNamespace is made up of the `Project.Name`, and name generation happens after mutating webhooks and before validating webhooks.
The reason for this is that the `BackingNamespace` is made up of the `Project.Name`, and name generation happens after mutating and before validating webhooks.


### On update

If the BackingNamespace field is empty, populate the BackingNamespace field with the project name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If the BackingNamespace field is empty, populate the BackingNamespace field with the project name.
If the `BackingNamespace` field is empty, it's populated with the project name.

backingNamespace = name.SafeConcatName(newProject.Spec.ClusterName, strings.ToLower(newProject.Name))
_, err = m.namespaceClient.Get(backingNamespace, v1.GetOptions{})
if err == nil {
return nil, fmt.Errorf("failed to create project: namespace %v already exists", backingNamespace)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("failed to create project: namespace %v already exists", backingNamespace)
return nil, fmt.Errorf("failed to create project: namespace %s already exists", backingNamespace)

Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Should we throw an error or just make it a no-op? 🤔

Comment on lines 161 to 163
// updateProjectNamespace fills in BackingNamespace with the project name if it wasn't already set
// this was the naming convention of project namespaces prior to using the BackingNamespace field. Filling
// it here is just to maintain backwards compatibility
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// updateProjectNamespace fills in BackingNamespace with the project name if it wasn't already set
// this was the naming convention of project namespaces prior to using the BackingNamespace field. Filling
// it here is just to maintain backwards compatibility
// updateProjectNamespace fills in BackingNamespace with the project name if it wasn't already set.
// This was the naming convention for project namespaces prior to using the BackingNamespace field.
// Filling it here is just to maintain backwards compatibility.

@JonCrowther JonCrowther merged commit b174447 into rancher:main Oct 30, 2024
2 checks passed
@JonCrowther JonCrowther deleted the project-namespace-checks branch October 30, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants