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

Tidy up syntax for passing additional parameters #450

Merged
merged 1 commit into from
Aug 24, 2021

Conversation

mszostok
Copy link
Member

@mszostok mszostok commented Aug 19, 2021

Description

Changed syntax

  1. Policy changes:
    • Changed syntax from map to list to unify syntax with additionalTypeInstances and requiredTypeInstances

    • Renamed inject.additionalInput to inject.additionalParameters

    • The name was previously hardcoded to additional-parameters

    • New feature: Support multiple input parameters on Implementation

      Before After
      inject:
        additionalInput:
          additional-parameters:
              replicaCount: 3
      inject:
        additionalParameters:
          - name: rds-parameters
            value:
              replicaCount: 3
  2. Implementation OCF changes:
    • Require parameter name same as we have for additional TypeInstances

      Before After
      additionalInput:
        parameters:
          typeRef:
            path: cap.type.aws.rds.install-input
            revision: 0.1.0
      additionalInput:
        parameters:
          rds-parameters:
            typeRef:
              path: cap.type.aws.rds.install-input
              revision: 0.1.0

Changes proposed in this pull request:

Out of scope:

  • Additional coverage for TestResolveTypeRefsToJSONSchemasFailures (non happy path) - thanks to that I found bug that we ignored errors in non-happy path.
  • Additional coverage for TestValidateImplementationParameters
  • Fix bug in db populator. We ignored required verbs for additionalInput.typeInstances,
    • error: #1: graphql: Cannot return null for non-nullable field InputTypeInstance.verbs.
    • query for debugging:
       MATCH (n:InputTypeInstance)<-[:CONTAINS]-(impl:ImplementationAdditionalInput)<-[:USES]-(spec: ImplementationSpec)<-[:SPECIFIED_BY]-(rev: ImplementationRevision)-[:DESCRIBED_BY]->(meta: ImplementationMetadata)  RETURN n.name, n.verbs, n, rev, meta
      Screenshot 2021-08-20 at 12 49 22
      Here is diff, tbh I don't understand why GH doesn't show this change: 64f556a#diff-81d3dd9650f4d66d745d9ccb905dbc589f1b0e46483c9c24367960cb060b5b2bR317-R318
  • Create policy always when necessary: Fix creating Action Policy, replace gotest.tools with testify and unify cmds naming #457

Testing

  1. Checkout PR, and create cluster make dev-cluster.

  2. Update Global Policy via GraphQL:

    mutation UpdatePolicy {
    updatePolicy(
    in: {
    rules: [
    {
    interface: {
    path: "cap.interface.capactio.capact.validation.hub.install"
    }
    oneOf: [
    {
    implementationConstraints: {
    path: "cap.implementation.capactio.capact.validation.io.install"
    }
    inject: {
    additionalParameters: [
    {
    name: "mattermost-parameters"
    value: { revisionHistoryLimit: 123 }
    }
    {
    name: "rocketchat-parameters"
    value: { replicaCount: 3 }
    }
    ]
    }
    }
    {
    implementationConstraints: {
    requires: { path: "cap.core.type.platform.kubernetes" }
    }
    }
    ]
    }
    {
    interface: { path: "cap.*" }
    oneOf: [
    {
    implementationConstraints: {
    requires: { path: "cap.core.type.platform.kubernetes" }
    }
    }
    {}
    ]
    }
    ]
    }
    ) {
    ...PolicyFields
    }
    }

    1. or Capact CLI:
    cat > /tmp/policy.yaml << ENDOFFILE
    rules:
      - interface:
          path: "cap.interface.capactio.capact.validation.hub.install"
        oneOf:
          - implementationConstraints:
              path: "cap.implementation.capactio.capact.validation.io.install"
            inject:
              additionalParameters:
                - name: mattermost-parameters
                  value:
                    revisionHistoryLimit: 123
                - name: rocketchat-parameters
                  value:
                    replicaCount: 3
    
      - interface:
          path: cap.*
        oneOf:
          - implementationConstraints:
              requires:
                - path: "cap.core.type.platform.kubernetes"
          - implementationConstraints: {} # fallback to any Implementation
    ENDOFFILE
    
    capact policy apply -f /tmp/policy.yaml
  3. Create Action Policy:

    cat <<EOF > /tmp/act-policy.yaml
    rules:
      - interface:
          path: cap.interface.capactio.capact.validation.hub.install
        oneOf:
          - implementationConstraints:
              path: "cap.implementation.capactio.capact.validation.io.install"
            inject:
              additionalParameters:
                - name: "mattermost-parameters"
                  value:
                    replicaCount: 3
                - name: "rocketchat-parameters"
                  value:
                    replicaCount: 5
    EOF
  4. Create Action with the given policy via Capact CLI:

    capact act create cap.interface.capactio.capact.validation.hub.install --name test --action-policy-from-file /tmp/act-policy.yaml
  5. Wait until READY_TO_RUN: watch -n 1 capact action get test

  6. Run Action: capact act run test

  7. Watch Action : capact act watch test

  8. Check logs argo logs test -n default.
    Expected, that the mattermost-parameters values are merged, and rocketchat-parameters has overwritten replicaCount.

    Example:

    test-2994129991: optional postgresql TypeInstance was not specified
    test-3931835117: cat /mattermost-parameters.yaml
    test-3931835117: replicaCount: 3
    test-3931835117: revisionHistoryLimit: 123
    test-3931835117: cat /rocketchat-parameters.yaml
    test-3931835117: replicaCount: 5

