Conversation
alexsomesan
left a comment
There was a problem hiding this comment.
Sweet! Really love these! Nicely done, @redeux !
One thing I wanted to mention before we merge: in the case of ClusterIP there are some actual server-generated attribute values (the IP addresses) that would be useful to capture in assertions. See my comment below for the whole story.
| "kubernetes_manifest.test.object.spec.ports.0.targetPort": json.Number("8080"), | ||
| "kubernetes_manifest.test.object.spec.ports.0.protocol": "TCP", | ||
| "kubernetes_manifest.test.object.spec.selector.app": "test", | ||
| "kubernetes_manifest.test.object.spec.type": "ClusterIP", |
There was a problem hiding this comment.
When a service of type "ClusterIP" is created, the resulting resource gets two attributes added by the controller manager which hold the actual cluster IP address(es) allocated to the service. These were causing inconsistent state issues in the pre-0.3.0 provider and are a simple demonstration of why we need the OpenAPI type system.
It would be useful to add assertions for the presence of these two attributes which demonstrate the resource is correctly typed and Terraform saves these computed values as well.
Here an example of how they show up in state:
resource "kubernetes_manifest" "test" {
manifest = {
apiVersion = "v1"
kind = "Service"
metadata = {
name = "alextest"
namespace = "default"
}
spec = {
ports = [
{
name = "http"
port = 80
protocol = "TCP"
targetPort = 8080
},
]
selector = {
app = "test"
}
type = "ClusterIP"
}
}
object = {
apiVersion = "v1"
kind = "Service"
metadata = {
annotations = null
clusterName = null
creationTimestamp = null
deletionGracePeriodSeconds = null
deletionTimestamp = null
finalizers = null
generateName = null
generation = null
labels = null
managedFields = null
name = "alextest"
namespace = "default"
ownerReferences = null
resourceVersion = null
selfLink = null
uid = null
}
spec = {
allocateLoadBalancerNodePorts = null
clusterIP = "10.104.36.74"
clusterIPs = [
"10.104.36.74",
]
externalIPs = null
externalName = null
externalTrafficPolicy = null
healthCheckNodePort = null
ipFamilies = null
ipFamilyPolicy = null
loadBalancerIP = null
loadBalancerSourceRanges = null
ports = [
{
appProtocol = null
name = "http"
nodePort = null
port = 80
protocol = "TCP"
targetPort = 8080
},
]
publishNotReadyAddresses = null
selector = {
"app" = "test"
}
sessionAffinity = "None"
sessionAffinityConfig = {
clientIP = {
timeoutSeconds = null
}
}
topologyKeys = null
type = "ClusterIP"
}
}
}
Description
Tests for the Kubernetes Service resource.
Includes test for types:
References
https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/
Community Note