Skip to content

Commit 66704a2

Browse files
authored
feat: update hub-agent to use custom cluster affinity plugin in scheduler when property checker is enabled (#1221)
2 parents 59944d4 + 0e92d1a commit 66704a2

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
//Copyright (c) Microsoft Corporation.
3+
//Licensed under the MIT license.
4+
5+
package options
6+
7+
import (
8+
"flag"
9+
)
10+
11+
// AzurePropertyCheckerOptions holds the options for the Azure property checker.
12+
type AzurePropertyCheckerOptions struct {
13+
// IsEnabled indicates whether the Azure property checker is enabled.
14+
IsEnabled bool
15+
// ComputeServiceAddressWithBasePath is the address of the Azure compute service with base path.
16+
ComputeServiceAddressWithBasePath string
17+
}
18+
19+
// NewAzurePropertyCheckerOptions creates a new AzurePropertyCheckerOptions with default values.
20+
func NewAzurePropertyCheckerOptions() AzurePropertyCheckerOptions {
21+
return AzurePropertyCheckerOptions{
22+
IsEnabled: false,
23+
ComputeServiceAddressWithBasePath: "http://localhost:8421/compute",
24+
}
25+
}
26+
27+
// AddFlags adds flags for Azure Property Checker options to the given FlagSet.
28+
func (o AzurePropertyCheckerOptions) AddFlags(flags *flag.FlagSet) {
29+
flags.BoolVar(&o.IsEnabled, "azure-property-checker-enabled", o.IsEnabled, "Enable Azure property checker for validating Azure-specific cluster properties.")
30+
flags.StringVar(&o.ComputeServiceAddressWithBasePath, "azure-compute-server-address", o.ComputeServiceAddressWithBasePath, "The address of the Azure compute service with base path.")
31+
}

cmd/hubagent/options/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ type Options struct {
112112
ResourceSnapshotCreationMinimumInterval time.Duration
113113
// ResourceChangesCollectionDuration is the duration for collecting resource changes into one snapshot.
114114
ResourceChangesCollectionDuration time.Duration
115+
// AzurePropertyCheckerOpts contains options for Azure property checker
116+
AzurePropertyCheckerOpts AzurePropertyCheckerOptions
115117
}
116118

117119
// NewOptions builds an empty options.
@@ -134,6 +136,7 @@ func NewOptions() *Options {
134136
PprofPort: 6065,
135137
ResourceSnapshotCreationMinimumInterval: 30 * time.Second,
136138
ResourceChangesCollectionDuration: 15 * time.Second,
139+
AzurePropertyCheckerOpts: NewAzurePropertyCheckerOptions(),
137140
}
138141
}
139142

@@ -185,4 +188,5 @@ func (o *Options) AddFlags(flags *flag.FlagSet) {
185188
flags.DurationVar(&o.ResourceChangesCollectionDuration, "resource-changes-collection-duration", 15*time.Second,
186189
"The duration for collecting resource changes into one snapshot. The default is 15 seconds, which means that the controller will collect resource changes for 15 seconds before creating a resource snapshot.")
187190
o.RateLimiterOpts.AddFlags(flags)
191+
o.AzurePropertyCheckerOpts.AddFlags(flags)
188192
}

cmd/hubagent/workload/setup.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
clusterv1beta1 "go.goms.io/fleet/apis/cluster/v1beta1"
3434
placementv1beta1 "go.goms.io/fleet/apis/placement/v1beta1"
3535
"go.goms.io/fleet/cmd/hubagent/options"
36+
"go.goms.io/fleet/pkg/clients/azure/compute"
37+
"go.goms.io/fleet/pkg/clients/httputil"
3638
"go.goms.io/fleet/pkg/controllers/bindingwatcher"
3739
"go.goms.io/fleet/pkg/controllers/clusterinventory/clusterprofile"
3840
"go.goms.io/fleet/pkg/controllers/clusterresourceplacementeviction"
@@ -45,10 +47,12 @@ import (
4547
"go.goms.io/fleet/pkg/controllers/schedulingpolicysnapshot"
4648
"go.goms.io/fleet/pkg/controllers/updaterun"
4749
"go.goms.io/fleet/pkg/controllers/workgenerator"
50+
"go.goms.io/fleet/pkg/propertychecker/azure"
4851
"go.goms.io/fleet/pkg/resourcewatcher"
4952
"go.goms.io/fleet/pkg/scheduler"
5053
"go.goms.io/fleet/pkg/scheduler/clustereligibilitychecker"
5154
"go.goms.io/fleet/pkg/scheduler/framework"
55+
"go.goms.io/fleet/pkg/scheduler/framework/plugins/clusteraffinity"
5256
"go.goms.io/fleet/pkg/scheduler/profile"
5357
"go.goms.io/fleet/pkg/scheduler/queue"
5458
schedulerbindingwatcher "go.goms.io/fleet/pkg/scheduler/watchers/binding"
@@ -354,8 +358,22 @@ func SetupControllers(ctx context.Context, wg *sync.WaitGroup, mgr ctrl.Manager,
354358

355359
// Set up the scheduler
356360
klog.Info("Setting up scheduler")
357-
defaultProfile := profile.NewDefaultProfile()
358-
defaultFramework := framework.NewFramework(defaultProfile, mgr)
361+
schedulerProfile := profile.NewDefaultProfile()
362+
if opts.AzurePropertyCheckerOpts.IsEnabled {
363+
klog.Info("Azure property checker is enabled for cluster property validation")
364+
client, err := compute.NewAttributeBasedVMSizeRecommenderClient(opts.AzurePropertyCheckerOpts.ComputeServiceAddressWithBasePath, httputil.DefaultClientForAzure)
365+
if err != nil {
366+
klog.ErrorS(err, "Unable to create Azure vm size recommender client")
367+
return err
368+
}
369+
klog.Info("Setting up cluster affinity plugin with Azure property checker")
370+
clusterAffinityPlugin := clusteraffinity.New(clusteraffinity.WithPropertyChecker(azure.NewPropertyChecker(*client)))
371+
profileOpts := profile.Options{
372+
ClusterAffinityPlugin: &clusterAffinityPlugin,
373+
}
374+
schedulerProfile = profile.NewProfile(profileOpts)
375+
}
376+
defaultFramework := framework.NewFramework(schedulerProfile, mgr)
359377
defaultSchedulingQueue := queue.NewSimplePlacementSchedulingQueue(
360378
queue.WithName(schedulerQueueName),
361379
)

0 commit comments

Comments
 (0)