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

New feature: reservations #37

Merged
merged 20 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions .github/workflows/pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
VERSION=temporary-pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [ "${{ github.event_name }}" = "push" ]; then
Expand Down Expand Up @@ -55,41 +55,41 @@ jobs:
tags: ${{ steps.prep.outputs.tags }}
# images from Pull expire after 1d
labels: |
quay.expires-after=1d
quay.expires-after=7d
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}

build-and-push-api:
concurrency:
group: pr-${{ github.event.number }}
group: temporary-pr-${{ github.event.number }}
cancel-in-progress: true

uses: ./.github/workflows/build-push.yml
secrets:
registry_username: ${{ secrets.QUAY_RHPDS_SANDBOX_API_USER }}
registry_password: ${{ secrets.QUAY_RHPDS_SANDBOX_API_PASSWORD }}
with:
tag: pr-${{ github.event.number }}
tag: temporary-pr-${{ github.event.number }}
image: api
labels: |-
quay.expires-after=1d
quay.expires-after=7d
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.revision=${{ github.sha }}

build-and-push-admin:
concurrency:
group: pr-${{ github.event.number }}-admin
group: temporary-pr-${{ github.event.number }}-admin
cancel-in-progress: true

uses: ./.github/workflows/build-push.yml
secrets:
registry_username: ${{ secrets.QUAY_RHPDS_SANDBOX_API_USER }}
registry_password: ${{ secrets.QUAY_RHPDS_SANDBOX_API_PASSWORD }}
with:
tag: pr-${{ github.event.number }}
tag: temporary-pr-${{ github.event.number }}
image: admin
labels: |-
quay.expires-after=1d
quay.expires-after=7d
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.revision=${{ github.sha }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
VERSION=temporary-pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [ "${{ github.event_name }}" = "push" ]; then
Expand Down
10 changes: 8 additions & 2 deletions Containerfile.admin
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.20
ARG GO_VERSION=1.21
# Switch back to Red Hat go-toolset when it supports go 1.20
#FROM registry.access.redhat.com/ubi8/go-toolset:latest AS builder
FROM docker.io/golang:${GO_VERSION} as builder
Expand Down Expand Up @@ -33,13 +33,19 @@ RUN dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x
unzip \
vim \
wget \
&& dnf clean all
&& dnf clean all \
&& VERSION=4.1.0 \
&& curl --silent --location https://github.com/Orange-OpenSource/hurl/releases/download/$VERSION/hurl-$VERSION-x86_64-unknown-linux-gnu.tar.gz \
| tar -xz -C /usr/local/bin --strip-components=1 --wildcards '*/hurl' '*/hurlfmt'

COPY --from=docker.io/migrate/migrate /usr/local/bin/migrate /usr/local/bin/migrate
WORKDIR /sandbox/
USER ${USER_UID}
COPY build/github_known_hosts /ssh/known_hosts
env SSH_KNOWN_HOSTS /ssh/known_hosts
COPY --from=builder /sandbox/build/sandbox-* ./
COPY --from=builder /sandbox/tools ./tools
COPY --from=builder /sandbox/tests ./tests
CMD ["/bin/bash"]


Expand Down
2 changes: 1 addition & 1 deletion Containerfile.api
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.20
ARG GO_VERSION=1.21
# Switch back to Red Hat go-toolset when it supports go 1.20
#FROM registry.access.redhat.com/ubi8/go-toolset:latest AS builder
FROM docker.io/golang:${GO_VERSION} as builder
Expand Down
2 changes: 1 addition & 1 deletion Containerfile.metrics
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.20
ARG GO_VERSION=1.21
# Switch back to Red Hat go-toolset when it supports go 1.20
#FROM registry.access.redhat.com/ubi8/go-toolset:latest AS builder
FROM docker.io/golang:${GO_VERSION} as builder
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test:
@echo "VERSION: $(VERSION)"
@go test -v ./...

run-api: cmd/sandbox-api/assets/swagger.yaml .dev.pgenv .dev.jwtauth_env migrate
run-api: cmd/sandbox-api/assets/swagger.yaml .dev.pgenv .dev.jwtauth_env #migrate
. ./.dev.pgenv && . ./.dev.jwtauth_env && cd cmd/sandbox-api && CGO_ENABLED=0 go run .

rm-local-pg:
Expand All @@ -25,7 +25,7 @@ rm-local-pg:

run-local-pg: .dev.pg_password rm-local-pg
@echo "Running local postgres..."
@podman run -p 5432:5432 --name localpg -e POSTGRES_PASSWORD=$(shell cat .dev.pg_password) -d postgres
@podman run -p 5432:5432 --name localpg -e POSTGRES_PASSWORD=$(shell cat .dev.pg_password) -d postgres:16-bullseye
# See full list of parameters here:
# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS

Expand Down
29 changes: 19 additions & 10 deletions cmd/sandbox-api/account_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/jackc/pgx/v4"
"github.com/rhpds/sandbox/internal/api/v1"
"github.com/rhpds/sandbox/internal/config"
"github.com/rhpds/sandbox/internal/log"
"github.com/rhpds/sandbox/internal/models"

Expand All @@ -15,12 +16,12 @@ import (
)

type AccountHandler struct {
accountProvider models.AwsAccountProvider
awsAccountProvider models.AwsAccountProvider
}

func NewAccountHandler(accountProvider models.AwsAccountProvider) *AccountHandler {
func NewAccountHandler(awsAccountProvider models.AwsAccountProvider) *AccountHandler {
return &AccountHandler{
accountProvider: accountProvider,
awsAccountProvider: awsAccountProvider,
}
}

Expand All @@ -32,16 +33,23 @@ func (h *AccountHandler) GetAccountsHandler(w http.ResponseWriter, r *http.Reque

serviceUuid := r.URL.Query().Get("service_uuid")

// Get available from Query
available := r.URL.Query().Get("available")

var (
accounts []models.AwsAccount
err error
)
if serviceUuid != "" {
// Get the account from DynamoDB
accounts, err = h.accountProvider.FetchAllByServiceUuid(serviceUuid)
accounts, err = h.awsAccountProvider.FetchAllByServiceUuid(serviceUuid)

} else {
accounts, err = h.accountProvider.FetchAll()
if available != "" && available == "true" {
accounts, err = h.awsAccountProvider.FetchAllAvailable()
} else {
accounts, err = h.awsAccountProvider.FetchAll()
}
}

if err != nil {
Expand Down Expand Up @@ -85,7 +93,7 @@ func (h *AccountHandler) GetAccountHandler(w http.ResponseWriter, r *http.Reques
// by the swagger openAPI spec.

// Get the account from DynamoDB
sandbox, err := h.accountProvider.FetchByName(accountName)
sandbox, err := h.awsAccountProvider.FetchByName(accountName)
if err != nil {
if err == models.ErrAccountNotFound {
log.Logger.Warn("GET account", "error", err)
Expand Down Expand Up @@ -124,7 +132,7 @@ func (h *AccountHandler) CleanupAccountHandler(w http.ResponseWriter, r *http.Re
// by the swagger openAPI spec.

// Get the account from DynamoDB
sandbox, err := h.accountProvider.FetchByName(accountName)
sandbox, err := h.awsAccountProvider.FetchByName(accountName)
if err != nil {
if err == models.ErrAccountNotFound {
log.Logger.Warn("GET account", "error", err)
Expand All @@ -145,7 +153,7 @@ func (h *AccountHandler) CleanupAccountHandler(w http.ResponseWriter, r *http.Re
return
}
// Mark account for cleanup
if err := h.accountProvider.MarkForCleanup(sandbox.Name); err != nil {
if err := h.awsAccountProvider.MarkForCleanup(sandbox.Name); err != nil {
log.Logger.Error("PUT account cleanup", "error", err)
w.WriteHeader(http.StatusInternalServerError)
render.Render(w, r, &v1.Error{
Expand Down Expand Up @@ -173,7 +181,7 @@ func (h *BaseHandler) LifeCycleAccountHandler(action string) http.HandlerFunc {
reqId := GetReqID(r.Context())

// Get the account from DynamoDB
sandbox, err := h.accountProvider.FetchByName(accountName)
sandbox, err := h.awsAccountProvider.FetchByName(accountName)
if err != nil {
if err == models.ErrAccountNotFound {
log.Logger.Warn("GET account", "error", err)
Expand All @@ -198,6 +206,7 @@ func (h *BaseHandler) LifeCycleAccountHandler(action string) http.HandlerFunc {
lifecycleResourceJob := models.LifecycleResourceJob{
ResourceType: sandbox.Kind,
ResourceName: sandbox.Name,
Locality: config.LocalityID,
RequestID: reqId,
Action: action,
Status: "new",
Expand Down Expand Up @@ -233,7 +242,7 @@ func (h *BaseHandler) GetStatusAccountHandler(w http.ResponseWriter, r *http.Req
// by the swagger openAPI spec.

// Get the account from DynamoDB
sandbox, err := h.accountProvider.FetchByName(accountName)
sandbox, err := h.awsAccountProvider.FetchByName(accountName)
if err != nil {
if err == models.ErrAccountNotFound {
log.Logger.Warn("GET account", "error", err)
Expand Down
Loading