forked from hashicorp/hcp-terraform-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
313 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
internal/controller/workspace_controller_trigger_patterns.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package controller | ||
|
||
import ( | ||
tfc "github.com/hashicorp/go-tfe" | ||
appv1alpha2 "github.com/hashicorp/hcp-terraform-operator/api/v1alpha2" | ||
) | ||
|
||
// HELPERS | ||
|
||
// getTriggerPatterns return a map that maps consist of all trigger patterns defined in a object specification | ||
// and values 'true' to simulate the Set structure | ||
func getTriggerPatterns(instance *appv1alpha2.Workspace) map[string]bool { | ||
patterns := make(map[string]bool) | ||
|
||
if len(instance.Spec.TriggerPatterns) == 0 { | ||
return patterns | ||
} | ||
|
||
for _, t := range instance.Spec.TriggerPatterns { | ||
patterns[string(t)] = true | ||
} | ||
|
||
return patterns | ||
} | ||
|
||
// getWorkspaceTriggerPatterns return a map that maps consist of all trigger patterns assigned to workspace | ||
// and values 'true' to simulate the Set structure | ||
func getWorkspaceTriggerPatterns(workspace *tfc.Workspace) map[string]bool { | ||
patterns := make(map[string]bool) | ||
|
||
if len(workspace.TriggerPatterns) == 0 { | ||
return patterns | ||
} | ||
|
||
for _, t := range workspace.TriggerPatterns { | ||
patterns[t] = true | ||
} | ||
|
||
return patterns | ||
} | ||
|
||
// triggerPatternsDifference returns the list of trigger patterns that consists of the elements of leftTriggerPatterns | ||
// which are not elements of rightTriggerPatterns | ||
func triggerPatternsDifference(leftTriggerPatterns, rightTriggerPatterns map[string]bool) []string { | ||
var d []string | ||
|
||
for t := range leftTriggerPatterns { | ||
if !rightTriggerPatterns[t] { | ||
d = append(d, t) | ||
} | ||
} | ||
|
||
return d | ||
} |
Oops, something went wrong.