Skip to content

Commit

Permalink
add module benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
m00g3n committed Nov 22, 2023
1 parent d79e85b commit c913319
Show file tree
Hide file tree
Showing 16 changed files with 1,072 additions and 0 deletions.
62 changes: 62 additions & 0 deletions hack/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# kyma-infrastructure-manager

## API

### example input

```json
[
{
"srcSecret": {
"name: "kubeconfig-runtime-id",
"namespace": "kcp-system",
},
"dst": {
"namespace": "frog-test-invalid",
"labels": {
"instance/type": "removed"
},
},
"count": 10
},
{
"srcSecret": {
"name: "kubeconfig-runtime-xyz",
"namespace": "kcp-system",
},
"dst": {
"namespace": "frog-test-valid",
"labels": {
"instance/type": "hibernated"
},
},
"count": 10
},
{
"srcSecret": {
"name: "kubeconfig-runtime-123",
"namespace": "kcp-system",
},
"dst": {
"namespace": "frog-test-valid",
"labels": {
"instance/type": "valid"
},
},
"count": 25
}
]
```

### example output

```json
[
{
"runtimeID", "xxx-yyy-zzz",
"shootID", "xxx-yyy-zzz",
"xxx": [
]
},
]
```
144 changes: 144 additions & 0 deletions hack/benchmark/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package main

import (
"context"
"encoding/json"
"fmt"
"os"
"strings"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
LabelInstanceID = "kyma-project.io/instance-id"
LabelRuntimeID = "kyma-project.io/runtime-id"
LabelPlanID = "kyma-project.io/broker-plan-id"
LabelPlanName = "kyma-project.io/broker-plan-name"
LabelGlobalAccountID = "kyma-project.io/global-account-id"
LabelSubaccountID = "kyma-project.io/subaccount-id"
LabelShootName = "kyma-project.io/shoot-name"
LabelRegion = "kyma-project.io/region"
LabelKynaName = "operator.kyma-project.io/kyma-name"
)

type srcSecret struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
}

type dst struct {
Namespace string `json:"namespace"`
Labels map[string]string `json:"labels"`
}

type input struct {
SrcSecret srcSecret `json:"srcSecret"`
Dst dst `json:"dst"`
Count int `json:"count"`
}

func main() {
if err := run(); err != nil {
exit1(err)
}
}

// exit1 - exits application with return code 1 and given error
// printed on stderr
func exit1(err error) {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
}

// fetchSecretOpts - fetchSecrets function options
type getSecretArgs struct {
client client.Client
key client.ObjectKey
}

// fetchSecrets - fetches labeld secret from k8s
func getSecret(ctx context.Context, s *corev1.Secret, opts getSecretArgs) error {
return opts.client.Get(ctx, opts.key, s)
}

var (
ErrInvalidSecret = fmt.Errorf("invalid secret")

labelKeys = []string{
LabelInstanceID,
LabelRuntimeID,
LabelPlanID,
LabelPlanName,
LabelGlobalAccountID,
LabelSubaccountID,
LabelShootName,
LabelRegion,
LabelKynaName,
}
)

func mustBeValidSecret(s *corev1.Secret) error {
if s == nil {
return fmt.Errorf("%w: nil", ErrInvalidSecret)
}

var notFound []string
for _, label := range labelKeys {
_, found := s.Labels[label]
if !found {
notFound = append(notFound, label)
continue
}
}

if len(notFound) > 0 {
return fmt.Errorf("%w: %s not found", ErrInvalidSecret, strings.Join(notFound, ","))
}

if s.Data != nil {
return fmt.Errorf("%w: empty data", ErrInvalidSecret)
}

return nil
}

func run() error {
// parse piped data
var inputs []input
decoder := json.NewDecoder(os.Stdin)

if err := decoder.Decode(&inputs); err != nil {
return fmt.Errorf("unable to decode JSON: %w", err)
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var k8sClient client.Client

for range inputs {
// fetch src secret that contains all the metadata that
// will be used to create dst secret and GardenerCluster CRs
var srcSecret corev1.Secret
getArgs := getSecretArgs{
client: k8sClient,
key: client.ObjectKeyFromObject(&srcSecret),
}

if err := getSecret(ctx, &srcSecret, getArgs); err != nil {
exit1(err)
}

if err := mustBeValidSecret(&srcSecret); err != nil {
exit1(err)
}

// convert to CR base on src secret
// create dst secret base on src secret
// apply cr and secret
}

return nil
}
60 changes: 60 additions & 0 deletions hack/benchmark/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module github.tools.sap/framefrog/kim-benchmark

go 1.21.3

require (
github.com/google/uuid v1.3.0
github.com/kyma-project/infrastructure-manager v0.0.0-20231120125151-d79e85b35639
github.com/onsi/ginkgo/v2 v2.13.1
github.com/onsi/gomega v1.30.0
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
sigs.k8s.io/controller-runtime v0.16.3
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // 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/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // 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/apiextensions-apiserver v0.28.3 // indirect
k8s.io/client-go v0.28.3 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // 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 c913319

Please sign in to comment.