@@ -1654,6 +1654,7 @@ user_data_collector_config: {}
16541654
16551655 Context ("Proxy settings" , func () {
16561656 const caConfigMapName = "test-ca-configmap"
1657+ const proxyURL = "https://proxy.example.com:8080"
16571658 var proxyCACm * corev1.ConfigMap
16581659
16591660 BeforeEach (func () {
@@ -1727,15 +1728,19 @@ user_data_collector_config: {}
17271728 ))
17281729
17291730 cr .Spec .OLSConfig .ProxyConfig = & olsv1alpha1.ProxyConfig {
1730- ProxyURL : "https://proxy.example.com:8080" ,
1731- ProxyCACertificateRef : & corev1.LocalObjectReference {
1732- Name : caConfigMapName ,
1731+ ProxyURL : proxyURL ,
1732+ ProxyCACertificateRef : & olsv1alpha1.ProxyCACertConfigMapRef {
1733+ LocalObjectReference : corev1.LocalObjectReference {
1734+ Name : caConfigMapName ,
1735+ },
1736+ // No Key specified - tests backward compatibility
17331737 },
17341738 }
17351739
17361740 olsCm , err = GenerateOLSConfigMap (testReconcilerInstance , ctx , cr )
17371741 Expect (err ).NotTo (HaveOccurred ())
1738- Expect (olsCm .Data [utils .OLSConfigFilename ]).To (ContainSubstring ("proxy_config:\n proxy_ca_cert_path: /etc/certs/proxy-ca/proxy-ca.crt\n proxy_url: https://proxy.example.com:8080\n " ))
1742+ Expect (olsCm .Data [utils .OLSConfigFilename ]).To (ContainSubstring ("proxy_ca_cert_path: /etc/certs/proxy-ca/" + utils .ProxyCACertFileName ))
1743+ Expect (olsCm .Data [utils .OLSConfigFilename ]).To (ContainSubstring ("proxy_url: " + proxyURL ))
17391744
17401745 dep , err = GenerateOLSDeployment (testReconcilerInstance , cr )
17411746 Expect (err ).NotTo (HaveOccurred ())
@@ -1748,6 +1753,9 @@ user_data_collector_config: {}
17481753 Name : caConfigMapName ,
17491754 },
17501755 DefaultMode : & defaultVolumeMode ,
1756+ Items : []corev1.KeyToPath {
1757+ {Key : utils .ProxyCACertFileName , Path : utils .ProxyCACertFileName },
1758+ },
17511759 },
17521760 },
17531761 }))
@@ -1766,15 +1774,38 @@ user_data_collector_config: {}
17661774 Expect (err ).NotTo (HaveOccurred ())
17671775
17681776 cr .Spec .OLSConfig .ProxyConfig = & olsv1alpha1.ProxyConfig {
1769- ProxyURL : "https://proxy.example.com:8080" ,
1770- ProxyCACertificateRef : & corev1.LocalObjectReference {
1771- Name : caConfigMapName ,
1777+ ProxyURL : proxyURL ,
1778+ ProxyCACertificateRef : & olsv1alpha1.ProxyCACertConfigMapRef {
1779+ LocalObjectReference : corev1.LocalObjectReference {
1780+ Name : caConfigMapName ,
1781+ },
1782+ // No Key specified - tests backward compatibility
17721783 },
17731784 }
17741785 _ , err = GenerateOLSConfigMap (testReconcilerInstance , ctx , cr )
17751786 Expect (err ).To (HaveOccurred ())
17761787 Expect (err .Error ()).To (ContainSubstring ("failed to validate proxy CA certificate" ))
17771788 })
1789+
1790+ It ("should use custom Key when ProxyCACertificateRef.Key is set" , func () {
1791+ const proxyCertKey = "my-proxy-ca.crt"
1792+ proxyCACm .Data [proxyCertKey ] = utils .TestCACert
1793+ err := testReconcilerInstance .Update (ctx , proxyCACm )
1794+ Expect (err ).NotTo (HaveOccurred ())
1795+
1796+ cr .Spec .OLSConfig .ProxyConfig = & olsv1alpha1.ProxyConfig {
1797+ ProxyURL : proxyURL ,
1798+ ProxyCACertificateRef : & olsv1alpha1.ProxyCACertConfigMapRef {
1799+ LocalObjectReference : corev1.LocalObjectReference {Name : caConfigMapName },
1800+ Key : proxyCertKey ,
1801+ },
1802+ }
1803+
1804+ olsCm , err := GenerateOLSConfigMap (testReconcilerInstance , ctx , cr )
1805+ Expect (err ).NotTo (HaveOccurred ())
1806+ Expect (olsCm .Data [utils .OLSConfigFilename ]).To (ContainSubstring ("proxy_ca_cert_path: /etc/certs/proxy-ca/" + proxyCertKey ))
1807+ Expect (olsCm .Data [utils .OLSConfigFilename ]).To (ContainSubstring ("proxy_url: " + proxyURL ))
1808+ })
17781809 })
17791810})
17801811
0 commit comments