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

Add runtime_class_name to pod #1895

Merged
merged 4 commits into from
Nov 17, 2022
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/1895.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
Add a new optional attribute `runtime_class_name` to `pod.spec`. That affects all resources and data sources that use `pod.spec` directly or as a template.
```
10 changes: 10 additions & 0 deletions kubernetes/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ func skipIfNotRunningInEks(t *testing.T) {
}
}

func skipIfRunningInEks(t *testing.T) {
isInEks, err := isRunningInEks()
if err != nil {
t.Fatal(err)
}
if isInEks {
t.Skip("This test cannot be run in EKS cluster")
}
}

func skipIfNotRunningInMinikube(t *testing.T) {
isInMinikube, err := isRunningInMinikube()
if err != nil {
Expand Down
81 changes: 81 additions & 0 deletions kubernetes/resource_kubernetes_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

api "k8s.io/api/core/v1"
nodev1 "k8s.io/api/node/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
Expand Down Expand Up @@ -1331,6 +1332,70 @@ func TestAccKubernetesPod_topologySpreadConstraint(t *testing.T) {
})
}

func TestAccKubernetesPod_runtimeClassName(t *testing.T) {
var conf1 api.Pod

name := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "kubernetes_pod_v1.test"
runtimeHandler := fmt.Sprintf("runc-%s", name)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
skipIfRunningInEks(t)
createRuncRuntimeClass(runtimeHandler)
},
ProviderFactories: testAccProviderFactories,
CheckDestroy: func(s *terraform.State) error {
err := deleteRuntimeClass(runtimeHandler)
if err != nil {
return err
}
return testAccCheckKubernetesPodDestroy(s)
},
Steps: []resource.TestStep{
{
Config: testAccKubernetesPodConfigRuntimeClassName(name, busyboxImageVersion, runtimeHandler),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPodExists(resourceName, &conf1),
resource.TestCheckResourceAttr(resourceName, "spec.0.runtime_class_name", runtimeHandler),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version"},
},
},
})
}

func createRuncRuntimeClass(rn string) error {
conn, err := testAccProvider.Meta().(KubeClientsets).MainClientset()
if err != nil {
return err
}
_, err = conn.NodeV1().RuntimeClasses().Create(context.Background(), &nodev1.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{
Name: rn,
},
Handler: "runc",
}, metav1.CreateOptions{})
if err != nil {
return err
}
return nil
}

func deleteRuntimeClass(rn string) error {
conn, err := testAccProvider.Meta().(KubeClientsets).MainClientset()
if err != nil {
return err
}
return conn.NodeV1().RuntimeClasses().Delete(context.Background(), rn, metav1.DeleteOptions{})
}

func testAccCheckCSIDriverExists(csiDriverName string) error {
conn, err := testAccProvider.Meta().(KubeClientsets).MainClientset()
if err != nil {
Expand Down Expand Up @@ -2810,3 +2875,19 @@ func testAccKubernetesPodTopologySpreadConstraintConfig(podName, imageName strin
}
`, podName, imageName)
}

