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

Remove limit for taints in kubernetes_node_taint resource #2046

Merged
merged 17 commits into from
Apr 4, 2023

Conversation

BBBmau
Copy link
Contributor

@BBBmau BBBmau commented Mar 15, 2023

Description

Fixes #2035

Removes the MaxItems line from the "taint" attribute. Should allow the ability of multiple taint blocks if desired.

Release Note

Release note for CHANGELOG:

`kubernetes/resource_kubernetes_node_taint.go`: Remove MaxItems from taint attribute

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

@BBBmau BBBmau requested a review from a team as a code owner March 15, 2023 20:43
Copy link
Contributor

@arybolovlev arybolovlev left a comment

Choose a reason for hiding this comment

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

This PR does not address the issue. Yes, Terraform is not throwing an error message anymore. However, the kubernetes_node_taint resource takes into account only the first taint in the list, the rest doesn't apply. As the result, we get diff with every plan run.

Another point here is that tests were not updated to validate changes. I would suggest here the TDD approach. The idea is you first write a test that reproduces an issue without changing the code. In short, the tests should fail at this point. Once you have that done, you make changes in the code and run tests again, if the issue is addressed, the tests will pass.

@github-actions github-actions bot added size/S and removed size/XS labels Mar 22, 2023
@github-actions github-actions bot added size/M and removed size/S labels Mar 24, 2023
@github-actions github-actions bot added size/L and removed size/M labels Mar 30, 2023
@github-actions github-actions bot added size/XL and removed size/L labels Mar 31, 2023
@BBBmau
Copy link
Contributor Author

BBBmau commented Mar 31, 2023

Tried the case where a user will add taints with the same key but different values. A panic is outputted but the tfstate still shows the applied config.

tfconfig:

provider "kubernetes" {
  config_path    = "~/.kube/config"
}

resource "kubernetes_node_taint" "tainttest" {
  metadata {
    name = "minikube"
  }

  taint {
    key    = "node-role.kubernetes.io/example"
    value  = "false"
    effect = "NoSchedule"
  }
    taint {
    key    = "node-role.kubernetes.io/example"
    value  = "true"
    effect = "NoSchedule"
  }
}

tfstate:

            "taint": [
              {
                "effect": "NoSchedule",
                "key": "node-role.kubernetes.io/example",
                "value": "false"
              },
              {
                "effect": "NoSchedule",
                "key": "node-role.kubernetes.io/example",
                "value": "true"
              }
            ]

doing terraform refresh turns it back to the state before, but this extra step shouldn't be needed.

@jrhouston
Copy link
Collaborator

@BBBmau This is expected behaviour, you can't set multiple taints with the same key. We should add some validation here so that it fails on the plan instead of generating the error at apply time.

@jrhouston
Copy link
Collaborator

The list type doesn't support validators so I've pushed some logic that does the validation in a custom diff.

@jrhouston
Copy link
Collaborator

Now it will show on plan time:

terraform plan
╷
│ Error: taint: duplicate taint key "node-role.kubernetes.io/example": taint keys must be unique
│
│   with kubernetes_node_taint.tainttest,
│   on main.tf line 5, in resource "kubernetes_node_taint" "tainttest":
│    5: resource "kubernetes_node_taint" "tainttest" {
│
╵

@jrhouston jrhouston dismissed arybolovlev’s stale review April 4, 2023 21:50

Review resolved

@jrhouston jrhouston merged commit 927c705 into main Apr 4, 2023
@jrhouston jrhouston deleted the remove-taint-limit branch April 4, 2023 21:50
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubernetes_node_taint: Too many taint blocks
3 participants