@@ -38,6 +38,7 @@ import (
38
38
projectFixture "github.com/argoproj/argo-cd/v2/test/e2e/fixture/project"
39
39
repoFixture "github.com/argoproj/argo-cd/v2/test/e2e/fixture/repos"
40
40
"github.com/argoproj/argo-cd/v2/test/e2e/testdata"
41
+ "github.com/argoproj/argo-cd/v2/util/argo"
41
42
. "github.com/argoproj/argo-cd/v2/util/argo"
42
43
. "github.com/argoproj/argo-cd/v2/util/errors"
43
44
"github.com/argoproj/argo-cd/v2/util/io"
@@ -2063,3 +2064,189 @@ func TestDisableManifestGeneration(t *testing.T) {
2063
2064
assert .Equal (t , app .Status .SourceType , ApplicationSourceTypeDirectory )
2064
2065
})
2065
2066
}
2067
+
2068
+ func TestSwitchTrackingMethod (t * testing.T ) {
2069
+ ctx := Given (t )
2070
+
2071
+ ctx .
2072
+ SetTrackingMethod (string (argo .TrackingMethodAnnotation )).
2073
+ Path ("deployment" ).
2074
+ When ().
2075
+ CreateApp ().
2076
+ Sync ().
2077
+ Refresh (RefreshTypeNormal ).
2078
+ Then ().
2079
+ Expect (OperationPhaseIs (OperationSucceeded )).
2080
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2081
+ Expect (HealthIs (health .HealthStatusHealthy )).
2082
+ When ().
2083
+ And (func () {
2084
+ // Add resource with tracking annotation. This should put the
2085
+ // application OutOfSync.
2086
+ FailOnErr (KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Create (context .Background (), & v1.ConfigMap {
2087
+ ObjectMeta : metav1.ObjectMeta {
2088
+ Name : "other-configmap" ,
2089
+ Annotations : map [string ]string {
2090
+ common .AnnotationKeyAppInstance : fmt .Sprintf ("%s:/ConfigMap:%s/other-configmap" , Name (), DeploymentNamespace ()),
2091
+ },
2092
+ },
2093
+ }, metav1.CreateOptions {}))
2094
+ }).
2095
+ Then ().
2096
+ Expect (OperationPhaseIs (OperationSucceeded )).
2097
+ Expect (SyncStatusIs (SyncStatusCodeOutOfSync )).
2098
+ Expect (HealthIs (health .HealthStatusHealthy )).
2099
+ When ().
2100
+ And (func () {
2101
+ // Delete resource to bring application back in sync
2102
+ FailOnErr (nil , KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Delete (context .Background (), "other-configmap" , metav1.DeleteOptions {}))
2103
+ }).
2104
+ Then ().
2105
+ Expect (OperationPhaseIs (OperationSucceeded )).
2106
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2107
+ Expect (HealthIs (health .HealthStatusHealthy )).
2108
+ When ().
2109
+ SetTrackingMethod (string (argo .TrackingMethodLabel )).
2110
+ Sync ().
2111
+ Then ().
2112
+ Expect (OperationPhaseIs (OperationSucceeded )).
2113
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2114
+ Expect (HealthIs (health .HealthStatusHealthy )).
2115
+ When ().
2116
+ And (func () {
2117
+ // Add a resource with a tracking annotation. This should not
2118
+ // affect the application, because we now use the tracking method
2119
+ // "label".
2120
+ FailOnErr (KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Create (context .Background (), & v1.ConfigMap {
2121
+ ObjectMeta : metav1.ObjectMeta {
2122
+ Name : "other-configmap" ,
2123
+ Annotations : map [string ]string {
2124
+ common .AnnotationKeyAppInstance : fmt .Sprintf ("%s:/ConfigMap:%s/other-configmap" , Name (), DeploymentNamespace ()),
2125
+ },
2126
+ },
2127
+ }, metav1.CreateOptions {}))
2128
+ }).
2129
+ Then ().
2130
+ Expect (OperationPhaseIs (OperationSucceeded )).
2131
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2132
+ Expect (HealthIs (health .HealthStatusHealthy )).
2133
+ When ().
2134
+ And (func () {
2135
+ // Add a resource with the tracking label. The app should become
2136
+ // OutOfSync.
2137
+ FailOnErr (KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Create (context .Background (), & v1.ConfigMap {
2138
+ ObjectMeta : metav1.ObjectMeta {
2139
+ Name : "extra-configmap" ,
2140
+ Labels : map [string ]string {
2141
+ common .LabelKeyAppInstance : Name (),
2142
+ },
2143
+ },
2144
+ }, metav1.CreateOptions {}))
2145
+ }).
2146
+ Then ().
2147
+ Expect (OperationPhaseIs (OperationSucceeded )).
2148
+ Expect (SyncStatusIs (SyncStatusCodeOutOfSync )).
2149
+ Expect (HealthIs (health .HealthStatusHealthy )).
2150
+ When ().
2151
+ And (func () {
2152
+ // Delete resource to bring application back in sync
2153
+ FailOnErr (nil , KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Delete (context .Background (), "extra-configmap" , metav1.DeleteOptions {}))
2154
+ }).
2155
+ Then ().
2156
+ Expect (OperationPhaseIs (OperationSucceeded )).
2157
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2158
+ Expect (HealthIs (health .HealthStatusHealthy ))
2159
+ }
2160
+
2161
+ func TestSwitchTrackingLabel (t * testing.T ) {
2162
+ ctx := Given (t )
2163
+
2164
+ ctx .
2165
+ Path ("deployment" ).
2166
+ When ().
2167
+ CreateApp ().
2168
+ Sync ().
2169
+ Refresh (RefreshTypeNormal ).
2170
+ Then ().
2171
+ Expect (OperationPhaseIs (OperationSucceeded )).
2172
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2173
+ Expect (HealthIs (health .HealthStatusHealthy )).
2174
+ When ().
2175
+ And (func () {
2176
+ // Add extra resource that carries the default tracking label
2177
+ // We expect the app to go out of sync.
2178
+ FailOnErr (KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Create (context .Background (), & v1.ConfigMap {
2179
+ ObjectMeta : metav1.ObjectMeta {
2180
+ Name : "other-configmap" ,
2181
+ Labels : map [string ]string {
2182
+ common .LabelKeyAppInstance : Name (),
2183
+ },
2184
+ },
2185
+ }, metav1.CreateOptions {}))
2186
+ }).
2187
+ Then ().
2188
+ Expect (OperationPhaseIs (OperationSucceeded )).
2189
+ Expect (SyncStatusIs (SyncStatusCodeOutOfSync )).
2190
+ Expect (HealthIs (health .HealthStatusHealthy )).
2191
+ When ().
2192
+ And (func () {
2193
+ // Delete resource to bring application back in sync
2194
+ FailOnErr (nil , KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Delete (context .Background (), "other-configmap" , metav1.DeleteOptions {}))
2195
+ }).
2196
+ Then ().
2197
+ Expect (OperationPhaseIs (OperationSucceeded )).
2198
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2199
+ Expect (HealthIs (health .HealthStatusHealthy )).
2200
+ When ().
2201
+ // Change tracking label
2202
+ SetTrackingLabel ("argocd.tracking" ).
2203
+ Sync ().
2204
+ Then ().
2205
+ Expect (OperationPhaseIs (OperationSucceeded )).
2206
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2207
+ Expect (HealthIs (health .HealthStatusHealthy )).
2208
+ When ().
2209
+ And (func () {
2210
+ // Create resource with the new tracking label, the application
2211
+ // is expected to go out of sync
2212
+ FailOnErr (KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Create (context .Background (), & v1.ConfigMap {
2213
+ ObjectMeta : metav1.ObjectMeta {
2214
+ Name : "other-configmap" ,
2215
+ Labels : map [string ]string {
2216
+ "argocd.tracking" : Name (),
2217
+ },
2218
+ },
2219
+ }, metav1.CreateOptions {}))
2220
+ }).
2221
+ Then ().
2222
+ Expect (OperationPhaseIs (OperationSucceeded )).
2223
+ Expect (SyncStatusIs (SyncStatusCodeOutOfSync )).
2224
+ Expect (HealthIs (health .HealthStatusHealthy )).
2225
+ When ().
2226
+ And (func () {
2227
+ // Delete resource to bring application back in sync
2228
+ FailOnErr (nil , KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Delete (context .Background (), "other-configmap" , metav1.DeleteOptions {}))
2229
+ }).
2230
+ Then ().
2231
+ Expect (OperationPhaseIs (OperationSucceeded )).
2232
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2233
+ Expect (HealthIs (health .HealthStatusHealthy )).
2234
+ When ().
2235
+ And (func () {
2236
+ // Add extra resource that carries the default tracking label
2237
+ // We expect the app to stay in sync, because the configured
2238
+ // label is different.
2239
+ FailOnErr (KubeClientset .CoreV1 ().ConfigMaps (DeploymentNamespace ()).Create (context .Background (), & v1.ConfigMap {
2240
+ ObjectMeta : metav1.ObjectMeta {
2241
+ Name : "other-configmap" ,
2242
+ Labels : map [string ]string {
2243
+ common .LabelKeyAppInstance : Name (),
2244
+ },
2245
+ },
2246
+ }, metav1.CreateOptions {}))
2247
+ }).
2248
+ Then ().
2249
+ Expect (OperationPhaseIs (OperationSucceeded )).
2250
+ Expect (SyncStatusIs (SyncStatusCodeSynced )).
2251
+ Expect (HealthIs (health .HealthStatusHealthy ))
2252
+ }
0 commit comments