Related issue(s)

@mszostok mszostok added WIP Work in progress breaking Contains breaking change area/engine Relates to Engine area/hub Relates to Hub area/ocf Relates to Open Capability Format labels Aug 19, 2021
@mszostok mszostok force-pushed the policy/additional-params branch 2 times, most recently from 39a376d to db5b226 Compare August 19, 2021 10:31
@mszostok mszostok force-pushed the policy/additional-params branch from 116394a to 36d0060 Compare August 20, 2021 08:52
@pkosiec pkosiec self-assigned this Aug 23, 2021
@mszostok mszostok force-pushed the policy/additional-params branch from 36d0060 to 64f556a Compare August 23, 2021 11:32
@mszostok mszostok removed the WIP Work in progress label Aug 23, 2021
@mszostok
Copy link
Member Author

FYI: I will update our generator or we will update it here: #447
Depends what will be first.

pkg/engine/api/graphql/schema.graphql Outdated Show resolved Hide resolved
pkg/engine/api/graphql/schema.graphql Outdated Show resolved Hide resolved
ocf-spec/0.0.1/schema/implementation.json Outdated Show resolved Hide resolved
pkg/sdk/validation/action/io_validator.go Outdated Show resolved Hide resolved
pkg/sdk/validation/action/io_validator.go Show resolved Hide resolved
pkg/sdk/validation/action/io_validator.go Outdated Show resolved Hide resolved
hack/lib/const.sh Show resolved Hide resolved
Copy link
Member

@pkosiec pkosiec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, works like a charm. Just a few really minor comments.

@mszostok mszostok force-pushed the policy/additional-params branch from 054233e to fffa319 Compare August 24, 2021 13:25
@mszostok mszostok mentioned this pull request Aug 24, 2021
@mszostok mszostok force-pushed the policy/additional-params branch 2 times, most recently from baf48fb to ef7409b Compare August 24, 2021 14:33
Add option to specify names for additional input parameters

* Update APIs (GraphQL, OCF schemas)
* Update validator
* Update populator

* Additional coverage for TestResolveTypeRefsToJSONSchemasFailures (non happy path)
* Additional coverage for TestValidateImplementationParameters

wip

Adjust validator, policy schema, engine, renderer part

Add ParametersCollection, remove todo, update manifest source

Update schemas, fix db populator, fix client

Run make generate

Update e2e test expected len after addding new Implementation manifest

Apply suggestion after review
@mszostok mszostok force-pushed the policy/additional-params branch from ef7409b to e69dfe6 Compare August 24, 2021 14:51
@mszostok mszostok merged commit 40de869 into capactio:main Aug 24, 2021
@mszostok mszostok deleted the policy/additional-params branch August 24, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/engine Relates to Engine area/hub Relates to Hub area/ocf Relates to Open Capability Format breaking Contains breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants