@@ -1275,6 +1275,108 @@ func TestSecretReplicator(t *testing.T) {
12751275
12761276 })
12771277
1278+ t .Run ("replication copies annotations" , func (t * testing.T ) {
1279+ sourceLabels := map [string ]string {
1280+ "foo" : "bar" ,
1281+ "hello" : "world" ,
1282+ }
1283+ source := corev1.Secret {
1284+ ObjectMeta : metav1.ObjectMeta {
1285+ Name : "annotation-push" ,
1286+ Namespace : ns .Name ,
1287+ Annotations : map [string ]string {
1288+ common .ReplicateTo : prefix + "test2" ,
1289+ "test-annotation" : "bar" ,
1290+ },
1291+ Labels : sourceLabels ,
1292+ },
1293+ Type : corev1 .SecretTypeOpaque ,
1294+ Data : map [string ][]byte {
1295+ "foo" : []byte ("Hello Foo" ),
1296+ "bar" : []byte ("Hello Bar" ),
1297+ },
1298+ }
1299+
1300+ wg , stop := waitForSecrets (client , 2 , EventHandlerFuncs {
1301+ AddFunc : func (wg * sync.WaitGroup , obj interface {}) {
1302+ secret := obj .(* corev1.Secret )
1303+ if secret .Namespace == source .Namespace && secret .Name == source .Name {
1304+ log .Debugf ("AddFunc %+v" , obj )
1305+ wg .Done ()
1306+ } else if secret .Namespace == prefix + "test2" && secret .Name == source .Name {
1307+ log .Debugf ("AddFunc %+v" , obj )
1308+ wg .Done ()
1309+ }
1310+ },
1311+ })
1312+ _ , err := secrets .Create (context .TODO (), & source , metav1.CreateOptions {})
1313+ require .NoError (t , err )
1314+
1315+ waitWithTimeout (wg , MaxWaitTime )
1316+ close (stop )
1317+
1318+ secrets2 := client .CoreV1 ().Secrets (prefix + "test2" )
1319+ updTarget , err := secrets2 .Get (context .TODO (), source .Name , metav1.GetOptions {})
1320+
1321+ require .NoError (t , err )
1322+ require .Equal (t , []byte ("Hello Foo" ), updTarget .Data ["foo" ])
1323+ require .True (t , reflect .DeepEqual (sourceLabels , updTarget .Labels ))
1324+
1325+ require .Equal (t , "bar" , updTarget .Annotations ["test-annotation" ])
1326+ })
1327+
1328+ t .Run ("replication copies annotations but honors strip-annotations" , func (t * testing.T ) {
1329+ sourceLabels := map [string ]string {
1330+ "foo" : "bar" ,
1331+ "hello" : "world" ,
1332+ }
1333+ source := corev1.Secret {
1334+ ObjectMeta : metav1.ObjectMeta {
1335+ Name : "annotation-push-strip" ,
1336+ Namespace : ns .Name ,
1337+ Annotations : map [string ]string {
1338+ common .ReplicateTo : prefix + "test2" ,
1339+ common .StripAnnotations : "true" ,
1340+ "test-annotation" : "bar" ,
1341+ },
1342+ Labels : sourceLabels ,
1343+ },
1344+ Type : corev1 .SecretTypeOpaque ,
1345+ Data : map [string ][]byte {
1346+ "foo" : []byte ("Hello Foo" ),
1347+ "bar" : []byte ("Hello Bar" ),
1348+ },
1349+ }
1350+
1351+ wg , stop := waitForSecrets (client , 2 , EventHandlerFuncs {
1352+ AddFunc : func (wg * sync.WaitGroup , obj interface {}) {
1353+ secret := obj .(* corev1.Secret )
1354+ if secret .Namespace == source .Namespace && secret .Name == source .Name {
1355+ log .Debugf ("AddFunc %+v" , obj )
1356+ wg .Done ()
1357+ } else if secret .Namespace == prefix + "test2" && secret .Name == source .Name {
1358+ log .Debugf ("AddFunc %+v" , obj )
1359+ wg .Done ()
1360+ }
1361+ },
1362+ })
1363+ _ , err := secrets .Create (context .TODO (), & source , metav1.CreateOptions {})
1364+ require .NoError (t , err )
1365+
1366+ waitWithTimeout (wg , MaxWaitTime )
1367+ close (stop )
1368+
1369+ secrets2 := client .CoreV1 ().Secrets (prefix + "test2" )
1370+ updTarget , err := secrets2 .Get (context .TODO (), source .Name , metav1.GetOptions {})
1371+
1372+ require .NoError (t , err )
1373+ require .Equal (t , []byte ("Hello Foo" ), updTarget .Data ["foo" ])
1374+ require .True (t , reflect .DeepEqual (sourceLabels , updTarget .Labels ))
1375+
1376+ _ , exists := updTarget .Annotations ["test-annotation" ]
1377+ require .False (t , exists )
1378+ })
1379+
12781380}
12791381
12801382func waitForNamespaces (client * kubernetes.Clientset , count int , eventHandlers EventHandlerFuncs ) (wg * sync.WaitGroup , stop chan struct {}) {
0 commit comments