Skip to content

Commit

Permalink
Add Disk (from microsoft.compute/20200930) to generated resources (#1568
Browse files Browse the repository at this point in the history
)

* Add microsoft.compute/20200930/Disk to generated resources

With a CRUD test.

* Add references found in Disk types to the list
  • Loading branch information
babbageclunk authored Jun 16, 2021
1 parent a4d3a51 commit 2ceb10b
Show file tree
Hide file tree
Showing 4 changed files with 992 additions and 0 deletions.
77 changes: 77 additions & 0 deletions hack/generated/controllers/crd_disk_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
*/

package controllers_test

import (
"testing"

. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/client"

compute "github.com/Azure/azure-service-operator/hack/generated/_apis/microsoft.compute/v1alpha1api20200930"
"github.com/Azure/azure-service-operator/hack/generated/pkg/testcommon"
)

func Test_Disk_CRUD(t *testing.T) {
t.Parallel()

tc := globalTestContext.ForTest(t)

rg := tc.CreateNewTestResourceGroupAndWait()

// Create a disk.
standardSkuName := compute.DiskSkuNameStandardLRS
sizeInGb := 500
disk := &compute.Disk{
ObjectMeta: tc.MakeObjectMeta("disk"),
Spec: compute.Disks_Spec{
Location: tc.AzureRegion,
Owner: testcommon.AsOwner(rg.ObjectMeta),
Sku: &compute.DiskSku{
Name: &standardSkuName,
},
Properties: compute.DiskProperties{
CreationData: compute.CreationData{
CreateOption: "Empty",
},
DiskSizeGB: &sizeInGb,
},
},
}
tc.CreateResourceAndWait(disk)

tc.Expect(disk.Status.Location).To(Equal(tc.AzureRegion))
tc.Expect(disk.Status.Sku.Name).To(BeEquivalentTo(&standardSkuName))
tc.Expect(*disk.Status.Properties.DiskSizeGB).To(BeNumerically(">=", 500))
tc.Expect(disk.Status.Id).ToNot(BeNil())
armId := *disk.Status.Id

// Perform a simple patch.
patcher := tc.NewResourcePatcher(disk)
networkAccessPolicy := compute.DiskPropertiesNetworkAccessPolicyDenyAll
disk.Spec.Properties.NetworkAccessPolicy = &networkAccessPolicy
patcher.Patch(disk)

objectKey, err := client.ObjectKeyFromObject(disk)
tc.Expect(err).ToNot(HaveOccurred())

// Ensure state eventually gets updated in k8s from change in Azure.
tc.Eventually(func() *compute.NetworkAccessPolicy_Status {
var updatedDisk compute.Disk
tc.GetResource(objectKey, &updatedDisk)
return updatedDisk.Status.Properties.NetworkAccessPolicy
}).Should(BeEquivalentTo(&networkAccessPolicy))

tc.DeleteResourceAndWait(disk)

// Ensure that the resource group was really deleted in Azure
exists, _, err := tc.AzureClient.HeadResource(
tc.Ctx,
armId,
string(compute.DisksSpecAPIVersion20200930))
tc.Expect(err).ToNot(HaveOccurred())
tc.Expect(exists).To(BeFalse())
}
Loading

0 comments on commit 2ceb10b

Please sign in to comment.