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

Make attribute ingress_class_name of resource kubernetes_ingress_v1 computed #1947

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1947.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
`resource/kubernetes_ingress_v1`: make the attribute `spec.ingress_class_name` computed
```
59 changes: 0 additions & 59 deletions kubernetes/resource_kubernetes_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,6 @@ func TestAccKubernetesIngress_WaitForLoadBalancerGoogleCloud(t *testing.T) {
})
}

func testAccCheckKubernetesIngressForceNew(old, new *api.Ingress, wantNew bool) resource.TestCheckFunc {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not related to the original issue, just noticed that it is not in use, and since I touched this file, I cleaned it up a bit.

return func(s *terraform.State) error {
if wantNew {
if old.ObjectMeta.UID == new.ObjectMeta.UID {
return fmt.Errorf("Expecting new resource for Ingress %s", old.ObjectMeta.UID)
}
} else {
if old.ObjectMeta.UID != new.ObjectMeta.UID {
return fmt.Errorf("Expecting Ingress UIDs to be the same: expected %s got %s", old.ObjectMeta.UID, new.ObjectMeta.UID)
}
}
return nil
}
}

func testAccCheckKubernetesIngressDestroy(s *terraform.State) error {
conn, err := testAccProvider.Meta().(KubeClientsets).MainClientset()

Expand Down Expand Up @@ -452,47 +437,3 @@ resource "kubernetes_ingress" "test" {
wait_for_load_balancer = true
}`, name, name, name, name, name, name, name)
}

func testAccKubernetesIngressConfig_stateUpgradev0(provider, name string) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not related to the original issue, just noticed that it is not in use, and since I touched this file, I cleaned it up a bit.

return fmt.Sprintf(`resource "kubernetes_service" "test" {
provider = "%s"
metadata {
name = "%s"
}
spec {
port {
port = 80
target_port = 80
protocol = "TCP"
}
type = "NodePort"
}
}

resource "kubernetes_ingress" "test" {
provider = "%s"
wait_for_load_balancer = false
metadata {
name = "%s"
annotations = {
"kubernetes.io/ingress.class" = "alb"
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"alb.ingress.kubernetes.io/target-type" = "ip"
}
}
spec {
rule {
http {
path {
path = "/*"
backend {
service_name = kubernetes_service.test.metadata.0.name
service_port = 80
}
}
}
}
}
}
`, provider, name, provider, name)
}
1 change: 1 addition & 0 deletions kubernetes/resource_kubernetes_ingress_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func resourceKubernetesIngressV1Schema() map[string]*schema.Schema {
Type: schema.TypeString,
Description: docIngressSpec["ingressClassName"],
Optional: true,
Computed: true,
},
"default_backend": backendSpecFieldsV1(defaultBackendDescriptionV1),
"rule": {
Expand Down
82 changes: 69 additions & 13 deletions kubernetes/resource_kubernetes_ingress_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,33 @@ func TestAccKubernetesIngressV1_multipleRulesDifferentHosts(t *testing.T) {
})
}

func testAccCheckKubernetesIngressV1ForceNew(old, new *networking.Ingress, wantNew bool) resource.TestCheckFunc {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not related to the original issue, just noticed that it is not in use, and since I touched this file, I cleaned it up a bit.

return func(s *terraform.State) error {
if wantNew {
if old.ObjectMeta.UID == new.ObjectMeta.UID {
return fmt.Errorf("Expecting new resource for Ingress %s", old.ObjectMeta.UID)
}
} else {
if old.ObjectMeta.UID != new.ObjectMeta.UID {
return fmt.Errorf("Expecting Ingress UIDs to be the same: expected %s got %s", old.ObjectMeta.UID, new.ObjectMeta.UID)
}
}
return nil
}
func TestAccKubernetesIngressV1_defaultIngressClass(t *testing.T) {
var conf networking.Ingress
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
ingressClass := "default-ingress-class"
resourceName := "kubernetes_ingress_v1.test"

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
skipIfClusterVersionLessThan(t, "1.22.0")
},
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckKubernetesIngressV1Destroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesIngressV1Config_defaultIngressClass(ingressClass, name),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesIngressV1Exists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.ingress_class_name", "default-ingress-class"),
),
},
},
})
}

func testAccCheckKubernetesIngressV1Destroy(s *terraform.State) error {
Expand Down Expand Up @@ -724,3 +738,45 @@ func testAccKubernetesIngressV1Config_multipleRulesDifferentHosts(name string) s
}
}`, name)
}

func testAccKubernetesIngressV1Config_defaultIngressClass(ingressClass, name string) string {
return fmt.Sprintf(`resource "kubernetes_ingress_class_v1" "test" {
metadata {
name = "%s"
labels = {
"app.kubernetes.io/component" = "controller"
}
annotations = {
"ingressclass.kubernetes.io/is-default-class" = "true"
}
}
spec {
controller = "k8s.io/ingress-nginx"
}
}

resource "kubernetes_ingress_v1" "test" {
metadata {
name = "%s"
}
spec {
rule {
host = "server.domain.com"
http {
path {
backend {
service {
name = "app1"
port {
number = 8080
}
}
}
path = "/app1/*"
}
}
}
}
depends_on = ["kubernetes_ingress_class_v1.test"]
}`, ingressClass, name)
}