Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KUBE-503: adjust Github workflows, adjust for latest Proto definitions and add e2e test #3

Merged
merged 9 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
with:
cluster_name: cloud-proxy-e2e

- uses: azure/[email protected]

- name: Run e2e tests
run: |
echo "$GCP_CREDENTIALS_JSON" > "$GCP_CREDENTIALS"
./e2e/run.sh
env:
GCP_CREDENTIALS_JSON: ${{ secrets.TEST_GCP_CREDENTIALS }}
GCP_CREDENTIALS: gcp-credentials.json

- name: Login to Google Artifact Registry
uses: docker/login-action@v3
with:
Expand Down Expand Up @@ -85,15 +100,3 @@ jobs:
us-docker.pkg.dev/castai-hub/library/cloud-proxy:${{ env.RELEASE_TAG }}
us-docker.pkg.dev/castai-hub/library/cloud-proxy:latest

#- name: Docker pull for fossa main
# if: github.event_name == 'release'
# run: docker pull us-docker.pkg.dev/castai-hub/library/cloud-proxy:${{ env.RELEASE_TAG }}
#
#- name: FOSSA scan docker image
# if: github.event_name == 'release'
# continue-on-error: true
# uses: fossas/fossa-action@v1
# with:
# api-key: ${{ secrets.FOSSA_API_KEY }}
# container: us-docker.pkg.dev/castai-hub/library/cloud-proxy:${{ env.RELEASE_TAG }}

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
VERSION ?= poc2
REPO ?= lachezarcast/cloud-proxy
REPO ?= trojan295/cloud-proxy
ValyaB marked this conversation as resolved.
Show resolved Hide resolved

build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o bin/castai-cloud-proxy-amd64 ./cmd/proxy
#docker build -t us-docker.pkg.dev/castai-hub/library/svc:$(VERSION) .
docker build -t $(REPO):$(VERSION) --platform linux/amd64 .
.PHONY: build

push:
docker push $(REPO):$(VERSION)
Expand Down
14 changes: 14 additions & 0 deletions charts/cast-cloud-proxy/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ 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 }}
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 }}
Expand All @@ -51,3 +60,8 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: gcp-creds
secret:
secretName: {{ include "cast-cloud-proxy.fullname" . }}-gcp-creds
optional: true
11 changes: 11 additions & 0 deletions charts/cast-cloud-proxy/templates/gcp-credentials-secret.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

6 changes: 6 additions & 0 deletions charts/cast-cloud-proxy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
92 changes: 38 additions & 54 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 4 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

23 changes: 23 additions & 0 deletions e2e/chart/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
24 changes: 24 additions & 0 deletions e2e/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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"
62 changes: 62 additions & 0 deletions e2e/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
22 changes: 22 additions & 0 deletions e2e/chart/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "e2e.fullname" . }}
labels:
{{- include "e2e.labels" . | nindent 4}}
spec:
backoffLimit: 0
template:
metadata:
labels:
{{- include "e2e.selectorLabels" . | nindent 8 }}
spec:
restartPolicy: Never
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
name: {{ .Chart.Name }}
ports:
- containerPort: 50051
name: grpc

15 changes: 15 additions & 0 deletions e2e/chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions e2e/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
image:
repository: cloud-proxy-e2e
pullPolicy: IfNotPresent
tag: ""

Loading
Loading