Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into EVEREST-178-validate-s3-access
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Kralik committed Sep 21, 2023
2 parents cf34359 + bad3317 commit 22085e8
Show file tree
Hide file tree
Showing 45 changed files with 1,650 additions and 506 deletions.
123 changes: 123 additions & 0 deletions .github/workflows/rc_create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Create RC branches

on:
workflow_dispatch:
inputs:
version:
description: The release version in v*.*.* format
required: true

jobs:
build:
runs-on: ubuntu-latest
env:
VERSION: ${{ github.event.inputs.version }}
RC_BRANCH: ''
steps:
- name: Validate input
run: |
echo $RC_BRANCH
if [[ ! $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Wrong version format provided, please use v*.*.* format"
exit 1
fi
- name: Define release branch name in the format "release-*.*.*"
run: |
echo "RC_BRANCH=release-${VERSION#v}" >> $GITHUB_ENV
- name: Configure git for private modules
env:
ROBOT_TOKEN: ${{ secrets.ROBOT_TOKEN }}
run: git config --global url."https://percona-platform-robot:${ROBOT_TOKEN}@github.com".insteadOf "https://github.com"

- name: Check out Everest CLI
uses: actions/checkout@v4
with:
repository: percona/percona-everest-cli
ref: 'main'
path: percona-everest-cli
token: ${{ secrets.ROBOT_TOKEN }}

- name: Create Everest CLI RC-branch
run: |
cd percona-everest-cli
# Check if the branch already exists
git fetch
check_branch=$(git ls-remote --heads origin ${RC_BRANCH})
if [[ -z ${check_branch} ]]; then
git checkout -b $RC_BRANCH
git push origin $RC_BRANCH
fi
- name: Check out Everest catalog
uses: actions/checkout@v4
with:
repository: percona/everest-catalog
ref: 'main'
path: everest-catalog
token: ${{ secrets.ROBOT_TOKEN }}

- name: Create Everest catalog RC-branch
run: |
cd everest-catalog
# Check if the branch already exists
git fetch
check_branch=$(git ls-remote --heads origin ${RC_BRANCH})
if [[ -z ${check_branch} ]]; then
git checkout -b $RC_BRANCH
git push origin $RC_BRANCH
fi
- name: Check out Everest frontend
uses: actions/checkout@v4
with:
repository: percona/percona-everest-frontend
ref: 'main'
path: percona-everest-frontend
token: ${{ secrets.ROBOT_TOKEN }}

- name: Create Everest Frontend RC-branch
run: |
cd percona-everest-frontend
# Check if the branch already exists
git fetch
check_branch=$(git ls-remote --heads origin ${RC_BRANCH})
if [[ -z ${check_branch} ]]; then
git checkout -b $RC_BRANCH
git push origin $RC_BRANCH
fi
- name: Check out Everest Backend
uses: actions/checkout@v4
with:
path: ./backend
ref: 'main'

- name: Create and update Everest Backend RC-branch
run: |
cd backend
# Check if the branch already exists
git fetch
check_branch=$(git ls-remote --heads origin ${RC_BRANCH})
if [[ -z ${check_branch} ]]; then
git checkout -b $RC_BRANCH
git push origin $RC_BRANCH
# update tag refs in scripts
sed -i "s/dev-latest/$RC_BRANCH/g" deploy/quickstart-compose.yml deploy/quickstart-k8s.yaml
# configure userdata for commits
git config --global user.email "[email protected]"
git config --global user.name "Everest RC CI triggered by ${{ github.actor }}"
# commit and push the updated files
git commit -a -m "update version tag"
git push origin $RC_BRANCH
fi
95 changes: 95 additions & 0 deletions .github/workflows/rc_rebuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Build and push RC image

on:
push:
branches:
- release-[0-9]+.[0-9]+.[0-9]+*

jobs:
build:
runs-on: ubuntu-latest
env:
VERSION: ''
RELEASE_BRANCH_NAME: ''
steps:
- name: Define release branch name
run: |
echo "RELEASE_BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Define version name
run: |
semantic_version=${RELEASE_BRANCH_NAME#"release-"}
echo "VERSION=v${semantic_version}" >> $GITHUB_ENV
- name: Configure git for private modules
env:
ROBOT_TOKEN: ${{ secrets.ROBOT_TOKEN }}
run: git config --global url."https://percona-platform-robot:${ROBOT_TOKEN}@github.com".insteadOf "https://github.com"

- name: Check out Everest frontend
uses: actions/checkout@v4
with:
ref: $ {{ env.RELEASE_BRANCH_NAME }}
path: percona-everest-frontend
token: ${{ secrets.ROBOT_TOKEN }}

- name: Run with Node 16
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install Bit Version Manager
run: npm i -g @teambit/bvm

- name: Install latest Bit version
run: bvm install 0.2.3

- name: Add bvm bin folder to path
run: echo "$HOME/bin" >> $GITHUB_PATH

- name: Set up bit config
env:
BIT_TOKEN: ${{ secrets.BIT_TOKEN }}
run: bit config set user.token $BIT_TOKEN

- name: Build Everest Frontend app
run: |
cd ${GITHUB_WORKSPACE}/percona-everest-frontend
bit install --recurring-install
bit snap
bit artifacts percona.apps/everest --out-dir build
mkdir ${GITHUB_WORKSPACE}/front
cp -rf build/percona.apps_everest/react-common-js/everest/public/* ${GITHUB_WORKSPACE}/front/
- name: Check out Everest Backend
uses: actions/checkout@v4
with:
path: ./backend
ref: $ {{ env.RELEASE_BRANCH_NAME }}
token: ${{ secrets.ROBOT_TOKEN }}

- name: Embed Everest Frontend app into backend
run: |
cp -rf ${GITHUB_WORKSPACE}/front/* ${GITHUB_WORKSPACE}/backend/public/dist/
cd ${GITHUB_WORKSPACE}/backend
- name: Setup docker build metadata
uses: docker/metadata-action@v4
id: meta
with:
images: perconalab/everest
tags: ${{ env.VERSION }}


- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push everest RC-image
uses: docker/build-push-action@v4
with:
context: backend
push: true
tags: ${{ steps.meta.outputs.tags }}
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ linters-settings:
- $all
- "!$test"
deny:
- pkg: errors
desc: use "github.com/pkg/errors" instead
- pkg: github.com/pkg/errors
desc: use "errors" instead
- pkg: github.com/gogo/protobuf/proto
desc: use "github.com/golang/protobuf/proto" instead

Expand All @@ -33,6 +33,7 @@ linters-settings:
linters:
enable-all: true
disable:
- goerr113 # not useful after migration to the standard errors
- exhaustruct # not useful
- exhaustivestruct # annoying and duplicates exhaustruct
- godox # fails to be nolint-ed when necessary
Expand Down
8 changes: 7 additions & 1 deletion api-tests/tests/backup-storages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ test('update backup storage failures', async ({ request }) => {
},
errorText: '\'url\' is an invalid URL',
},
{
payload: {
bucket: '-asldf;asdfk;sadf',
},
errorText: 'request body has an error: doesn\'t match schema #/components/schemas/UpdateBackupStorageParams: property \"bucket\" is unsupported',
},
];

for (const testCase of testCases) {
Expand All @@ -198,7 +204,7 @@ test('update: backup storage not found', async ({ request }) => {

const response = await request.patch(`/v1/backup-storages/${name}`, {
data: {
type: 's3',
bucketName: 's3',
},
});

Expand Down
2 changes: 1 addition & 1 deletion api-tests/tests/monitoring-instances.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ test('patch monitoring instance type fails on missing key', async ({ request })

const getJson = await updated.json()

expect(getJson.message).toMatch('pmm key is required')
expect(getJson.message).toMatch('Pmm key is required')
})

test('create monitoring instance failures', async ({ request }) => {
Expand Down
28 changes: 14 additions & 14 deletions api/backup_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package api

import (
"context"
"errors"
"fmt"
"net/http"

Expand All @@ -26,7 +27,6 @@ import (
"github.com/jinzhu/gorm"
"github.com/labstack/echo/v4"
"github.com/lib/pq"
"github.com/pkg/errors"

"github.com/percona/percona-everest-backend/model"
"github.com/percona/percona-everest-backend/pkg/kubernetes"
Expand Down Expand Up @@ -76,7 +76,7 @@ func (e *EverestServer) CreateBackupStorage(ctx echo.Context) error { //nolint:f
})
}
if existingStorage != nil {
err = errors.Errorf("Storage %s already exists", params.Name)
err = fmt.Errorf("storage %s already exists", params.Name)
e.l.Error(err)
return ctx.JSON(http.StatusConflict, Error{Message: pointer.ToString(err.Error())})
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func (e *EverestServer) DeleteBackupStorage(ctx echo.Context, backupStorageName

ks, err := e.storage.ListKubernetesClusters(c)
if err != nil {
e.l.Error(errors.Wrap(err, "Could not list Kubernetes clusters"))
e.l.Error(errors.Join(err, errors.New("could not list Kubernetes clusters")))
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString("Could not list Kubernetes clusters")})
}
if len(ks) == 0 {
Expand All @@ -162,30 +162,30 @@ func (e *EverestServer) DeleteBackupStorage(ctx echo.Context, backupStorageName
// FIXME: Revisit it once multi k8s support will be enabled
_, kubeClient, _, err := e.initKubeClient(ctx.Request().Context(), ks[0].ID)
if err != nil {
e.l.Error(errors.Wrap(err, "could not init kube client for config"))
e.l.Error(errors.Join(err, errors.New("could not init kube client for config")))
return nil
}

err = kubeClient.DeleteConfig(ctx.Request().Context(), bs, func(ctx context.Context, name string) (bool, error) {
return kubernetes.IsBackupStorageConfigInUse(ctx, name, kubeClient)
})
if err != nil && !errors.Is(err, kubernetes.ErrConfigInUse) {
e.l.Error(errors.Wrap(err, "could not delete config"))
e.l.Error(errors.Join(err, errors.New("could not delete config")))
return nil
}

err = e.storage.Transaction(func(tx *gorm.DB) error {
err := e.storage.DeleteBackupStorage(c, backupStorageName, tx)
if err != nil {
e.l.Error(err)
return errors.New("Could not delete backup storage")
return errors.New("could not delete backup storage")
}
if _, err := e.secretsStorage.DeleteSecret(c, bs.AccessKeyID); err != nil {
return errors.Wrap(err, "could not delete access key from secrets storage")
return errors.Join(err, errors.New("could not delete access key from secrets storage"))
}

if _, err := e.secretsStorage.DeleteSecret(c, bs.SecretKeyID); err != nil {
return errors.Wrap(err, "could not delete secret key from secrets storage")
return errors.Join(err, errors.New("could not delete secret key from secrets storage"))
}

return nil
Expand Down Expand Up @@ -300,12 +300,12 @@ func (e *EverestServer) performBackupStorageUpdate(
// FIXME: Revisit it once multi k8s support will be enabled
_, kubeClient, _, err := e.initKubeClient(ctx.Request().Context(), ks[0].ID)
if err != nil {
e.l.Error(errors.Wrap(err, "could not init kube client to update config"))
e.l.Error(errors.Join(err, errors.New("could not init kube client to update config")))
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString("Could not init kubernetes client to update config")})
}

if err := kubeClient.UpdateConfig(ctx.Request().Context(), bs, e.secretsStorage.GetSecret); err != nil {
e.l.Error(errors.Wrap(err, "could not update config"))
e.l.Error(errors.Join(err, errors.New("could not update config")))
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString("Could not update config on the kubernetes cluster")})
}

Expand Down Expand Up @@ -336,7 +336,7 @@ func (e *EverestServer) createSecrets(
err := e.secretsStorage.CreateSecret(ctx, newID, *accessKey)
if err != nil {
e.l.Error(err)
return newAccessKeyID, newSecretKeyID, errors.New("Could not store access key in secrets storage")
return newAccessKeyID, newSecretKeyID, errors.New("could not store access key in secrets storage")
}
}

Expand All @@ -348,7 +348,7 @@ func (e *EverestServer) createSecrets(
err := e.secretsStorage.CreateSecret(ctx, newID, *secretKey)
if err != nil {
e.l.Error(err)
return newAccessKeyID, newSecretKeyID, errors.New("Could not store secret key in secrets storage")
return newAccessKeyID, newSecretKeyID, errors.New("could not store secret key in secrets storage")
}
}

Expand Down Expand Up @@ -443,12 +443,12 @@ func (e *EverestServer) updateBackupStorage(
var pgErr *pq.Error
if errors.As(err, &pgErr) {
if pgErr.Code.Name() == pgErrUniqueViolation {
return http.StatusBadRequest, errors.New("Backup storage with the same name already exists. " + pgErr.Detail)
return http.StatusBadRequest, errors.New("backup storage with the same name already exists. " + pgErr.Detail)
}
}

e.l.Error(err)
return http.StatusInternalServerError, errors.New("Could not update backup storage")
return http.StatusInternalServerError, errors.New("could not update backup storage")
}

return 0, nil
Expand Down
Loading

0 comments on commit 22085e8

Please sign in to comment.