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

feat(tekton): Add support for CEL filtering #5531

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/IBM/cloudant-go-sdk v0.0.43
github.com/IBM/code-engine-go-sdk v0.0.0-20240126185534-a6e054aa01ed
github.com/IBM/container-registry-go-sdk v1.1.0
github.com/IBM/continuous-delivery-go-sdk v1.5.0
github.com/IBM/continuous-delivery-go-sdk v1.6.0
github.com/IBM/event-notifications-go-admin-sdk v0.6.1
github.com/IBM/eventstreams-go-sdk v1.4.0
github.com/IBM/go-sdk-core/v3 v3.2.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ github.com/IBM/code-engine-go-sdk v0.0.0-20240126185534-a6e054aa01ed h1:X0VrZW5u
github.com/IBM/code-engine-go-sdk v0.0.0-20240126185534-a6e054aa01ed/go.mod h1:m4pD/58c6NVzlAFkN3XCYXpmDFmUyTG31ivLy/loyHQ=
github.com/IBM/container-registry-go-sdk v1.1.0 h1:sYyknIod8R4RJZQqAheiduP6wbSTphE9Ag8ho28yXjc=
github.com/IBM/container-registry-go-sdk v1.1.0/go.mod h1:4TwsCnQtVfZ4Vkapy/KPvQBKFc3VOyUZYkwRU4FTPrs=
github.com/IBM/continuous-delivery-go-sdk v1.5.0 h1:FHSRruNt9WK7SavpIVuV6N+xll90UgZsuQjZvQ+slB4=
github.com/IBM/continuous-delivery-go-sdk v1.5.0/go.mod h1:nZdKUnubXNLo+zo28R4Rd+TGDqiJ/xoE8WO/A3kLw1E=
github.com/IBM/continuous-delivery-go-sdk v1.6.0 h1:eAL/jIWHrDFlWDF+Qd9Y5UN99Pr5Mjd/H/bvTbXUbz4=
github.com/IBM/continuous-delivery-go-sdk v1.6.0/go.mod h1:nZdKUnubXNLo+zo28R4Rd+TGDqiJ/xoE8WO/A3kLw1E=
github.com/IBM/event-notifications-go-admin-sdk v0.6.1 h1:85gB9evVX8AmNyd4Fh1O2G/0mgpt2HIQpyeWOoftEb4=
github.com/IBM/event-notifications-go-admin-sdk v0.6.1/go.mod h1:xRsMCxmPLXvmmWEXF8rshZlZgMrllPSiT9MBi4+Q6cs=
github.com/IBM/eventstreams-go-sdk v1.4.0 h1:yS/Ns29sBOe8W2tynQmz9HTKqQZ0ckse4Py5Oy/F2rM=
Expand Down
38 changes: 26 additions & 12 deletions ibm/service/cdtektonpipeline/data_source_ibm_cd_tekton_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func DataSourceIBMCdTektonPipeline() *schema.Resource {
"properties": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Optional trigger properties used to override or supplement the pipeline properties when triggering a pipeline run.",
Description: "Optional trigger properties are used to override or supplement the pipeline properties when triggering a pipeline run.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -320,7 +320,7 @@ func DataSourceIBMCdTektonPipeline() *schema.Resource {
"enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether the trigger is enabled.",
Description: "Flag to check if the trigger is enabled.",
},
"favorite": &schema.Schema{
Type: schema.TypeBool,
Expand Down Expand Up @@ -352,12 +352,12 @@ func DataSourceIBMCdTektonPipeline() *schema.Resource {
"branch": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Name of a branch from the repo. One of branch or pattern must be specified, but only one or the other.",
Description: "Name of a branch from the repo. Only one of branch, pattern, or filter should be specified.",
},
"pattern": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The pattern of Git branch or tag to which to listen. You can specify a glob pattern such as '!test' or '*master' to match against multiple tags/branches in the repository. The glob pattern used must conform to Bash 4.3 specifications, see bash documentation for more info: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching. One of branch or pattern must be specified, but only one or the other.",
Description: "The pattern of Git branch or tag. You can specify a glob pattern such as '!test' or '*master' to match against multiple tags or branches in the repository.The glob pattern used must conform to Bash 4.3 specifications, see bash documentation for more info: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching. Only one of branch, pattern, or filter should be specified.",
},
"blind_connection": &schema.Schema{
Type: schema.TypeBool,
Expand All @@ -367,7 +367,7 @@ func DataSourceIBMCdTektonPipeline() *schema.Resource {
"hook_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID of the webhook from the repo. Computed upon creation of the trigger.",
Description: "Repository webhook ID. It is generated upon trigger creation.",
},
"tool": &schema.Schema{
Type: schema.TypeList,
Expand All @@ -392,25 +392,30 @@ func DataSourceIBMCdTektonPipeline() *schema.Resource {
"events": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Only needed for Git triggers. List of events to which a Git trigger listens. Choose one or more from: 'push', 'pull_request' and 'pull_request_closed'. For SCM repositories that use 'merge request' events, such events map to the equivalent 'pull request' events.",
Description: "Either 'events' or 'filter' is required specifically for Git triggers. Stores a list of events that a Git trigger listens to. Choose one or more from 'push', 'pull_request', and 'pull_request_closed'. If SCM repositories use the 'merge request' term, they correspond to the generic term i.e. 'pull request'.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"filter": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Either 'events' or 'filter' can be used. Stores the CEL (Common Expression Language) expression value which is used for event filtering against the Git webhook payloads.",
},
"cron": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Only needed for timer triggers. Cron expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: 0 *_/2 * * * - every 2 hours.",
Description: "Only needed for timer triggers. CRON expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: The CRON expression 0 *_/2 * * * - translates to - every 2 hours.",
},
"timezone": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the cron activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones.",
Description: "Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the CRON activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones.",
},
"secret": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Only needed for generic webhook trigger type. Secret used to start generic webhook trigger.",
Description: "Only needed for Generic Webhook trigger type. The secret is used to start the Generic Webhook trigger.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand Down Expand Up @@ -496,17 +501,17 @@ func DataSourceIBMCdTektonPipeline() *schema.Resource {
"enable_notifications": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether to enable notifications for this pipeline. When enabled, pipeline run events will be published on all slack integration specified channels in the parent toolchain. If omitted, this feature is disabled by default.",
Description: "Flag to enable notifications for this pipeline. If enabled, the Tekton pipeline run events will be published to all the destinations specified by the Slack and Event Notifications integrations in the parent toolchain. If omitted, this feature is disabled by default.",
},
"enable_partial_cloning": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether to enable partial cloning for this pipeline. When partial clone is enabled, only the files contained within the paths specified in definition repositories are read and cloned, this means that symbolic links might not work. If omitted, this feature is disabled by default.",
Description: "Flag to enable partial cloning for this pipeline. When partial clone is enabled, only the files contained within the paths specified in definition repositories are read and cloned, this means that symbolic links might not work. If omitted, this feature is disabled by default.",
},
"enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether this pipeline is enabled.",
Description: "Flag to check if the trigger is enabled.",
},
},
}
Expand Down Expand Up @@ -810,6 +815,9 @@ func dataSourceIBMCdTektonPipelineTriggerToMap(model cdtektonpipelinev2.TriggerI
if model.Events != nil {
modelMap["events"] = model.Events
}
if model.Filter != nil {
modelMap["filter"] = model.Filter
}
if model.Cron != nil {
modelMap["cron"] = model.Cron
}
Expand Down Expand Up @@ -1005,6 +1013,9 @@ func dataSourceIBMCdTektonPipelineTriggerScmTriggerToMap(model *cdtektonpipeline
if model.Events != nil {
modelMap["events"] = model.Events
}
if model.Filter != nil {
modelMap["filter"] = model.Filter
}
return modelMap, nil
}

Expand Down Expand Up @@ -1101,5 +1112,8 @@ func dataSourceIBMCdTektonPipelineTriggerGenericTriggerToMap(model *cdtektonpipe
if model.WebhookURL != nil {
modelMap["webhook_url"] = model.WebhookURL
}
if model.Filter != nil {
modelMap["filter"] = model.Filter
}
return modelMap, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func TestAccIBMCdTektonPipelinePropertyDataSourceBasic(t *testing.T) {

func TestAccIBMCdTektonPipelinePropertyDataSourceAllArgs(t *testing.T) {
propertyName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100))
propertyValue := fmt.Sprintf("tf_value_%d", acctest.RandIntRange(10, 100))
propertyType := "text"
propertyValue := fmt.Sprintf("tf_value_%d", acctest.RandIntRange(10, 100))
propertyLocked := "true"
propertyPath := fmt.Sprintf("tf_path_%d", acctest.RandIntRange(10, 100))

Expand All @@ -47,7 +47,7 @@ func TestAccIBMCdTektonPipelinePropertyDataSourceAllArgs(t *testing.T) {
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig("", propertyName, propertyValue, propertyType, propertyLocked, propertyPath),
Config: testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig("", propertyName, propertyType, propertyValue, propertyLocked, propertyPath),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "id"),
resource.TestCheckResourceAttrSet("data.ibm_cd_tekton_pipeline_property.cd_tekton_pipeline_property", "pipeline_id"),
Expand Down Expand Up @@ -106,7 +106,7 @@ func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfigBasic(propertyPipeli
`, rgName, tcName)
}

func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig(propertyPipelineID string, propertyName string, propertyValue string, propertyType string, propertyLocked string, propertyPath string) string {
func testAccCheckIBMCdTektonPipelinePropertyDataSourceConfig(propertyPipelineID string, propertyName string, propertyType string, propertyValue string, propertyLocked string, propertyPath string) string {
rgName := acc.CdResourceGroupName
tcName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100))
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func DataSourceIBMCdTektonPipelineTrigger() *schema.Resource {
"properties": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Optional trigger properties used to override or supplement the pipeline properties when triggering a pipeline run.",
Description: "Optional trigger properties are used to override or supplement the pipeline properties when triggering a pipeline run.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -138,7 +138,7 @@ func DataSourceIBMCdTektonPipelineTrigger() *schema.Resource {
"enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Flag whether the trigger is enabled.",
Description: "Flag to check if the trigger is enabled.",
},
"favorite": &schema.Schema{
Type: schema.TypeBool,
Expand Down Expand Up @@ -170,12 +170,12 @@ func DataSourceIBMCdTektonPipelineTrigger() *schema.Resource {
"branch": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Name of a branch from the repo. One of branch or pattern must be specified, but only one or the other.",
Description: "Name of a branch from the repo. Only one of branch, pattern, or filter should be specified.",
},
"pattern": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The pattern of Git branch or tag to which to listen. You can specify a glob pattern such as '!test' or '*master' to match against multiple tags/branches in the repository. The glob pattern used must conform to Bash 4.3 specifications, see bash documentation for more info: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching. One of branch or pattern must be specified, but only one or the other.",
Description: "The pattern of Git branch or tag. You can specify a glob pattern such as '!test' or '*master' to match against multiple tags or branches in the repository.The glob pattern used must conform to Bash 4.3 specifications, see bash documentation for more info: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching. Only one of branch, pattern, or filter should be specified.",
},
"blind_connection": &schema.Schema{
Type: schema.TypeBool,
Expand All @@ -185,7 +185,7 @@ func DataSourceIBMCdTektonPipelineTrigger() *schema.Resource {
"hook_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID of the webhook from the repo. Computed upon creation of the trigger.",
Description: "Repository webhook ID. It is generated upon trigger creation.",
},
"tool": &schema.Schema{
Type: schema.TypeList,
Expand All @@ -210,25 +210,30 @@ func DataSourceIBMCdTektonPipelineTrigger() *schema.Resource {
"events": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Only needed for Git triggers. List of events to which a Git trigger listens. Choose one or more from: 'push', 'pull_request' and 'pull_request_closed'. For SCM repositories that use 'merge request' events, such events map to the equivalent 'pull request' events.",
Description: "Either 'events' or 'filter' is required specifically for Git triggers. Stores a list of events that a Git trigger listens to. Choose one or more from 'push', 'pull_request', and 'pull_request_closed'. If SCM repositories use the 'merge request' term, they correspond to the generic term i.e. 'pull request'.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"filter": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Either 'events' or 'filter' can be used. Stores the CEL (Common Expression Language) expression value which is used for event filtering against the Git webhook payloads.",
},
"cron": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Only needed for timer triggers. Cron expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: 0 *_/2 * * * - every 2 hours.",
Description: "Only needed for timer triggers. CRON expression that indicates when this trigger will activate. Maximum frequency is every 5 minutes. The string is based on UNIX crontab syntax: minute, hour, day of month, month, day of week. Example: The CRON expression 0 *_/2 * * * - translates to - every 2 hours.",
},
"timezone": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the cron activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones.",
Description: "Only used for timer triggers. Specify the timezone used for this timer trigger, which will ensure the CRON activates this trigger relative to the specified timezone. If no timezone is specified, the default timezone used is UTC. Valid timezones are those listed in the IANA timezone database, https://www.iana.org/time-zones.",
},
"secret": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Only needed for generic webhook trigger type. Secret used to start generic webhook trigger.",
Description: "Only needed for Generic Webhook trigger type. The secret is used to start the Generic Webhook trigger.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand Down Expand Up @@ -366,6 +371,10 @@ func dataSourceIBMCdTektonPipelineTriggerRead(context context.Context, d *schema
return diag.FromErr(fmt.Errorf("Error setting source %s", err))
}

if err = d.Set("filter", trigger.Filter); err != nil {
return diag.FromErr(fmt.Errorf("Error setting filter: %s", err))
}

if err = d.Set("cron", trigger.Cron); err != nil {
return diag.FromErr(fmt.Errorf("Error setting cron: %s", err))
}
Expand Down
Loading
Loading