func testAccKubernetesPodConfigRuntimeClassName(name, imageName, runtimeHandler string) string {
return fmt.Sprintf(`resource "kubernetes_pod_v1" "test" {
metadata {
name = "%s"
}
spec {
runtime_class_name = "%s"
container {
image = "%s"
name = "containername"
}
}
}
`, name, runtimeHandler, imageName)
}
7 changes: 7 additions & 0 deletions kubernetes/schema_pod_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ func podSpecFields(isUpdatable, isComputed bool) map[string]*schema.Schema {
ForceNew: !isUpdatable,
Description: "NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. More info: http://kubernetes.io/docs/user-guide/node-selection.",
},
"runtime_class_name": {
Type: schema.TypeString,
Optional: true,
Computed: isComputed,
ForceNew: !isUpdatable,
Description: "RuntimeClassName is a feature for selecting the container runtime configuration. The container runtime configuration is used to run a Pod's containers. More info: https://kubernetes.io/docs/concepts/containers/runtime-class",
},
"priority_class_name": {
Type: schema.TypeString,
Optional: true,
Expand Down
7 changes: 7 additions & 0 deletions kubernetes/structures_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func flattenPodSpec(in v1.PodSpec) ([]interface{}, error) {
if len(in.NodeSelector) > 0 {
att["node_selector"] = in.NodeSelector
}
if in.RuntimeClassName != nil {
att["runtime_class_name"] = *in.RuntimeClassName
}
if in.PriorityClassName != "" {
att["priority_class_name"] = in.PriorityClassName
}
Expand Down Expand Up @@ -754,6 +757,10 @@ func expandPodSpec(p []interface{}) (*v1.PodSpec, error) {
obj.NodeSelector = nodeSelectors
}

if v, ok := in["runtime_class_name"].(string); ok && v != "" {
obj.RuntimeClassName = ptrToString(v)
}

if v, ok := in["priority_class_name"].(string); ok {
obj.PriorityClassName = v
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/pod.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The following arguments are supported:
* `node_selector` - NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/node-selection).
* `priority_class_name` - If specified, indicates the pod's priority. 'system-node-critical' and 'system-cluster-critical' are two special keywords which indicate the highest priorities with the formerer being the highest priority. Any other name must be defined by creating a PriorityClass object with that name. If not specified, the pod priority will be default or zero if there is no default.
* `restart_policy` - Restart policy for all containers within the pod. One of Always, OnFailure, Never. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/pod-states#restartpolicy).
* `runtime_class_name` - (Optional) RuntimeClassName is a feature for selecting the container runtime configuration. The container runtime configuration is used to run a Pod's containers. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/containers/runtime-class)
* `security_context` - (SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty
* `service_account_name` - ServiceAccountName is the name of the ServiceAccount to use to run this pod. For more info see https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/.
* `share_process_namespace` - Share a single process namespace between all of the containers in a pod. When this is set containers will be able to view and signal processes from other containers in the same pod, and the first process in each container will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both be set.
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/pod_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The following arguments are supported:
* `node_selector` - NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/node-selection).
* `priority_class_name` - If specified, indicates the pod's priority. 'system-node-critical' and 'system-cluster-critical' are two special keywords which indicate the highest priorities with the formerer being the highest priority. Any other name must be defined by creating a PriorityClass object with that name. If not specified, the pod priority will be default or zero if there is no default.
* `restart_policy` - Restart policy for all containers within the pod. One of Always, OnFailure, Never. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/pod-states#restartpolicy).
* `runtime_class_name` - (Optional) RuntimeClassName is a feature for selecting the container runtime configuration. The container runtime configuration is used to run a Pod's containers. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/containers/runtime-class)
* `security_context` - (SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty
* `service_account_name` - ServiceAccountName is the name of the ServiceAccount to use to run this pod. For more info see https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/.
* `share_process_namespace` - Share a single process namespace between all of the containers in a pod. When this is set containers will be able to view and signal processes from other containers in the same pod, and the first process in each container will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both be set.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/daemon_set_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ The following arguments are supported:
* `node_selector` - (Optional) NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/node-selection).
* `priority_class_name` - (Optional) If specified, indicates the pod's priority. 'system-node-critical' and 'system-cluster-critical' are two special keywords which indicate the highest priorities with the formerer being the highest priority. Any other name must be defined by creating a PriorityClass object with that name. If not specified, the pod priority will be default or zero if there is no default.
* `restart_policy` - (Optional) Restart policy for all containers within the pod. One of Always, OnFailure, Never. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/pod-states#restartpolicy).
* `runtime_class_name` - (Optional) RuntimeClassName is a feature for selecting the container runtime configuration. The container runtime configuration is used to run a Pod's containers. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/containers/runtime-class)
* `security_context` - (Optional) SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty
* `service_account_name` - (Optional) ServiceAccountName is the name of the ServiceAccount to use to run this pod. For more info see https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/.
* `share_process_namespace` - (Optional) Share a single process namespace between all of the containers in a pod. When this is set containers will be able to view and signal processes from other containers in the same pod, and the first process in each container will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both be set.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/daemonset.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ The following arguments are supported:
* `node_selector` - (Optional) NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/node-selection).
* `priority_class_name` - (Optional) If specified, indicates the pod's priority. 'system-node-critical' and 'system-cluster-critical' are two special keywords which indicate the highest priorities with the formerer being the highest priority. Any other name must be defined by creating a PriorityClass object with that name. If not specified, the pod priority will be default or zero if there is no default.
* `restart_policy` - (Optional) Restart policy for all containers within the pod. One of Always, OnFailure, Never. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/pod-states#restartpolicy).
* `runtime_class_name` - (Optional) RuntimeClassName is a feature for selecting the container runtime configuration. The container runtime configuration is used to run a Pod's containers. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/containers/runtime-class)
* `security_context` - (Optional) SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty
* `service_account_name` - (Optional) ServiceAccountName is the name of the ServiceAccount to use to run this pod. For more info see https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/.
* `share_process_namespace` - (Optional) Share a single process namespace between all of the containers in a pod. When this is set containers will be able to view and signal processes from other containers in the same pod, and the first process in each container will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both be set.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ The following arguments are supported:
* `node_selector` - (Optional) NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/node-selection).
* `priority_class_name` - (Optional) If specified, indicates the pod's priority. 'system-node-critical' and 'system-cluster-critical' are two special keywords which indicate the highest priorities with the formerer being the highest priority. Any other name must be defined by creating a PriorityClass object with that name. If not specified, the pod priority will be default or zero if there is no default.
* `restart_policy` - (Optional) Restart policy for all containers within the pod. One of Always, OnFailure, Never. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/pod-states#restartpolicy).
* `runtime_class_name` - (Optional) RuntimeClassName is a feature for selecting the container runtime configuration. The container runtime configuration is used to run a Pod's containers. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/containers/runtime-class)
* `security_context` - (Optional) SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty
* `service_account_name` - (Optional) ServiceAccountName is the name of the ServiceAccount to use to run this pod. For more info see https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/.
* `share_process_namespace` - (Optional) Share a single process namespace between all of the containers in a pod. When this is set containers will be able to view and signal processes from other containers in the same pod, and the first process in each container will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both be set.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/deployment_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ The following arguments are supported:
* `node_selector` - (Optional) NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/node-selection).
* `priority_class_name` - (Optional) If specified, indicates the pod's priority. 'system-node-critical' and 'system-cluster-critical' are two special keywords which indicate the highest priorities with the formerer being the highest priority. Any other name must be defined by creating a PriorityClass object with that name. If not specified, the pod priority will be default or zero if there is no default.
* `restart_policy` - (Optional) Restart policy for all containers within the pod. One of Always, OnFailure, Never. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/pod-states#restartpolicy).
* `runtime_class_name` - (Optional) RuntimeClassName is a feature for selecting the container runtime configuration. The container runtime configuration is used to run a Pod's containers. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/containers/runtime-class)
* `security_context` - (Optional) SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty
* `service_account_name` - (Optional) ServiceAccountName is the name of the ServiceAccount to use to run this pod. For more info see https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/.
* `share_process_namespace` - (Optional) Share a single process namespace between all of the containers in a pod. When this is set containers will be able to view and signal processes from other containers in the same pod, and the first process in each container will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both be set.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/pod.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ The following arguments are supported:
* `node_selector` - (Optional) NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/node-selection).
* `priority_class_name` - (Optional) If specified, indicates the pod's priority. 'system-node-critical' and 'system-cluster-critical' are two special keywords which indicate the highest priorities with the formerer being the highest priority. Any other name must be defined by creating a PriorityClass object with that name. If not specified, the pod priority will be default or zero if there is no default.
* `restart_policy` - (Optional) Restart policy for all containers within the pod. One of Always, OnFailure, Never. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/pod-states#restartpolicy).
* `runtime_class_name` - (Optional) RuntimeClassName is a feature for selecting the container runtime configuration. The container runtime configuration is used to run a Pod's containers. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/containers/runtime-class)
* `security_context` - (Optional) SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty
* `service_account_name` - (Optional) ServiceAccountName is the name of the ServiceAccount to use to run this pod. For more info see https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/.
* `share_process_namespace` - (Optional) Share a single process namespace between all of the containers in a pod. When this is set containers will be able to view and signal processes from other containers in the same pod, and the first process in each container will not be assigned PID 1. HostPID and ShareProcessNamespace cannot both be set.
Expand Down
Loading