IBM Support

Part 4: GitOps Variables and testing templates

White Papers


Abstract

This tutorial series explains how to configure and use the DataPower GitOps variables object and its relationship with GitOps template objects. The GitOps variables object is used to define name value pairs. The names that are configured in the GitOps variables object can be used as replacement values in any property in a GitOps template. In Part 4, you learn how to develop and test GitOps templates that use GitOps variables and simulate writes and reads on the configured template with the template test button.

Content

Introduction

GitOps templates are designed to modify configuration for a specific device or environment. In Part 3 GitOps Advanced Configuration, a multi-environment  example was demonstrated using two different templates ProductionAddresses and DevelopmentAddresses. These templates differed only by transform value and otherwise modify the same subset of configuration. Introduced in 10.6.0.0, the GitOps variables object makes it possible to create one template for multiple environments. The differing transform values can be converted to variable references and each device can configure GitOps variable entries with the corresponding names, which resolve device-specific values. To aid in the development of GitOps templates, with and without GitOps variables, a Test button has been added to the Add Template form. The Test button runs a full write that is then read of the current template entry on the domains persisted config.

Using GitOps variables
The GitOps variables object contains a vector of name value pairs. Each entry in the vector is considered a variable. Using the example from the Introduction section we will be creating a new, environment independent, template called Addresses. This template will be used on both Production and Development environments.
First configuring variables on each device with environment-specific values.

Development environment, the GitOps variables object Production environment, the GitOps variables object
gitops-variables
  admin-state enabled
  variable Port 8080
  variable Backend "https://dev.sample.com:4433"
exit 
gitops-variables
  admin-state enabled
  variable Port 80
  variable Backend "https://prod.sample.com:443"
exit 
 
Since each device has a GitOps variables object containing the Port and Backend variables, each device is now capable of resolving templates that have any of the preceding variables by name.

Configuring GitOps templates that use variables
Starting on the Development environment we can create the new template Addresses:
gitops-template Addresses
    template change MultiProtocolGateway Sample_MPGW BackendURL $(Backend)
    template change HTTPSourceProtocolHandler Sample_FSH LocalPort $(Port)
exit
Note the new syntax of $(<variable-value>) within the template. Based on the environment the template is configured in, the values with resolve according to the GitOps variables definition.
Testing a GitOps template entry
To test these templates, the "Test" button runs a full end to end simulation of the selected template entry. First a temporary copy of the domains persisted config, as JSON, is generated. It is then run though a simulated GitOps Write. The output of the write is then run through a simulated GitOps Read.
Each full document along with reduced size-captured documents that contain just the relevant config for GitOps Write and Read are saved for viewing. For debugging, the simulation result is displayed along with the underlying JSONata generated located under a collapsed section titled See JSONata.

Using the UI either by adding a new template entry or editing the MultiProtocolGateway Sample_MPGW template entry, produces the following screenshot. Note that the Read value is referencing the template variable Backend by using the syntax $(<variable-value>). Testing this template and how it resolves on this device can be performed by clicking the button Test:
image-20240528150011-1
After clicking Test, two new sections appear. In the first collapsed section See JSONata one can see the ReadValues's variable is resolved according to the Development devices value for the Backend variable. This variable resolution is reflected in the transformation value of the Read Transformation section within the See JSONata output:
image-20240528150805-1
Following the See JSONata section is the Output section. This section contains the configuration from the Write and Read simulation. Note that the Write output toggle is selected and is displaying a captured version of the relevant config. In this case the output displays the BackendURL with the templated value {{ change_MultiProtocolGateway_Sample_MPGW_BackendUrl }} :
image-20240528160358-1
Clicking the Read toggle displays the simulated Read output, captured similarly to the Write capture but with the BackendURL resolved to "https://dev.sample.com:4433":
image-20240528160416-2
 
Full documents of the simulation are available as links in each section. These full documents include:
"Review Input Document" - Persisted domain config as JSON.
"Review full Document" when Write is toggled, represents the JSON config templated simulating what would be on Git Source on GitOps Write.
"Review full Document" when Read is toggled, represents the JSON config resolved simulating what would be be configured on DataPower on GitOps Read.
If a failure occurs, the test template form displays various diagnostic results. Such results, depending on the failure, can include any subset of the following sections:
  • Syntax errors on JSONata Read, Write, or Query expressions.
  • Transformation Error or Query Match errors when transforming the configuration.
  • Variable resolution errors before creating the JSONata expressions.
  • Read or Write output that match no results when a nodeset is expected.
In these events the See JSONata and Output section or when indicated, default logs are instrumental in determining the failure condition.

[{"Type":"MASTER","Line of Business":{"code":"LOB77","label":"Automation Platform"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SS9H2Y","label":"IBM DataPower Gateway"},"ARM Category":[{"code":"a8m3p000000F82EAAS","label":"DataPower-\u003EMGMT (MM)-\u003EConfiguration"}],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]

Document Information

Modified date:
21 February 2025

UID

ibm17153183