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

feat: support generating cpu partitioning file from infra flag #3335

Closed
Closed
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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed on slack, but to clarify, if this only applies to bootstrap, if the MC does get generated, the install will fail due to a mismatch of configs generated by bootstrap and regular, causing a "can't find rendered-master-xxx" when the install happens. Basically #2114

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @yuqi-zhang , was looking through the code a bit, trying to understand this a little better. Does this mean that it's not possible to have a MC generated and maintain by MCO during bootstrap?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it is possible. You must have both the bootstrap and the "in-cluster" flow generate the same configs.

As an example, see this: #3015

which adds both for nodes.config.openshift.io objects

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.