Skip to content

OCPNODE-3372: Update defaultRuntime doc to show options and set default to crun #2370

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
name: "ContainerRuntimeConfig"
crdName: containerruntimeconfigs.machineconfiguration.openshift.io
tests:
onCreate:
- name: Should fail if set to empty string
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: ""
expectedError: "spec.containerRuntimeConfig.defaultRuntime: Unsupported value: \"\": supported values: \"crun\", \"runc\""
- name: Should not fail if not set and other fields set
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
logLevel: info
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should defaultRuntime be set to the empty string value here?

Copy link
Author

Choose a reason for hiding this comment

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

@everettraven I've reverted the omitempty removal and kept defaultRuntime as a non-pointer type.

My reasoning is:

  • MCO handles both unset and empty string values for defaultRuntime as a default to crun.
  • Changing it to a pointer would require extensive code changes. May be across MCO and API repos.
  • Keeping omitempty ensures the field is omitted when unset, avoiding a confusing empty string for users.
  • If a user explicitly sets it to an empty string, it will be included in the manifest, which is acceptable as MCO handles it.

Copy link
Contributor

Choose a reason for hiding this comment

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

MCO handles both unset and empty string values for defaultRuntime as a default to crun.

Without a pointer, MCO cannot tell the difference between unset and the empty string.

Does the empty string mean anything to crun?

Keeping omitempty ensures the field is omitted when unset, avoiding a confusing empty string for users.

This is called discoverability in our APIs. When a controller generates a configuration API object, we try to generate a complete set of fields so that a user can easily see from the object, where there are options they may not have known about (they can discover the new options).

If a user explicitly sets it to an empty string, it will be included in the manifest, which is acceptable as MCO handles it.

But it won't round trip. As soon as a structured client writes the object, the field will be removed from etcd and future reads will not render the "" value. This means that an unstructured apply would never reach a stable state when the controller is responding to the writes from the unstructured client.

Either remove omitempty, or remove "" from the enum of valid values. Removing an enum value is a breaking change btw, so if this is already shipped and the enum already allows "", you should remove omitempty as this is the least breaking change.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @JoelSpeed . I have removed omitempty and updated test cases.

Copy link
Author

Choose a reason for hiding this comment

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

@JoelSpeed can you review? Happy to address any comments you have

Copy link
Contributor

Choose a reason for hiding this comment

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

These are unstructured calls, unless there's an explicit default, I wouldn't expect the defaultRuntime to be added as part of this test

logLevel: info
- name: Should fail if set to a number
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: 1234
expectedError: "spec.containerRuntimeConfig.defaultRuntime: Invalid value: \"integer\": spec.containerRuntimeConfig.defaultRuntime in body must be of type string: \"integer\", spec.containerRuntimeConfig.defaultRuntime: Unsupported value: 1234: supported values: \"crun\", \"runc\""
- name: Should fail if set to a blank string
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: " "
expectedError: "Unsupported value: \" \": supported values: \"crun\", \"runc\""
- name: Should fail if invalid ContainerRuntimeConfig is provided
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: docker
expectedError: "Unsupported value: \"docker\": supported values: \"crun\", \"runc\""
- name: Should be able to set crun in ContainerRuntimeConfig
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: crun
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: crun
- name: Should be able to set runc in ContainerRuntimeConfig with other params
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: runc
logLevel: info
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: runc
logLevel: info
onUpdate:
- name: Case 1 - Change another field - Should be able to update other parameters with invalid defaultRuntime
initialCRDPatches:
- op: remove
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/containerRuntimeConfig/properties/defaultRuntime/enum
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the enum on thius one, "" is a valid choice no?

initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: docker
logLevel: fatal
updated: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: docker
logLevel: info
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: docker
logLevel: info
- name: Case 2 - Remove the field - Should be able to update from invalid to removed
initialCRDPatches:
- op: remove
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/containerRuntimeConfig/properties/defaultRuntime/enum
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the enum on this one? runc is a valid choice no?

initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: docker
updated: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig: {}
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig: {}
- name: Case 3 - Update the field - Should be able to update from invalid to correct value
initialCRDPatches:
- op: remove
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/containerRuntimeConfig/properties/defaultRuntime/enum
initial: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: docker
updated: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: runc
expected: |
apiVersion: machineconfiguration.openshift.io/v1
kind: ContainerRuntimeConfig
spec:
containerRuntimeConfig:
defaultRuntime: runc
11 changes: 9 additions & 2 deletions machineconfiguration/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,18 +844,25 @@ type ContainerRuntimeConfiguration struct {
// +optional
OverlaySize *resource.Quantity `json:"overlaySize,omitempty"`

// defaultRuntime is the name of the OCI runtime to be used as the default.
// defaultRuntime is the name of the OCI runtime to be used as the default for containers.
// Allowed values are `runc` and `crun`.
// When set to `runc`, OpenShift will use runc to execute the container
// When set to `crun`, OpenShift will use crun to execute the container
// When omitted, this means no opinion and the platform is left to choose a reasonable default,
// which is subject to change over time. Currently, the default is `crun`.
// +kubebuilder:validation:Enum=crun;runc
// +optional
DefaultRuntime ContainerRuntimeDefaultRuntime `json:"defaultRuntime,omitempty"`
}

type ContainerRuntimeDefaultRuntime string

// These constants are used in the Machine Config Operator (MCO)
const (
ContainerRuntimeDefaultRuntimeEmpty = ""
ContainerRuntimeDefaultRuntimeRunc = "runc"
ContainerRuntimeDefaultRuntimeCrun = "crun"
ContainerRuntimeDefaultRuntimeDefault = ContainerRuntimeDefaultRuntimeRunc
ContainerRuntimeDefaultRuntimeDefault = ContainerRuntimeDefaultRuntimeCrun
)

// ContainerRuntimeConfigStatus defines the observed state of a ContainerRuntimeConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ spec:
runtime.
properties:
defaultRuntime:
description: defaultRuntime is the name of the OCI runtime to
be used as the default.
description: |-
defaultRuntime is the name of the OCI runtime to be used as the default for containers.
Allowed values are `runc` and `crun`.
When set to `runc`, OpenShift will use runc to execute the container
When set to `crun`, OpenShift will use crun to execute the container
When omitted, this means no opinion and the platform is left to choose a reasonable default,
which is subject to change over time. Currently, the default is `crun`.
enum:
- crun
- runc
type: string
logLevel:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ spec:
runtime.
properties:
defaultRuntime:
description: defaultRuntime is the name of the OCI runtime to
be used as the default.
description: |-
defaultRuntime is the name of the OCI runtime to be used as the default for containers.
Allowed values are `runc` and `crun`.
When set to `runc`, OpenShift will use runc to execute the container
When set to `crun`, OpenShift will use crun to execute the container
When omitted, this means no opinion and the platform is left to choose a reasonable default,
which is subject to change over time. Currently, the default is `crun`.
enum:
- crun
- runc
type: string
logLevel:
description: |-
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ spec:
runtime.
properties:
defaultRuntime:
description: defaultRuntime is the name of the OCI runtime to
be used as the default.
description: |-
defaultRuntime is the name of the OCI runtime to be used as the default for containers.
Allowed values are `runc` and `crun`.
When set to `runc`, OpenShift will use runc to execute the container
When set to `crun`, OpenShift will use crun to execute the container
When omitted, this means no opinion and the platform is left to choose a reasonable default,
which is subject to change over time. Currently, the default is `crun`.
enum:
- crun
- runc
type: string
logLevel:
description: |-
Expand Down