@@ -1547,8 +1547,101 @@ func Test_BundleValidatingWebhookResourceGenerator_Succeeds(t *testing.T) {
1547
1547
APIVersion : admissionregistrationv1 .SchemeGroupVersion .String (),
1548
1548
},
1549
1549
ObjectMeta : metav1.ObjectMeta {
1550
- GenerateName : "my-webhook-" ,
1551
- Namespace : "install-namespace" ,
1550
+ Name : "my-webhook" ,
1551
+ Namespace : "install-namespace" ,
1552
+ },
1553
+ Webhooks : []admissionregistrationv1.ValidatingWebhook {
1554
+ {
1555
+ Name : "my-webhook" ,
1556
+ Rules : []admissionregistrationv1.RuleWithOperations {
1557
+ {
1558
+ Operations : []admissionregistrationv1.OperationType {
1559
+ admissionregistrationv1 .OperationAll ,
1560
+ },
1561
+ Rule : admissionregistrationv1.Rule {
1562
+ APIGroups : []string {"" },
1563
+ APIVersions : []string {"" },
1564
+ Resources : []string {"namespaces" },
1565
+ },
1566
+ },
1567
+ },
1568
+ FailurePolicy : ptr .To (admissionregistrationv1 .Fail ),
1569
+ ObjectSelector : & metav1.LabelSelector {
1570
+ MatchLabels : map [string ]string {
1571
+ "foo" : "bar" ,
1572
+ },
1573
+ },
1574
+ SideEffects : ptr .To (admissionregistrationv1 .SideEffectClassNone ),
1575
+ TimeoutSeconds : ptr .To (int32 (1 )),
1576
+ AdmissionReviewVersions : []string {
1577
+ "v1beta1" ,
1578
+ "v1beta2" ,
1579
+ },
1580
+ ClientConfig : admissionregistrationv1.WebhookClientConfig {
1581
+ Service : & admissionregistrationv1.ServiceReference {
1582
+ Namespace : "install-namespace" ,
1583
+ Name : "my-deployment-service" ,
1584
+ Path : ptr .To ("/webhook-path" ),
1585
+ Port : ptr .To (int32 (443 )),
1586
+ },
1587
+ },
1588
+ },
1589
+ },
1590
+ },
1591
+ },
1592
+ },
1593
+ {
1594
+ name : "removes any - suffixes from the webhook name (v0 used GenerateName to allow multiple operator installations - we don't want that in v1)" ,
1595
+ bundle : & render.RegistryV1 {
1596
+ CSV : MakeCSV (
1597
+ WithWebhookDefinitions (
1598
+ v1alpha1.WebhookDescription {
1599
+ Type : v1alpha1 .ValidatingAdmissionWebhook ,
1600
+ GenerateName : "my-webhook-" ,
1601
+ DeploymentName : "my-deployment" ,
1602
+ Rules : []admissionregistrationv1.RuleWithOperations {
1603
+ {
1604
+ Operations : []admissionregistrationv1.OperationType {
1605
+ admissionregistrationv1 .OperationAll ,
1606
+ },
1607
+ Rule : admissionregistrationv1.Rule {
1608
+ APIGroups : []string {"" },
1609
+ APIVersions : []string {"" },
1610
+ Resources : []string {"namespaces" },
1611
+ },
1612
+ },
1613
+ },
1614
+ FailurePolicy : ptr .To (admissionregistrationv1 .Fail ),
1615
+ ObjectSelector : & metav1.LabelSelector {
1616
+ MatchLabels : map [string ]string {
1617
+ "foo" : "bar" ,
1618
+ },
1619
+ },
1620
+ SideEffects : ptr .To (admissionregistrationv1 .SideEffectClassNone ),
1621
+ TimeoutSeconds : ptr .To (int32 (1 )),
1622
+ AdmissionReviewVersions : []string {
1623
+ "v1beta1" ,
1624
+ "v1beta2" ,
1625
+ },
1626
+ WebhookPath : ptr .To ("/webhook-path" ),
1627
+ ContainerPort : 443 ,
1628
+ },
1629
+ ),
1630
+ ),
1631
+ },
1632
+ opts : render.Options {
1633
+ InstallNamespace : "install-namespace" ,
1634
+ TargetNamespaces : []string {"watch-namespace-one" , "watch-namespace-two" },
1635
+ },
1636
+ expectedResources : []client.Object {
1637
+ & admissionregistrationv1.ValidatingWebhookConfiguration {
1638
+ TypeMeta : metav1.TypeMeta {
1639
+ Kind : "ValidatingWebhookConfiguration" ,
1640
+ APIVersion : admissionregistrationv1 .SchemeGroupVersion .String (),
1641
+ },
1642
+ ObjectMeta : metav1.ObjectMeta {
1643
+ Name : "my-webhook" ,
1644
+ Namespace : "install-namespace" ,
1552
1645
},
1553
1646
Webhooks : []admissionregistrationv1.ValidatingWebhook {
1554
1647
{
@@ -1616,8 +1709,8 @@ func Test_BundleValidatingWebhookResourceGenerator_Succeeds(t *testing.T) {
1616
1709
APIVersion : admissionregistrationv1 .SchemeGroupVersion .String (),
1617
1710
},
1618
1711
ObjectMeta : metav1.ObjectMeta {
1619
- GenerateName : "my-webhook- " ,
1620
- Namespace : "install-namespace" ,
1712
+ Name : "my-webhook" ,
1713
+ Namespace : "install-namespace" ,
1621
1714
Annotations : map [string ]string {
1622
1715
"cert-provider" : "annotation" ,
1623
1716
},
@@ -1719,8 +1812,103 @@ func Test_BundleMutatingWebhookResourceGenerator_Succeeds(t *testing.T) {
1719
1812
APIVersion : admissionregistrationv1 .SchemeGroupVersion .String (),
1720
1813
},
1721
1814
ObjectMeta : metav1.ObjectMeta {
1722
- GenerateName : "my-webhook-" ,
1723
- Namespace : "install-namespace" ,
1815
+ Name : "my-webhook" ,
1816
+ Namespace : "install-namespace" ,
1817
+ },
1818
+ Webhooks : []admissionregistrationv1.MutatingWebhook {
1819
+ {
1820
+ Name : "my-webhook" ,
1821
+ Rules : []admissionregistrationv1.RuleWithOperations {
1822
+ {
1823
+ Operations : []admissionregistrationv1.OperationType {
1824
+ admissionregistrationv1 .OperationAll ,
1825
+ },
1826
+ Rule : admissionregistrationv1.Rule {
1827
+ APIGroups : []string {"" },
1828
+ APIVersions : []string {"" },
1829
+ Resources : []string {"namespaces" },
1830
+ },
1831
+ },
1832
+ },
1833
+ FailurePolicy : ptr .To (admissionregistrationv1 .Fail ),
1834
+ ObjectSelector : & metav1.LabelSelector {
1835
+ MatchLabels : map [string ]string {
1836
+ "foo" : "bar" ,
1837
+ },
1838
+ },
1839
+ SideEffects : ptr .To (admissionregistrationv1 .SideEffectClassNone ),
1840
+ TimeoutSeconds : ptr .To (int32 (1 )),
1841
+ AdmissionReviewVersions : []string {
1842
+ "v1beta1" ,
1843
+ "v1beta2" ,
1844
+ },
1845
+ ReinvocationPolicy : ptr .To (admissionregistrationv1 .IfNeededReinvocationPolicy ),
1846
+ ClientConfig : admissionregistrationv1.WebhookClientConfig {
1847
+ Service : & admissionregistrationv1.ServiceReference {
1848
+ Namespace : "install-namespace" ,
1849
+ Name : "my-deployment-service" ,
1850
+ Path : ptr .To ("/webhook-path" ),
1851
+ Port : ptr .To (int32 (443 )),
1852
+ },
1853
+ },
1854
+ },
1855
+ },
1856
+ },
1857
+ },
1858
+ },
1859
+ {
1860
+ name : "removes any - suffixes from the webhook name (v0 used GenerateName to allow multiple operator installations - we don't want that in v1)" ,
1861
+ bundle : & render.RegistryV1 {
1862
+ CSV : MakeCSV (
1863
+ WithWebhookDefinitions (
1864
+ v1alpha1.WebhookDescription {
1865
+ Type : v1alpha1 .MutatingAdmissionWebhook ,
1866
+ GenerateName : "my-webhook-" ,
1867
+ DeploymentName : "my-deployment" ,
1868
+ Rules : []admissionregistrationv1.RuleWithOperations {
1869
+ {
1870
+ Operations : []admissionregistrationv1.OperationType {
1871
+ admissionregistrationv1 .OperationAll ,
1872
+ },
1873
+ Rule : admissionregistrationv1.Rule {
1874
+ APIGroups : []string {"" },
1875
+ APIVersions : []string {"" },
1876
+ Resources : []string {"namespaces" },
1877
+ },
1878
+ },
1879
+ },
1880
+ FailurePolicy : ptr .To (admissionregistrationv1 .Fail ),
1881
+ ObjectSelector : & metav1.LabelSelector {
1882
+ MatchLabels : map [string ]string {
1883
+ "foo" : "bar" ,
1884
+ },
1885
+ },
1886
+ SideEffects : ptr .To (admissionregistrationv1 .SideEffectClassNone ),
1887
+ TimeoutSeconds : ptr .To (int32 (1 )),
1888
+ AdmissionReviewVersions : []string {
1889
+ "v1beta1" ,
1890
+ "v1beta2" ,
1891
+ },
1892
+ WebhookPath : ptr .To ("/webhook-path" ),
1893
+ ContainerPort : 443 ,
1894
+ ReinvocationPolicy : ptr .To (admissionregistrationv1 .IfNeededReinvocationPolicy ),
1895
+ },
1896
+ ),
1897
+ ),
1898
+ },
1899
+ opts : render.Options {
1900
+ InstallNamespace : "install-namespace" ,
1901
+ TargetNamespaces : []string {"watch-namespace-one" , "watch-namespace-two" },
1902
+ },
1903
+ expectedResources : []client.Object {
1904
+ & admissionregistrationv1.MutatingWebhookConfiguration {
1905
+ TypeMeta : metav1.TypeMeta {
1906
+ Kind : "MutatingWebhookConfiguration" ,
1907
+ APIVersion : admissionregistrationv1 .SchemeGroupVersion .String (),
1908
+ },
1909
+ ObjectMeta : metav1.ObjectMeta {
1910
+ Name : "my-webhook" ,
1911
+ Namespace : "install-namespace" ,
1724
1912
},
1725
1913
Webhooks : []admissionregistrationv1.MutatingWebhook {
1726
1914
{
@@ -1789,8 +1977,8 @@ func Test_BundleMutatingWebhookResourceGenerator_Succeeds(t *testing.T) {
1789
1977
APIVersion : admissionregistrationv1 .SchemeGroupVersion .String (),
1790
1978
},
1791
1979
ObjectMeta : metav1.ObjectMeta {
1792
- GenerateName : "my-webhook- " ,
1793
- Namespace : "install-namespace" ,
1980
+ Name : "my-webhook" ,
1981
+ Namespace : "install-namespace" ,
1794
1982
Annotations : map [string ]string {
1795
1983
"cert-provider" : "annotation" ,
1796
1984
},
@@ -2258,6 +2446,7 @@ func Test_CertProviderResourceGenerator_Succeeds(t *testing.T) {
2258
2446
fakeProvider := FakeCertProvider {
2259
2447
AdditionalObjectsFn : func (cfg render.CertificateProvisionerConfig ) ([]unstructured.Unstructured , error ) {
2260
2448
return []unstructured.Unstructured {* ToUnstructuredT (t , & corev1.Secret {
2449
+ TypeMeta : metav1.TypeMeta {Kind : "Secret" , APIVersion : corev1 .SchemeGroupVersion .String ()},
2261
2450
ObjectMeta : metav1.ObjectMeta {
2262
2451
Name : cfg .CertName ,
2263
2452
},
@@ -2290,9 +2479,8 @@ func Test_CertProviderResourceGenerator_Succeeds(t *testing.T) {
2290
2479
require .NoError (t , err )
2291
2480
require .Equal (t , []client.Object {
2292
2481
ToUnstructuredT (t , & corev1.Secret {
2293
- ObjectMeta : metav1.ObjectMeta {
2294
- Name : "my-deployment-service-cert" ,
2295
- },
2482
+ TypeMeta : metav1.TypeMeta {Kind : "Secret" , APIVersion : corev1 .SchemeGroupVersion .String ()},
2483
+ ObjectMeta : metav1.ObjectMeta {Name : "my-deployment-service-cert" },
2296
2484
}),
2297
2485
}, objs )
2298
2486
}
0 commit comments