Skip to content

Commit

Permalink
formatted code
Browse files Browse the repository at this point in the history
Signed-off-by: 26tanishabanik <[email protected]>
  • Loading branch information
26tanishabanik committed Nov 1, 2022
1 parent f585b8d commit fe6862e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 451 deletions.
6 changes: 1 addition & 5 deletions pkg/scalers/couchdb_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
couchdb "github.com/go-kivik/couchdb/v3"
"github.com/go-kivik/kivik/v3"
"github.com/go-logr/logr"
kedautil "github.com/kedacore/keda/v2/pkg/util"
v2 "k8s.io/api/autoscaling/v2"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/metrics/pkg/apis/external_metrics"
"strconv"
kedautil "github.com/kedacore/keda/v2/pkg/util"
// kedascaler "couchbase/keda/pkg/scalers"
)

type couchDBScaler struct {
Expand Down Expand Up @@ -112,7 +111,6 @@ func parseCouchDBMetadata(config *ScalerConfig) (*couchDBMetadata, string, error
meta := couchDBMetadata{}

// parse metaData from ScaledJob config

if val, ok := config.TriggerMetadata["query"]; ok {
meta.query = val
} else {
Expand Down Expand Up @@ -203,8 +201,6 @@ func NewCouchDBScaler(ctx context.Context, config *ScalerConfig) (Scaler, error)
return nil, fmt.Errorf("failed to parsing couchDB metadata, because of %v", err)
}



client, err := kivik.New("couch", connStr)
if err != nil {
fmt.Println("Couldn't connect to couchdb: ", err)
Expand Down
1 change: 0 additions & 1 deletion pkg/scalers/couchdb_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var testCouchDBResolvedEnv = map[string]string{
"CouchDB_PASSWORD": "YeFvQno9LylIm5MDgwcV",
}


type parseCouchDBMetadataTestData struct {
metadata map[string]string
authParams map[string]string
Expand Down
82 changes: 39 additions & 43 deletions tests/scalers/couchdb/couchdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
)

var (
testNamespace = fmt.Sprintf("%s-ns", testName)
testNamespace = fmt.Sprintf("%s-ns", testName)
deploymentName = fmt.Sprintf("%s-deployment", testName)
jobName = fmt.Sprintf("%s-job", testName)
secretName = fmt.Sprintf("%s-secret", testName)
Expand Down Expand Up @@ -135,7 +135,6 @@ spec:
`
)


func CreateKubernetesResourcesCouchDB(t *testing.T, kc *kubernetes.Clientset, nsName string, data interface{}, templates []Template) {
KubectlApplyMultipleWithTemplate(t, data, templates)
}
Expand All @@ -150,7 +149,6 @@ func TestCouchDBScaler(t *testing.T) {
data, templates := getTemplateData(kc)
CreateKubernetesResourcesCouchDB(t, kc, testNamespace, data, templates)


assert.True(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, minReplicaCount, 60, 3),
"replica count should be %d after 3 minutes", minReplicaCount)

Expand Down Expand Up @@ -228,9 +226,9 @@ func deployPod(kc *kubernetes.Clientset, podName, args string) {
}

_, err := kc.CoreV1().Pods(testNamespace).Create(context.Background(), podSpec, metav1.CreateOptions{})
if err != nil {
fmt.Println("Failed to create test pod: ", err)
}
if err != nil {
fmt.Println("Failed to create test pod: ", err)
}
}

func testActivation(t *testing.T, kc *kubernetes.Clientset) {
Expand All @@ -247,7 +245,6 @@ func testActivation(t *testing.T, kc *kubernetes.Clientset) {
}
}


func insertRecord(kc *kubernetes.Clientset, password, record, name, uuid string) {
dsn := fmt.Sprintf(`http://admin:%s@test-release-svc-couchdb.%s.svc.cluster.local:5984/animals/%s`, password, testNamespace, uuid)
cmd := ` -X PUT ` + dsn + ` -d ` + record
Expand All @@ -274,9 +271,9 @@ func deployPodDelete(kc *kubernetes.Clientset, podName, args string) {
},
}
_, err := kc.CoreV1().Pods(testNamespace).Create(context.Background(), podSpec, metav1.CreateOptions{})
if err != nil {
fmt.Println("Failed to create test pod: ", err)
}
if err != nil {
fmt.Println("Failed to create test pod: ", err)
}
}

func deleteRecord(kc *kubernetes.Clientset, password, name , uuid, rev string) {
Expand All @@ -290,31 +287,30 @@ func deleteRecord(kc *kubernetes.Clientset, password, name , uuid, rev string) {
}

type PodLog struct {
OK bool `json:"ok"`
OK bool `json:"ok"`
ID string `json:"id"`
Rev string `json:"rev"`
}


func getPodLogs(kc *kubernetes.Clientset, podName string) (string, error) {
podLogOpts := corev1.PodLogOptions{}
req := kc.CoreV1().Pods(testNamespace).GetLogs(podName, &podLogOpts)
podLogs, err := req.Stream(context.Background())
if err != nil {
fmt.Println("error in opening stream: ", err)
return "", err
}
defer podLogs.Close()

buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
if err != nil {
fmt.Println("error in copy information from podLogs to buf: ", err)
return "", err
}
str := buf.String()
fmt.Println("Index: ", strings.Index(str, `"rev":`))
podLogOpts := corev1.PodLogOptions{}

req := kc.CoreV1().Pods(testNamespace).GetLogs(podName, &podLogOpts)
podLogs, err := req.Stream(context.Background())
if err != nil {
fmt.Println("error in opening stream: ", err)
return "", err
}
defer podLogs.Close()

buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
if err != nil {
fmt.Println("error in copy information from podLogs to buf: ", err)
return "", err
}
str := buf.String()
fmt.Println("Index: ", strings.Index(str, `"rev":`))
chars := str[strings.Index(str, `"rev":`)+7 : strings.Index(str, `}`)-1]
fmt.Println(chars)
fmt.Println("Type of chars: ", reflect.TypeOf(chars))
Expand Down Expand Up @@ -384,19 +380,19 @@ func getTemplateData(kc *kubernetes.Clientset) (templateData, []Template) {
base64ConnectionString := base64.StdEncoding.EncodeToString([]byte(connectionString))

return templateData{
TestNamespace: testNamespace,
DeploymentName: deploymentName,
HostName: hostName,
Port: "5984",
Username: base64.StdEncoding.EncodeToString([]byte(couchdbUser)),
Password: passwordEncoded,
TriggerAuthName: triggerAuthName,
SecretName: secretName,
ScaledObjectName: scaledObjectName,
CouchDBNamespace: couchdbNamespace,
Database: couchdbDBName,
Connection: connectionString,
Base64Connection: base64ConnectionString,
TestNamespace: testNamespace,
DeploymentName: deploymentName,
HostName: hostName,
Port: "5984",
Username: base64.StdEncoding.EncodeToString([]byte(couchdbUser)),
Password: passwordEncoded,
TriggerAuthName: triggerAuthName,
SecretName: secretName,
ScaledObjectName: scaledObjectName,
CouchDBNamespace: couchdbNamespace,
Database: couchdbDBName,
Connection: connectionString,
Base64Connection: base64ConnectionString,
}, []Template{
{Name: "deploymentTemplate", Config: deploymentTemplate},
{Name: "secretTemplate", Config: secretTemplate},
Expand Down
Loading

0 comments on commit fe6862e

Please sign in to comment.