Skip to content

Commit

Permalink
Make controllers/ golint compatible (kedacore#1065)
Browse files Browse the repository at this point in the history
Signed-off-by: Jobin John <[email protected]>
  • Loading branch information
Mystigan authored Sep 1, 2020
1 parent 598f1a4 commit f5064f6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ repos:
^api/v1alpha1/scaledjob_types\.go$|
^api/v1alpha1/scaledobject_types\.go$|
^api/v1alpha1/triggerauthentication_types\.go$|
^controllers/scaledjob_controller\.go$|
^controllers/scaledobject_controller\.go$|
^controllers/util/status\.go$|
^controllers/util/string_lists\.go$|
^hack/tools\.go$|
^pkg/scalers/artemis_scaler\.go$|
^pkg/scalers/azure/azure_aad_podidentity\.go$|
Expand Down
6 changes: 3 additions & 3 deletions controllers/scaledjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ScaledJobReconciler struct {
scaleHandler scaling.ScaleHandler
}

// SetupWithManager initializes the ScaledJobReconciler instance and starts a new controller managed by the passed Manager instance.
func (r *ScaledJobReconciler) SetupWithManager(mgr ctrl.Manager) error {

r.scaleHandler = scaling.NewScaleHandler(mgr.GetClient(), nil, mgr.GetScheme())
Expand All @@ -41,6 +42,7 @@ func (r *ScaledJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

// Reconcile performs reconciliation on the identified ScaledJob resource based on the request information passed, returns the result and an error (if any).
func (r *ScaledJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)

Expand Down Expand Up @@ -96,10 +98,8 @@ func (r *ScaledJobReconciler) reconcileScaledJob(logger logr.Logger, scaledJob *
err = r.requestScaleLoop(logger, scaledJob)
if err != nil {
return "Failed to start a new scale loop with scaling logic", err
} else {
logger.Info("Initializing Scaling logic according to ScaledObject Specification")
}

logger.Info("Initializing Scaling logic according to ScaledObject Specification")
return "ScaledJob is defined correctly and is ready to scaling", nil
}

Expand Down
13 changes: 6 additions & 7 deletions controllers/scaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ScaledObjectReconciler struct {
kubeVersion kedautil.K8sVersion
}

// SetupWithManager initializes the ScaledObjectReconciler instance and starts a new controller managed by the passed Manager instance.
func (r *ScaledObjectReconciler) SetupWithManager(mgr ctrl.Manager) error {

// create Discovery clientset
Expand Down Expand Up @@ -100,6 +101,7 @@ func initScaleClient(mgr manager.Manager, clientset *discovery.DiscoveryClient)
), nil
}

// Reconcile performs reconciliation on the identified ScaledObject resource based on the request information passed, returns the result and an error (if any).
func (r *ScaledObjectReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)

Expand Down Expand Up @@ -193,11 +195,9 @@ func (r *ScaledObjectReconciler) reconcileScaledObject(logger logr.Logger, scale
if newHPACreated || scaleObjectSpecChanged {
if r.requestScaleLoop(logger, scaledObject) != nil {
return "Failed to start a new scale loop with scaling logic", err
} else {
logger.Info("Initializing Scaling logic according to ScaledObject Specification")
}
logger.Info("Initializing Scaling logic according to ScaledObject Specification")
}

return "ScaledObject is defined correctly and is ready for scaling", nil
}

Expand Down Expand Up @@ -240,11 +240,10 @@ func (r *ScaledObjectReconciler) checkTargetResourceIsScalable(logger logr.Logge
// resource doesn't exist
logger.Error(err, "Target resource doesn't exist", "resource", gvkString, "name", scaledObject.Spec.ScaleTargetRef.Name)
return gvkr, err
} else {
// resource exist but doesn't expose /scale subresource
logger.Error(errScale, "Target resource doesn't expose /scale subresource", "resource", gvkString, "name", scaledObject.Spec.ScaleTargetRef.Name)
return gvkr, errScale
}
// resource exist but doesn't expose /scale subresource
logger.Error(errScale, "Target resource doesn't expose /scale subresource", "resource", gvkString, "name", scaledObject.Spec.ScaleTargetRef.Name)
return gvkr, errScale
}

// if it is not already present in ScaledObject Status:
Expand Down
2 changes: 2 additions & 0 deletions controllers/util/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
kedav1alpha1 "github.com/kedacore/keda/api/v1alpha1"
)

// SetStatusConditions patches given object with passed list of conditions based on the object's type or returns an error.
func SetStatusConditions(client runtimeclient.Client, logger logr.Logger, object interface{}, conditions *kedav1alpha1.Conditions) error {
var patch runtimeclient.Patch

Expand All @@ -35,6 +36,7 @@ func SetStatusConditions(client runtimeclient.Client, logger logr.Logger, object
return err
}

// UpdateScaledObjectStatus patches the given ScaledObject with the updated status passed to it or returns an error.
func UpdateScaledObjectStatus(client runtimeclient.Client, logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject, status *kedav1alpha1.ScaledObjectStatus) error {
patch := runtimeclient.MergeFrom(scaledObject.DeepCopy())
scaledObject.Status = *status
Expand Down
2 changes: 2 additions & 0 deletions controllers/util/string_lists.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package util

// Contains checks if the passed string is present in the given slice of strings.
func Contains(list []string, s string) bool {
for _, v := range list {
if v == s {
Expand All @@ -9,6 +10,7 @@ func Contains(list []string, s string) bool {
return false
}

// Remove deletes the passed string from the given slice of strings.
func Remove(list []string, s string) []string {
for i, v := range list {
if v == s {
Expand Down

0 comments on commit f5064f6

Please sign in to comment.