Skip to content

Commit

Permalink
[ Razorpay SQS Autoscaler ] Trivy, EOL Languages, Dependabot Fixes (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
telnet-harsha authored Mar 12, 2023
1 parent 6523e92 commit e38a4ca
Show file tree
Hide file tree
Showing 3,204 changed files with 670 additions and 2,076,006 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
29 changes: 0 additions & 29 deletions .drone.yml

This file was deleted.

58 changes: 58 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module github.com/razorpay/sqs-autoscaler-controller

go 1.20

require (
github.com/alecthomas/kingpin/v2 v2.3.2
github.com/aws/aws-sdk-go v1.44.219
github.com/pubnub/go-metrics-statsd v0.0.0-20170124014003-7da61f429d6b
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/sirupsen/logrus v1.9.0
github.com/vmg/backoff v1.0.0
k8s.io/api v0.26.2
k8s.io/apiextensions-apiserver v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
)

require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // 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
)
518 changes: 518 additions & 0 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
"os/signal"
"time"

log "github.com/Sirupsen/logrus"
"github.com/alecthomas/kingpin/v2"
"github.com/pubnub/go-metrics-statsd"
"github.com/rcrowley/go-metrics"
"gopkg.in/alecthomas/kingpin.v2"
log "github.com/sirupsen/logrus"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

"github.com/uswitch/sqs-autoscaler-controller/pkg/crd"
"github.com/uswitch/sqs-autoscaler-controller/pkg/scaler"
"github.com/razorpay/sqs-autoscaler-controller/pkg/crd"
"github.com/razorpay/sqs-autoscaler-controller/pkg/scaler"
)

type options struct {
Expand Down
5 changes: 3 additions & 2 deletions pkg/crd/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

log "github.com/Sirupsen/logrus"
metrics "github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -47,8 +47,9 @@ func NewCache(client *rest.RESTClient, syncInterval time.Duration) *Cache {
listWatch := cache.NewListWatchFromClient(client, "sqsautoscalers", "", fields.Everything())
store := cache.NewIndexer(cache.DeletionHandlingMetaNamespaceKeyFunc, cache.Indexers{})
c.Store = store
queueOptions := cache.DeltaFIFOOptions{KeyFunction: cache.MetaNamespaceKeyFunc, KnownObjects: store, EmitDeltaTypeReplaced: false}
config := &cache.Config{
Queue: cache.NewDeltaFIFO(cache.MetaNamespaceKeyFunc, nil, store),
Queue: cache.NewDeltaFIFOWithOptions(queueOptions),
ListerWatcher: listWatch,
ObjectType: &SqsAutoScaler{},
FullResyncPeriod: syncInterval,
Expand Down
10 changes: 4 additions & 6 deletions pkg/crd/crd.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package crd

import (
"context"
"reflect"

apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// metav1 "k8s.io/apiextensions-apiserver/vendor/k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -30,7 +32,7 @@ func EnsureResource(client apiextensionsclient.Interface) error {
},
},
}
_, err := client.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)
_, err := client.ApiextensionsV1beta1().CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})
if err != nil && apierrors.IsAlreadyExists(err) {
return nil
}
Expand All @@ -49,7 +51,7 @@ func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) {
config.GroupVersion = &SchemeGroupVersion
config.APIPath = "/apis"
config.ContentType = runtime.ContentTypeJSON
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}
config.NegotiatedSerializer = serializer.WithoutConversionCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}

client, err := rest.RESTClientFor(&config)
if err != nil {
Expand All @@ -59,10 +61,6 @@ func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) {
return client, scheme, err
}

func addToScheme() {
runtime.NewSchemeBuilder(addKnownTypes)
}

const (
GroupName = "aws.uswitch.com"
Version = "v1"
Expand Down
71 changes: 71 additions & 0 deletions pkg/crd/deepcopy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package crd

import "k8s.io/apimachinery/pkg/runtime"

func (in *ScaleSpec) DeepCopyInto(out *ScaleSpec) {
*out = *in
out.Threshold = in.Threshold
out.Amount = in.Amount
}

func (in *AutoScalerSpec) DeepCopyInto(out *AutoScalerSpec) {
*out = *in
out.Queue = in.Queue
out.Deployment = in.Deployment
out.MinPods = in.MinPods
out.MaxPods = in.MaxPods
in.ScaleUp.DeepCopyInto(&out.ScaleUp)
in.ScaleDown.DeepCopyInto(&out.ScaleDown)
}

func (in *SqsAutoScaler) DeepCopyInto(out *SqsAutoScaler) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
}

func (in *SqsAutoScaler) DeepCopy() *SqsAutoScaler {
if in == nil {
return nil
}
out := new(SqsAutoScaler)
in.DeepCopyInto(out)
return out
}

func (in *SqsAutoScaler) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}

func (in *SqsAutoScalerList) DeepCopyInto(out *SqsAutoScalerList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]SqsAutoScaler, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}

func (in *SqsAutoScalerList) DeepCopy() *SqsAutoScalerList {
if in == nil {
return nil
}
out := new(SqsAutoScalerList)
in.DeepCopyInto(out)
return out
}

func (in *SqsAutoScalerList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
5 changes: 3 additions & 2 deletions pkg/crd/events.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package crd

import (
"context"
"time"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -38,7 +39,7 @@ func (s *SqsAutoScaler) RecordEvent(k *kubernetes.Clientset, eventType, reason,
Message: message,
Type: eventType,
}
_, err := k.CoreV1().Events(s.ObjectMeta.Namespace).Create(event)
_, err := k.CoreV1().Events(s.ObjectMeta.Namespace).Create(context.TODO(), event, metav1.CreateOptions{})

return err
}
4 changes: 3 additions & 1 deletion pkg/crd/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package crd

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type SqsAutoScaler struct {
metav1.TypeMeta `json:",inline"`
Expand Down
12 changes: 6 additions & 6 deletions pkg/scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"fmt"
"time"

log "github.com/Sirupsen/logrus"
"github.com/razorpay/sqs-autoscaler-controller/pkg/crd"
"github.com/rcrowley/go-metrics"
"github.com/uswitch/sqs-autoscaler-controller/pkg/crd"
log "github.com/sirupsen/logrus"
"github.com/vmg/backoff"
appsv1 "k8s.io/api/apps/v1beta1"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -82,8 +82,8 @@ func (s Scaler) executeScale(ctx context.Context, sess *session.Session, scale *
return nil, 0, err
}

deployments := s.client.Apps().Deployments(scale.ObjectMeta.Namespace)
deployment, err := deployments.Get(scale.Spec.Deployment, metav1.GetOptions{})
deployments := s.client.AppsV1().Deployments(scale.ObjectMeta.Namespace)
deployment, err := deployments.Get(context.TODO(), scale.Spec.Deployment, metav1.GetOptions{})
if err != nil {
return nil, 0, err
}
Expand All @@ -99,7 +99,7 @@ func (s Scaler) executeScale(ctx context.Context, sess *session.Session, scale *

delta := replicas - *deployment.Spec.Replicas
deployment.Spec.Replicas = &replicas
updated, err := deployments.Update(deployment)
updated, err := deployments.Update(context.TODO(), deployment, metav1.UpdateOptions{})

if delta != 0 && err == nil {
metrics.GetOrRegisterMeter("scaler.adjust", metrics.DefaultRegistry).Mark(1)
Expand Down
Loading

0 comments on commit e38a4ca

Please sign in to comment.