diff --git a/manifests/klusterlet/management/klusterlet-agent-deployment.yaml b/manifests/klusterlet/management/klusterlet-agent-deployment.yaml index aca23aabd..fdf29b37b 100644 --- a/manifests/klusterlet/management/klusterlet-agent-deployment.yaml +++ b/manifests/klusterlet/management/klusterlet-agent-deployment.yaml @@ -142,6 +142,9 @@ spec: resources: {{ .ResourceRequirements | indent 10 }} {{- end }} + {{- if .PriorityClassName }} + priorityClassName: "{{ .PriorityClassName }}" + {{- end }} volumes: - name: bootstrap-secret secret: diff --git a/manifests/klusterlet/management/klusterlet-registration-deployment.yaml b/manifests/klusterlet/management/klusterlet-registration-deployment.yaml index 22c711b8e..80620b16b 100644 --- a/manifests/klusterlet/management/klusterlet-registration-deployment.yaml +++ b/manifests/klusterlet/management/klusterlet-registration-deployment.yaml @@ -133,6 +133,9 @@ spec: resources: {{ .ResourceRequirements | indent 10 }} {{- end }} + {{- if .PriorityClassName }} + priorityClassName: "{{ .PriorityClassName }}" + {{- end }} volumes: - name: bootstrap-secret secret: diff --git a/manifests/klusterlet/management/klusterlet-work-deployment.yaml b/manifests/klusterlet/management/klusterlet-work-deployment.yaml index 73692a250..042c836fc 100644 --- a/manifests/klusterlet/management/klusterlet-work-deployment.yaml +++ b/manifests/klusterlet/management/klusterlet-work-deployment.yaml @@ -126,6 +126,9 @@ spec: resources: {{ .ResourceRequirements | indent 10 }} {{- end }} + {{- if .PriorityClassName }} + priorityClassName: "{{ .PriorityClassName }}" + {{- end }} volumes: - name: hub-kubeconfig-secret secret: diff --git a/pkg/cmd/spoke/operator.go b/pkg/cmd/spoke/operator.go index bc0d128aa..70a4bece4 100644 --- a/pkg/cmd/spoke/operator.go +++ b/pkg/cmd/spoke/operator.go @@ -34,6 +34,7 @@ func NewKlusterletOperatorCmd() *cobra.Command { cmd.Flags().BoolVar(&klOptions.SkipPlaceholderHubSecret, "skip-placeholder-hub-secret", false, "If set, will skip ensuring a placeholder hub secret which is originally intended for pulling "+ "work image before approved") + cmd.Flags().StringVar(&klOptions.AgentPriorityClassName, "agent-priority-class", "", "PriorityClass name of the klusterlet agents.") opts.AddFlags(flags) return cmd diff --git a/pkg/operator/operators/klusterlet/controllers/klusterletcontroller/klusterlet_controller.go b/pkg/operator/operators/klusterlet/controllers/klusterletcontroller/klusterlet_controller.go index 982638eb0..618e3639b 100644 --- a/pkg/operator/operators/klusterlet/controllers/klusterletcontroller/klusterlet_controller.go +++ b/pkg/operator/operators/klusterlet/controllers/klusterletcontroller/klusterlet_controller.go @@ -53,6 +53,7 @@ type klusterletController struct { kubeClient kubernetes.Interface kubeVersion *version.Version operatorNamespace string + agentPriorityClassName string skipHubSecretPlaceholder bool cache resourceapply.ResourceCache managedClusterClientsBuilder managedClusterClientsBuilderInterface @@ -80,7 +81,7 @@ func NewKlusterletController( deploymentInformer appsinformer.DeploymentInformer, appliedManifestWorkClient workv1client.AppliedManifestWorkInterface, kubeVersion *version.Version, - operatorNamespace string, + operatorNamespace, agentPriorityClassName string, recorder events.Recorder, skipHubSecretPlaceholder bool) factory.Controller { controller := &klusterletController{ @@ -90,6 +91,7 @@ func NewKlusterletController( klusterletLister: klusterletInformer.Lister(), kubeVersion: kubeVersion, operatorNamespace: operatorNamespace, + agentPriorityClassName: agentPriorityClassName, skipHubSecretPlaceholder: skipHubSecretPlaceholder, cache: resourceapply.NewResourceCache(), managedClusterClientsBuilder: newManagedClusterClientsBuilder(kubeClient, apiExtensionClient, appliedManifestWorkClient, recorder), @@ -147,6 +149,9 @@ type klusterletConfig struct { ExternalManagedKubeConfigAgentSecret string InstallMode operatorapiv1.InstallMode + //PriorityClassName is the name of the PriorityClass accociated with the deployed agents + PriorityClassName string + RegistrationFeatureGates []string WorkFeatureGates []string @@ -192,6 +197,7 @@ func (n *klusterletController) sync(ctx context.Context, controllerContext facto ExternalServerURL: getServersFromKlusterlet(klusterlet), OperatorNamespace: n.operatorNamespace, Replica: helpers.DetermineReplica(ctx, n.kubeClient, klusterlet.Spec.DeployOption.Mode, n.kubeVersion), + PriorityClassName: n.agentPriorityClassName, ExternalManagedKubeConfigSecret: helpers.ExternalManagedKubeConfig, ExternalManagedKubeConfigRegistrationSecret: helpers.ExternalManagedKubeConfigRegistration, diff --git a/pkg/operator/operators/klusterlet/options.go b/pkg/operator/operators/klusterlet/options.go index 58fd960f8..72819828b 100644 --- a/pkg/operator/operators/klusterlet/options.go +++ b/pkg/operator/operators/klusterlet/options.go @@ -30,6 +30,7 @@ const defaultComponentNamespace = "open-cluster-management" type Options struct { SkipPlaceholderHubSecret bool + AgentPriorityClassName string } // RunKlusterletOperator starts a new klusterlet operator @@ -107,6 +108,7 @@ func (o *Options) RunKlusterletOperator(ctx context.Context, controllerContext * workClient.WorkV1().AppliedManifestWorks(), kubeVersion, operatorNamespace, + o.AgentPriorityClassName, controllerContext.EventRecorder, o.SkipPlaceholderHubSecret)