diff --git a/.github/workflows/ci-e2e-tests.yml b/.github/workflows/ci-e2e-tests.yml index 312c9f0..0ef962b 100644 --- a/.github/workflows/ci-e2e-tests.yml +++ b/.github/workflows/ci-e2e-tests.yml @@ -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 @@ -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 @@ -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' @@ -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 }} @@ -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} @@ -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" @@ -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 diff --git a/kontrol-service/api/server.go b/kontrol-service/api/server.go index d63ec00..c89ed9b 100644 --- a/kontrol-service/api/server.go +++ b/kontrol-service/api/server.go @@ -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 } @@ -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 } @@ -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" @@ -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) } @@ -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 { diff --git a/kontrol-service/go.mod b/kontrol-service/go.mod index 0c73c2d..256e143 100644 --- a/kontrol-service/go.mod +++ b/kontrol-service/go.mod @@ -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-20240913122732-d5a75f64bec6 + github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240913122732-d5a75f64bec6 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 diff --git a/kontrol-service/go.sum b/kontrol-service/go.sum index 2090799..1da2942 100644 --- a/kontrol-service/go.sum +++ b/kontrol-service/go.sum @@ -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-20240913122732-d5a75f64bec6 h1:GRc+gtucOX6yPGf1soNVRM1Wiqf0Clyn8gmCenV1Hm4= +github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api v0.0.0-20240913122732-d5a75f64bec6/go.mod h1:yvON5b9BHp3yJ99+i+JUMGb985g3h6Eco+w9swS5rds= +github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240913122732-d5a75f64bec6 h1:Nq/aD04cx4fj1pzhzINyQSUTOB4g5oZb1XMBCZ7EiCA= +github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api v0.0.0-20240913122732-d5a75f64bec6/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= diff --git a/kontrol-service/gomod2nix.toml b/kontrol-service/gomod2nix.toml index 46e81e1..8cc959d 100644 --- a/kontrol-service/gomod2nix.toml +++ b/kontrol-service/gomod2nix.toml @@ -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-20240913122732-d5a75f64bec6" + 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-20240913122732-d5a75f64bec6" hash = "sha256-Y1vl6Cqpvc+b9+JPnajRGPeAXqA/XQEgcGBCXsiuTek=" [mod."github.com/kurtosis-tech/stacktrace"] version = "v0.0.0-20211028211901-1c67a77b5409"