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

Ability to Pass patches to argo application crd #369

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
Expand All @@ -32,4 +33,4 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
9 changes: 1 addition & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ builds:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
targets:
- darwin_arm64
- darwin_amd64
- linux_amd64
- linux_arm
- linux_arm64
- windows_amd64
- windows_arm
- freebsd_amd64
- freebsd_arm
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip
Expand All @@ -38,7 +31,7 @@ release:
draft: true
disable: false
github:
owner: oboukili
owner: Facets-cloud
name: terraform-provider-argocd
changelog:
skip: false
Expand Down
17 changes: 17 additions & 0 deletions argocd/schema_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,23 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
Elem: &schema.Schema{Type: schema.TypeString},
ValidateFunc: validateMetadataAnnotations,
},
"patches": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"target": {
Type: schema.TypeMap,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"patch": {
Type: schema.TypeString,
Required: true,
},
},
},
},
},
},
},
Expand Down
71 changes: 71 additions & 0 deletions argocd/structure_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,46 @@
}
}

if patches, ok := a["patches"]; ok {
result.Patches = application.KustomizePatches{}
patchList := patches.([]interface{})
for _, patchItem := range patchList {

Check failure on line 240 in argocd/structure_application.go

View workflow job for this annotation

GitHub Actions / Build

only one cuddle assignment allowed before range statement (wsl)
patchMap := patchItem.(map[string]interface{})

patch := application.KustomizePatch{}
safeGet := func(m map[string]interface{}, key string, val string) string {
if value, ok := m[key]; ok {
return value.(string)
}
return val // default value if key is not present

Check failure on line 248 in argocd/structure_application.go

View workflow job for this annotation

GitHub Actions / Build

return statements should not be cuddled if block has more than two lines (wsl)
}
// Handling of the target field
if target, tOk := patchMap["target"]; tOk {
targetMap := target.(map[string]interface{})
patch.Target = &application.KustomizeSelector{
KustomizeResId: application.KustomizeResId{
KustomizeGvk: application.KustomizeGvk{
Group: safeGet(targetMap, "group", ""),
Version: safeGet(targetMap, "version", ""),
Kind: safeGet(targetMap, "kind", ""),
},
Name: safeGet(targetMap, "name", ""),
Namespace: safeGet(targetMap, "namespace", ""),
},
AnnotationSelector: safeGet(targetMap, "annotationSelector", ""),
LabelSelector: safeGet(targetMap, "labelSelector", ""),
}
}

// Handling of the patch string
if patchStr, pStrOk := patchMap["patch"]; pStrOk {
patch.Patch = patchStr.(string)
}

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

return result
}

Expand Down Expand Up @@ -745,18 +785,49 @@
images = append(images, string(i))
}

// Assuming result.Patches is the slice of KustomizePatch you want to convert
patches := make([]interface{}, 0)

for _, patch := range a.Patches {
patchMap := make(map[string]interface{})

// Convert the target field back to map
if patch.Target != nil {
targetMap := map[string]string{
"group": patch.Target.KustomizeResId.KustomizeGvk.Group,
"version": patch.Target.KustomizeResId.KustomizeGvk.Version,
"kind": patch.Target.KustomizeResId.KustomizeGvk.Kind,
"name": patch.Target.KustomizeResId.Name,
"namespace": patch.Target.KustomizeResId.Namespace,
"annotationSelector": patch.Target.AnnotationSelector,
"labelSelector": patch.Target.LabelSelector,
}
patchMap["target"] = targetMap
}

// Convert the patch string back
if patch.Patch != "" {
patchMap["patch"] = patch.Patch
}

patches = append(patches, patchMap)
}

// `a` is now the map representation of the KustomizePatches

result = append(result, map[string]interface{}{
"common_annotations": a.CommonAnnotations,
"common_labels": a.CommonLabels,
"images": images,
"name_prefix": a.NamePrefix,
"name_suffix": a.NameSuffix,
"version": a.Version,
"patches": patches, //TODO implement this
})
}
}

return

Check failure on line 830 in argocd/structure_application.go

View workflow job for this annotation

GitHub Actions / Build

naked return in func `flattenApplicationSourceKustomize` with 51 lines of code (nakedret)
}

