[go: nahoru, domu]

Skip to content

Commit

Permalink
Argo-CD example improvements (prometheus-operator#2200)
Browse files Browse the repository at this point in the history
* Sync ArgoCD example with latest components from example.jsonnet

* Extend the ArgoCD example to include ArgoCD related annotations to make everything work on first try

* Run jsonnetfmt
  • Loading branch information
roosmaa authored Aug 31, 2023
1 parent fb1f32d commit c11655a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
8 changes: 5 additions & 3 deletions examples/continuous-delivery/argocd/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## ArgoCD Example

This is the simplest, working example of an argocd app, the JSON object built is now an array of objects as that is the prefered format for ArgoCD.
This is the simplest, working example of an argocd app, the JSON object built is now an array of objects as that is the prefered format for ArgoCD. And ArgoCD specific annotations are added to manifests.

Requirements:

**ArgoCD 1.7+**
- **ArgoCD 1.7+**

Follow the vendor generation steps at the root of this repository and generate a `vendored` folder (referenced in `application.yaml`).
- Follow the vendor generation steps at the root of this repository and generate a `vendored` folder (referenced in `application.yaml`).

- Make sure that argocd-cm has `application.instanceLabelKey` set to something else than `app.kubernetes.io/instance`, otherwise it will cause problems with prometheus target discovery. (see also [Why Is My App Out Of Sync Even After Syncing?](https://argo-cd.readthedocs.io/en/stable/faq/#why-is-my-app-out-of-sync-even-after-syncing))
Original file line number Diff line number Diff line change
@@ -1,14 +1,66 @@
local kp = (import 'kube-prometheus/main.libsonnet') + {
values+:: {
common+: {
namespace: 'monitoring',
// NB! Make sure that argocd-cm has `application.instanceLabelKey` set to something else than `app.kubernetes.io/instance`,
// otherwise it will cause problems with prometheus target discovery.
// See also https://argo-cd.readthedocs.io/en/stable/faq/#why-is-my-app-out-of-sync-even-after-syncing

local kp =
(import 'kube-prometheus/main.libsonnet') +
// Uncomment the following imports to enable its patches
// (import 'kube-prometheus/addons/anti-affinity.libsonnet') +
// (import 'kube-prometheus/addons/managed-cluster.libsonnet') +
// (import 'kube-prometheus/addons/node-ports.libsonnet') +
// (import 'kube-prometheus/addons/static-etcd.libsonnet') +
// (import 'kube-prometheus/addons/custom-metrics.libsonnet') +
// (import 'kube-prometheus/addons/external-metrics.libsonnet') +
// (import 'kube-prometheus/addons/pyrra.libsonnet') +
{
values+:: {
common+: {
namespace: 'monitoring',
},
},
},
};

[kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus)] +
[kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator)] +
[kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter)] +
[kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics)] +
[kp.prometheus[name] for name in std.objectFields(kp.prometheus)] +
[kp.prometheusAdapter[name] for name in std.objectFields(kp.prometheusAdapter)]
};

// Unlike in kube-prometheus/example.jsonnet where a map of file-names to manifests is returned,
// for ArgoCD we need to return just a regular list with all the manifests.
local manifests =
[kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus)] +
[kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator)] +
[kp.alertmanager[name] for name in std.objectFields(kp.alertmanager)] +
[kp.blackboxExporter[name] for name in std.objectFields(kp.blackboxExporter)] +
[kp.grafana[name] for name in std.objectFields(kp.grafana)] +
// [ kp.pyrra[name] for name in std.objectFields(kp.pyrra)] +
[kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics)] +
[kp.kubernetesControlPlane[name] for name in std.objectFields(kp.kubernetesControlPlane)] +
[kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter)] +
[kp.prometheus[name] for name in std.objectFields(kp.prometheus)] +
[kp.prometheusAdapter[name] for name in std.objectFields(kp.prometheusAdapter)];

local argoAnnotations(manifest) =
manifest {
metadata+: {
annotations+: {
'argocd.argoproj.io/sync-wave':
// Make sure to sync the Namespace & CRDs before anything else (to avoid sync failures)
if std.member(['CustomResourceDefinition', 'Namespace'], manifest.kind)
then '-5'
// And sync all the roles outside of the main & kube-system last (in case some of the namespaces don't exist yet)
else if std.objectHas(manifest, 'metadata')
&& std.objectHas(manifest.metadata, 'namespace')
&& !std.member([kp.values.common.namespace, 'kube-system'], manifest.metadata.namespace)
then '10'
else '5',
'argocd.argoproj.io/sync-options':
// Use replace strategy for CRDs, as they're too big fit into the last-applied-configuration annotation that kubectl apply wants to use
if manifest.kind == 'CustomResourceDefinition' then 'Replace=true'
else '',
},
},
};

// Add argo-cd annotations to all the manifests
[
if std.endsWith(manifest.kind, 'List') && std.objectHas(manifest, 'items')
then manifest { items: [argoAnnotations(item) for item in manifest.items] }
else argoAnnotations(manifest)
for manifest in manifests
]

0 comments on commit c11655a

Please sign in to comment.