Skip to content

Commit

Permalink
Merge 72b594e into 9f78d9e
Browse files Browse the repository at this point in the history
  • Loading branch information
Porges authored Jun 27, 2021
2 parents 9f78d9e + 72b594e commit 969588e
Show file tree
Hide file tree
Showing 75 changed files with 2,066 additions and 309 deletions.
16 changes: 7 additions & 9 deletions hack/generated/controllers/crd_cosmosdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ func Test_CosmosDB_CRUD(t *testing.T) {
acct := &documentdb.DatabaseAccount{
ObjectMeta: tc.MakeObjectMetaWithName(namer.GenerateName("db")),
Spec: documentdb.DatabaseAccounts_Spec{
Location: &tc.AzureRegion,
Owner: testcommon.AsOwner(rg.ObjectMeta),
Kind: &kind,
Properties: documentdb.DatabaseAccountCreateUpdateProperties{
DatabaseAccountOfferType: documentdb.DatabaseAccountCreateUpdatePropertiesDatabaseAccountOfferTypeStandard,
Locations: []documentdb.Location{
{
LocationName: &tc.AzureRegion,
},
Location: &tc.AzureRegion,
Owner: testcommon.AsOwner(rg.ObjectMeta),
Kind: &kind,
DatabaseAccountOfferType: documentdb.DatabaseAccountsSpecPropertiesDatabaseAccountOfferTypeStandard,
Locations: []documentdb.Location{
{
LocationName: &tc.AzureRegion,
},
},
},
Expand Down
16 changes: 7 additions & 9 deletions hack/generated/controllers/crd_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,24 @@ func Test_Disk_CRUD(t *testing.T) {
Sku: &compute.DiskSku{
Name: &standardSkuName,
},
Properties: compute.DiskProperties{
CreationData: compute.CreationData{
CreateOption: "Empty",
},
DiskSizeGB: &sizeInGb,
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.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
networkAccessPolicy := compute.DisksSpecPropertiesNetworkAccessPolicyDenyAll
disk.Spec.NetworkAccessPolicy = &networkAccessPolicy
patcher.Patch(disk)

objectKey, err := client.ObjectKeyFromObject(disk)
Expand All @@ -62,7 +60,7 @@ func Test_Disk_CRUD(t *testing.T) {
tc.Eventually(func() *compute.NetworkAccessPolicy_Status {
var updatedDisk compute.Disk
tc.GetResource(objectKey, &updatedDisk)
return updatedDisk.Status.Properties.NetworkAccessPolicy
return updatedDisk.Status.NetworkAccessPolicy
}).Should(BeEquivalentTo(&networkAccessPolicy))

tc.DeleteResourceAndWait(disk)
Expand Down
46 changes: 21 additions & 25 deletions hack/generated/controllers/crd_networking_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ func Test_LoadBalancer_CRUD(t *testing.T) {
Sku: &network.PublicIPAddressSku{
Name: &sku,
},
Properties: network.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: network.PublicIPAddressPropertiesFormatPublicIPAllocationMethodStatic,
},
PublicIPAllocationMethod: network.PublicIPAddressesSpecPropertiesPublicIPAllocationMethodStatic,
},
}

Expand All @@ -60,33 +58,31 @@ func Test_LoadBalancer_CRUD(t *testing.T) {
Sku: &network.LoadBalancerSku{
Name: &loadBalancerSku,
},
Properties: network.LoadBalancerPropertiesFormat{
FrontendIPConfigurations: []network.FrontendIPConfiguration{
{
Name: lbFrontendName,
Properties: &network.FrontendIPConfigurationPropertiesFormat{
PublicIPAddress: &network.SubResource{
Reference: tc.MakeReferenceFromResource(publicIPAddress),
},
FrontendIPConfigurations: []network.FrontendIPConfiguration{
{
Name: lbFrontendName,
Properties: &network.FrontendIPConfigurationPropertiesFormat{
PublicIPAddress: &network.SubResource{
Reference: tc.MakeReferenceFromResource(publicIPAddress),
},
},
},
// TODO: The below stuff isn't really necessary for LB CRUD but is required for VMSS...
InboundNatPools: []network.InboundNatPool{
{
Name: "MyFancyNatPool",
Properties: &network.InboundNatPoolPropertiesFormat{
FrontendIPConfiguration: network.SubResource{
Reference: genruntime.ResourceReference{
// TODO: This is still really awkward
ARMID: tc.MakeARMId(rg.Name, "Microsoft.Network", "loadBalancers", lbName, "frontendIPConfigurations", lbFrontendName),
},
},
// TODO: The below stuff isn't really necessary for LB CRUD but is required for VMSS...
InboundNatPools: []network.InboundNatPool{
{
Name: "MyFancyNatPool",
Properties: &network.InboundNatPoolPropertiesFormat{
FrontendIPConfiguration: network.SubResource{
Reference: genruntime.ResourceReference{
// TODO: This is still really awkward
ARMID: tc.MakeARMId(rg.Name, "Microsoft.Network", "loadBalancers", lbName, "frontendIPConfigurations", lbFrontendName),
},
Protocol: network.InboundNatPoolPropertiesFormatProtocolTcp,
FrontendPortRangeStart: 50000,
FrontendPortRangeEnd: 51000,
BackendPort: 22,
},
Protocol: network.InboundNatPoolPropertiesFormatProtocolTcp,
FrontendPortRangeStart: 50000,
FrontendPortRangeEnd: 51000,
BackendPort: 22,
},
},
},
Expand Down
8 changes: 3 additions & 5 deletions hack/generated/controllers/crd_networking_publicip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ func Test_PublicIP_CRUD(t *testing.T) {
Sku: &network.PublicIPAddressSku{
Name: &sku,
},
Properties: network.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: network.PublicIPAddressPropertiesFormatPublicIPAllocationMethodStatic,
},
PublicIPAllocationMethod: network.PublicIPAddressesSpecPropertiesPublicIPAllocationMethodStatic,
},
}

Expand All @@ -49,7 +47,7 @@ func Test_PublicIP_CRUD(t *testing.T) {
patcher := tc.NewResourcePatcher(publicIPAddress)

idleTimeoutInMinutes := 7
publicIPAddress.Spec.Properties.IdleTimeoutInMinutes = &idleTimeoutInMinutes
publicIPAddress.Spec.IdleTimeoutInMinutes = &idleTimeoutInMinutes
patcher.Patch(publicIPAddress)

objectKey, err := client.ObjectKeyFromObject(publicIPAddress)
Expand All @@ -59,7 +57,7 @@ func Test_PublicIP_CRUD(t *testing.T) {
tc.Eventually(func() *int {
updatedIP := &network.PublicIPAddresses{}
tc.GetResource(objectKey, updatedIP)
return updatedIP.Status.Properties.IdleTimeoutInMinutes
return updatedIP.Status.IdleTimeoutInMinutes
}).Should(Equal(&idleTimeoutInMinutes))

tc.DeleteResourceAndWait(publicIPAddress)
Expand Down
8 changes: 3 additions & 5 deletions hack/generated/controllers/crd_servicebus_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func Test_ServiceBus_Basic_CRUD(t *testing.T) {
Sku: &servicebus.SBSku{
Name: servicebus.SBSkuNameBasic,
},
Properties: servicebus.SBNamespaceProperties{
ZoneRedundant: &zoneRedundant,
},
ZoneRedundant: &zoneRedundant,
},
}

Expand Down Expand Up @@ -76,6 +74,6 @@ func ServiceBus_Queue_CRUD(tc testcommon.KubePerTestContext, sbNamespace metav1.
tc.Expect(queue.Status.Id).ToNot(BeNil())

// a basic assertion on a property
tc.Expect(queue.Status.Properties.SizeInBytes).ToNot(BeNil())
tc.Expect(*queue.Status.Properties.SizeInBytes).To(Equal(0))
tc.Expect(queue.Status.SizeInBytes).ToNot(BeNil())
tc.Expect(*queue.Status.SizeInBytes).To(Equal(0))
}
8 changes: 3 additions & 5 deletions hack/generated/controllers/crd_servicebus_standard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func Test_ServiceBus_Standard_CRUD(t *testing.T) {
Sku: &servicebus.SBSku{
Name: servicebus.SBSkuNameStandard,
},
Properties: servicebus.SBNamespaceProperties{
ZoneRedundant: &zoneRedundant,
},
ZoneRedundant: &zoneRedundant,
},
}

Expand Down Expand Up @@ -79,6 +77,6 @@ func ServiceBus_Topic_CRUD(tc testcommon.KubePerTestContext, sbNamespace metav1.
tc.Expect(topic.Status.Id).ToNot(BeNil())

// a basic assertion on a property
tc.Expect(topic.Status.Properties.SizeInBytes).ToNot(BeNil())
tc.Expect(*topic.Status.Properties.SizeInBytes).To(Equal(0))
tc.Expect(topic.Status.SizeInBytes).ToNot(BeNil())
tc.Expect(*topic.Status.SizeInBytes).To(Equal(0))
}
8 changes: 3 additions & 5 deletions hack/generated/controllers/crd_storageaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ func Test_StorageAccount_CRUD(t *testing.T) {
Location: tc.AzureRegion,
Owner: testcommon.AsOwner(rg.ObjectMeta),
Kind: storage.StorageAccountsSpecKindBlobStorage,
Sku: storage.Sku{
Name: storage.SkuNameStandardLRS,
Sku: storage.StorageAccounts_Spec_Sku{
Name: storage.StorageAccountsSpecSkuNameStandardLRS,
},
// TODO: They mark this property as optional but actually it is required
Properties: &storage.StorageAccountPropertiesCreateParameters{
AccessTier: &accessTier,
},
AccessTier: &accessTier,
},
}

Expand Down
6 changes: 2 additions & 4 deletions hack/generated/controllers/crd_virtualnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ func Test_VirtualNetwork_CRUD(t *testing.T) {
Spec: network.VirtualNetworks_Spec{
Owner: testcommon.AsOwner(rg.ObjectMeta),
Location: testcommon.DefaultTestRegion,
Properties: network.VirtualNetworkPropertiesFormat{
AddressSpace: network.AddressSpace{
AddressPrefixes: []string{"10.0.0.0/8"},
},
AddressSpace: network.AddressSpace{
AddressPrefixes: []string{"10.0.0.0/8"},
},
},
}
Expand Down
16 changes: 6 additions & 10 deletions hack/generated/pkg/reconcilers/azure_deployment_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ const (
DeleteActionMonitorDelete = DeleteAction("MonitorDelete")
)

type CreateOrUpdateActionFunc = func(ctx context.Context) (ctrl.Result, error)
type DeleteActionFunc = func(ctx context.Context) (ctrl.Result, error)
type (
CreateOrUpdateActionFunc = func(ctx context.Context) (ctrl.Result, error)
DeleteActionFunc = func(ctx context.Context) (ctrl.Result, error)
)

var _ genruntime.Reconciler = &AzureDeploymentReconciler{}

Expand Down Expand Up @@ -109,7 +111,6 @@ func NewAzureDeploymentReconciler(

func (r *AzureDeploymentReconciler) CreateOrUpdate(ctx context.Context) (ctrl.Result, error) {
action, actionFunc, err := r.DetermineCreateOrUpdateAction()

if err != nil {
r.log.Error(err, "error determining create or update action")
r.recorder.Event(r.obj, v1.EventTypeWarning, "DetermineCreateOrUpdateActionError", err.Error())
Expand All @@ -128,7 +129,6 @@ func (r *AzureDeploymentReconciler) CreateOrUpdate(ctx context.Context) (ctrl.Re

func (r *AzureDeploymentReconciler) Delete(ctx context.Context) (ctrl.Result, error) {
action, actionFunc, err := r.DetermineDeleteAction()

if err != nil {
r.log.Error(err, "error determining delete action")
r.recorder.Event(r.obj, v1.EventTypeWarning, "DetermineDeleteActionError", err.Error())
Expand Down Expand Up @@ -350,7 +350,6 @@ func NoAction(_ context.Context) (ctrl.Result, error) {
// StartDeleteOfResource will begin the delete of a resource by telling Azure to start deleting it. The resource will be
// marked with the provisioning state of "Deleting".
func (r *AzureDeploymentReconciler) StartDeleteOfResource(ctx context.Context) (ctrl.Result, error) {

msg := "Starting delete of resource"
r.log.Info(msg)
r.recorder.Event(r.obj, v1.EventTypeNormal, string(DeleteActionBeginDelete), msg)
Expand All @@ -364,7 +363,6 @@ func (r *AzureDeploymentReconciler) StartDeleteOfResource(ctx context.Context) (
// TODO: return the data we need.
// TODO(matthchr): For now just emulate this with reflection
resource, err := r.constructArmResource(ctx)

if err != nil {
// If the error is that the owner isn't found, that probably
// means that the owner was deleted in Kubernetes. The current
Expand All @@ -373,9 +371,9 @@ func (r *AzureDeploymentReconciler) StartDeleteOfResource(ctx context.Context) (
var typedErr *genruntime.ReferenceNotFound
if errors.As(err, &typedErr) {
// TODO: We should confirm the above assumption by performing a HEAD on
// TODO: the resource in Azure. This requires GetApiVersion() on metaObj which
// TODO: the resource in Azure. This requires GetAPIVersion() on metaObj which
// TODO: we don't currently have in the interface.
// gr.ARMClient.HeadResource(ctx, data.resourceID, r.obj.GetApiVersion())
// gr.ARMClient.HeadResource(ctx, data.resourceID, r.obj.GetAPIVersion())
return ctrl.Result{}, r.deleteResourceSucceeded(ctx)
}

Expand Down Expand Up @@ -413,7 +411,6 @@ func (r *AzureDeploymentReconciler) StartDeleteOfResource(ctx context.Context) (
// MonitorDelete will call Azure to check if the resource still exists. If so, it will requeue, else,
// the finalizer will be removed.
func (r *AzureDeploymentReconciler) MonitorDelete(ctx context.Context) (ctrl.Result, error) {

msg := "Continue monitoring deletion"
r.log.V(1).Info(msg)
r.recorder.Event(r.obj, v1.EventTypeNormal, string(DeleteActionMonitorDelete), msg)
Expand Down Expand Up @@ -594,7 +591,6 @@ func (r *AzureDeploymentReconciler) MonitorDeployment(ctx context.Context) (ctrl
func (r *AzureDeploymentReconciler) ManageOwnership(ctx context.Context) (ctrl.Result, error) {
r.log.V(1).Info("applying ownership", "action", CreateOrUpdateActionManageOwnership)
isOwnerReady, err := r.isOwnerReady(ctx)

if err != nil {
return ctrl.Result{}, err
}
Expand Down
5 changes: 3 additions & 2 deletions hack/generated/pkg/reflecthelpers/reflect_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

//nolint:staticcheck // ignoring deprecation (SA1019) to unblock CI builds
"sigs.k8s.io/controller-runtime/pkg/client/fake"

resources "github.com/Azure/azure-service-operator/hack/generated/_apis/microsoft.resources/v1alpha1api20200601"
"github.com/Azure/azure-service-operator/hack/generated/pkg/genruntime"
"github.com/Azure/azure-service-operator/hack/generated/pkg/reflecthelpers"
"github.com/Azure/azure-service-operator/hack/generated/pkg/util/kubeclient"

// TODO: Do we want to use a sample object rather than a code generated one?
batch "github.com/Azure/azure-service-operator/hack/generated/_apis/microsoft.batch/v1alpha1api20210101"

Expand Down Expand Up @@ -51,7 +53,6 @@ func createDummyResource() *batch.BatchAccount {
Owner: genruntime.KnownResourceReference{
Name: "myrg",
},
Properties: batch.BatchAccountCreateProperties{},
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-group",
Expand Down Expand Up @@ -162,7 +163,7 @@ func Test_FindReferences(t *testing.T) {
g.Expect(test.client.Create(ctx, rg)).To(Succeed())
account := createDummyResource()
ref := genruntime.ResourceReference{ARMID: "test"}
account.Spec.Properties.KeyVaultReference = &batch.KeyVaultReference{
account.Spec.KeyVaultReference = &batch.KeyVaultReference{
Reference: ref,
}
g.Expect(test.client.Create(ctx, account)).To(Succeed())
Expand Down
1 change: 0 additions & 1 deletion hack/generated/pkg/util/patch/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func TestPatchNotFound(t *testing.T) {
}

func TestHelperPatch(t *testing.T) {

tests := []struct {
name string
before runtime.Object
Expand Down
4 changes: 2 additions & 2 deletions hack/generator/azure-arm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ typeTransformers:
because: it has no writable properties in swagger

# Deal with properties that should have been marked readOnly but weren't
- name: SBNamespaceProperties
- name: Namespaces_Spec
group: microsoft.servicebus
property: PrivateEndpointConnections
remove: true
because: The this property should have been marked readonly but wasn't.
because: This property should have been marked readonly but wasn't.

status:
schemaRoot: "./specs/azure-rest-api-specs/specification"
Expand Down
11 changes: 11 additions & 0 deletions hack/generator/pkg/astbuilder/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ func SimpleAssignment(lhs dst.Expr, tok token.Token, rhs dst.Expr) *dst.AssignSt
}
}

// QualifiedAssignment performs a simple assignment like:
// <lhs>.<lhsSel> := <rhs> // tok = token.DEFINE
// or <lhs>.<lhsSel> = <rhs> // tok = token.ASSIGN
func QualifiedAssignment(lhs dst.Expr, lhsSel string, tok token.Token, rhs dst.Expr) *dst.AssignStmt {
return &dst.AssignStmt{
Lhs: []dst.Expr{Selector(lhs, lhsSel)},
Tok: tok,
Rhs: []dst.Expr{dst.Clone(rhs).(dst.Expr)},
}
}

// SimpleAssignmentWithErr performs a simple assignment like:
// <lhs>, err := <rhs> // tok = token.DEFINE
// or <lhs>, err = <rhs> // tok = token.ASSIGN
Expand Down
Loading

0 comments on commit 969588e

Please sign in to comment.