-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync deployment replicas when it is controlled by hpa
Signed-off-by: chaosi-zju <[email protected]>
- Loading branch information
1 parent
9ccc8be
commit 952f3bc
Showing
8 changed files
with
256 additions
and
525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
pkg/controllers/hpaautolabelretain/hpa_auto_label_retain_controller.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2023 The Karmada Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package hpaautolabelretain | ||
|
||
import ( | ||
"context" | ||
|
||
autoscalingv2 "k8s.io/api/autoscaling/v2" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/client-go/dynamic" | ||
controllerruntime "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/builder" | ||
|
||
"github.com/karmada-io/karmada/pkg/util" | ||
) | ||
|
||
const ( | ||
// ControllerName is the controller name that will be used when reporting events. | ||
ControllerName = "hpa-auto-label-retain" | ||
// scaleRefWorkerNum is the async Worker number | ||
scaleRefWorkerNum = 1 | ||
) | ||
|
||
// HPAAutoLabelRetain is to automatically add `retain-replicas` label to resource template mananged by HPA. | ||
type HPAAutoLabelRetain struct { | ||
DynamicClient dynamic.Interface | ||
RESTMapper meta.RESTMapper | ||
|
||
scaleRefWorker util.AsyncWorker | ||
} | ||
|
||
// SetupWithManager creates a controller and register to controller manager. | ||
func (r *HPAAutoLabelRetain) SetupWithManager(mgr controllerruntime.Manager) error { | ||
scaleRefWorkerOptions := util.Options{ | ||
Name: "scale ref worker", | ||
ReconcileFunc: r.reconcileScaleRef, | ||
} | ||
r.scaleRefWorker = util.NewAsyncWorker(scaleRefWorkerOptions) | ||
r.scaleRefWorker.Run(scaleRefWorkerNum, context.Background().Done()) | ||
|
||
return controllerruntime.NewControllerManagedBy(mgr). | ||
Named(ControllerName). | ||
For(&autoscalingv2.HorizontalPodAutoscaler{}, builder.WithPredicates(r)). | ||
Complete(r) | ||
} | ||
|
||
// Reconcile performs a full reconciliation for the object referred to by the Request. | ||
// The Controller will requeue the Request to be processed again if an error is non-nil or | ||
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue. | ||
func (r *HPAAutoLabelRetain) Reconcile(_ context.Context, _ controllerruntime.Request) (controllerruntime.Result, error) { | ||
return controllerruntime.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 0 additions & 161 deletions
161
pkg/controllers/hpareplicassyncer/hpa_replicas_syncer_controller.go
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.