diff --git a/operator/pkg/controller/karmada/planner.go b/operator/pkg/controller/karmada/planner.go index 8ad583800..66c5dbe61 100644 --- a/operator/pkg/controller/karmada/planner.go +++ b/operator/pkg/controller/karmada/planner.go @@ -88,6 +88,7 @@ func (p *Planner) Execute() error { return err } if err := p.job.Run(); err != nil { + klog.ErrorS(err, "failed to executed the workflow", "workflow", p.action, "karmada", klog.KObj(p.karmada)) return p.runJobErr(err) } if err := p.afterRunJob(); err != nil { diff --git a/operator/pkg/controlplane/apiserver/apiserver.go b/operator/pkg/controlplane/apiserver/apiserver.go index 490e60500..9abf4b59b 100644 --- a/operator/pkg/controlplane/apiserver/apiserver.go +++ b/operator/pkg/controlplane/apiserver/apiserver.go @@ -59,7 +59,7 @@ func installKarmadaAPIServer(client clientset.Interface, cfg *operatorv1alpha1.K return fmt.Errorf("error when decoding karmadaApiserver deployment: %w", err) } patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels). - WithExtraArgs(cfg.ExtraArgs).ForDeployment(apiserverDeployment) + WithExtraArgs(cfg.ExtraArgs).WithResources(cfg.Resources).ForDeployment(apiserverDeployment) if err := apiclient.CreateOrUpdateDeployment(client, apiserverDeployment); err != nil { return fmt.Errorf("error when creating deployment for %s, err: %w", apiserverDeployment.Name, err) @@ -117,7 +117,7 @@ func installKarmadaAggregatedAPIServer(client clientset.Interface, cfg *operator } patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels). - WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).ForDeployment(aggregatedAPIServerDeployment) + WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).WithResources(cfg.Resources).ForDeployment(aggregatedAPIServerDeployment) if err := apiclient.CreateOrUpdateDeployment(client, aggregatedAPIServerDeployment); err != nil { return fmt.Errorf("error when creating deployment for %s, err: %w", aggregatedAPIServerDeployment.Name, err) diff --git a/operator/pkg/controlplane/controlplane.go b/operator/pkg/controlplane/controlplane.go index 368e5548f..558f4f7d7 100644 --- a/operator/pkg/controlplane/controlplane.go +++ b/operator/pkg/controlplane/controlplane.go @@ -89,7 +89,7 @@ func getKubeControllerManagerManifest(name, namespace string, cfg *operatorv1alp } patcher.NewPatcher().WithAnnotations(cfg.Annotations). - WithLabels(cfg.Labels).WithExtraArgs(cfg.ExtraArgs).ForDeployment(kcm) + WithLabels(cfg.Labels).WithExtraArgs(cfg.ExtraArgs).WithResources(cfg.Resources).ForDeployment(kcm) return kcm, nil } @@ -116,7 +116,7 @@ func getKarmadaControllerManagerManifest(name, namespace string, featureGates ma } patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels). - WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).ForDeployment(kcm) + WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).WithResources(cfg.Resources).ForDeployment(kcm) return kcm, nil } @@ -143,7 +143,7 @@ func getKarmadaSchedulerManifest(name, namespace string, featureGates map[string } patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels). - WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).ForDeployment(scheduler) + WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).WithResources(cfg.Resources).ForDeployment(scheduler) return scheduler, nil } @@ -170,7 +170,7 @@ func getKarmadaDeschedulerManifest(name, namespace string, featureGates map[stri } patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels). - WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).ForDeployment(descheduler) + WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).WithResources(cfg.Resources).ForDeployment(descheduler) return descheduler, nil } diff --git a/operator/pkg/controlplane/etcd/etcd.go b/operator/pkg/controlplane/etcd/etcd.go index 7c2380426..1ee02c3c8 100644 --- a/operator/pkg/controlplane/etcd/etcd.go +++ b/operator/pkg/controlplane/etcd/etcd.go @@ -72,7 +72,7 @@ func installKarmadaEtcd(client clientset.Interface, name, namespace string, cfg } patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels). - WithVolumeData(cfg.VolumeData).ForStatefulSet(etcdStatefulSet) + WithVolumeData(cfg.VolumeData).WithResources(cfg.Resources).ForStatefulSet(etcdStatefulSet) if err := apiclient.CreateOrUpdateStatefulSet(client, etcdStatefulSet); err != nil { return fmt.Errorf("error when creating Etcd statefulset, err: %w", err) diff --git a/operator/pkg/controlplane/metricsadapter/metricsadapter.go b/operator/pkg/controlplane/metricsadapter/metricsadapter.go index 7ef816b6c..2742e9bfd 100644 --- a/operator/pkg/controlplane/metricsadapter/metricsadapter.go +++ b/operator/pkg/controlplane/metricsadapter/metricsadapter.go @@ -46,7 +46,7 @@ func installKarmadaMetricAdapter(client clientset.Interface, cfg *operatorv1alph return fmt.Errorf("err when decoding KarmadaMetricAdapter Deployment: %w", err) } - patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).ForDeployment(metricAdapter) + patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).WithResources(cfg.Resources).ForDeployment(metricAdapter) if err := apiclient.CreateOrUpdateDeployment(client, metricAdapter); err != nil { return fmt.Errorf("error when creating deployment for %s, err: %w", metricAdapter.Name, err) diff --git a/operator/pkg/controlplane/webhook/webhook.go b/operator/pkg/controlplane/webhook/webhook.go index 8def05b3d..d38a4b6f5 100644 --- a/operator/pkg/controlplane/webhook/webhook.go +++ b/operator/pkg/controlplane/webhook/webhook.go @@ -47,7 +47,7 @@ func installKarmadaWebhook(client clientset.Interface, cfg *operatorv1alpha1.Kar } patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels). - WithExtraArgs(cfg.ExtraArgs).ForDeployment(webhookDeployment) + WithExtraArgs(cfg.ExtraArgs).WithResources(cfg.Resources).ForDeployment(webhookDeployment) if err := apiclient.CreateOrUpdateDeployment(client, webhookDeployment); err != nil { return fmt.Errorf("error when creating deployment for %s, err: %w", webhookDeployment.Name, err) diff --git a/operator/pkg/util/patcher/pather.go b/operator/pkg/util/patcher/pather.go index 4061ab8bc..6de77f49f 100644 --- a/operator/pkg/util/patcher/pather.go +++ b/operator/pkg/util/patcher/pather.go @@ -24,6 +24,7 @@ type Patcher struct { extraArgs map[string]string featureGates map[string]bool volume *operatorv1alpha1.VolumeData + resources corev1.ResourceRequirements } // NewPatcher returns a patcher. @@ -61,6 +62,12 @@ func (p *Patcher) WithVolumeData(volume *operatorv1alpha1.VolumeData) *Patcher { return p } +// WithResources sets resources to the patcher. +func (p *Patcher) WithResources(resources corev1.ResourceRequirements) *Patcher { + p.resources = resources + return p +} + // ForDeployment patches the deployment manifest. func (p *Patcher) ForDeployment(deployment *appsv1.Deployment) { deployment.Labels = labels.Merge(deployment.Labels, p.labels) @@ -69,6 +76,10 @@ func (p *Patcher) ForDeployment(deployment *appsv1.Deployment) { deployment.Annotations = labels.Merge(deployment.Annotations, p.annotations) deployment.Spec.Template.Annotations = labels.Merge(deployment.Spec.Template.Annotations, p.annotations) + if p.resources.Size() > 0 { + // It's considered the first container is the karmada component by default. + deployment.Spec.Template.Spec.Containers[0].Resources = p.resources + } if len(p.extraArgs) != 0 || len(p.featureGates) != 0 { // It's considered the first container is the karmada component by default. baseArguments := deployment.Spec.Template.Spec.Containers[0].Command @@ -109,6 +120,10 @@ func (p *Patcher) ForStatefulSet(sts *appsv1.StatefulSet) { patchVolumeForStatefulSet(sts, p.volume) } + if p.resources.Size() > 0 { + // It's considered the first container is the karmada component by default. + sts.Spec.Template.Spec.Containers[0].Resources = p.resources + } if len(p.extraArgs) != 0 { // It's considered the first container is the karmada component by default. baseArguments := sts.Spec.Template.Spec.Containers[0].Command