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

feat: dynamic baseline flow ID #20

Merged
merged 7 commits into from
Sep 13, 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
22 changes: 14 additions & 8 deletions .github/workflows/ci-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Install Nix
uses: cachix/install-nix-action@v27
# relax sandbox due impure kontrol-service tests during build
Expand All @@ -34,10 +34,10 @@ jobs:
uses: DeterminateSystems/magic-nix-cache-action@v7

- name: Build and load kontrol service image
run: |
run: |
docker load < $(nix build ./#kontrol-service-container --no-link --print-out-paths)

- name: Start kontrol service and Postgres
- name: Start kontrol service and Postgres
run: |
docker version
docker compose -f ci/docker-compose.yml up -d
Expand All @@ -47,9 +47,9 @@ jobs:
run: sleep 10s
shell: bash

- name: Install CLI
- name: Install CLI
run: curl get.kardinal.dev -sL | sh

- name: Verify kardinal command
run: bash -c 'source ~/.bashrc; if kardinal | grep -q "Kardinal CLI"; then exit 0; else exit 1; fi'

Expand All @@ -67,10 +67,12 @@ jobs:
run: |
tenant_id=${{ steps.tenant.outputs.id }}
services=$(curl http://localhost:8080/tenant/${tenant_id}/cluster-resources | jq -r '.services[].metadata.name' | tr " " "\n" | sort -g | tr "\n" " " | xargs)
echo "Services: $services"
if [ "${services}" != "cartservice frontend postgres productcatalogservice" ]; then exit 1; fi
deployments=$(curl http://localhost:8080/tenant/${tenant_id}/cluster-resources | jq -r '.deployments[].metadata.name' | tr " " "\n" | sort -g | tr "\n" " " | xargs)
echo "Deployments: $deployments"
if [ "${deployments}" != "cartservice-prod frontend-prod postgres-prod productcatalogservice-prod" ]; then exit 1; fi

- name: Validate topology endpoint
run: |
tenant_id=${{ steps.tenant.outputs.id }}
Expand All @@ -81,8 +83,10 @@ jobs:
run: |
KARDINAL_CLI_DEV_MODE=TRUE kardinal flow create frontend kurtosistech/frontend:demo-frontend > kardinal.out
flow_id=$(grep "Flow.*created" kardinal.out | cut -d ' ' -f2 | tr -d "\"")
echo "FlowID: $flow_id"
tenant_id=${{ steps.tenant.outputs.id }}
deployments=$(curl http://localhost:8080/tenant/${tenant_id}/cluster-resources | jq -r '.deployments[].metadata.name' | tr " " "\n" | sort -g | tr "\n" " " | xargs)
echo "Deployments: $deployments"
if [ "${deployments}" != "cartservice-prod frontend-${flow_id} frontend-prod postgres-prod productcatalogservice-prod" ]; then exit 1; fi
KARDINAL_CLI_DEV_MODE=TRUE kardinal flow ls | grep ${flow_id}
KARDINAL_CLI_DEV_MODE=TRUE kardinal flow delete ${flow_id}
Expand All @@ -91,12 +95,14 @@ jobs:
run: |
KARDINAL_CLI_DEV_MODE=TRUE kardinal flow create frontend kurtosistech/frontend:demo-on-sale -s productcatalogservice=kurtosistech/productcatalogservice:demo-on-sale > kardinal.out
flow_id=$(grep "Flow.*created" kardinal.out | cut -d ' ' -f2 | tr -d "\"")
echo "FlowID: $flow_id"
tenant_id=${{ steps.tenant.outputs.id }}
deployments=$(curl http://localhost:8080/tenant/${tenant_id}/cluster-resources | jq -r '.deployments[].metadata.name' | tr " " "\n" | sort -g | tr "\n" " " | xargs)
echo "Deployments: $deployments"
if [ "${deployments}" != "cartservice-prod frontend-${flow_id} frontend-prod postgres-prod productcatalogservice-${flow_id} productcatalogservice-prod" ]; then exit 1; fi
KARDINAL_CLI_DEV_MODE=TRUE kardinal flow ls | grep ${flow_id}
KARDINAL_CLI_DEV_MODE=TRUE kardinal flow delete ${flow_id}

- name: Create template
run: |
KARDINAL_CLI_DEV_MODE=TRUE kardinal template create extra-item-shared --template-yaml ci/template.yaml --description "Extra item and postgres is shared"
Expand All @@ -108,7 +114,7 @@ jobs:
flow_id=$(grep "Flow.*created" kardinal.out | cut -d ' ' -f2 | tr -d "\"")
KARDINAL_CLI_DEV_MODE=TRUE kardinal flow ls | grep ${flow_id}
KARDINAL_CLI_DEV_MODE=TRUE kardinal flow delete ${flow_id}

- name: Delete template
run: |
KARDINAL_CLI_DEV_MODE=TRUE kardinal template delete extra-item-shared
Expand Down
19 changes: 12 additions & 7 deletions kontrol-service/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func (sv *Server) GetTenantUuidFlows(_ context.Context, request api.GetTenantUui

finalTopology := flow.MergeClusterTopologies(*clusterTopology, lo.Values(allFlows))
flowHostMapping := finalTopology.GetFlowHostMapping()

resp := lo.MapToSlice(flowHostMapping, func(flowId string, flowUrls []string) apitypes.Flow {
return apitypes.Flow{FlowId: flowId, FlowUrls: flowUrls}
isBaselineFlow := flowId == prodFlowId
return apitypes.Flow{FlowId: flowId, FlowUrls: flowUrls, IsBaseline: &isBaselineFlow}
})
return api.GetTenantUuidFlows200JSONResponse(resp), nil
}
Expand All @@ -87,15 +89,15 @@ func (sv *Server) PostTenantUuidDeploy(_ context.Context, request api.PostTenant
flowId := prodFlowId
err, urls := applyProdOnlyFlow(sv, request.Uuid, serviceConfigs, ingressConfigs, namespace, flowId)
if err != nil {
errMsg := fmt.Sprintf("An error occurred deploying flow '%v'", prodFlowId)
errMsg := fmt.Sprintf("An error occurred deploying flow '%v'", flowId)
errResp := api.ErrorJSONResponse{
Error: err.Error(),
Msg: &errMsg,
}
return api.PostTenantUuidDeploy500JSONResponse{errResp}, nil
return api.PostTenantUuidDeploy500JSONResponse{ErrorJSONResponse: errResp}, nil
}

resp := apitypes.Flow{FlowId: prodFlowId, FlowUrls: urls}
resp := apitypes.Flow{FlowId: flowId, FlowUrls: urls}
return api.PostTenantUuidDeploy200JSONResponse(resp), nil
}

Expand All @@ -111,7 +113,7 @@ func (sv *Server) DeleteTenantUuidFlowFlowId(_ context.Context, request api.Dele
}

if request.FlowId == prodFlowId {
// We received a request to delete the base topology so we do that + the flows
// We received a request to delete the base topology, so we do that + the flows
err = deleteTenantTopologies(sv, request.Uuid)
if err != nil {
errMsg := "An error occurred deleting the topologies"
Expand Down Expand Up @@ -456,7 +458,10 @@ func applyProdDevFlow(sv *Server, tenantUuidStr string, patches []flow_spec.Serv
return nil, []string{}, fmt.Errorf("template with name '%v' doesn't exist for tenant uuid '%v'", templateSpec.TemplateName, tenantUuidStr)
}
serviceConfigs = template.ApplyTemplateOverrides(serviceConfigs, templateSpec)
baseClusterTopologyWithTemplateOverridesPtr, err := engine.GenerateProdOnlyCluster(prodFlowId, serviceConfigs, ingressConfigs, baseTopology.Namespace)

baselineFlowID := prodFlowId

baseClusterTopologyWithTemplateOverridesPtr, err := engine.GenerateProdOnlyCluster(baselineFlowID, serviceConfigs, ingressConfigs, baseTopology.Namespace)
if err != nil {
return nil, []string{}, fmt.Errorf("an error occurred while creating base cluster topology from templates:\n %s", err)
}
Expand Down Expand Up @@ -499,7 +504,7 @@ func applyProdDevFlow(sv *Server, tenantUuidStr string, patches []flow_spec.Serv
// - Templates
// - Base service configs
// - Base ingress configs
// TOOD: Could return a struct if it becomes too heavy to manipulate the return values.
// TODO: Could return a struct if it becomes too heavy to manipulate the return values.
func getTenantTopologies(sv *Server, tenantUuidStr string) (*resolved.ClusterTopology, map[string]resolved.ClusterTopology, map[string]templates.Template, []apitypes.ServiceConfig, []apitypes.IngressConfig, error) {
tenant, err := sv.db.GetTenant(tenantUuidStr)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions kontrol-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ toolchain go1.22.3
require (
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/dominikbraun/graph v0.23.0
github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240823131700-b4e7d7134bda
github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240823131700-b4e7d7134bda
github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240911204943-8af51bd3e442
github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240911170357-f4242f2f122c
github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409
github.com/labstack/echo/v4 v4.12.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
Expand Down
8 changes: 4 additions & 4 deletions kontrol-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ 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/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240823131700-b4e7d7134bda h1:lOK8sxDAeO23OwVKCCuSSxQf5LsZoXPy1IFHigi0aXU=
github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240823131700-b4e7d7134bda/go.mod h1:yvON5b9BHp3yJ99+i+JUMGb985g3h6Eco+w9swS5rds=
github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240823131700-b4e7d7134bda h1:7mLaOF2HfGNKrSCXbz72yLE7YIN1eHg/qm4x42/i6dM=
github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240823131700-b4e7d7134bda/go.mod h1:lj6oLhpXgnc9ZaulV7jysgRaeZUDPK6XiM2TxpcGRqM=
github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240911204943-8af51bd3e442 h1:rz9ZaCDuVlGK26U7pHUlgIj6oFnwHZy199Ch0h4wBrc=
github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240911204943-8af51bd3e442/go.mod h1:yvON5b9BHp3yJ99+i+JUMGb985g3h6Eco+w9swS5rds=
github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240911170357-f4242f2f122c h1:3szOElqNcIm6bcrZFh6YFgHD92qyhkpLdNEDUBWNJpI=
github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240911170357-f4242f2f122c/go.mod h1:lj6oLhpXgnc9ZaulV7jysgRaeZUDPK6XiM2TxpcGRqM=
github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409 h1:YQTATifMUwZEtZYb0LVA7DK2pj8s71iY8rzweuUQ5+g=
github.com/kurtosis-tech/stacktrace v0.0.0-20211028211901-1c67a77b5409/go.mod h1:y5weVs5d9wXXHcDA1awRxkIhhHC1xxYJN8a7aXnE6S8=
github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=
Expand Down
6 changes: 3 additions & 3 deletions kontrol-service/gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ schema = 3
version = "v0.2.0"
hash = "sha256-fadcWxZOORv44oak3jTxm6YcITcFxdGt4bpn869HxUE="
[mod."github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api"]
version = "v0.0.0-20240823131700-b4e7d7134bda"
hash = "sha256-B6Vp8HQ5GSFstVkkSRll1c/9WJnSXtwAqSxLENdkoIE="
version = "v0.0.0-20240911204943-8af51bd3e442"
hash = "sha256-Snene5X+e60ztYbCLluEcT8wMtd2w3MOJHGz/KhXr3w="
[mod."github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api"]
version = "v0.0.0-20240823131700-b4e7d7134bda"
version = "v0.0.0-20240911170357-f4242f2f122c"
hash = "sha256-Y1vl6Cqpvc+b9+JPnajRGPeAXqA/XQEgcGBCXsiuTek="
[mod."github.com/kurtosis-tech/stacktrace"]
version = "v0.0.0-20211028211901-1c67a77b5409"
Expand Down
Loading