Skip to content

Commit

Permalink
feat: support generating cpu partitioning file from infra flag
Browse files Browse the repository at this point in the history
Signed-off-by: ehila <ehila@redhat.com>
  • Loading branch information
eggfoobar committed Sep 14, 2022
1 parent 8276d9c commit 0bd1a77
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/controller/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (b *Bootstrap) Run(destDir string) error {
var cconfig *mcfgv1.ControllerConfig
var featureGate *apicfgv1.FeatureGate
var nodeConfig *apicfgv1.Node
var infraConfig *apicfgv1.Infrastructure
var kconfigs []*mcfgv1.KubeletConfig
var pools []*mcfgv1.MachineConfigPool
var configs []*mcfgv1.MachineConfig
Expand Down Expand Up @@ -131,6 +132,10 @@ func (b *Bootstrap) Run(destDir string) error {
if obj.GetName() == ctrlcommon.ClusterNodeInstanceName {
nodeConfig = obj
}
case *apicfgv1.Infrastructure:
if obj.GetName() == ctrlcommon.ClusterInfrastructureInstanceName {
infraConfig = obj
}
default:
glog.Infof("skipping %q [%d] manifest because of unhandled %T", file.Name(), idx+1, obji)
}
Expand Down Expand Up @@ -183,6 +188,14 @@ func (b *Bootstrap) Run(destDir string) error {
configs = append(configs, kconfigs...)
}

if infraConfig.Status.CPUPartitioning != apicfgv1.CPUPartitioningNone {
cpuPartMCs, err := kubeletconfig.GenerateCPUPartitioningMC()
if err != nil {
return err
}
configs = append(configs, cpuPartMCs...)
}

fpools, gconfigs, err := render.RunBootstrap(pools, configs, cconfig)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const (
// ClusterNodeInstanceName is a singleton name for node configuration
ClusterNodeInstanceName = "cluster"

// ClusterInfrastructureInstanceName is a singleton name for infrastructure configuration
ClusterInfrastructureInstanceName = "cluster"

// MachineConfigPoolMaster is the MachineConfigPool name given to the master
MachineConfigPoolMaster = "master"
// MachineConfigPoolWorker is the MachineConfigPool name given to the worker
Expand Down
56 changes: 56 additions & 0 deletions pkg/controller/kubelet-config/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,59 @@ func generateKubeletIgnFiles(kubeletConfig *mcfgv1.KubeletConfig, originalKubeCo

return kubeletIgnition, logLevelIgnition, autoSizingReservedIgnition, nil
}

func cpuPartitionMC(role string, ignitionConfig ign3types.Config) (*mcfgv1.MachineConfig, error) {
rawIgnition, err := json.Marshal(ignitionConfig)
if err != nil {
return nil, err
}

mc := &mcfgv1.MachineConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: mcfgv1.GroupVersion.String(),
Kind: "MachineConfig",
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("01-%s-cpu-partitioning", role),
Labels: map[string]string{
"machineconfiguration.openshift.io/role": role,
},
},
Spec: mcfgv1.MachineConfigSpec{},
}
mc.Spec.Config = runtime.RawExtension{Raw: rawIgnition}
return mc, nil
}

func GenerateCPUPartitioningMC() (mc []*mcfgv1.MachineConfig, err error) {
mode := 420
source := "data:text/plain;charset=utf-8;base64,ewogICJtYW5hZ2VtZW50IjogewogICAgImNwdXNldCI6ICIiCiAgfQp9Cg=="
ignitionConfig := ign3types.Config{
Ignition: ign3types.Ignition{
Version: ign3types.MaxVersion.String(),
},
Storage: ign3types.Storage{
Files: []ign3types.File{{
Node: ign3types.Node{
Path: "/etc/kubernetes/openshift-workload-pinning",
},
FileEmbedded1: ign3types.FileEmbedded1{
Contents: ign3types.Resource{
Source: &source,
},
Mode: &mode,
},
}},
},
}
masterMC, err := cpuPartitionMC("master", ignitionConfig)
if err != nil {
return nil, err
}
workerMC, err := cpuPartitionMC("worker", ignitionConfig)
if err != nil {
return nil, err
}
mc = append(mc, masterMC, workerMC)
return
}

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

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

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

0 comments on commit 0bd1a77

Please sign in to comment.