Skip to content

Commit

Permalink
consolidated pause logic, called Pause in reconcileloop
Browse files Browse the repository at this point in the history
Signed-off-by: keegancwinchester <keegan.winchester@shiptcom>
  • Loading branch information
keegancwinchester committed Oct 24, 2022
1 parent 8bdd442 commit a8b3e3f
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 186 deletions.
2 changes: 2 additions & 0 deletions config/crd/bases/keda.sh_scaledjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7740,6 +7740,8 @@ spec:
lastActiveTime:
format: date-time
type: string
Paused:
type: string
type: object
type: object
served: true
Expand Down
66 changes: 66 additions & 0 deletions controllers/keda/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,69 @@ func getHPAMaxReplicas(scaledObject *kedav1alpha1.ScaledObject) int32 {
}
return defaultHPAMaxReplicas
}

// func (r *ReconcileScaledJob) Reconcile(request reconcile.Request) (reconcile.Result, error) {
// scaledJob := &kedav1alpha1.ScaledJob{}
// err := r.client.Get(context.TODO(), request.NamespacedName, scaledJob)
// if err != nil {
// if errors.IsNotFound(err) {
// // Request object not found, could have been deleted after reconcile request.
// // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// // Return and don't requeue
// return reconcile.Result{}, nil
// }
// // Error reading the object - requeue the request.
// return reconcile.Result{}, err
// }

// // call Pause function
// err = scaleExecutor.Pause(context.TODO(), log, scaledJob)
// if err != nil {
// return reconcile.Result{}, err
// }
// return reconcile.Result{}, nil
// }
// //call ScaledJobReconciler from scaledjob_controller.go
// func (r *ReconcileScaledJob) Reconcile(request reconcile.Request) (reconcile.Result, error) {
// scaledJob := &kedav1alpha1.ScaledJob{}
// err := r.client.Get(context.TODO(), request.NamespacedName, scaledJob)
// if err != nil {
// if errors.IsNotFound(err) {
// // Request object not found, could have been deleted after reconcile request.
// // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// // Return and don't requeue
// return reconcile.Result{}, nil
// }
// // Error reading the object - requeue the request.
// return reconcile.Result{}, err
// }

// // call ScaledJobReconciler function
// err = scaleExecutor.ScaledJobReconciler(context.TODO(), log, scaledJob)
// if err != nil {
// return reconcile.Result{}, err
// }
// return reconcile.Result{}, nil
// }

// func (r *ReconcileScaledJob) Reconcile(request reconcile.Request) (reconcile.Result, error) {
// scaledJob := &kedav1alpha1.ScaledJob{}
// err := r.client.Get(context.TODO(), request.NamespacedName, scaledJob)
// if err != nil {
// if errors.IsNotFound(err) {
// // Request object not found, could have been deleted after reconcile request.
// // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// // Return and don't requeue
// return reconcile.Result{}, nil
// }
// // Error reading the object - requeue the request.
// return reconcile.Result{}, err
// }

// // call Pause function
// err = scaleExecutor.Pause(context.TODO(), log, scaledJob)
// if err != nil {
// return reconcile.Result{}, err
// }
// return reconcile.Result{}, nil
// }
21 changes: 18 additions & 3 deletions controllers/keda/scaledjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
kedacontrollerutil "github.com/kedacore/keda/v2/controllers/keda/util"
"github.com/kedacore/keda/v2/pkg/eventreason"
"github.com/kedacore/keda/v2/pkg/scaling"
//"github.com/kedacore/keda/v2/pkg/scaling/executor"
)

// +kubebuilder:rbac:groups=keda.sh,resources=scaledjobs;scaledjobs/finalizers;scaledjobs/status,verbs="*"
Expand Down Expand Up @@ -174,6 +175,15 @@ func (r *ScaledJobReconciler) reconcileScaledJob(ctx context.Context, logger log
}
logger.Info("Initializing Scaling logic according to ScaledJob Specification")
return "ScaledJob is defined correctly and is ready to scaling", nil

// // call Pause if scaledJob.Status.IsPaused constant is set
// err = r.Pause(ctx, logger, scaledJob)
// if err != nil {
// return "Failed to pause the scale loop", err
// }
// logger.Info("ScaledJob is paused")
// return "ScaledJob is paused", nil

}

// Delete Jobs owned by the previous version of the scaledJob based on the rolloutStrategy given for this scaledJob, if any
Expand Down Expand Up @@ -233,7 +243,12 @@ func (r *ScaledJobReconciler) stopScaleLoop(ctx context.Context, logger logr.Log
}

// stopScaleLoop when scaledJob.Status.IsPaused() is set
func (r *ScaledJobReconciler) stopScaleLoopWhenPaused(ctx context.Context, logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) error {
logger.V(1).Info("Stopping a ScaleLoop when scaledJob is paused")
return r.scaleHandler.DeleteScalableObject(ctx, scaledJob)
func (r *ScaledJobReconciler) Pause(ctx context.Context, logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) error {
if scaledJob.Annotations["scaledjob.keda.sh/paused"] == "true" {
logger.V(1).Info("Stopping a ScaleLoop when scaledJob is paused")
// stopScaleLoop
return r.stopScaleLoop(ctx, logger, scaledJob)
//return r.scaleHandler.DeleteScalableObject(ctx, scaledJob)
}
return nil
}
45 changes: 23 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ require (
google.golang.org/genproto v0.0.0-20220829175752-36a9c930ecbf
google.golang.org/grpc v1.49.0
google.golang.org/protobuf v1.28.1
k8s.io/api v0.24.3
k8s.io/apimachinery v0.24.3
k8s.io/apiserver v0.24.3
k8s.io/client-go v0.24.3
k8s.io/code-generator v0.24.3
k8s.io/api v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/apiserver v0.25.0
k8s.io/client-go v0.25.0
k8s.io/code-generator v0.25.0
k8s.io/klog/v2 v2.70.2-0.20220707122935-0990e81f1a8f
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1
k8s.io/metrics v0.24.3
knative.dev/pkg v0.0.0-20220826162920-93b66e6a8700
sigs.k8s.io/controller-runtime v0.12.3
sigs.k8s.io/controller-runtime v0.13.0
sigs.k8s.io/custom-metrics-apiserver v1.24.0
)

Expand Down Expand Up @@ -105,7 +105,7 @@ require (
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
github.com/Azure/go-amqp v0.16.4 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
Expand Down Expand Up @@ -135,12 +135,13 @@ require (
github.com/eapache/queue v1.1.0 // indirect
github.com/emicklei/go-restful v2.16.0+incompatible // indirect
github.com/emicklei/go-restful-swagger12 v0.0.0-20201014110547-68ccff494617 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
Expand Down Expand Up @@ -239,9 +240,9 @@ require (
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/xdg/stringprep v1.0.3 // indirect
go.etcd.io/etcd/api/v3 v3.5.1 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.1 // indirect
go.etcd.io/etcd/client/v3 v3.5.1 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/v3 v3.5.4 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/contrib v0.20.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0 // indirect
Expand All @@ -256,17 +257,17 @@ require (
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect
golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand All @@ -276,13 +277,13 @@ require (
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.24.2 // indirect
k8s.io/component-base v0.24.3 // indirect
k8s.io/apiextensions-apiserver v0.25.0 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/gengo v0.0.0-20220613173612-397b4ae3bce7 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
nhooyr.io/websocket v1.8.7 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.32 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit a8b3e3f

Please sign in to comment.