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

fix cluster role binding namespace handling #2633

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JaylonmcShan03
Copy link
Contributor

@JaylonmcShan03 JaylonmcShan03 commented Nov 25, 2024

Description

Fixes #710
This PR addresses and fixes the handling of namespaces in the kubernetes_cluster_role_binding_v1 resource

I am looking for feedback on my fix! Initially, I implemented logic in structures_rbac.go to handle namespace values directly. However, during acceptance testing, I encountered plan difference errors, where the namespace field was toggling between "default" and null. These differences caused Terraform to repeatedly attempt updates, believing the resource was not in the desired state.

To address this issue, I modified the schema to include diff suppression for the namespace field:
Diff suppression ensures that when the namespace field is either "default" (defaulted by Kubernetes) or null (irrelevant for Group and User), Terraform does not detect a difference.

Acceptance tests

  • Have you added an acceptance test for the functionality being added?
  • Have you run the acceptance tests on this branch?

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

...
irectory=/var/folders/bp/l16ph9cj7958ml9t254_zcv00000gn/T/plugintest2388791179 test_step_number=1
2024-11-25T08:43:36.326-0600 [DEBUG] sdk.helper_resource: Finished TestCase: test_name=TestAccKubernetesClusterRoleBindingV1_namespaceHandling
--- PASS: TestAccKubernetesClusterRoleBindingV1_namespaceHandling (1.77s)
PASS
ok      github.com/hashicorp/terraform-provider-kubernetes/kubernetes

Release Note

Release note for CHANGELOG:

...

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

@JaylonmcShan03 JaylonmcShan03 marked this pull request as ready for review January 6, 2025 16:33
@JaylonmcShan03 JaylonmcShan03 requested a review from a team as a code owner January 6, 2025 16:33
subject.Namespace = v.(string)

// Handle namespace logic
if subject.Kind == "Group" || subject.Kind == "User" {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like the logic can be simplified a bit more where the condition only handles the Kind that use the namespace. See if you can simplify this a bit more. Same goes for the flattener.

Copy link
Contributor

@BBBmau BBBmau left a comment

Choose a reason for hiding this comment

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

This looks good, only thing missing is a changelog-entry. after that i can approve this PR!

Copy link
Contributor

@BBBmau BBBmau left a comment

Choose a reason for hiding this comment

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

so i'm unsure if people are still running into this. Despite the comments on the previous issue I went and attempted to reproduce the bug but came across the expected behavior:
terraform init:
image

tf apply:
image

tfconfig:
image

terraform.tfstate:
image

I even went ahead and downgrade from 1.31->1.26 and still unable to reproduce the bug.

can you provide me with your kubectl configs as well as confirming that you can reproduce it yourself?

@stevehipwell
Copy link
Contributor

@BBBmau it looks like your test is making use of the workaround of providing namespace = "" for cluster scoped subjects. To test this please remove lines 15 & 22 from your config.

@BBBmau
Copy link
Contributor

BBBmau commented Jan 27, 2025

@BBBmau it looks like your test is making use of the workaround of providing namespace = "" for cluster scoped subjects. To test this please remove lines 15 & 22 from your config.

That's what I get for attempting to reproduce a bug late at night. Thanks!

Copy link
Contributor

@BBBmau BBBmau left a comment

Choose a reason for hiding this comment

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

works great! I fixed up the test since it was explicitly setting the namespace to "". removed and tests pass as well as confirming by doing some manual tests.

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

Successfully merging this pull request may close these issues.

kubernetes_cluster_role_binding & kubernetes_role_binding adding namespace when subject kind is Group
3 participants