Skip to content

Commit

Permalink
support config karmada components resources
Browse files Browse the repository at this point in the history
Signed-off-by: 张潇 <[email protected]>
  • Loading branch information
wawa0210 committed Sep 13, 2023
1 parent 244c73c commit a20e8de
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions operator/pkg/controller/karmada/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions operator/pkg/controlplane/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions operator/pkg/controlplane/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
2 changes: 1 addition & 1 deletion operator/pkg/controlplane/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/controlplane/metricsadapter/metricsadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/controlplane/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions operator/pkg/util/patcher/pather.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -69,6 +76,9 @@ 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 {
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
Expand Down Expand Up @@ -109,6 +119,9 @@ func (p *Patcher) ForStatefulSet(sts *appsv1.StatefulSet) {
patchVolumeForStatefulSet(sts, p.volume)
}

if p.resources.Size() > 0 {
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
Expand Down

0 comments on commit a20e8de

Please sign in to comment.