Skip to content

Commit 13584a6

Browse files
authored
fix: standardize logFormat field naming across ArgoCD components (#2108)
* fix: standardize logFormat field naming across ArgoCD components Signed-off-by: Tejas Soham <tejassoham05@gmail.com> * Regenerate CRDs and bundle after logFormat consistency change Signed-off-by: Tejas Soham <tejassoham05@gmail.com> * support both logformat (deprecated) and logFormat fields for backward compatibility Signed-off-by: Tejas Soham <tejassoham05@gmail.com> * fix validation marker and add backward compatibility for logformat Signed-off-by: Tejas Soham <tejassoham05@gmail.com> * fix lint: suppress deprecated logformat fallback warning Signed-off-by: Tejas Soham <tejassoham05@gmail.com> * Added unit tests and e2e tests for testing Signed-off-by: Tejas Soham <tejassoham05@gmail.com> * revert the changes from 0.18.0 files Signed-off-by: Tejas Soham <tejassoham05@gmail.com> --------- Signed-off-by: Tejas Soham <tejassoham05@gmail.com>
1 parent 20acfea commit 13584a6

10 files changed

Lines changed: 341 additions & 59 deletions

File tree

api/v1alpha1/argocd_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,12 @@ type ArgoCDNotifications struct {
347347
// LogLevel describes the log level that should be used by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel if not set. Valid options are debug,info, error, and warn.
348348
LogLevel string `json:"logLevel,omitempty"`
349349

350+
// Deprecated: use LogFormat instead.
351+
Logformat string `json:"logformat,omitempty"`
352+
350353
// LogFormat refers to the log format used by the argocd-notifications. Defaults to ArgoCDDefaultLogFormat if not configured. Valid options are text or json.
351354
// +kubebuilder:validation:Enum=text;json
352-
LogFormat string `json:"logformat,omitempty"`
355+
LogFormat string `json:"logFormat,omitempty"`
353356
}
354357

355358
// ArgoCDPrometheusSpec defines the desired state for the Prometheus component.

api/v1beta1/argocd_types.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,12 @@ type ArgoCDApplicationSet struct {
217217
// VolumeMounts adds volumeMounts to the Argo CD ApplicationSet Controller container.
218218
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
219219

220+
// Deprecated: use LogFormat instead.
221+
Logformat string `json:"logformat,omitempty"`
222+
220223
// LogFormat refers to the log format used by the ApplicationSet component. Defaults to ArgoCDDefaultLogFormat if not configured. Valid options are text or json.
221224
// +kubebuilder:validation:Enum=text;json
222-
LogFormat string `json:"logformat,omitempty"`
225+
LogFormat string `json:"logFormat,omitempty"`
223226
}
224227

225228
func (a *ArgoCDApplicationSet) IsEnabled() bool {
@@ -429,9 +432,12 @@ type ArgoCDNotifications struct {
429432
// LogLevel describes the log level that should be used by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel if not set. Valid options are debug,info, error, and warn.
430433
LogLevel string `json:"logLevel,omitempty"`
431434

435+
// Deprecated: use LogFormat instead.
436+
Logformat string `json:"logformat,omitempty"`
437+
432438
// LogFormat refers to the log format used by the argocd-notifications. Defaults to ArgoCDDefaultLogFormat if not configured. Valid options are text or json.
433439
// +kubebuilder:validation:Enum=text;json
434-
LogFormat string `json:"logformat,omitempty"`
440+
LogFormat string `json:"logFormat,omitempty"`
435441
}
436442

437443
// ArgoCDPrometheusSpec defines the desired state for the Prometheus component.

bundle/manifests/argoproj.io_argocds.yaml

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,19 +2133,22 @@ spec:
21332133
image:
21342134
description: Image is the Argo CD Notifications image (optional)
21352135
type: string
2136-
logLevel:
2137-
description: LogLevel describes the log level that should be used
2138-
by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel
2139-
if not set. Valid options are debug,info, error, and warn.
2140-
type: string
2141-
logformat:
2136+
logFormat:
21422137
description: LogFormat refers to the log format used by the argocd-notifications.
21432138
Defaults to ArgoCDDefaultLogFormat if not configured. Valid
21442139
options are text or json.
21452140
enum:
21462141
- text
21472142
- json
21482143
type: string
2144+
logLevel:
2145+
description: LogLevel describes the log level that should be used
2146+
by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel
2147+
if not set. Valid options are debug,info, error, and warn.
2148+
type: string
2149+
logformat:
2150+
description: 'Deprecated: use LogFormat instead.'
2151+
type: string
21492152
replicas:
21502153
description: Replicas defines the number of replicas to run for
21512154
notifications-controller
@@ -9154,19 +9157,22 @@ spec:
91549157
type: string
91559158
description: Custom labels to pods deployed by the operator
91569159
type: object
9157-
logLevel:
9158-
description: LogLevel describes the log level that should be used
9159-
by the ApplicationSet controller. Defaults to ArgoCDDefaultLogLevel
9160-
if not set. Valid options are debug,info, error, and warn.
9161-
type: string
9162-
logformat:
9160+
logFormat:
91639161
description: LogFormat refers to the log format used by the ApplicationSet
91649162
component. Defaults to ArgoCDDefaultLogFormat if not configured.
91659163
Valid options are text or json.
91669164
enum:
91679165
- text
91689166
- json
91699167
type: string
9168+
logLevel:
9169+
description: LogLevel describes the log level that should be used
9170+
by the ApplicationSet controller. Defaults to ArgoCDDefaultLogLevel
9171+
if not set. Valid options are debug,info, error, and warn.
9172+
type: string
9173+
logformat:
9174+
description: 'Deprecated: use LogFormat instead.'
9175+
type: string
91709176
resources:
91719177
description: Resources defines the Compute Resources required
91729178
by the container for ApplicationSet.
@@ -18292,19 +18298,22 @@ spec:
1829218298
image:
1829318299
description: Image is the Argo CD Notifications image (optional)
1829418300
type: string
18295-
logLevel:
18296-
description: LogLevel describes the log level that should be used
18297-
by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel
18298-
if not set. Valid options are debug,info, error, and warn.
18299-
type: string
18300-
logformat:
18301+
logFormat:
1830118302
description: LogFormat refers to the log format used by the argocd-notifications.
1830218303
Defaults to ArgoCDDefaultLogFormat if not configured. Valid
1830318304
options are text or json.
1830418305
enum:
1830518306
- text
1830618307
- json
1830718308
type: string
18309+
logLevel:
18310+
description: LogLevel describes the log level that should be used
18311+
by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel
18312+
if not set. Valid options are debug,info, error, and warn.
18313+
type: string
18314+
logformat:
18315+
description: 'Deprecated: use LogFormat instead.'
18316+
type: string
1830818317
replicas:
1830918318
description: Replicas defines the number of replicas to run for
1831018319
notifications-controller

config/crd/bases/argoproj.io_argocds.yaml

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,19 +2122,22 @@ spec:
21222122
image:
21232123
description: Image is the Argo CD Notifications image (optional)
21242124
type: string
2125-
logLevel:
2126-
description: LogLevel describes the log level that should be used
2127-
by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel
2128-
if not set. Valid options are debug,info, error, and warn.
2129-
type: string
2130-
logformat:
2125+
logFormat:
21312126
description: LogFormat refers to the log format used by the argocd-notifications.
21322127
Defaults to ArgoCDDefaultLogFormat if not configured. Valid
21332128
options are text or json.
21342129
enum:
21352130
- text
21362131
- json
21372132
type: string
2133+
logLevel:
2134+
description: LogLevel describes the log level that should be used
2135+
by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel
2136+
if not set. Valid options are debug,info, error, and warn.
2137+
type: string
2138+
logformat:
2139+
description: 'Deprecated: use LogFormat instead.'
2140+
type: string
21382141
replicas:
21392142
description: Replicas defines the number of replicas to run for
21402143
notifications-controller
@@ -9143,19 +9146,22 @@ spec:
91439146
type: string
91449147
description: Custom labels to pods deployed by the operator
91459148
type: object
9146-
logLevel:
9147-
description: LogLevel describes the log level that should be used
9148-
by the ApplicationSet controller. Defaults to ArgoCDDefaultLogLevel
9149-
if not set. Valid options are debug,info, error, and warn.
9150-
type: string
9151-
logformat:
9149+
logFormat:
91529150
description: LogFormat refers to the log format used by the ApplicationSet
91539151
component. Defaults to ArgoCDDefaultLogFormat if not configured.
91549152
Valid options are text or json.
91559153
enum:
91569154
- text
91579155
- json
91589156
type: string
9157+
logLevel:
9158+
description: LogLevel describes the log level that should be used
9159+
by the ApplicationSet controller. Defaults to ArgoCDDefaultLogLevel
9160+
if not set. Valid options are debug,info, error, and warn.
9161+
type: string
9162+
logformat:
9163+
description: 'Deprecated: use LogFormat instead.'
9164+
type: string
91599165
resources:
91609166
description: Resources defines the Compute Resources required
91619167
by the container for ApplicationSet.
@@ -18281,19 +18287,22 @@ spec:
1828118287
image:
1828218288
description: Image is the Argo CD Notifications image (optional)
1828318289
type: string
18284-
logLevel:
18285-
description: LogLevel describes the log level that should be used
18286-
by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel
18287-
if not set. Valid options are debug,info, error, and warn.
18288-
type: string
18289-
logformat:
18290+
logFormat:
1829018291
description: LogFormat refers to the log format used by the argocd-notifications.
1829118292
Defaults to ArgoCDDefaultLogFormat if not configured. Valid
1829218293
options are text or json.
1829318294
enum:
1829418295
- text
1829518296
- json
1829618297
type: string
18298+
logLevel:
18299+
description: LogLevel describes the log level that should be used
18300+
by the argocd-notifications. Defaults to ArgoCDDefaultLogLevel
18301+
if not set. Valid options are debug,info, error, and warn.
18302+
type: string
18303+
logformat:
18304+
description: 'Deprecated: use LogFormat instead.'
18305+
type: string
1829718306
replicas:
1829818307
description: Replicas defines the number of replicas to run for
1829918308
notifications-controller

controllers/argocd/applicationset.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ func (r *ReconcileArgoCD) getArgoApplicationSetCommand(cr *argoproj.ArgoCD) ([]s
6262
cmd = append(cmd, "--loglevel")
6363
cmd = append(cmd, getLogLevel(cr.Spec.ApplicationSet.LogLevel))
6464

65+
// Higher Preference to the new logFormat field. Fall back to the deprecated logformat field for backward compatibility.
66+
logFormat := cr.Spec.ApplicationSet.LogFormat
67+
if logFormat == "" {
68+
//nolint:staticcheck // fallback to deprecated field for backward compatibility
69+
logFormat = cr.Spec.ApplicationSet.Logformat
70+
}
71+
6572
cmd = append(cmd, "--logformat")
66-
cmd = append(cmd, getLogFormat(cr.Spec.ApplicationSet.LogFormat))
73+
cmd = append(cmd, getLogFormat(logFormat))
6774

6875
if cr.Spec.ApplicationSet.SCMRootCAConfigMap != "" {
6976
cmd = append(cmd, "--scm-root-ca-path")

controllers/argocd/applicationset_test.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2021 ArgoCD Operator Developers
2+
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License");
45
// you may not use this file except in compliance with the License.
@@ -1642,6 +1643,97 @@ func TestReconcileApplicationSetSourceNamespacesResources_NonClusterConfigNamesp
16421643
}
16431644
}
16441645

1646+
func TestReconcileApplicationSet_LogFormatFallback(t *testing.T) {
1647+
logf.SetLogger(ZapLogger(true))
1648+
1649+
tests := []struct {
1650+
name string
1651+
// logFormat has priority over logformat
1652+
logFormat string
1653+
logformat string
1654+
wantFormat string
1655+
}{
1656+
{
1657+
// Production code path: logFormat != "" so the if-fallback is never triggered
1658+
name: "new LogFormat field is used when set",
1659+
logFormat: "json",
1660+
logformat: "",
1661+
wantFormat: "json",
1662+
},
1663+
{
1664+
// Backward compatibility path: logFormat == "" so code enters the if block and reads the deprecated logformat field instead
1665+
name: "deprecated logformat field used as fallback when LogFormat is empty",
1666+
logFormat: "",
1667+
logformat: "json",
1668+
wantFormat: "json",
1669+
},
1670+
{
1671+
// Priority check - both fields contain some value
1672+
name: "new LogFormat takes precedence when both fields are set",
1673+
logFormat: "json",
1674+
logformat: "text",
1675+
wantFormat: "json",
1676+
},
1677+
{
1678+
// Both fields are empty
1679+
name: "default format text is used when neither field is set",
1680+
logFormat: "",
1681+
logformat: "",
1682+
wantFormat: common.ArgoCDDefaultLogFormat,
1683+
},
1684+
}
1685+
1686+
for _, tt := range tests {
1687+
t.Run(tt.name, func(t *testing.T) {
1688+
// Provides base ArgoCD CR with namespace "argocd"
1689+
a := makeTestArgoCD()
1690+
1691+
// cr.Spec.ApplicationSet.LogFormat.
1692+
spec := argoproj.ArgoCDApplicationSet{
1693+
LogFormat: tt.logFormat,
1694+
}
1695+
//nolint:staticcheck // intentionally setting deprecated field to exercise the backward-compatibility fallback
1696+
spec.Logformat = tt.logformat
1697+
a.Spec.ApplicationSet = &spec
1698+
1699+
// Seed fake client with ArgoCD CR so that reconciler can read & write K8s objects without a real cluster
1700+
resObjs := []client.Object{a}
1701+
subresObjs := []client.Object{a}
1702+
runtimeObjs := []runtime.Object{}
1703+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
1704+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
1705+
r := makeTestReconciler(cl, sch, testclient.NewSimpleClientset())
1706+
1707+
assert.NoError(t, r.reconcileApplicationSetController(a))
1708+
1709+
deployment := &appsv1.Deployment{}
1710+
assert.NoError(t, r.Get(
1711+
context.TODO(),
1712+
types.NamespacedName{
1713+
Name: "argocd-applicationset-controller",
1714+
Namespace: a.Namespace,
1715+
},
1716+
deployment))
1717+
1718+
cmd := deployment.Spec.Template.Spec.Containers[0].Command
1719+
logFormatIdx := -1
1720+
for i, arg := range cmd {
1721+
if arg == "--logformat" {
1722+
logFormatIdx = i
1723+
break
1724+
}
1725+
}
1726+
1727+
if assert.NotEqual(t, -1, logFormatIdx,
1728+
"--logFormat flag must be present in the applicationset-controller command") {
1729+
assert.Equal(t, tt.wantFormat, cmd[logFormatIdx+1],
1730+
"wrong value after --logformat flag (logFormat=%q logformat=%q)",
1731+
tt.logFormat, tt.logformat)
1732+
}
1733+
})
1734+
}
1735+
}
1736+
16451737
func TestGetApplicationSetContainerImage(t *testing.T) {
16461738
logf.SetLogger(ZapLogger(true))
16471739

controllers/argocd/notifications.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,14 @@ func (r *ReconcileArgoCD) getNotificationsCommand(cr *argoproj.ArgoCD) []string
844844
cmd = append(cmd, "--loglevel")
845845
cmd = append(cmd, getLogLevel(cr.Spec.Notifications.LogLevel))
846846

847+
logFormat := cr.Spec.Notifications.LogFormat
848+
if logFormat == "" {
849+
//nolint:staticcheck // fallback to deprecated field for backward compatibility
850+
logFormat = cr.Spec.Notifications.Logformat
851+
}
852+
847853
cmd = append(cmd, "--logformat")
848-
cmd = append(cmd, getLogFormat(cr.Spec.Notifications.LogFormat))
854+
cmd = append(cmd, getLogFormat(logFormat))
849855

850856
if cr.Spec.Repo.IsEnabled() {
851857
cmd = append(cmd, "--argocd-repo-server", getRepoServerAddress(cr))

0 commit comments

Comments
 (0)