Uploaded image for project: 'Service Binding'
  1. Service Binding
  2. APPSVC-1393

ServiceClass composite fields

XMLWordPrintable

    • Icon: Story Story
    • Resolution: Unresolved
    • Icon: Normal Normal
    • Primaza 0.1
    • None
    • Service Binding
    • None

      Owner: Architect:

      Francesco Ilario

      Story (Required)

      As a Service Administrator,
      I would like to compose data extracted from Resources
      so that I can create Composite data in RegisteredServices

      Background (Required)

      Given the following CRD

      apiVersion: mypsql.io/v1alpha1
      kind: MyPostgres
      spec: 
        port: 5432
        host: my-psql.my-cloud-provider.dev
      

      There is actually no way of having a field in the generated RegisteredService that uses the port and host to create a new field url: psql://my-psql.my-cloud-provider.dev:5432

      See epic for arch document link.

      Glossary

      See glossary in architecture document

      Out of scope

      NA

      In Scope

      • ServiceClass CRD changes
      • Using GoTemplate in ServiceClass data extraction

      Approach(Required)

      An example of ServiceClass as of now is the following

      apiVersion: primaza.io/v1alpha1
      kind: ServiceClass
      metadata: 
          name: myserviceclass
          namespace: services
      spec: 
          resource: 
              apiVersion: stable.example.com/v1
              kind: Backend
              serviceEndpointDefinitionMappings: 
                  resourceFields: 
                  - name: host
                    jsonPath: .spec.host
                    secret: false
          serviceClassIdentity: 
            - name: type
              value: backend
      

      We can update the resourceFields spec to support the following specifications

      resourceFields: 
        - name: url
          secret: false
          value: 
            template: "psql://{{.spec.host}}:{{.spec.port}}"
        - name: host
          secret: false
          value: 
            jsonPath: .spec.host
      

      The value field should have the kubebuilder constraints on mix and max properties set to 1, i.e.:

      // +kubebuilder:validation:MaxProperties:=1
      // +kubebuilder:validation:MinProperties:=1
      

      Using GoTemplates directly on the Service data structure or unstructured.Unstructured may result in inconsistent fields naming for the Primaza user.
      For mitigating this issue, we can unmarshal the JSON representation of the Service to a generic Go map, like in the following (not tested) snippet:

      t := template.Must(template.New("").Parse(templ))
      
      m := map[string]interface{}
      if err := json.Unmarshal([]byte(jsondata), &m); err != nil {
          return err
      }
      
      var buf bytes.Buffer
      w := bufio.NewWriter(&b)
      if err := t.Execute(w, m); err != nil {
          return err
      }
      

      Demo requirements(Required)

      NA

      Dependencies

      NA

      Edge Case

      NA

      BDD Tests

      You can find BDD Test specification for this story in the "Testing Instruction" Field Tab or in the GitHub Issue linked to this story.
      Click here for all BDD Tests Issues.

      Acceptance Criteria

      • Development
        ServiceClass CRD Updates
        Extract data using Go Template on Service JSON representation
      • QE
        There are test cases for data extracted using template field
      • Docs
        There is a section in our ServiceClass doc dedicated to explaining how to extract data using the template approach
        Update architecture document with any changes while implementing

      INVEST Checklist

      Dependencies identified
      Blockers noted and expected delivery timelines set
      Design is implementable
      Acceptance criteria agreed upon
      Story estimated

      Legend

      Unknown
      Verified
      Unsatisfied

              Unassigned Unassigned
              rh-ee-filario Francesco Ilario
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: