@@ -18,17 +18,13 @@ package scope
1818
1919import (
2020 "context"
21- "crypto/sha256"
22- "encoding/base64"
2321 "fmt"
24- "io"
2522 "reflect"
2623 "testing"
2724 "time"
2825
2926 "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
3027 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2"
31- "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
3228 azureautorest "github.com/Azure/go-autorest/autorest/azure"
3329 "github.com/Azure/go-autorest/autorest/azure/auth"
3430 . "github.com/onsi/gomega"
@@ -1750,148 +1746,3 @@ func TestMachinePoolScope_setProvisioningStateAndConditions(t *testing.T) {
17501746 })
17511747 }
17521748}
1753-
1754- func TestBootstrapDataChanges (t * testing.T ) {
1755- ctx , cancel := context .WithCancel (t .Context ())
1756- defer cancel ()
1757- scheme := runtime .NewScheme ()
1758- _ = clusterv1 .AddToScheme (scheme )
1759- _ = infrav1 .AddToScheme (scheme )
1760- _ = infrav1exp .AddToScheme (scheme )
1761- _ = corev1 .AddToScheme (scheme )
1762-
1763- var (
1764- g = NewWithT (t )
1765- mockCtrl = gomock .NewController (t )
1766- cb = fake .NewClientBuilder ().WithScheme (scheme )
1767- cluster = & clusterv1.Cluster {
1768- ObjectMeta : metav1.ObjectMeta {
1769- Name : "cluster1" ,
1770- Namespace : "default" ,
1771- },
1772- Spec : clusterv1.ClusterSpec {
1773- InfrastructureRef : & corev1.ObjectReference {
1774- Name : "azCluster1" ,
1775- },
1776- },
1777- Status : clusterv1.ClusterStatus {
1778- InfrastructureReady : true ,
1779- },
1780- }
1781- azureCluster = & infrav1.AzureCluster {
1782- ObjectMeta : metav1.ObjectMeta {
1783- Name : "azCluster1" ,
1784- Namespace : "default" ,
1785- },
1786- Spec : infrav1.AzureClusterSpec {
1787- AzureClusterClassSpec : infrav1.AzureClusterClassSpec {
1788- Location : "test" ,
1789- },
1790- },
1791- }
1792- mp = & expv1.MachinePool {
1793- ObjectMeta : metav1.ObjectMeta {
1794- Name : "mp1" ,
1795- Namespace : "default" ,
1796- OwnerReferences : []metav1.OwnerReference {
1797- {
1798- Name : "cluster1" ,
1799- Kind : "Cluster" ,
1800- APIVersion : clusterv1 .GroupVersion .String (),
1801- },
1802- },
1803- },
1804- Spec : expv1.MachinePoolSpec {
1805- Template : clusterv1.MachineTemplateSpec {
1806- Spec : clusterv1.MachineSpec {
1807- Bootstrap : clusterv1.Bootstrap {
1808- DataSecretName : ptr .To ("mp-secret" ),
1809- },
1810- Version : ptr .To ("v1.31.0" ),
1811- },
1812- },
1813- },
1814- }
1815- bootstrapData = "test"
1816- bootstrapDataHash = sha256Hash (base64 .StdEncoding .EncodeToString ([]byte (bootstrapData )))
1817- bootstrapSecret = corev1.Secret {
1818- ObjectMeta : metav1.ObjectMeta {
1819- Name : "mp-secret" ,
1820- Namespace : "default" ,
1821- },
1822- Data : map [string ][]byte {"value" : []byte (bootstrapData )},
1823- }
1824- amp = & infrav1exp.AzureMachinePool {
1825- ObjectMeta : metav1.ObjectMeta {
1826- Name : "amp1" ,
1827- Namespace : "default" ,
1828- OwnerReferences : []metav1.OwnerReference {
1829- {
1830- Name : "mp1" ,
1831- Kind : "MachinePool" ,
1832- APIVersion : expv1 .GroupVersion .String (),
1833- },
1834- },
1835- Annotations : map [string ]string {
1836- azure .CustomDataHashAnnotation : fmt .Sprintf ("%x" , bootstrapDataHash ),
1837- },
1838- },
1839- Spec : infrav1exp.AzureMachinePoolSpec {
1840- Template : infrav1exp.AzureMachinePoolMachineTemplate {
1841- Image : & infrav1.Image {},
1842- NetworkInterfaces : []infrav1.NetworkInterface {
1843- {
1844- SubnetName : "test" ,
1845- },
1846- },
1847- VMSize : "VM_SIZE" ,
1848- },
1849- },
1850- }
1851- vmssState = & azure.VMSS {}
1852- )
1853- defer mockCtrl .Finish ()
1854-
1855- s := & MachinePoolScope {
1856- client : cb .
1857- WithObjects (& bootstrapSecret ).
1858- Build (),
1859- ClusterScoper : & ClusterScope {
1860- Cluster : cluster ,
1861- AzureCluster : azureCluster ,
1862- },
1863- skuCache : resourceskus .NewStaticCache ([]armcompute.ResourceSKU {
1864- {
1865- Name : ptr .To ("VM_SIZE" ),
1866- },
1867- }, "test" ),
1868- MachinePool : mp ,
1869- AzureMachinePool : amp ,
1870- vmssState : vmssState ,
1871- }
1872-
1873- g .Expect (s .InitMachinePoolCache (ctx )).NotTo (HaveOccurred ())
1874-
1875- spec := s .ScaleSetSpec (ctx )
1876- sSpec := spec .(* scalesets.ScaleSetSpec )
1877- g .Expect (sSpec .ShouldPatchCustomData ).To (BeFalse ())
1878-
1879- amp .Annotations [azure .CustomDataHashAnnotation ] = "old"
1880-
1881- // reset cache to be able to build up the cache again
1882- s .cache = nil
1883- g .Expect (s .InitMachinePoolCache (ctx )).NotTo (HaveOccurred ())
1884-
1885- spec = s .ScaleSetSpec (ctx )
1886- sSpec = spec .(* scalesets.ScaleSetSpec )
1887- g .Expect (sSpec .ShouldPatchCustomData ).To (BeTrue ())
1888- }
1889-
1890- func sha256Hash (text string ) []byte {
1891- h := sha256 .New ()
1892- _ , err := io .WriteString (h , text )
1893- if err != nil {
1894- panic (err )
1895- }
1896- return h .Sum (nil )
1897- }
0 commit comments