capactio / capact

Simple way to manage applications and infrastructure.
https://capact.io
Apache License 2.0
80 stars 19 forks source link

Improve readability of context schema #694

Closed mkuziemko closed 2 years ago

mkuziemko commented 2 years ago

Description

Changes proposed in this pull request:

Testing

Using test backend storage TypeInstance:

  1. Checkout this PR
  2. Create cluster using DISABLE_MONITORING_INSTALLATION=true USE_TEST_SETUP=true make dev-cluster
  3. Change manifests source to my branch:
    kubectl set env deploy/capact-hub-public -n capact-system -c hub-public-populator MANIFESTS_SOURCES="github.com/mkuziemko/hub-manifests?ref=fix_context_schema"
  4. Create a test storage TypeInstance where the contextSchema is an object:
    cat > /tmp/storage-ti.yaml << ENDOFFILE
    typeInstances:
    - alias: "helm-storage"
    typeRef:
    path: cap.type.capactio.capact.validation.storage
    revision: 0.1.0
    value:
    acceptValue: true
    url: capact-test-storage-backend.capact-system:50051
    contextSchema: {
      "\$schema": "http://json-schema.org/draft-07/schema",
      "type": "object",
      "required": [
        "provider"
      ],
      "properties": {
        "provider": {
          "\$id": "#/properties/context/properties/provider",
          "type": "string",
          "enum": [
            "aws_secretsmanager",
            "dotenv"
          ]
        }
      },
      "additionalProperties": false
    }
    ENDOFFILE
    export STORAGE_TI=$(capact ti create -f /tmp/storage-ti.yaml -ojson | jq -r '.[] | select(.alias == "helm-storage") | .id')
  5. Create a download TypeInstance that uses this test storage backend:
    cat > /tmp/download-ti.yaml << ENDOFFILE
    typeInstances:
    - alias: "download"
    typeRef:
    path: cap.type.capactio.capact.validation.download
    revision: 0.1.0
    value:
    key: "true"
    backend:
    context:
      provider: dotenv
    id: $STORAGE_TI
    ENDOFFILE
    export DOWNLOAD_TI=$(capact ti create -f /tmp/download-ti.yaml -ojson | jq -r '.[] | select(.alias == "download") | .id')
  6. Try one more time but in this case with an incorrect provider - it should correct read the contextSchema object and reject the request:
    cat > /tmp/download-ti.yaml << ENDOFFILE
    typeInstances:
    - alias: "download"
    typeRef:
    path: cap.type.capactio.capact.validation.download
    revision: 0.1.0
    value:
    key: "true"
    backend:
    context:
      provider: test
    id: $STORAGE_TI
    ENDOFFILE
    export DOWNLOAD_TI=$(capact ti create -f /tmp/download-ti.yaml -ojson | jq -r '.[] | select(.alias == "download") | .id')

    Error output message:

    Error: while executing mutation to create TypeInstances: All attempts fail:
    #1: graphql: failed to create the TypeInstances: 2 error occurred:
    * Error: External backend "2cc59261-41d4-4cd2-a96c-164bca9378b9": invalid input: context/provider must be equal to one of the allowed values
    * Error: rollback externally stored values: External backend "2cc59261-41d4-4cd2-a96c-164bca9378b9": invalid input: context/provider must be equal to one of the allowed values

Install Mattermost using the Helm storage:

  1. Create Helm storage input params:
    cat > /tmp/helm-storage-input-params.yaml << ENDOFFILE
    input-parameters: {}
    # Optional input parameters:
    # version: 0.6.0-bf8d006
    ENDOFFILE
  2. Follow the instruction for installation of the Helm storage from here and update the policy
  3. Follow the instruction for installation of the Mattermost from here

Related issue(s)