func flattenApplicationSourceHelm(as []*application.ApplicationSourceHelm) (result []map[string]interface{}) {
Expand Down
69 changes: 43 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/ProtonMail/gopenpgp/v2 v2.7.1
github.com/argoproj/argo-cd/v2 v2.8.8
github.com/argoproj/argo-cd/v2 v2.9.6
github.com/argoproj/gitops-engine v0.7.3
github.com/argoproj/pkg v0.13.7-0.20230627120311-a4dd357b057e
github.com/cristalhq/jwt/v3 v3.1.0
Expand All @@ -23,8 +23,8 @@ require (
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.17.0
k8s.io/apiextensions-apiserver v0.24.2
k8s.io/apimachinery v0.24.2
k8s.io/client-go v0.24.2
k8s.io/apimachinery v0.24.17
k8s.io/client-go v0.24.17
)

require (
Expand All @@ -43,24 +43,37 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/PagerDuty/go-pagerduty v1.6.0 // indirect
github.com/PagerDuty/go-pagerduty v1.7.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20210112200207-10ab4d695d60 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/alicebob/miniredis/v2 v2.30.3 // indirect
github.com/antonmedv/expr v1.12.5 // indirect
github.com/alicebob/miniredis/v2 v2.30.4 // indirect
github.com/antonmedv/expr v1.15.2 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/argoproj/notifications-engine v0.4.1-0.20230620204159-3446d4ae8520 // indirect
github.com/argoproj/notifications-engine v0.4.1-0.20230905144632-9dcecdc3eebf // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.3 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.8 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.28 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.21 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.20.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.0 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect
github.com/bombsimon/logrusr/v2 v2.0.1 // indirect
github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 // indirect
github.com/casbin/casbin/v2 v2.71.1 // indirect
github.com/bradleyfalzon/ghinstallation/v2 v2.6.0 // indirect
github.com/casbin/casbin/v2 v2.77.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
Expand Down Expand Up @@ -94,27 +107,27 @@ require (
github.com/go-openapi/strfmt v0.21.7 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/go-playground/webhooks/v6 v6.3.0 // indirect
github.com/go-redis/cache/v9 v9.0.0 // indirect
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogits/go-gogs-client v0.0.0-20190616193657-5a05380e4bc2 // indirect
github.com/gogits/go-gogs-client v0.0.0-20200905025246-8bb8a50cb355 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-github/v41 v41.0.0 // indirect
github.com/google/go-github/v53 v53.0.0 // indirect
github.com/google/go-github/v53 v53.2.0 // indirect
github.com/google/go-jsonnet v0.20.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gregdel/pushover v1.1.0 // indirect
github.com/gregdel/pushover v1.2.1 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
Expand All @@ -141,6 +154,8 @@ require (
github.com/imdario/mergo v0.3.16 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/gojq v0.12.13 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down Expand Up @@ -168,7 +183,7 @@ require (
github.com/oklog/run v1.0.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc.3 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opsgenie/opsgenie-go-sdk-v2 v1.0.5 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
Expand All @@ -188,11 +203,14 @@ require (
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/slack-go/slack v0.12.1 // indirect
github.com/slack-go/slack v0.12.2 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vmihailenco/go-tinylfu v0.2.2 // indirect
Expand Down Expand Up @@ -229,36 +247,35 @@ require (
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/go-playground/webhooks.v5 v5.17.0 // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.24.2 // indirect
k8s.io/apiserver v0.24.2 // indirect
k8s.io/cli-runtime v0.24.2 // indirect
k8s.io/component-base v0.24.2 // indirect
k8s.io/component-helpers v0.24.2 // indirect
k8s.io/api v0.24.17 // indirect
k8s.io/apiserver v0.24.17 // indirect
k8s.io/cli-runtime v0.24.17 // indirect
k8s.io/component-base v0.24.17 // indirect
k8s.io/component-helpers v0.24.17 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-aggregator v0.24.2 // indirect
k8s.io/kube-openapi v0.0.0-20220627174259-011e075b9cb8 // indirect
k8s.io/kubectl v0.24.2 // indirect
k8s.io/kubernetes v1.24.15 // indirect
k8s.io/kubernetes v1.24.17 // indirect
k8s.io/utils v0.0.0-20220706174534-f6158b442e7c // indirect
layeh.com/gopher-json v0.0.0-20190114024228-97fed8db8427 // indirect
oras.land/oras-go/v2 v2.2.0 // indirect
oras.land/oras-go/v2 v2.3.0 // indirect
sigs.k8s.io/controller-runtime v0.11.0 // indirect
sigs.k8s.io/json v0.0.0-20220525155127-227cbc7cc124 // indirect
sigs.k8s.io/kustomize/api v0.11.5 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.7 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace (
// https://github.com/argoproj/gitops-engine/issues/447
github.com/argoproj/gitops-engine => github.com/argoproj/gitops-engine v0.7.1-0.20230607163028-425d65e07695
github.com/argoproj/gitops-engine => github.com/argoproj/gitops-engine v0.7.1-0.20230906152414-b0fffe419a0f

// https://github.com/golang/go/issues/33546#issuecomment-519656923
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
Expand Down
Loading
Loading