Skip to content

Commit

Permalink
Add the Hyperthreading field to MachinePool which allows the user to
Browse files Browse the repository at this point in the history
enable or disable hyperthreading for machines. The default is for
hyperthreading to be enabled.

RHCOS ships with pivot.service that uses the `/etc/pivot/kernel-args` to override the kernel arguments for hosts. Adding `nosmt` kernel argument switches hyperthreading off.

Add MachineConfig to disable hyperthreading for control plane and compute that have the hyperthreading option disabled.
  • Loading branch information
staebler authored and abhinavdahiya committed Apr 3, 2019
1 parent 3d904d3 commit 71c6f2d
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 103 deletions.
30 changes: 18 additions & 12 deletions pkg/asset/installconfig/installconfig_test.go
Expand Up @@ -76,13 +76,15 @@ func TestInstallConfigGenerate_FillsInDefaults(t *testing.T) {
},
},
ControlPlane: &types.MachinePool{
Name: "master",
Replicas: pointer.Int64Ptr(3),
Name: "master",
Replicas: pointer.Int64Ptr(3),
Hyperthreading: types.HyperthreadingEnabled,
},
Compute: []types.MachinePool{
{
Name: "worker",
Replicas: pointer.Int64Ptr(3),
Name: "worker",
Replicas: pointer.Int64Ptr(3),
Hyperthreading: types.HyperthreadingEnabled,
},
},
Platform: types.Platform{
Expand Down Expand Up @@ -135,13 +137,15 @@ pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"authorization value\"}}}"
},
},
ControlPlane: &types.MachinePool{
Name: "master",
Replicas: pointer.Int64Ptr(3),
Name: "master",
Replicas: pointer.Int64Ptr(3),
Hyperthreading: types.HyperthreadingEnabled,
},
Compute: []types.MachinePool{
{
Name: "worker",
Replicas: pointer.Int64Ptr(3),
Name: "worker",
Replicas: pointer.Int64Ptr(3),
Hyperthreading: types.HyperthreadingEnabled,
},
},
Platform: types.Platform{
Expand Down Expand Up @@ -214,13 +218,15 @@ network:
},
},
ControlPlane: &types.MachinePool{
Name: "master",
Replicas: pointer.Int64Ptr(3),
Name: "master",
Replicas: pointer.Int64Ptr(3),
Hyperthreading: types.HyperthreadingEnabled,
},
Compute: []types.MachinePool{
{
Name: "worker",
Replicas: pointer.Int64Ptr(3),
Name: "worker",
Replicas: pointer.Int64Ptr(3),
Hyperthreading: types.HyperthreadingEnabled,
},
},
Platform: types.Platform{
Expand Down
40 changes: 40 additions & 0 deletions pkg/asset/machines/machineconfig/hyperthreading.go
@@ -0,0 +1,40 @@
package machineconfig

import (
"fmt"

igntypes "github.com/coreos/ignition/config/v2_2/types"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/openshift/installer/pkg/asset/ignition"
)

// ForHyperthreadingDisabled creates the MachineConfig to disable hyperthreading.
// RHCOS ships with pivot.service that uses the `/etc/pivot/kernel-args` to override the kernel arguments for hosts.
func ForHyperthreadingDisabled(role string) *mcfgv1.MachineConfig {
return &mcfgv1.MachineConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "machineconfiguration.openshift.io/v1",
Kind: "MachineConfig",
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("99-%s-disable-hyperthreading", role),
Labels: map[string]string{
"machineconfiguration.openshift.io/role": role,
},
},
Spec: mcfgv1.MachineConfigSpec{
Config: igntypes.Config{
Ignition: igntypes.Ignition{
Version: igntypes.MaxVersion.String(),
},
Storage: igntypes.Storage{
Files: []igntypes.File{
ignition.FileFromString("/etc/pivot/kernel-args", "root", 0600, "ADD nosmt"),
},
},
},
},
}
}
22 changes: 14 additions & 8 deletions pkg/asset/machines/master.go
Expand Up @@ -9,6 +9,15 @@ import (
libvirtapi "github.com/openshift/cluster-api-provider-libvirt/pkg/apis"
libvirtprovider "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1alpha1"
machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
awsapi "sigs.k8s.io/cluster-api-provider-aws/pkg/apis"
awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1"
openstackapi "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis"
openstackprovider "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/ignition/machine"
"github.com/openshift/installer/pkg/asset/installconfig"
Expand All @@ -17,20 +26,13 @@ import (
"github.com/openshift/installer/pkg/asset/machines/machineconfig"
"github.com/openshift/installer/pkg/asset/machines/openstack"
"github.com/openshift/installer/pkg/asset/rhcos"
"github.com/openshift/installer/pkg/types"
awstypes "github.com/openshift/installer/pkg/types/aws"
awsdefaults "github.com/openshift/installer/pkg/types/aws/defaults"
libvirttypes "github.com/openshift/installer/pkg/types/libvirt"
nonetypes "github.com/openshift/installer/pkg/types/none"
openstacktypes "github.com/openshift/installer/pkg/types/openstack"
vspheretypes "github.com/openshift/installer/pkg/types/vsphere"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
awsapi "sigs.k8s.io/cluster-api-provider-aws/pkg/apis"
awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1"
openstackapi "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis"
openstackprovider "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1"
)

// Master generates the machines for the `master` machine pool.
Expand Down Expand Up @@ -91,6 +93,7 @@ func (m *Master) Generate(dependencies asset.Parents) error {
dependencies.Get(clusterID, installconfig, rhcosImage, mign)

ic := installconfig.Config

pool := ic.ControlPlane
var err error
machines := []machineapi.Machine{}
Expand Down Expand Up @@ -150,6 +153,9 @@ func (m *Master) Generate(dependencies asset.Parents) error {
}

machineConfigs := []*mcfgv1.MachineConfig{}
if pool.Hyperthreading == types.HyperthreadingDisabled {
machineConfigs = append(machineConfigs, machineconfig.ForHyperthreadingDisabled("master"))
}
if ic.SSHKey != "" {
machineConfigs = append(machineConfigs, machineconfig.ForAuthorizedKeys(ic.SSHKey, "master"))
}
Expand Down
108 changes: 104 additions & 4 deletions pkg/asset/machines/master_test.go
Expand Up @@ -19,17 +19,116 @@ func TestMasterGenerateMachineConfigs(t *testing.T) {
cases := []struct {
name string
key string
hyperthreading types.HyperthreadingMode
expectedMachineConfig string
}{
{
name: "no key",
name: "no key hyperthreading enabled",
hyperthreading: types.HyperthreadingEnabled,
},
{
name: "key present",
key: "ssh-rsa: dummy-key",
name: "key present hyperthreading enabled",
key: "ssh-rsa: dummy-key",
hyperthreading: types.HyperthreadingEnabled,
expectedMachineConfig: `---
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
creationTimestamp: null
labels:
machineconfiguration.openshift.io/role: master
name: 99-master-ssh
spec:
config:
ignition:
config: {}
security:
tls: {}
timeouts: {}
version: 2.2.0
networkd: {}
passwd:
users:
- name: core
sshAuthorizedKeys:
- 'ssh-rsa: dummy-key'
storage: {}
systemd: {}
osImageURL: ""
`,
},
{
name: "no key hyperthreading disabled",
hyperthreading: types.HyperthreadingDisabled,
expectedMachineConfig: `---
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
creationTimestamp: null
labels:
machineconfiguration.openshift.io/role: master
name: 99-master-disable-hyperthreading
spec:
config:
ignition:
config: {}
security:
tls: {}
timeouts: {}
version: 2.2.0
networkd: {}
passwd: {}
storage:
files:
- contents:
source: data:text/plain;charset=utf-8;base64,QUREIG5vc210
verification: {}
filesystem: root
mode: 384
path: /etc/pivot/kernel-args
user:
name: root
systemd: {}
osImageURL: ""
`,
},
{
name: "key present hyperthreading disabled",
key: "ssh-rsa: dummy-key",
hyperthreading: types.HyperthreadingDisabled,
expectedMachineConfig: `---
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
creationTimestamp: null
labels:
machineconfiguration.openshift.io/role: master
name: 99-master-disable-hyperthreading
spec:
config:
ignition:
config: {}
security:
tls: {}
timeouts: {}
version: 2.2.0
networkd: {}
passwd: {}
storage:
files:
- contents:
source: data:text/plain;charset=utf-8;base64,QUREIG5vc210
verification: {}
filesystem: root
mode: 384
path: /etc/pivot/kernel-args
user:
name: root
systemd: {}
osImageURL: ""
---
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
creationTimestamp: null
labels:
Expand Down Expand Up @@ -76,7 +175,8 @@ spec:
},
},
ControlPlane: &types.MachinePool{
Replicas: pointer.Int64Ptr(1),
Hyperthreading: tc.hyperthreading,
Replicas: pointer.Int64Ptr(1),
Platform: types.MachinePoolPlatform{
AWS: &awstypes.MachinePool{
Zones: []string{"us-east-1a"},
Expand Down
7 changes: 6 additions & 1 deletion pkg/asset/machines/worker.go
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/openshift/installer/pkg/asset/machines/machineconfig"
"github.com/openshift/installer/pkg/asset/machines/openstack"
"github.com/openshift/installer/pkg/asset/rhcos"
"github.com/openshift/installer/pkg/types"
awstypes "github.com/openshift/installer/pkg/types/aws"
awsdefaults "github.com/openshift/installer/pkg/types/aws/defaults"
libvirttypes "github.com/openshift/installer/pkg/types/libvirt"
Expand Down Expand Up @@ -110,11 +111,16 @@ func (w *Worker) Generate(dependencies asset.Parents) error {

machineConfigs := []*mcfgv1.MachineConfig{}
machineSets := []runtime.Object{}
var err error
ic := installconfig.Config
for _, pool := range ic.Compute {
if pool.Hyperthreading == types.HyperthreadingDisabled {
machineConfigs = append(machineConfigs, machineconfig.ForHyperthreadingDisabled("worker"))
}
if ic.SSHKey != "" {
machineConfigs = append(machineConfigs, machineconfig.ForAuthorizedKeys(ic.SSHKey, "worker"))
}

switch ic.Platform.Name() {
case awstypes.Name:
mpool := defaultAWSMachinePoolPlatform()
Expand Down Expand Up @@ -196,7 +202,6 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
Data: data,
}
}

return nil
}

Expand Down

0 comments on commit 71c6f2d

Please sign in to comment.