Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Karl Dasan <[email protected]>
  • Loading branch information
ikarldasan committed Jun 5, 2021
1 parent 97d38c9 commit 69ab2c7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 32 deletions.
4 changes: 2 additions & 2 deletions apis/network/v1alpha3/register.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Crossplane Authors.
Copyright 2021 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,7 @@ var (
SubnetGroupVersionKind = SchemeGroupVersion.WithKind(SubnetKind)
)

// Subnet type metadata.
// DdosProtectionPlan type metadata.
var (
DdosProtectionPlanKind = reflect.TypeOf(DdosProtectionPlan{}).Name()
DdosProtectionPlanGroupKind = schema.GroupKind{Group: Group, Kind: DdosProtectionPlanKind}.String()
Expand Down
11 changes: 4 additions & 7 deletions apis/network/v1alpha3/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Crossplane Authors.
Copyright 2021 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -236,9 +236,6 @@ type DdosProtectionPlanPropertiesFormat struct {
// ProvisioningState - The provisioning state of the DDoS protection plan resource.
// +optional
ProvisioningState *string `json:"provisioningState,omitempty"`

// VirtualNetworks - The list of virtual networks associated with the DDoS protection plan resource.
// VirtualNetworks *[]network.SubResource `json:"virtualNetworks,omitempty"`
}

// A DdosProtectionPlanSpec defines the desired state of a DdosProtectionPlan.
Expand All @@ -256,13 +253,13 @@ type DdosProtectionPlanSpec struct {
// +optional
DdosProtectionPlanPropertiesFormat `json:"properties,omitempty"`

// ResourceGroupName - Name of the Subnet's resource group.
// ResourceGroupName - Name of the Ddos Protection Plan's resource group.
ResourceGroupName string `json:"resourceGroupName,omitempty"`

// ResourceGroupNameRef - A reference to the the Subnets's resource group.
// ResourceGroupNameRef - A reference to the the Ddos Protection Plan's resource group.
ResourceGroupNameRef *xpv1.Reference `json:"resourceGroupNameRef,omitempty"`

// ResourceGroupNameSelector - Selects a reference to the the Subnets's
// ResourceGroupNameSelector - Selects a reference to the the Ddos Protection Plan's
// resource group.
ResourceGroupNameSelector *xpv1.Selector `json:"resourceGroupNameSelector,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ spec:
- name
type: object
resourceGroupName:
description: ResourceGroupName - Name of the Subnet's resource group.
description: ResourceGroupName - Name of the Ddos Protection Plan's resource group.
type: string
resourceGroupNameRef:
description: ResourceGroupNameRef - A reference to the the Subnets's resource group.
description: ResourceGroupNameRef - A reference to the the Ddos Protection Plan's resource group.
properties:
name:
description: Name of the referenced object.
Expand All @@ -100,7 +100,7 @@ spec:
- name
type: object
resourceGroupNameSelector:
description: ResourceGroupNameSelector - Selects a reference to the the Subnets's resource group.
description: ResourceGroupNameSelector - Selects a reference to the the Ddos Protection Plan's resource group.
properties:
matchControllerRef:
description: MatchControllerRef ensures an object with the same controller reference as the selecting object is selected.
Expand Down
4 changes: 1 addition & 3 deletions pkg/clients/network/network.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Crossplane Authors.
Copyright 2021 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -107,8 +107,6 @@ func UpdateSubnetStatusFromAzure(v *v1alpha3.Subnet, az networkmgmt.Subnet) {
v.Status.Purpose = azure.ToString(az.Purpose)
}

// --------------------------------------------------------------------------------------------------- //

// NewDdosProtectionPlanParameters returns an Azure DdosProtectionPlan object from a ddosProtectionPlan spec
func NewDdosProtectionPlanParameters(d *v1alpha3.DdosProtectionPlan) networkmgmt.DdosProtectionPlan {
return networkmgmt.DdosProtectionPlan{
Expand Down
18 changes: 1 addition & 17 deletions pkg/controller/network/ddosprotectionplan/managed.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Crossplane Authors.
Copyright 2021 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -15,7 +15,6 @@ package ddosprotectionplan

import (
"context"
"fmt"

azurenetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network/networkapi"
Expand Down Expand Up @@ -89,16 +88,13 @@ func (c *connecter) Connect(ctx context.Context, mg resource.Managed) (managed.E
}

func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.ExternalObservation, error) {
fmt.Println("=====================OBSERVE START=====================")
d, ok := mg.(*v1alpha3.DdosProtectionPlan)
if !ok {
fmt.Println("=====================OBSERVE END ONE=====================")
return managed.ExternalObservation{}, errors.New(errNotDdosProtectionPlan)
}

az, err := e.client.Get(ctx, d.Spec.ResourceGroupName, meta.GetExternalName(d))
if err != nil {
fmt.Println("=====================OBSERVE END THREE=====================")
return managed.ExternalObservation{}, errors.Wrap(resource.Ignore(azureclients.IsNotFound, err), errGetDdosProtectionPlan)
}

Expand All @@ -120,12 +116,10 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
},
}

fmt.Println("=====================OBSERVE END LAST=====================")
return o, nil
}

func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.ExternalCreation, error) {
fmt.Println("***********************CREATE START***********************")
d, ok := mg.(*v1alpha3.DdosProtectionPlan)
if !ok {
return managed.ExternalCreation{}, errors.New(errNotDdosProtectionPlan)
Expand All @@ -136,49 +130,39 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
ddos := network.NewDdosProtectionPlanParameters(d)

if _, err := e.client.CreateOrUpdate(ctx, d.Spec.ResourceGroupName, meta.GetExternalName(d), ddos); err != nil {
fmt.Println("***********************CREATE END ONE***********************")
return managed.ExternalCreation{}, errors.Wrap(err, errCreateDdosProtectionPlan)
}
fmt.Println("***********************CREATE END LAST***********************")
return managed.ExternalCreation{}, nil
}

func (e *external) Update(ctx context.Context, mg resource.Managed) (managed.ExternalUpdate, error) {
fmt.Println("^^^^^^^^^^^^^^^^^^^^UPDATE START^^^^^^^^^^^^^^^^^^^^")
d, ok := mg.(*v1alpha3.DdosProtectionPlan)
if !ok {
fmt.Println("^^^^^^^^^^^^^^^^^^^^UPDATE END ONE^^^^^^^^^^^^^^^^^^^^")
return managed.ExternalUpdate{}, errors.New(errNotDdosProtectionPlan)
}

az, err := e.client.Get(ctx, d.Spec.ResourceGroupName, meta.GetExternalName(d))
if err != nil {
fmt.Println("^^^^^^^^^^^^^^^^^^^^UPDATE END TWO^^^^^^^^^^^^^^^^^^^^")
return managed.ExternalUpdate{}, errors.Wrap(err, errGetDdosProtectionPlan)
}

if !network.IsDdosProtectionPlanUpToDate(d, az) {
ddos := network.NewDdosProtectionPlanParameters(d)
if _, err := e.client.CreateOrUpdate(ctx, d.Spec.ResourceGroupName, meta.GetExternalName(d), ddos); err != nil {
fmt.Println("^^^^^^^^^^^^^^^^^^^^UPDATE END THREE^^^^^^^^^^^^^^^^^^^^")
return managed.ExternalUpdate{}, errors.Wrap(err, errUpdateDdosProtectionPlan)
}
}
fmt.Println("^^^^^^^^^^^^^^^^^^^^UPDATE END LAST^^^^^^^^^^^^^^^^^^^^")
return managed.ExternalUpdate{}, nil
}

func (e *external) Delete(ctx context.Context, mg resource.Managed) error {
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!DELETE START!!!!!!!!!!!!!!!!!!!!!!!!!")
d, ok := mg.(*v1alpha3.DdosProtectionPlan)
if !ok {
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!DELETE END ONE!!!!!!!!!!!!!!!!!!!!!!!!!")
return errors.New(errNotDdosProtectionPlan)
}

mg.SetConditions(xpv1.Deleting())

_, err := e.client.Delete(ctx, d.Spec.ResourceGroupName, meta.GetExternalName(d))
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!DELETE LAST!!!!!!!!!!!!!!!!!!!!!!!!!")
return errors.Wrap(resource.Ignore(azureclients.IsNotFound, err), errDeleteDdosProtectionPlan)
}

0 comments on commit 69ab2c7

Please sign in to comment.