Skip to content

Commit 6f94158

Browse files
committed
add deployment changes to include property checker in hub agent
Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
1 parent 59944d4 commit 6f94158

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

charts/hub-agent/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ spec:
5353
- --cluster-unhealthy-threshold={{ .Values.clusterUnhealthyThreshold }}
5454
- --resource-snapshot-creation-minimum-interval={{ .Values.resourceSnapshotCreationMinimumInterval }}
5555
- --resource-changes-collection-duration={{ .Values.resourceChangesCollectionDuration }}
56+
- --azure-property-checker-enabled={{ .Values.azurePropertyChecker.isEnabled }}
57+
{{- if .Values.azurePropertyChecker.isEnabled }}
58+
- --azure-property-checker-config-file={{ .Values.azurePropertyChecker.computeServiceAddressWithBasePath }}
59+
{{- end }}
5660
ports:
5761
- name: metrics
5862
containerPort: 8080

charts/hub-agent/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ hubAPIBurst: 1000
5858
MaxConcurrentClusterPlacement: 100
5959
ConcurrentResourceChangeSyncs: 20
6060
MaxFleetSizeSupported: 100
61+
62+
azurePropertyChecker:
63+
isEnabled: false
64+
computeServiceAddressWithBasePath: "http://localhost:8421/compute"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}
32+
33+
// IsEnabled returns whether the Azure property checker is enabled.
34+
func (o *AzurePropertyCheckerOptions) IsEnabled() bool {
35+
return o.isEnabled
36+
}
37+
38+
// ComputeServiceAddressWithBasePath returns the address of the Azure compute service with base path.
39+
func (o *AzurePropertyCheckerOptions) ComputeServiceAddressWithBasePath() string {
40+
return o.computeServiceAddressWithBasePath
41+
}

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+
// AzurePropertyCheckerOptions contains options for Azure property checker
116+
AzurePropertyCheckerOptions *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+
AzurePropertyCheckerOptions: 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.AzurePropertyCheckerOptions.AddFlags(flags)
188192
}

cmd/hubagent/workload/setup.go

Lines changed: 18 additions & 0 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"
@@ -355,6 +359,20 @@ func SetupControllers(ctx context.Context, wg *sync.WaitGroup, mgr ctrl.Manager,
355359
// Set up the scheduler
356360
klog.Info("Setting up scheduler")
357361
defaultProfile := profile.NewDefaultProfile()
362+
if opts.AzurePropertyCheckerOptions.IsEnabled() {
363+
klog.Info("Azure property checker is enabled for cluster property validation")
364+
client, err := compute.NewAttributeBasedVMSizeRecommenderClient(opts.AzurePropertyCheckerOptions.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+
defaultProfile = profile.NewProfile(profileOpts)
375+
}
358376
defaultFramework := framework.NewFramework(defaultProfile, mgr)
359377
defaultSchedulingQueue := queue.NewSimplePlacementSchedulingQueue(
360378
queue.WithName(schedulerQueueName),

pkg/scheduler/framework/plugins/clusteraffinity/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type clusterAffinityPluginOptions struct {
6666
type Option func(*clusterAffinityPluginOptions)
6767

6868
var defaultPluginOptions = clusterAffinityPluginOptions{
69-
name: "ClusterAffinity",
69+
name: "ClusterAffinity",
7070
}
7171

7272
// WithName sets the name of the plugin.

0 commit comments

Comments
 (0)