@@ -37,6 +37,7 @@ import (
3737 machineconfigv1 "github.com/openshift/api/machineconfiguration/v1"
3838 performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
3939 "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator"
40+ "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator/autosize"
4041 "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator/cmd/hypershift"
4142 "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator/serialize"
4243 "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/profilecreator/toleration"
@@ -116,10 +117,10 @@ func NewRootCommand() *cobra.Command {
116117 pcArgs := & ProfileCreatorArgs {
117118 UserLevelNetworking : ptr .To (false ),
118119 PerPodPowerManagement : ptr .To (false ),
120+ Autosize : ptr .To (false ),
119121 }
120122
121123 var requiredFlags = []string {
122- "reserved-cpu-count" ,
123124 "rt-kernel" ,
124125 "must-gather-dir-path" ,
125126 }
@@ -164,10 +165,26 @@ func NewRootCommand() *cobra.Command {
164165 if err != nil {
165166 return fmt .Errorf ("targeted nodes differ: %w" , err )
166167 }
168+
169+ sizing := autosize.Values {
170+ ReservedCPUCount : pcArgs .ReservedCPUCount ,
171+ }
172+ if isAutosizeEnabled (pcArgs ) {
173+ params := autosize.Params {
174+ OfflinedCPUCount : pcArgs .OfflinedCPUCount ,
175+ UserLevelNetworking : (pcArgs .UserLevelNetworking != nil && * pcArgs .UserLevelNetworking ),
176+ MachineData : nodesHandlers [0 ], // assume all nodes equal, pick the easiest
177+ }
178+ sizing , _ , err = autosize .Compute (autosize .DefaultEnv (), params )
179+ if err != nil {
180+ return fmt .Errorf ("failed to autosize the cluster values: %v" , err )
181+ }
182+ }
183+
167184 // We make sure that the matched Nodes are the same
168185 // Assumption here is moving forward matchedNodes[0] is representative of how all the nodes are
169186 // same from hardware topology point of view
170- profileData , err := makeProfileDataFrom (nodesHandlers [0 ], pcArgs )
187+ profileData , err := makeProfileDataFrom (nodesHandlers [0 ], pcArgs , sizing )
171188 if err != nil {
172189 return fmt .Errorf ("failed to make profile data from node handler: %w" , err )
173190 }
@@ -218,6 +235,9 @@ func validateProfileCreatorFlags(pcArgs *ProfileCreatorArgs) error {
218235 if pcArgs .MCPName != "" && pcArgs .NodePoolName != "" {
219236 return fmt .Errorf ("--mcp-name and --node-pool-name options cannot be used together" )
220237 }
238+ if ! isAutosizeEnabled (pcArgs ) && pcArgs .ReservedCPUCount == 0 {
239+ return fmt .Errorf ("--reserved-cpu-count need to be set and greater than zero if autosizing (--autosize) is disabled" )
240+ }
221241 if pcArgs .NodePoolName == "" {
222242 // NodePoolName is an alias of MCPName
223243 pcArgs .NodePoolName = pcArgs .MCPName
@@ -299,12 +319,13 @@ func makeClusterData(mustGatherDirPath string, createForHypershift bool) (Cluste
299319 return clusterData , nil
300320}
301321
302- func makeProfileDataFrom (nodeHandler * profilecreator.GHWHandler , args * ProfileCreatorArgs ) (* ProfileData , error ) {
322+ func makeProfileDataFrom (nodeHandler * profilecreator.GHWHandler , args * ProfileCreatorArgs , sizing autosize. Values ) (* ProfileData , error ) {
303323 systemInfo , err := nodeHandler .GatherSystemInfo ()
304324 if err != nil {
305325 return nil , fmt .Errorf ("failed to compute get system information: %v" , err )
306326 }
307- reservedCPUs , isolatedCPUs , offlinedCPUs , err := profilecreator .CalculateCPUSets (systemInfo , args .ReservedCPUCount , args .OfflinedCPUCount , args .SplitReservedCPUsAcrossNUMA , args .DisableHT , args .PowerConsumptionMode == ultraLowLatency )
327+
328+ reservedCPUs , isolatedCPUs , offlinedCPUs , err := profilecreator .CalculateCPUSets (systemInfo , sizing .ReservedCPUCount , args .OfflinedCPUCount , args .SplitReservedCPUsAcrossNUMA , args .DisableHT , args .PowerConsumptionMode == ultraLowLatency )
308329 if err != nil {
309330 return nil , fmt .Errorf ("failed to compute the reserved and isolated CPUs: %v" , err )
310331 }
@@ -407,13 +428,14 @@ type ProfileCreatorArgs struct {
407428 TMPolicy string `json:"topology-manager-policy"`
408429 PerPodPowerManagement * bool `json:"per-pod-power-management,omitempty"`
409430 EnableHardwareTuning bool `json:"enable-hardware-tuning,omitempty"`
431+ Autosize * bool `json:"autosize,omitempty"`
410432 // internal only this argument not passed by the user
411433 // but detected automatically
412434 createForHypershift bool
413435}
414436
415437func (pca * ProfileCreatorArgs ) AddFlags (flags * pflag.FlagSet ) {
416- flags .IntVar (& pca .ReservedCPUCount , "reserved-cpu-count" , 0 , "Number of reserved CPUs (required) " )
438+ flags .IntVar (& pca .ReservedCPUCount , "reserved-cpu-count" , 0 , "Number of reserved CPUs" )
417439 flags .IntVar (& pca .OfflinedCPUCount , "offlined-cpu-count" , 0 , "Number of offlined CPUs" )
418440 flags .BoolVar (& pca .SplitReservedCPUsAcrossNUMA , "split-reserved-cpus-across-numa" , false , "Split the Reserved CPUs across NUMA nodes" )
419441 flags .StringVar (& pca .MCPName , "mcp-name" , "" , "MCP name corresponding to the target machines (required)" )
@@ -427,6 +449,7 @@ func (pca *ProfileCreatorArgs) AddFlags(flags *pflag.FlagSet) {
427449 flags .BoolVar (pca .PerPodPowerManagement , "per-pod-power-management" , false , "Enable Per Pod Power Management" )
428450 flags .BoolVar (& pca .EnableHardwareTuning , "enable-hardware-tuning" , false , "Enable setting maximum cpu frequencies" )
429451 flags .StringVar (& pca .NodePoolName , "node-pool-name" , "" , "Node pool name corresponding to the target machines (HyperShift only)" )
452+ flags .BoolVar (pca .Autosize , "autosize" , false , "autosize the control plane" )
430453}
431454
432455func makePerformanceProfileFrom (profileData ProfileData ) (runtime.Object , error ) {
@@ -578,3 +601,7 @@ func setSelectorsFor(profileData *ProfileData, args *ProfileCreatorArgs) error {
578601 profileData .mcpSelector = mcpSelector
579602 return nil
580603}
604+
605+ func isAutosizeEnabled (pcArgs * ProfileCreatorArgs ) bool {
606+ return pcArgs .Autosize != nil && * pcArgs .Autosize
607+ }
0 commit comments