Skip to content

Commit

Permalink
code-refactoring: adding utility and helper functions (argoproj-labs#…
Browse files Browse the repository at this point in the history
…1228)

* fix: don't set phase to available during host reconciliation  (argoproj-labs#918)

* upgrade golangci-lint

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* fix phase reconciliation during host reconciliation

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* address review comment

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* set phase to pending if ingress not found

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

---------

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* update owners file (argoproj-labs#953)

* Move to only adding two roles for managed namespaces (argoproj-labs#954)

* Move to only adding two roles for managed namespaces
---------

Signed-off-by: Salem Elrahal <selrahal@redhat.com>
Co-authored-by: Salem Elrahal <selrahal@redhat.com>

* feat: expose operator metrics  (argoproj-labs#928)

Track and expose custom operator performance metrics
---------

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* add build.os config for readthedocs (argoproj-labs#967)

* setup 0.8.0 (argoproj-labs#966)

* feat: Add conversion webhook for ArgoCD v1alpha1 to v1beta1 migration (argoproj-labs#964)

* Add ArgoCD v1beta1 & deprecate v1alpha1

- Add new ArgoCD v1beta1 api
- Mark ArgoCD v1alpha1 as deprecated & add back the removed sso fields
- Use server side validation for "kubectl apply" as client side results into
  failure due to exceeding annotation size limit.

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Add funcs for ArgoCD alpha to beta conversion

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Add conversion webhook

- Create webhook & setup webhook server on 9443
- Disable operator namespaced install via OLM so that OLM can handle certs for webhook server
- For manual install, user needs to explicitly configure cert manager to inject certs and enable
  webhook server in operator by setting env ENABLE_CONVERSION_WEBHOOK="true"

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Resolve local build issues

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Tweak webhook configs

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Update operator installation docs

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Add e2e tests

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Minor updates

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Fix go-lint ci failure

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Update docs

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Remove webhook from 0.7.0 bundle

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

Add spaces in bundle

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* update 0.8.0 bundle

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

---------

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* chore(deps): bump pygments from 2.7.4 to 2.15.0 in /docs (argoproj-labs#950)

Bumps [pygments](https://github.com/pygments/pygments) from 2.7.4 to 2.15.0.
- [Release notes](https://github.com/pygments/pygments/releases)
- [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES)
- [Commits](pygments/pygments@2.7.4...2.15.0)

---
updated-dependencies:
- dependency-name: pygments
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: upgrade RH-SSO from 7.5 to 7.6 (argoproj-labs#977)

* upgrade RH-SSO from 7.5 to 7.6

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

* fix: failing tests

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

* fix: failing tests

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

---------

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

* refactor: Remove dead code (argoproj-labs#979)

* Remove dead code

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Fix import

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Fix imports

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

---------

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Replace ArgoCD v1alpha1 references with v1beta1 (argoproj-labs#975)

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* refactor: Remove deprecated .spec.resourceCustomizations (argoproj-labs#973)

* Remove .spec.resourceCustomizations code

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Update docs

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Update docs

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Address review comments

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Fix typo

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

---------

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* upgrade ArgoCD version to 2.8.2 and update the CRDs (argoproj-labs#984)

* upgrade ArgoCD version to 2.8.2 and update the CRDs

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Update argocd image

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

---------

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* chore: Update ArgoCD v1alpha1 deprecation message (argoproj-labs#988)

* Update ArgoCD v1alpha1 deprecation message

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Run code gen

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

---------

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Add support for tls self signed certs in AppSet Gitlab SCM Provider (argoproj-labs#985)

* add support for tls self signed certs in AppSet Gitlab SCM Provider

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* add e2e test

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* add unit tests

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* renamed field ScmRootCaPath to SCMRootCaPath

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Add documentation and address comments

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Address comments

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

---------

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* chore(deps): bump github.com/argoproj/argo-cd/v2 from 2.8.2 to 2.8.3 (argoproj-labs#992)

Bumps [github.com/argoproj/argo-cd/v2](https://github.com/argoproj/argo-cd) from 2.8.2 to 2.8.3.
- [Release notes](https://github.com/argoproj/argo-cd/releases)
- [Changelog](https://github.com/argoproj/argo-cd/blob/master/CHANGELOG.md)
- [Commits](argoproj/argo-cd@v2.8.2...v2.8.3)

---
updated-dependencies:
- dependency-name: github.com/argoproj/argo-cd/v2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: pick up argo cd v2.8.3 (argoproj-labs#993)

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

* fix: replace deprecated syntax in kustomization.yaml (argoproj-labs#1000)

Signed-off-by: minchao <minchao.220@gmail.com>

* Missing syntax-highlighting, toggle button for screen mode in argocd-operator docs (argoproj-labs#1002)

* Update requirements.txt

added markdown= 3.3.7 and  markdown-include=0.6.0

Signed-off-by: Surajyadav <harrypotter1108@gmail.com>

* Delete docs/assets/extra.css

deleted extra.css

Signed-off-by: Surajyadav <harrypotter1108@gmail.com>

* Update mkdocs.yml

added markdown_extension  markdown_include with  codehighlight and toggle for screen mode

Signed-off-by: Surajyadav <harrypotter1108@gmail.com>

* Update mkdocs.yml

Signed-off-by: Surajyadav <harrypotter1108@gmail.com>

---------

Signed-off-by: Surajyadav <harrypotter1108@gmail.com>

* fix: keycloak probes failure and intermittent perforamance issues (argoproj-labs#1007)

* fix: keycloak probes failure results in pod crash

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

* fix: use latest keycloak image to handle performance issue

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

---------

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

* bug: fix heathcheck subkey generation for resources with no group  (argoproj-labs#1013)

* account for empty group during resource customization config subkey generation

---------

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* chore(deps): bump golang.org/x/net from 0.11.0 to 0.17.0 (argoproj-labs#1019)

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.11.0 to 0.17.0.
- [Commits](golang/net@v0.11.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add labelSelector option to filter the ArgoCD instances for reconciliation (argoproj-labs#961)

* Added labelselector string to map conversion

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Changed data-type for labelSelector to parse string

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Added code to reconcile selected ArgoCD instances based on label selector

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* remove comments

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Updated argoCD label fetch, renamed env var

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Updated unit test and yaml

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Updated unit test

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Fix yaml env ValueFrom field

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Added comments and labelSelector check in main.go

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* removed label-selector option from manifest

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* updated label-selector format in manifests

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* added label selector logs

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* go mod tidy

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* added e2e tests for label-selector

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* restructured kuttl files and added operator patch file

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* go mod tidy

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* corrected kuttl tests for cm failure

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Added documentation for Environment Variable ARGOCD_LABEL_SELECTOR

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* cleanup

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* improved unit tests and some minor changes

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* kuttl rerun

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* removed env var

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* misc modifications

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* argocd-operator csv correction

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* fix bundle error

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* fix bundle error

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* fix manifests build

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: Ishita Sequeira <ishiseq29@gmail.com>
Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Added more unit test cases

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* rebase

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* removed excess reconcilers

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* minor fix

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* removed extraneous test case and cleaned manager.yaml

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* cleaned manager.yaml

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* fix make bundle issue

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* fix make bundle issue

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

---------

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: Ishita Sequeira <ishiseq29@gmail.com>
Co-authored-by: ishitasequeira <ishiseq29@gmail.com>

* fix: address CVE-2023-39325 (argoproj-labs#1022)

*address CVE-2023-39325
- upgrade to golang v1.20.10
- disable http/2 for webhook and metrics server, use http/1.1 by default but make it a configurable flag
- upgarde k8s library packages to v0.28.3
- Add new structs for keycloak API that were previously part of the (now deprecated) keycloak-operator repo
- upgrade to controller-runtime to v0.16.3
- refactor all unit tests

---------

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* Add gcp cherry-pick bot config (argoproj-labs#1023)

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* Add .github/dependabot.yml to enable auto dependency version updates (argoproj-labs#1025)

* feat(dex): add optional env field (argoproj-labs#1005)

* feat(dex): add optional env field

Signed-off-by: Robert Deusser <robertjdeusser@gmail.com>

* fix: remove non-default configuration

Signed-off-by: Robert Deusser <robertjdeusser@gmail.com>

* fix: v1alpha1 is deprecated

Signed-off-by: Robert Deusser <robertjdeusser@gmail.com>

* fix: convert dex spec between api versions

Signed-off-by: Robert Deusser <robertjdeusser@gmail.com>

* fix: ensure there is no diff in the bundle

Signed-off-by: Robert Deusser <robertjdeusser@gmail.com>

---------

Signed-off-by: Robert Deusser <robertjdeusser@gmail.com>

* fix: replace deprecated AddToScheme with Install, and deprecated SchemeGroupVersion with GroupVersion. (argoproj-labs#1066)

Signed-off-by: Cheng Fang <cfang@redhat.com>

* allow enabling ArgoCD workloads independently (argoproj-labs#1021)

* allow enabling ArgoCD core workloads independently

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix lint

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* check for dependent component urls if dependent components are disabled

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix build

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix make bundle

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix tests

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Update flags for each component

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Update configuration using remote flag

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix CI

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Address comments

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Addressed feedback

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* update conversion webhook

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix make build

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

---------

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* chore(deps): bump argoproj/argocd in /build/util (argoproj-labs#1080)

Bumps argoproj/argocd from `d40da8f` to `644c386`.

---
updated-dependencies:
- dependency-name: argoproj/argocd
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: upgrade Argo CD for release v.9.0 (argoproj-labs#1082)

* feat: upgrade Argo CD for release v.9.0

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

* fix: unit test failures

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

---------

Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>

* fix the logic for applicationset resources reconcilation when spec.applicationset.enabled is false (argoproj-labs#1089)

* fix the logic for applicationset resources reconciliation when spec.applicationset.enabled is false

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>
Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix tests

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>
Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* delete repo server when repo.enabled is set to false

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>
Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Update status.Phase based on component enabled flag

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>
Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Added kuttl tests

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Added namespace creation step

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* delete services created for resources

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* delete server deployment when enabled flag set to false

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix e2e test

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix log message

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* revert kuttl test timeout

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Added test for reverse scenario

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Dir rename

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

* Added e2e test for ha mode

Signed-off-by: Raghavi Shirur <rshirur@redhat.com>

---------

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>
Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Co-authored-by: Raghavi Shirur <rshirur@redhat.com>

* docs: enabling/disabling individual argocd core components (argoproj-labs#1098)

* Add documentation for enabling/disabling argocd core components

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* rephrase doc

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* Address comments

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

---------

Signed-off-by: ishitasequeira <ishiseq29@gmail.com>

* fix: Proper reference to where to find default admin password (argoproj-labs#1094)

Signed-off-by: ikegentz <isaac.gentz@gmail.com>

* adding applicationsets in server rbac policy rule (argoproj-labs#1140)

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* remove extra argoutils

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* fix logic to allow processor operation to be less than default value (argoproj-labs#1146)

* fix logic to allow operation processors to be less than default value

---------

Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>

* Use correct repo-server address for notification controller (argoproj-labs#1125)

Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>

* remove notifs files

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

* separating general code from configmaps

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>

---------

Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>
Signed-off-by: Salem Elrahal <selrahal@redhat.com>
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: iam-veeramalla <abhishek.veeramalla@gmail.com>
Signed-off-by: ishitasequeira <ishiseq29@gmail.com>
Signed-off-by: minchao <minchao.220@gmail.com>
Signed-off-by: Surajyadav <harrypotter1108@gmail.com>
Signed-off-by: Raghavi Shirur <rshirur@redhat.com>
Signed-off-by: Ishita Sequeira <ishiseq29@gmail.com>
Signed-off-by: Robert Deusser <robertjdeusser@gmail.com>
Signed-off-by: Cheng Fang <cfang@redhat.com>
Signed-off-by: ikegentz <isaac.gentz@gmail.com>
Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
Co-authored-by: Regina Scott <50851526+reginapizza@users.noreply.github.com>
Co-authored-by: Salem Elrahal <salemelrahal@gmail.com>
Co-authored-by: Salem Elrahal <selrahal@redhat.com>
Co-authored-by: Siddhesh Ghadi <61187612+svghadi@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhishek Veeramalla <abhishek.veeramalla@gmail.com>
Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Co-authored-by: Minchao <minchao.220@gmail.com>
Co-authored-by: Suraj yadav <harrypotter1108@gmail.com>
Co-authored-by: Raghavi <rshirur@redhat.com>
Co-authored-by: ishitasequeira <ishiseq29@gmail.com>
Co-authored-by: Cheng Fang <cfang@redhat.com>
Co-authored-by: Robert Deusser <5935071+rdeusser@users.noreply.github.com>
Co-authored-by: Isaac Gentz <isaac.gentz@gmail.com>
Co-authored-by: Mangaal <44372157+Mangaal@users.noreply.github.com>
Co-authored-by: Anand Kumar Singh <anandrkskd@gmail.com>
  • Loading branch information
17 people authored and Julia Teslia committed Apr 24, 2024
1 parent 1a1872d commit 676e7e8
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 4 deletions.
3 changes: 3 additions & 0 deletions common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ const (
// ArgoCDDefaultRSAKeySize is the default RSA key size when not specified.
ArgoCDDefaultRSAKeySize = 2048

// ArgoCDDefaultServer is the default server address
ArgoCDDefaultServer = "https://kubernetes.default.svc"

// ArgoCDDefaultSSHKnownHosts is the default SSH Known hosts data.
ArgoCDDefaultSSHKnownHosts = `[ssh.github.com]:443 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
[ssh.github.com]:443 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
Expand Down
10 changes: 8 additions & 2 deletions common/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ const (
// ArgoCDKeyTLSCACert is the key for TLS CA certificates.
ArgoCDKeyTLSCACert = "ca.crt"

// ArgoCDPolicyMatcherMode is the key for matchers function for casbin.
// ArgoCDKeyPolicyMatcherMode is the key for matchers function for casbin.
// There are two options for this, 'glob' for glob matcher or 'regex' for regex matcher.
ArgoCDPolicyMatcherMode = "policy.matchMode"
ArgoCDKeyPolicyMatcherMode = "policy.matchMode"

// ArgoCDKeyUsersAnonymousEnabled is the configuration key for anonymous user access.
ArgoCDKeyUsersAnonymousEnabled = "users.anonymous.enabled"

<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
// ArgoCDDexImageEnvName is the environment variable used to get the image
Expand Down Expand Up @@ -179,8 +180,13 @@ const (
ArgoCDDefaultServer = "https://kubernetes.default.svc"

>>>>>>> ae37d0a (retain old and new constants. .github folder changes, fix errors (#1133))
=======
>>>>>>> 52e4741 (code-refactoring: adding utility and helper functions (#1228))
// ArgoCDDexSecretKey is used to reference Dex secret from Argo CD secret into Argo CD configmap
ArgoCDDexSecretKey = "oidc.dex.clientSecret"

ArgoCDKeyKustomizeVersion = "kustomize.version."
ArgoCDKeyResourceCustomizations = "resource.customizations."
)

// openshift.io keys
Expand Down
54 changes: 54 additions & 0 deletions controllers/argocd/argocdcommon/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,43 @@ import (
"reflect"

"github.com/argoproj-labs/argocd-operator/pkg/util"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
)

// FieldToCompare contains a field from an existing resource, the same field in the desired state of the resource, and an action to be taken after comparison
type FieldToCompare struct {
Existing interface{}
Desired interface{}
ExtraAction func()
}

// FieldCompFnCm is a function type for comparing fields of two ConfigMaps.
type FieldCompFnCm func(*corev1.ConfigMap, *corev1.ConfigMap) []FieldToCompare

// FieldCompFnDeployment is a function type for comparing fields of two Deployments.
type FieldCompFnDeployment func(appsv1.Deployment, appsv1.Deployment) []FieldToCompare

// FieldCompFnSecret is a function type for comparing fields of two Secrets.
type FieldCompFnSecret func(corev1.Secret, corev1.Secret) []FieldToCompare

// FieldCompFnService is a function type for comparing fields of two Services.
type FieldCompFnService func(corev1.Service, corev1.Service) []FieldToCompare

// FieldCompFnIngress is a function type for comparing fields of two Ingresses.
type FieldCompFnIngress func(networkingv1.Ingress, networkingv1.Ingress) []FieldToCompare

// FieldCompFnRole is a function type for comparing fields of two Roles.
type FieldCompFnRole func(rbacv1.Role, rbacv1.Role) []FieldToCompare

// FieldCompFnRoleBinding is a function type for comparing fields of two RoleBindings.
type FieldCompFnRoleBinding func(rbacv1.RoleBinding, rbacv1.RoleBinding) []FieldToCompare

// FieldCompFnStatefulSet is a function type for comparing fields of two StatefulSets.
type FieldCompFnStatefulSet func(appsv1.StatefulSet, appsv1.StatefulSet) []FieldToCompare

// UpdateIfChanged accepts a slice of fields to be compared, along with a bool ptr. It compares all the provided fields, updating any fields and setting the bool ptr to true if a drift is detected
func UpdateIfChanged(ftc []FieldToCompare, changed *bool) {
for _, field := range ftc {
Expand Down Expand Up @@ -51,3 +80,28 @@ func IsMergable(extraArgs []string, cmd []string) error {
}
return nil
}

// GetValueOrDefault returns the value if it's non-empty, otherwise returns the default value.
func GetValueOrDefault(value interface{}, defaultValue interface{}) interface{} {
if util.IsPtr(value) {
if reflect.ValueOf(value).IsNil() {
return defaultValue
}
return reflect.ValueOf(value).String()
}

switch v := value.(type) {
case string:
if len(v) > 0 {
return v
}
return defaultValue
case map[string]string:
if len(v) > 0 {
return v
}
return defaultValue
}

return defaultValue
}
4 changes: 2 additions & 2 deletions controllers/argocd/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ func (r *ReconcileArgoCD) reconcileRBACConfigMap(cm *corev1.ConfigMap, cr *argop
}

// Default Policy Matcher Mode
if cr.Spec.RBAC.PolicyMatcherMode != nil && cm.Data[common.ArgoCDPolicyMatcherMode] != *cr.Spec.RBAC.PolicyMatcherMode {
cm.Data[common.ArgoCDPolicyMatcherMode] = *cr.Spec.RBAC.PolicyMatcherMode
if cr.Spec.RBAC.PolicyMatcherMode != nil && cm.Data[common.ArgoCDKeyPolicyMatcherMode] != *cr.Spec.RBAC.PolicyMatcherMode {
cm.Data[common.ArgoCDKeyPolicyMatcherMode] = *cr.Spec.RBAC.PolicyMatcherMode
changed = true
}

Expand Down
237 changes: 237 additions & 0 deletions controllers/argocd/instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
package argocd

import (
"fmt"
"reflect"

argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
"github.com/argoproj-labs/argocd-operator/common"
"github.com/argoproj-labs/argocd-operator/controllers/argocd/argocdcommon"
"github.com/argoproj-labs/argocd-operator/pkg/argoutil"
"github.com/argoproj-labs/argocd-operator/pkg/util"
"gopkg.in/yaml.v2"
)

const (
healthKey = "health"
ignoreDIffKey = "ignoreDifferences"
actionsKey = "actions"
allKey = "all"
)

// getApplicationInstanceLabelKey returns the application instance label key for the given ArgoCD.
func (r *ArgoCDReconciler) getApplicationInstanceLabelKey() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.ApplicationInstanceLabelKey, common.ArgoCDDefaultApplicationInstanceLabelKey).(string)
}

// getCAConfigMapName returns the CA ConfigMap name for the given ArgoCD.
func (r *ArgoCDReconciler) getCAConfigMapName() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.TLS.CA.ConfigMapName, argoutil.GenerateResourceName(r.Instance.Name, common.ArgoCDCASuffix)).(string)
}

// getSCMRootCAConfigMapName returns the SCMRootCA ConfigMap name for the given ArgoCD ApplicationSet Controller.
func (r *ArgoCDReconciler) getSCMRootCAConfigMapName() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.ApplicationSet.SCMRootCAConfigMap, "").(string)
}

// getConfigManagementPlugins returns the config management plugins for the given ArgoCD.
func (r *ArgoCDReconciler) getConfigManagementPlugins() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.ConfigManagementPlugins, common.ArgoCDDefaultConfigManagementPlugins).(string)
}

// getGATrackingID returns the google analytics tracking ID for the given Argo CD.
func (r *ArgoCDReconciler) getGATrackingID() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.GATrackingID, common.ArgoCDDefaultGATrackingID).(string)
}

// getHelpChatURL returns the help chat URL for the given Argo CD.
func (r *ArgoCDReconciler) getHelpChatURL() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.HelpChatURL, common.ArgoCDDefaultHelpChatURL).(string)
}

// getHelpChatText returns the help chat text for the given Argo CD.
func (r *ArgoCDReconciler) getHelpChatText() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.HelpChatText, common.ArgoCDDefaultHelpChatText).(string)
}

// getKustomizeBuildOptions returns the kuztomize build options for the given ArgoCD.
func (r *ArgoCDReconciler) getKustomizeBuildOptions() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.KustomizeBuildOptions, common.ArgoCDDefaultKustomizeBuildOptions).(string)
}

// getOIDCConfig returns the OIDC configuration for the given instance.
func (r *ArgoCDReconciler) getOIDCConfig() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.OIDCConfig, common.ArgoCDDefaultOIDCConfig).(string)
}

// getRBACPolicy will return the RBAC policy for the given ArgoCD instance.
func (r *ArgoCDReconciler) getRBACPolicy() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.RBAC.Policy, common.ArgoCDDefaultRBACPolicy).(string)
}

// getRBACPolicyMatcherMode will return the RBAC policy matcher mode for the given ArgoCD instance.
func (r *ArgoCDReconciler) getRBACPolicyMatcherMode() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.RBAC.PolicyMatcherMode, nil).(string)
}

// getRBACDefaultPolicy will return the RBAC default policy for the given ArgoCD instance.
func (r *ArgoCDReconciler) getRBACDefaultPolicy() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.RBAC.DefaultPolicy, common.ArgoCDDefaultRBACPolicy).(string)
}

// getRBACScopes will return the RBAC scopes for the given ArgoCD instance.
func (r *ArgoCDReconciler) getRBACScopes() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.RBAC.Scopes, common.ArgoCDDefaultRBACScopes).(string)
}

// getResourceExclusions will return the resource exclusions for the given ArgoCD instance.
func (r *ArgoCDReconciler) getResourceExclusions() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.ResourceExclusions, common.ArgoCDDefaultResourceExclusions).(string)
}

// getResourceInclusions will return the resource inclusions for the given ArgoCD instance.
func (r *ArgoCDReconciler) getResourceInclusions() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.ResourceInclusions, common.ArgoCDDefaultResourceInclusions).(string)
}

// getInitialRepositories will return the initial repositories for the given ArgoCD instance.
func (r *ArgoCDReconciler) getInitialRepositories() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.InitialRepositories, common.ArgoCDDefaultRepositories).(string)
}

// getRepositoryCredentials will return the repository credentials for the given ArgoCD instance.
func (r *ArgoCDReconciler) getRepositoryCredentials() string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.RepositoryCredentials, common.ArgoCDDefaultRepositoryCredentials).(string)
}

// getInitialTLSCerts will return the TLS certs for the given ArgoCD instance.
func (r *ArgoCDReconciler) getInitialTLSCerts() map[string]string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.TLS.InitialCerts, make(map[string]string)).(map[string]string)
}

// getSSHKnownHosts will return the SSH Known Hosts data for the given ArgoCD instance.
func (r *ArgoCDReconciler) getInitialSSHKnownHosts() string {
skh := common.ArgoCDDefaultSSHKnownHosts
if r.Instance.Spec.InitialSSHKnownHosts.ExcludeDefaultHosts {
skh = ""
}
if len(r.Instance.Spec.InitialSSHKnownHosts.Keys) > 0 {
skh += r.Instance.Spec.InitialSSHKnownHosts.Keys
}
return skh
}

func (r *ArgoCDReconciler) getDisableAdmin() string {
return fmt.Sprintf("%t", !r.Instance.Spec.DisableAdmin)
}

func (r *ArgoCDReconciler) getGAAnonymizeUsers() string {
return fmt.Sprintf("%t", r.Instance.Spec.GAAnonymizeUsers)
}

func (r *ArgoCDReconciler) getStatusBadgeEnabled() string {
return fmt.Sprintf("%t", r.Instance.Spec.StatusBadgeEnabled)
}

func (r *ArgoCDReconciler) getUsersAnonymousEnabled() string {
return fmt.Sprintf("%t", r.Instance.Spec.UsersAnonymousEnabled)
}

// getResourceTrackingMethod will return the resource tracking method for the given ArgoCD instance
func (r *ArgoCDReconciler) getResourceTrackingMethod() string {
rtm := argoproj.ParseResourceTrackingMethod(r.Instance.Spec.ResourceTrackingMethod)
if rtm == argoproj.ResourceTrackingMethodInvalid {
r.Logger.Debug(fmt.Sprintf("found invalid resource tracking method '%s'; defaulting to 'label' method", r.Instance.Spec.ResourceTrackingMethod))
} else if r.Instance.Spec.ResourceTrackingMethod != "" {
r.Logger.Debug(fmt.Sprintf("found resource tracking method '%s'", r.Instance.Spec.ResourceTrackingMethod))
} else {
r.Logger.Debug("using default resource tracking method 'label'")
}
return rtm.String()
}

func (r *ArgoCDReconciler) getKustomizeVersions() map[string]string {
versions := make(map[string]string)
for _, kv := range r.Instance.Spec.KustomizeVersions {
versions[common.ArgoCDKeyKustomizeVersion+kv.Version] = kv.Path
}
return versions
}

func (r *ArgoCDReconciler) getBanner() map[string]string {
banner := make(map[string]string)
if r.Instance.Spec.Banner != nil {
banner[common.ArgoCDKeyBannerContent] = argocdcommon.GetValueOrDefault(r.Instance.Spec.Banner.Content, "").(string)
banner[common.ArgoCDKeyBannerURL] = argocdcommon.GetValueOrDefault(r.Instance.Spec.Banner.URL, "").(string)
}
return banner
}

func (r *ArgoCDReconciler) getExtraConfig() map[string]string {
return argocdcommon.GetValueOrDefault(r.Instance.Spec.ExtraConfig, make(map[string]string)).(map[string]string)
}

// getResourceHealthChecks loads health customizations to `resource.customizations.health` from argocd-cm ConfigMap
func (r *ArgoCDReconciler) getResourceHealthChecks() map[string]string {
healthCheck := make(map[string]string)

if r.Instance.Spec.ResourceHealthChecks != nil {
rhc := r.Instance.Spec.ResourceHealthChecks
for _, hc := range rhc {
subkey := util.ConstructString(util.DotSep, common.ArgoCDKeyResourceCustomizations, healthKey, util.ConstructString(util.UnderscoreSep, hc.Group, hc.Kind))
subvalue := hc.Check
healthCheck[subkey] = subvalue
}
}

return healthCheck
}

// getResourceActions loads custom actions to `resource.customizations.actions` from argocd-cm ConfigMap
func (r *ArgoCDReconciler) getResourceActions() map[string]string {
actions := make(map[string]string)

if r.Instance.Spec.ResourceActions != nil {
ra := r.Instance.Spec.ResourceActions
for _, a := range ra {
subkey := util.ConstructString(util.DotSep, common.ArgoCDKeyResourceCustomizations, actionsKey, util.ConstructString(util.UnderscoreSep, a.Group, a.Kind))
subvalue := a.Action
actions[subkey] = subvalue
}
}

return actions
}

// getResourceIgnoreDifferences loads ignore differences customizations to `resource.customizations.ignoreDifferences` from argocd-cm ConfigMap
func (r *ArgoCDReconciler) getResourceIgnoreDifferences() map[string]string {
ignoreDiff := make(map[string]string)

if r.Instance.Spec.ResourceIgnoreDifferences != nil {
rid := r.Instance.Spec.ResourceIgnoreDifferences

if !reflect.DeepEqual(rid.All, &argoproj.IgnoreDifferenceCustomization{}) {
subkey := util.ConstructString(util.DotSep, common.ArgoCDKeyResourceCustomizations, ignoreDIffKey, allKey)
bytes, err := yaml.Marshal(rid.All)
if err != nil {
r.Logger.Error(err, "getResourceIgnoreDifferences")
return ignoreDiff
}
subvalue := string(bytes)
ignoreDiff[subkey] = subvalue
}

for _, id := range rid.ResourceIdentifiers {
subkey := util.ConstructString(util.DotSep, common.ArgoCDKeyResourceCustomizations, ignoreDIffKey, util.ConstructString(util.UnderscoreSep, id.Group, id.Kind))
bytes, err := yaml.Marshal(id.Customization)
if err != nil {
r.Logger.Error(err, "getResourceIgnoreDifferences")
return ignoreDiff
}
subvalue := string(bytes)
ignoreDiff[subkey] = subvalue
}
}

return ignoreDiff
}
10 changes: 10 additions & 0 deletions pkg/util/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"strings"
)

const (
DotSep = "."
UnderscoreSep = "_"
)

// SplitList accepts a string input containing a list of comma separated values, and returns a slice containing those values as separate elements
func SplitList(s string) []string {
if s == "" {
Expand Down Expand Up @@ -73,3 +78,8 @@ func GenerateRandomString(s int) (string, error) {
func StringPtr(val string) *string {
return &val
}

// ConstructString concatenates the supplied parts by using the provided separator. Any empty strings are skipped
func ConstructString(separtor string, parts ...string) string {
return strings.Join(RemoveString(parts, ""), separtor)
}

0 comments on commit 676e7e8

Please sign in to comment.