diff --git a/charts/cast-cloud-proxy/templates/deployment.yaml b/charts/cast-cloud-proxy/templates/deployment.yaml index bc0694b..b4019fd 100644 --- a/charts/cast-cloud-proxy/templates/deployment.yaml +++ b/charts/cast-cloud-proxy/templates/deployment.yaml @@ -33,12 +33,25 @@ spec: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: GRPC_ENDPOINT + value: {{ .Values.config.grpc.endpoint | quote }} + - name: GRPC_KEY + value: {{ .Values.config.grpc.key | quote }} + {{- if .Values.config.gcpCredentials }} + - name: GOOGLE_APPLICATION_CREDENTIALS2 + value: dasd + {{- end }} livenessProbe: {{- toYaml .Values.livenessProbe | nindent 12 }} readinessProbe: {{- toYaml .Values.readinessProbe | nindent 12 }} resources: {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: gcp-creds + mountPath: "/root/.config/gcloud" + readOnly: true {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} @@ -51,3 +64,8 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + volumes: + - name: gcp-creds + secret: + secretName: {{ include "cast-cloud-proxy.fullname" . }}-gcp-creds + optional: true diff --git a/charts/cast-cloud-proxy/templates/gcp-credentials-secret.yaml b/charts/cast-cloud-proxy/templates/gcp-credentials-secret.yaml new file mode 100644 index 0000000..9fafc99 --- /dev/null +++ b/charts/cast-cloud-proxy/templates/gcp-credentials-secret.yaml @@ -0,0 +1,11 @@ +{{- if .Values.config.gcpCredentials }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "cast-cloud-proxy.fullname" . }}-gcp-creds + labels: + {{- include "cast-cloud-proxy.labels" . | nindent 4 }} +stringData: + application_default_credentials.json: | {{ .Values.config.gcpCredentials | nindent 4 }} +{{- end }} + diff --git a/charts/cast-cloud-proxy/values.yaml b/charts/cast-cloud-proxy/values.yaml index 71d1aac..bedf6b2 100644 --- a/charts/cast-cloud-proxy/values.yaml +++ b/charts/cast-cloud-proxy/values.yaml @@ -2,6 +2,12 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. +config: + gcpCredentials: "" + grpc: + endpoint: "" + key: "" + replicaCount: 1 image: diff --git a/cmd/proxy/main.go b/cmd/proxy/main.go index f1a1e50..5ef54c6 100644 --- a/cmd/proxy/main.go +++ b/cmd/proxy/main.go @@ -1,76 +1,60 @@ package main import ( - "flag" - "log" + "fmt" "net/http" - "os" - "time" + "path" + "runtime" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/castai/cloud-proxy/internal/castai/dummy" + "github.com/castai/cloud-proxy/internal/config" "github.com/castai/cloud-proxy/internal/gcpauth" - "github.com/castai/cloud-proxy/internal/localtest" "github.com/castai/cloud-proxy/internal/proxy" -) - -const ( - // TODO: Change accordingly for local testing - - projectID = "engineering-test-353509" - location = "europe-north1-a" - testCluster = "lachezar-2708" + "github.com/sirupsen/logrus" ) var ( - runSanityTests = flag.Bool("sanity-checks", false, "run sanity checks that validate auth loading and basic executor function") - runMockCastTest = flag.Bool("mockcast", true, "run a test using a mock Cast.AI server") + GitCommit = "undefined" + GitRef = "no-ref" + Version = "local" ) func main() { - flag.Parse() - - if runSanityTests != nil && *runSanityTests { - log.Println("run sanity tests is true, starting") - go func() { - localtest.RunBasicTests(projectID, location, testCluster) - localtest.RunProxyTest(projectID, location, testCluster) - }() + cfg := config.Get() + + logger := logrus.New() + logger.SetLevel(logrus.Level(cfg.Log.Level)) + logger.SetReportCaller(true) + logger.Formatter = &logrus.TextFormatter{ + CallerPrettyfier: func(f *runtime.Frame) (function string, file string) { + filename := path.Base(f.File) + return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line) + }, } - if runMockCastTest != nil && *runMockCastTest { - log.Println("run mockcast tests is true, starting") - go func() { - log.Println("Starting mock cast instance") - mockCast := &dummy.MockCast{} - if err := mockCast.Run(); err != nil { - log.Panicln("Error running mock Cast:", err) - } - }() + logger.WithFields(logrus.Fields{ + "GitCommit": GitCommit, + "GitRef": GitRef, + "Version": Version, + }).Println("Starting cloud-proxy") - go func() { - loggerClientProxy := log.New(os.Stderr, "[CLUSTER PROXY] ", log.LstdFlags) - loggerClientProxy.Println("Starting proxy client") - conn, err := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - loggerClientProxy.Panicf("Failed to connect to server: %v", err) - } - defer func(conn *grpc.ClientConn) { - err := conn.Close() - if err != nil { - loggerClientProxy.Panicf("Failed to close gRPC connection: %v", err) - } - }(conn) - - src := gcpauth.GCPCredentialsSource{} - executor := proxy.NewExecutor(src, http.DefaultClient) - client := proxy.NewClient(executor, loggerClientProxy) - client.Run(conn) - }() + conn, err := grpc.NewClient(cfg.GRPC.Endpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + logger.Panicf("Failed to connect to server: %v", err) } - log.Println("Sleeping for 1h, feel free to kill me") - time.Sleep(1 * time.Hour) + defer func(conn *grpc.ClientConn) { + err := conn.Close() + if err != nil { + logger.Panicf("Failed to close gRPC connection: %v", err) + } + }(conn) + + src := gcpauth.GCPCredentialsSource{} + + executor := proxy.NewExecutor(src, http.DefaultClient) + client := proxy.NewClient(executor, logger) + client.Run(conn) } diff --git a/e2e/Dockerfile b/e2e/Dockerfile new file mode 100644 index 0000000..fa98e3e --- /dev/null +++ b/e2e/Dockerfile @@ -0,0 +1,4 @@ +FROM gcr.io/distroless/static-debian11 +COPY bin/cloud-proxy-e2e /usr/local/bin/cloud-proxy-e2e +CMD ["cloud-proxy-e2e"] + diff --git a/e2e/chart/.helmignore b/e2e/chart/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/e2e/chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/e2e/chart/Chart.yaml b/e2e/chart/Chart.yaml new file mode 100644 index 0000000..973b09a --- /dev/null +++ b/e2e/chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: cloud-proxy-e2e +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/e2e/chart/templates/_helpers.tpl b/e2e/chart/templates/_helpers.tpl new file mode 100644 index 0000000..60d16d1 --- /dev/null +++ b/e2e/chart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "e2e.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "e2e.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "e2e.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "e2e.labels" -}} +helm.sh/chart: {{ include "e2e.chart" . }} +{{ include "e2e.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "e2e.selectorLabels" -}} +app.kubernetes.io/name: {{ include "e2e.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "e2e.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "e2e.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/e2e/chart/templates/job.yaml b/e2e/chart/templates/job.yaml new file mode 100644 index 0000000..9926711 --- /dev/null +++ b/e2e/chart/templates/job.yaml @@ -0,0 +1,21 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "e2e.fullname" . }} + labels: + {{- include "e2e.labels" . | nindent 4}} +spec: + template: + metadata: + labels: + {{- include "e2e.selectorLabels" . | nindent 8 }} + spec: + restartPolicy: Never + containers: + - image: {{ .Values.image.repository }}:{{ .Values.image.tag }} + imagePullPolicy: Never + name: {{ .Chart.Name }} + ports: + - containerPort: 50051 + name: grpc + diff --git a/e2e/chart/templates/service.yaml b/e2e/chart/templates/service.yaml new file mode 100644 index 0000000..dc82ef8 --- /dev/null +++ b/e2e/chart/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "e2e.fullname" . }} + labels: + {{- include "e2e.labels" . | nindent 4 }} +spec: + type: ClusterIP + ports: + - port: 50051 + targetPort: grpc + protocol: TCP + name: grpc + selector: + {{- include "e2e.selectorLabels" . | nindent 4 }} diff --git a/e2e/chart/values.yaml b/e2e/chart/values.yaml new file mode 100644 index 0000000..beb389b --- /dev/null +++ b/e2e/chart/values.yaml @@ -0,0 +1,5 @@ +image: + repository: cloud-proxy-e2e + pullPolicy: IfNotPresent + tag: "" + diff --git a/e2e/main.go b/e2e/main.go new file mode 100644 index 0000000..9d55b5b --- /dev/null +++ b/e2e/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "log" + + "github.com/castai/cloud-proxy/internal/castai/dummy" +) + +func main() { + log.Println("Starting mock cast instance") + mockCast := &dummy.MockCast{} + if err := mockCast.Run(); err != nil { + log.Panicln("Error running mock Cast:", err) + } +} diff --git a/e2e/run.sh b/e2e/run.sh new file mode 100755 index 0000000..b77eb5b --- /dev/null +++ b/e2e/run.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +set -eEu + +CLUSTER_NAME=cloud-proxy-e2e +IMAGE_TAG=$RANDOM + +kind::ensure() { + if ! kind export kubeconfig --name "${CLUSTER_NAME}"; then + kind create cluster --name "${CLUSTER_NAME}" + fi +} + +kind::load_images() { + kind load docker-image --name "${CLUSTER_NAME}" cloud-proxy:$IMAGE_TAG + kind load docker-image --name "${CLUSTER_NAME}" cloud-proxy-e2e:$IMAGE_TAG + +} + +cloud_proxy::build_image() { + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o bin/castai-cloud-proxy-amd64 ./cmd/proxy + docker build -t cloud-proxy:$IMAGE_TAG . +} + +cloud_proxy::helm_install() { + helm upgrade --install --wait \ + --set image.repository=cloud-proxy \ + --set image.tag=$IMAGE_TAG \ + --set config.grpc.endpoint=cloud-proxy-e2e:50051 \ + --set config.grpc.key=test \ + --set-file config.gcpCredentials="${GCP_CREDENTIALS}" \ + cast-cloud-proxy ./charts/cast-cloud-proxy +} + +e2e::build_image() { + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o bin/cloud-proxy-e2e ./e2e + docker build -t cloud-proxy-e2e:$IMAGE_TAG -f ./e2e/Dockerfile . +} + +e2e::helm_install() { + helm upgrade --install --wait \ + --set image.tag=$IMAGE_TAG \ + cloud-proxy-e2e ./e2e/chart +} + +e2e::helm_uninstall() { + helm delete cloud-proxy-e2e +} + +main() { + [[ -z "${GCP_CREDENTIALS:-}" ]] && echo "Missing GCP_CREDENTIALS" && exit 1 + + kind::ensure + cloud_proxy::build_image + e2e::build_image + kind::load_images + cloud_proxy::helm_install + e2e::helm_install + + #e2e::helm_uninstall +} + +main $@ diff --git a/go.mod b/go.mod index 6dcdbd4..55a1ef5 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,8 @@ require ( cloud.google.com/go/container v1.39.0 github.com/google/uuid v1.6.0 github.com/googleapis/gax-go/v2 v2.13.0 + github.com/sirupsen/logrus v1.9.3 + github.com/spf13/viper v1.19.0 golang.org/x/oauth2 v0.22.0 golang.org/x/sync v0.8.0 google.golang.org/api v0.193.0 @@ -18,22 +20,39 @@ require ( cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect cloud.google.com/go/compute/metadata v0.5.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect go.opentelemetry.io/otel v1.28.0 // indirect go.opentelemetry.io/otel/metric v1.28.0 // indirect go.opentelemetry.io/otel/trace v1.28.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.6.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 43555c7..0edce92 100644 --- a/go.sum +++ b/go.sum @@ -14,14 +14,19 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -60,17 +65,54 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfF github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDPT0hH1s= github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 h1:vS1Ao/R55RNV4O7TA2Qopok8yN+X0LIP6RVWLFkprck= @@ -85,11 +127,17 @@ go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBq go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -113,6 +161,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -157,6 +206,10 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/castai/dummy/mock_cast.go b/internal/castai/dummy/mock_cast.go index 2c8b93c..bc65111 100644 --- a/internal/castai/dummy/mock_cast.go +++ b/internal/castai/dummy/mock_cast.go @@ -19,7 +19,6 @@ import ( // - "dispatcher" that uses proxy to send requests // - "client" that does GCP cloud calls type MockCast struct { - proxyServer *MockCastServer } func (mc *MockCast) Run() error { diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..1f4f688 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,57 @@ +package config + +import ( + "fmt" + + "github.com/sirupsen/logrus" + "github.com/spf13/viper" +) + +type Config struct { + GRPC GRPC + Log Log +} + +type GRPC struct { + Endpoint string + Key string +} + +type Log struct { + Level int +} + +var cfg *Config = nil + +func Get() Config { + if cfg != nil { + return *cfg + } + + _ = viper.BindEnv("grpc.endpoint", "GRPC_ENDPOINT") + _ = viper.BindEnv("grpc.key", "GRPC_KEY") + _ = viper.BindEnv("log.level", "LOG_LEVEL") + + cfg = &Config{} + if err := viper.Unmarshal(cfg); err != nil { + panic(fmt.Errorf("while parsing config: %w", err)) + } + + if cfg.GRPC.Endpoint == "" { + required("GRPC_ENDPOINT") + } + + if cfg.GRPC.Key == "" { + required("GRPC_KEY") + } + + if cfg.Log.Level == 0 { + cfg.Log.Level = int(logrus.InfoLevel) + } + + return *cfg +} + +func required(variable string) { + panic(fmt.Errorf("variable %s is required", variable)) +} diff --git a/internal/proxy/proxy_client.go b/internal/proxy/proxy_client.go index 07b8630..f553728 100644 --- a/internal/proxy/proxy_client.go +++ b/internal/proxy/proxy_client.go @@ -3,21 +3,21 @@ package proxy import ( "context" "io" - "log" "time" "google.golang.org/grpc" "github.com/castai/cloud-proxy/internal/castai/proto" + "github.com/sirupsen/logrus" ) type Client struct { executor *Executor - logger *log.Logger + logger *logrus.Logger } -func NewClient(executor *Executor, logger *log.Logger) *Client { +func NewClient(executor *Executor, logger *logrus.Logger) *Client { return &Client{executor: executor, logger: logger} }