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

Add support for Kustomize patches to argocd_application #360

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
36529ba
argocd version updated to 2.9.2
chidambaram27 Dec 26, 2023
4e48621
support for kustomize patches added
chidambaram27 Dec 26, 2023
6913749
testcase updated
chidambaram27 Dec 26, 2023
2aa2648
go formatted
chidambaram27 Dec 26, 2023
1453657
test case value updated
chidambaram27 Dec 26, 2023
e493cd0
flattenApplicationSourceKustomize updated with patch config
chidambaram27 Dec 26, 2023
2a589ce
go lint issue fixed
chidambaram27 Dec 26, 2023
923e02f
flattenApplicationSourceKustomize return statement updated
chidambaram27 Dec 26, 2023
d049568
v2.9.2 added to the test
chidambaram27 Dec 27, 2023
1360a2a
testcase alignment formatted
chidambaram27 Dec 27, 2023
8564961
application schema updated
chidambaram27 Dec 27, 2023
57751de
Merge branch 'master' into feature/kustomize-patches
onematchfox Mar 23, 2024
98013ee
chore: tabs over spaces
onematchfox Mar 23, 2024
ba00bfc
feature flag added
chidambaram27 Mar 25, 2024
013d9bd
format updated
chidambaram27 Mar 25, 2024
5ac370a
Merge branch 'master' of ssh://github.com/oboukili/terraform-provider…
chidambaram27 Mar 26, 2024
452bb1e
typo fixed
chidambaram27 Mar 26, 2024
252d112
test case format updated
chidambaram27 Mar 26, 2024
47a5d13
structure applications updated
chidambaram27 Mar 28, 2024
cb9dcf0
fmt updated
chidambaram27 Mar 28, 2024
f8eef63
merge conflict resolved
chidambaram27 Sep 12, 2024
022810e
merge conflict resolved
chidambaram27 Sep 12, 2024
dc55c66
Merge branch 'feature/kustomize-patches' of https://github.com/chidam…
chidambaram27 Sep 12, 2024
110d98f
Merge branch 'feature/kustomize-patches' of https://github.com/chidam…
chidambaram27 Sep 12, 2024
dd81bbf
Merge branch 'feature/kustomize-patches' of https://github.com/chidam…
chidambaram27 Sep 12, 2024
f198831
Merge branch 'main' into feature/kustomize-patches
mkilchhofer Oct 23, 2024
ea2980f
Merge branch 'main' into feature/kustomize-patches
mkilchhofer Oct 24, 2024
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
16 changes: 8 additions & 8 deletions argocd/resource_argocd_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestAccArgoCDApplication_Helm_FileParameters(t *testing.T) {

func TestAccArgoCDApplication_Kustomize(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationKustomizePatches) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -1293,13 +1293,13 @@ resource "argocd_application" "helm_file_parameters" {
func testAccArgoCDApplicationKustomize(name string, path string, validate bool) string {
return fmt.Sprintf(`
resource "argocd_application" "kustomize" {
metadata {
name = "%s"
namespace = "argocd"
labels = {
acceptance = "true"
}
}
metadata {
name = "%s"
namespace = "argocd"
labels = {
acceptance = "true"
}
}

spec {
source {
Expand Down
71 changes: 71 additions & 0 deletions argocd/schema_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,77 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
Elem: &schema.Schema{Type: schema.TypeString},
ValidateFunc: validateMetadataAnnotations,
},
"patches": {
Type: schema.TypeList,
Description: "Patches is a list of Kustomize patches",
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"target": {
Type: schema.TypeSet,
Description: "Targets to Patch",
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kind": {
Type: schema.TypeString,
Description: "kind",
Optional: true,
},
"name": {
Type: schema.TypeString,
Description: "name",
Optional: true,
},
"label_selector": {
Type: schema.TypeString,
Description: "Label Selectors",
Optional: true,
},
"annotation_selector": {
Type: schema.TypeString,
Description: "Annotation Selectors",
Optional: true,
},
"group": {
Type: schema.TypeString,
Description: "group",
Optional: true,
},
"namespace": {
Type: schema.TypeString,
Description: "namespace",
Optional: true,
},
"version": {
Type: schema.TypeString,
Description: "version",
Optional: true,
},
},
},
},
"patch": {
Type: schema.TypeString,
Description: "patch",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"path": {
Type: schema.TypeString,
Description: "path",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"options": {
Type: schema.TypeMap,
Description: "options",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeBool},
},
},
},
},
},
},
},
Expand Down
82 changes: 81 additions & 1 deletion argocd/structure_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,61 @@ func expandApplicationSourceKustomize(in []interface{}) *application.Application
}
}

if patches, ok := a["patches"]; ok {
for _, v := range patches.([]interface{}) {
patchMap := v.(map[string]interface{})
kustomizePatch := application.KustomizePatch{}

if patch, ok := patchMap["patch"]; ok {
kustomizePatch.Patch = patch.(string)
}

if target, ok := patchMap["target"]; ok {
targetList := target.(*schema.Set).List()
if len(targetList) > 0 {
targetMap := targetList[0].(map[string]interface{})
kustomizeSelector := application.KustomizeSelector{
KustomizeResId: application.KustomizeResId{
KustomizeGvk: application.KustomizeGvk{},
},
}

if group, ok := targetMap["group"]; ok {
kustomizeSelector.KustomizeResId.KustomizeGvk.Group = group.(string)
}

if version, ok := targetMap["version"]; ok {
kustomizeSelector.KustomizeResId.KustomizeGvk.Version = version.(string)
}

if kind, ok := targetMap["kind"]; ok {
kustomizeSelector.KustomizeResId.KustomizeGvk.Kind = kind.(string)
}

if name, ok := targetMap["name"]; ok {
kustomizeSelector.KustomizeResId.Name = name.(string)
}

if namespace, ok := targetMap["namespace"]; ok {
kustomizeSelector.KustomizeResId.Namespace = namespace.(string)
}

if label_selector, ok := targetMap["label_selector"]; ok {
kustomizeSelector.LabelSelector = label_selector.(string)
}

if annotation_selector, ok := targetMap["annotation_selector"]; ok {
kustomizeSelector.AnnotationSelector = annotation_selector.(string)
}

kustomizePatch.Target = &kustomizeSelector
}
}

result.Patches = append(result.Patches, kustomizePatch)
}
}

return result
}

Expand Down Expand Up @@ -757,7 +812,32 @@ func flattenApplicationSourceKustomize(as []*application.ApplicationSourceKustom
images = append(images, string(i))
}

var patches []map[string]interface{}

for _, p := range a.Patches {
target := make(map[string]interface{})
if p.Target != nil {
target = map[string]interface{}{
"group": p.Target.KustomizeResId.KustomizeGvk.Group,
"version": p.Target.KustomizeResId.KustomizeGvk.Version,
"kind": p.Target.KustomizeResId.KustomizeGvk.Kind,
"name": p.Target.KustomizeResId.Name,
"namespace": p.Target.KustomizeResId.Namespace,
"label_selector": p.Target.LabelSelector,
"annotation_selector": p.Target.AnnotationSelector,
}
}

patches = append(patches, map[string]interface{}{
"patch": p.Patch,
"path": p.Path,
"options": p.Options,
"target": []map[string]interface{}{target},
})
}

result = append(result, map[string]interface{}{
"patches": patches,
"common_annotations": a.CommonAnnotations,
"common_labels": a.CommonLabels,
"images": images,
Expand All @@ -768,7 +848,7 @@ func flattenApplicationSourceKustomize(as []*application.ApplicationSourceKustom
}
}

return
return result
}

func flattenApplicationSourceHelm(as []*application.ApplicationSourceHelm) (result []map[string]interface{}) {
Expand Down
29 changes: 29 additions & 0 deletions docs/resources/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,37 @@ Optional:
- `images` (Set of String) List of Kustomize image override specifications.
- `name_prefix` (String) Prefix appended to resources for Kustomize apps.
- `name_suffix` (String) Suffix appended to resources for Kustomize apps.
- `patches` (Block List) Patches is a list of Kustomize patches (see [below for nested schema](#nestedblock--spec--source--kustomize--patches))
- `version` (String) Version of Kustomize to use for rendering manifests.

<a id="nestedblock--spec--source--kustomize--patches"></a>
### Nested Schema for `spec.source.kustomize.patches`

Required:

- `target` (Block Set, Min: 1) Targets to Patch (see [below for nested schema](#nestedblock--spec--source--kustomize--patches--target))

Optional:

- `options` (Map of Boolean) options
- `patch` (String) patch
- `path` (String) path

<a id="nestedblock--spec--source--kustomize--patches--target"></a>
### Nested Schema for `spec.source.kustomize.patches.target`

Optional:

- `annotation_selector` (String) Annotation Selectors
- `group` (String) group
- `kind` (String) kind
- `label_selector` (String) Label Selectors
- `name` (String) name
- `namespace` (String) namespace
- `version` (String) version




<a id="nestedblock--spec--source--plugin"></a>
### Nested Schema for `spec.source.plugin`
Expand Down
Loading
Loading