Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into feature/swagger-proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek committed Apr 28, 2021
2 parents 6fcb282 + 412bf37 commit 8e6a7c8
Show file tree
Hide file tree
Showing 39 changed files with 771 additions and 769 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ResourceGroupSpecArm struct {
Type ResourceGroupType `json:"type"`
}

var _ genruntime.ArmResourceSpec = &ResourceGroupSpecArm{}
var _ genruntime.ARMResourceSpec = &ResourceGroupSpecArm{}

// GetApiVersion returns the ApiVersion of the resource
func (spec ResourceGroupSpecArm) GetApiVersion() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ type ResourceGroupStatus struct {
Properties *ResourceGroupStatusProperties `json:"properties,omitempty"` // TODO: Is this required or optional?
}

var _ genruntime.ArmTransformer = &ResourceGroupStatus{}
var _ genruntime.ARMTransformer = &ResourceGroupStatus{}

func (status *ResourceGroupStatus) CreateEmptyArmValue() interface{} {
func (status *ResourceGroupStatus) CreateEmptyARMValue() interface{} {
return ResourceGroupStatusArm{}
}

// ConvertToArm converts from a Kubernetes CRD object to an ARM object
func (status *ResourceGroupStatus) ConvertToArm(name string) (interface{}, error) {
func (status *ResourceGroupStatus) ConvertToARM(name string) (interface{}, error) {
if status == nil {
return nil, nil
}
Expand All @@ -93,7 +93,7 @@ func (status *ResourceGroupStatus) ConvertToArm(name string) (interface{}, error
result.Name = status.Name
result.Tags = status.Tags
if status.Properties != nil {
properties, err := status.Properties.ConvertToArm(name)
properties, err := status.Properties.ConvertToARM(name)
if err != nil {
return nil, err
}
Expand All @@ -104,7 +104,7 @@ func (status *ResourceGroupStatus) ConvertToArm(name string) (interface{}, error
}

// PopulateFromArm populates a Kubernetes CRD object from an Azure ARM object
func (status *ResourceGroupStatus) PopulateFromArm(owner genruntime.KnownResourceReference, armInput interface{}) error {
func (status *ResourceGroupStatus) PopulateFromARM(owner genruntime.KnownResourceReference, armInput interface{}) error {
typedInput, ok := armInput.(ResourceGroupStatusArm)
if !ok {
return fmt.Errorf("unexpected type supplied for PopulateFromArm() function. Expected ResourceGroupStatusArm, got %T", armInput)
Expand All @@ -117,7 +117,7 @@ func (status *ResourceGroupStatus) PopulateFromArm(owner genruntime.KnownResourc
var err error
if typedInput.Properties != nil {
properties := ResourceGroupStatusProperties{}
err = properties.PopulateFromArm(owner, *typedInput.Properties)
err = properties.PopulateFromARM(owner, *typedInput.Properties)
if err != nil {
return err
}
Expand All @@ -130,14 +130,14 @@ type ResourceGroupStatusProperties struct {
ProvisioningState string `json:"provisioningState,omitempty"` // TODO: Wrong, needs to be in properties
}

var _ genruntime.ArmTransformer = &ResourceGroupStatusProperties{}
var _ genruntime.ARMTransformer = &ResourceGroupStatusProperties{}

func (p *ResourceGroupStatusProperties) CreateEmptyArmValue() interface{} {
func (p *ResourceGroupStatusProperties) CreateEmptyARMValue() interface{} {
return ResourceGroupStatusPropertiesArm{}
}

// ConvertToArm converts from a Kubernetes CRD object to an ARM object
func (p *ResourceGroupStatusProperties) ConvertToArm(name string) (interface{}, error) {
func (p *ResourceGroupStatusProperties) ConvertToARM(name string) (interface{}, error) {
if p == nil {
return nil, nil
}
Expand All @@ -147,7 +147,7 @@ func (p *ResourceGroupStatusProperties) ConvertToArm(name string) (interface{},
}

// PopulateFromArm populates a Kubernetes CRD object from an Azure ARM object
func (p *ResourceGroupStatusProperties) PopulateFromArm(owner genruntime.KnownResourceReference, armInput interface{}) error {
func (p *ResourceGroupStatusProperties) PopulateFromARM(owner genruntime.KnownResourceReference, armInput interface{}) error {
typedInput, ok := armInput.(ResourceGroupStatusPropertiesArm)
if !ok {
return fmt.Errorf("unexpected type supplied for PopulateFromArm() function. Expected ResourceGroupStatusPropertiesArm, got %T", armInput)
Expand All @@ -172,14 +172,14 @@ type ResourceGroupSpec struct {
Tags map[string]string `json:"tags,omitempty"`
}

var _ genruntime.ArmTransformer = &ResourceGroupSpec{}
var _ genruntime.ARMTransformer = &ResourceGroupSpec{}

func (spec *ResourceGroupSpec) CreateEmptyArmValue() interface{} {
func (spec *ResourceGroupSpec) CreateEmptyARMValue() interface{} {
return ResourceGroupSpecArm{}
}

// ConvertToArm converts from a Kubernetes CRD object to an ARM object
func (spec *ResourceGroupSpec) ConvertToArm(name string) (interface{}, error) {
func (spec *ResourceGroupSpec) ConvertToARM(name string) (interface{}, error) {
if spec == nil {
return nil, nil
}
Expand All @@ -194,13 +194,13 @@ func (spec *ResourceGroupSpec) ConvertToArm(name string) (interface{}, error) {
}

// PopulateFromArm populates a Kubernetes CRD object from an Azure ARM object
func (spec *ResourceGroupSpec) PopulateFromArm(owner genruntime.KnownResourceReference, armInput interface{}) error {
func (spec *ResourceGroupSpec) PopulateFromARM(owner genruntime.KnownResourceReference, armInput interface{}) error {
typedInput, ok := armInput.(ResourceGroupSpecArm)
if !ok {
return fmt.Errorf("unexpected type supplied for PopulateFromArm() function. Expected ResourceGroupSpecArm, got %T", armInput)
}
// spec.ApiVersion = typedInput.ApiVersion
spec.SetAzureName(genruntime.ExtractKubernetesResourceNameFromArmName(typedInput.Name))
spec.SetAzureName(genruntime.ExtractKubernetesResourceNameFromARMName(typedInput.Name))
spec.Location = typedInput.Location
spec.ManagedBy = typedInput.ManagedBy
spec.Tags = typedInput.Tags
Expand Down
18 changes: 9 additions & 9 deletions hack/generated/pkg/armclient/template_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type Applier interface {
CreateDeployment(ctx context.Context, deployment *Deployment) error
DeleteDeployment(ctx context.Context, deploymentId string) (time.Duration, error)
GetDeployment(ctx context.Context, deploymentId string) (*Deployment, time.Duration, error)
NewResourceGroupDeployment(resourceGroup string, deploymentName string, resourceSpec genruntime.ArmResourceSpec) *Deployment
NewSubscriptionDeployment(location string, deploymentName string, resourceSpec genruntime.ArmResourceSpec) *Deployment
NewResourceGroupDeployment(resourceGroup string, deploymentName string, resourceSpec genruntime.ARMResourceSpec) *Deployment
NewSubscriptionDeployment(location string, deploymentName string, resourceSpec genruntime.ARMResourceSpec) *Deployment

SubscriptionID() string

// TODO: These functions take an empty status and fill it out with the response from Azure (rather than as
// TODO: the return type. I don't love that pattern but don't have a better one either.
BeginDeleteResource(ctx context.Context, id string, apiVersion string, status genruntime.ArmResourceStatus) (time.Duration, error)
GetResource(ctx context.Context, id string, apiVersion string, status genruntime.ArmResourceStatus) (time.Duration, error)
BeginDeleteResource(ctx context.Context, id string, apiVersion string, status genruntime.ARMResourceStatus) (time.Duration, error)
GetResource(ctx context.Context, id string, apiVersion string, status genruntime.ARMResourceStatus) (time.Duration, error)
HeadResource(ctx context.Context, id string, apiVersion string) (bool, time.Duration, error)
}

Expand Down Expand Up @@ -200,7 +200,7 @@ func (atc *AzureTemplateClient) GetResource(
ctx context.Context,
id string,
apiVersion string,
status genruntime.ArmResourceStatus) (time.Duration, error) {
status genruntime.ARMResourceStatus) (time.Duration, error) {

if id == "" {
return zeroDuration, errors.Errorf("resource ID cannot be empty")
Expand Down Expand Up @@ -238,7 +238,7 @@ func (atc *AzureTemplateClient) GetDeployment(ctx context.Context, deploymentId
return &deployment, retryAfter, nil
}

func createResourceIdTemplate(resourceSpec genruntime.ArmResourceSpec) map[string]Output {
func createResourceIdTemplate(resourceSpec genruntime.ARMResourceSpec) map[string]Output {
resourceName := resourceSpec.GetName()
names := strings.Split(resourceName, "/")
formattedNames := make([]string, len(names))
Expand All @@ -257,13 +257,13 @@ func createResourceIdTemplate(resourceSpec genruntime.ArmResourceSpec) map[strin
return result
}

func (atc *AzureTemplateClient) NewResourceGroupDeployment(resourceGroup string, deploymentName string, resourceSpec genruntime.ArmResourceSpec) *Deployment {
func (atc *AzureTemplateClient) NewResourceGroupDeployment(resourceGroup string, deploymentName string, resourceSpec genruntime.ARMResourceSpec) *Deployment {
deployment := NewResourceGroupDeployment(atc.subscriptionID, resourceGroup, deploymentName, resourceSpec)
deployment.Properties.Template.Outputs = createResourceIdTemplate(resourceSpec)
return deployment
}

func (atc *AzureTemplateClient) NewSubscriptionDeployment(location string, deploymentName string, resourceSpec genruntime.ArmResourceSpec) *Deployment {
func (atc *AzureTemplateClient) NewSubscriptionDeployment(location string, deploymentName string, resourceSpec genruntime.ARMResourceSpec) *Deployment {
deployment := NewSubscriptionDeployment(atc.subscriptionID, location, deploymentName, resourceSpec)
deployment.Properties.Template.Outputs = createResourceIdTemplate(resourceSpec)
return deployment
Expand All @@ -273,7 +273,7 @@ func (atc *AzureTemplateClient) BeginDeleteResource(
ctx context.Context,
id string,
apiVersion string,
status genruntime.ArmResourceStatus) (time.Duration, error) {
status genruntime.ARMResourceStatus) (time.Duration, error) {

if id == "" {
return zeroDuration, errors.Errorf("resource ID cannot be empty")
Expand Down
4 changes: 2 additions & 2 deletions hack/generated/pkg/armclient/template_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Test_NewResourceGroupDeployment(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())

resourceGroup := testContext.NewTestResourceGroup()
resourceGroupSpec, err := resourceGroup.Spec.ConvertToArm(resourceGroup.Name)
resourceGroupSpec, err := resourceGroup.Spec.ConvertToARM(resourceGroup.Name)
g.Expect(err).ToNot(HaveOccurred())

typedResourceGroupSpec := resourceGroupSpec.(resources.ResourceGroupSpecArm)
Expand Down Expand Up @@ -86,7 +86,7 @@ func Test_NewResourceGroupDeployment_Error(t *testing.T) {
},
}

resourceGroupSpec, err := resourceGroup.Spec.ConvertToArm(rgName)
resourceGroupSpec, err := resourceGroup.Spec.ConvertToARM(rgName)
g.Expect(err).ToNot(HaveOccurred())

deployment := armclient.NewSubscriptionDeployment(
Expand Down
24 changes: 12 additions & 12 deletions hack/generated/pkg/genruntime/arm_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ import (
"strings"
)

type ToArmConverter interface {
type ToARMConverter interface {
// ConvertToArm converts this to an ARM resource. The name parameter is the fully qualified name of the resource in Azure ("a/b/c").
ConvertToArm(name string) (interface{}, error) // TODO: Should be ConvertToARM (same below)
ConvertToARM(name string) (interface{}, error)
}

type FromArmConverter interface {
CreateEmptyArmValue() interface{}
PopulateFromArm(owner KnownResourceReference, input interface{}) error
type FromARMConverter interface {
CreateEmptyARMValue() interface{}
PopulateFromARM(owner KnownResourceReference, input interface{}) error
}

// TODO: Consider ArmSpecTransformer and ArmTransformer, so we don't have to pass owningName/name through all the calls
// ArmTransformer is a type which can be converted to/from an Arm object shape.
// TODO: Consider ArmSpecTransformer and ARMTransformer, so we don't have to pass owningName/name through all the calls
// ARMTransformer is a type which can be converted to/from an Arm object shape.
// Each CRD resource must implement these methods.
type ArmTransformer interface {
ToArmConverter
FromArmConverter
type ARMTransformer interface {
ToARMConverter
FromARMConverter
}

// ExtractKubernetesResourceNameFromArmName extracts the Kubernetes resource name from an ARM name.
// ExtractKubernetesResourceNameFromARMName extracts the Kubernetes resource name from an ARM name.
// See https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/child-resource-name-type#outside-parent-resource
// for details on the format of the name field in ARM templates.
func ExtractKubernetesResourceNameFromArmName(armName string) string {
func ExtractKubernetesResourceNameFromARMName(armName string) string {
if len(armName) == 0 {
return ""
}
Expand Down
40 changes: 20 additions & 20 deletions hack/generated/pkg/genruntime/base_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,34 @@ func AddAnnotation(obj MetaObject, k string, v string) {
obj.SetAnnotations(annotations)
}

// ArmResourceSpec is an ARM resource specification. This interface contains
// ARMResourceSpec is an ARM resource specification. This interface contains
// methods to access properties common to all ARM Resource Specs. An Azure
// Deployment is made of these.
type ArmResourceSpec interface {
type ARMResourceSpec interface {
GetApiVersion() string

GetType() string

GetName() string
}

// ArmResourceStatus is an ARM resource status
type ArmResourceStatus interface {
// ARMResourceStatus is an ARM resource status
type ARMResourceStatus interface {
// TODO: Unsure what the actual content of this interface needs to be.
// TODO: We need to define it and generate the code for it

// GetId() string
}

type ArmResource interface {
Spec() ArmResourceSpec
Status() ArmResourceStatus
type ARMResource interface {
Spec() ARMResourceSpec
Status() ARMResourceStatus

// TODO: Golang wants this to be GetID
GetId() string // TODO: Should this be on Status instead?
}

func NewArmResource(spec ArmResourceSpec, status ArmResourceStatus, id string) ArmResource {
func NewArmResource(spec ARMResourceSpec, status ARMResourceStatus, id string) ARMResource {
return &armResourceImpl{
spec: spec,
status: status,
Expand All @@ -119,18 +119,18 @@ func NewArmResource(spec ArmResourceSpec, status ArmResourceStatus, id string) A
}

type armResourceImpl struct {
spec ArmResourceSpec
status ArmResourceStatus
spec ARMResourceSpec
status ARMResourceStatus
Id string
}

var _ ArmResource = &armResourceImpl{}
var _ ARMResource = &armResourceImpl{}

func (resource *armResourceImpl) Spec() ArmResourceSpec {
func (resource *armResourceImpl) Spec() ARMResourceSpec {
return resource.spec
}

func (resource *armResourceImpl) Status() ArmResourceStatus {
func (resource *armResourceImpl) Status() ARMResourceStatus {
return resource.status
}

Expand All @@ -139,17 +139,17 @@ func (resource *armResourceImpl) GetId() string {
}

type DeployableResource interface {
Spec() ArmResourceSpec
Spec() ARMResourceSpec
}

func NewDeployableResourceGroupResource(resourceGroup string, spec ArmResourceSpec) *ResourceGroupResource {
func NewDeployableResourceGroupResource(resourceGroup string, spec ARMResourceSpec) *ResourceGroupResource {
return &ResourceGroupResource{
resourceGroup: resourceGroup,
spec: spec,
}
}

func NewDeployableSubscriptionResource(location string, spec ArmResourceSpec) *SubscriptionResource {
func NewDeployableSubscriptionResource(location string, spec ARMResourceSpec) *SubscriptionResource {
return &SubscriptionResource{
location: location,
spec: spec,
Expand All @@ -160,7 +160,7 @@ func NewDeployableSubscriptionResource(location string, spec ArmResourceSpec) *S
// resource group.
type ResourceGroupResource struct {
resourceGroup string
spec ArmResourceSpec
spec ARMResourceSpec
}

var _ DeployableResource = &ResourceGroupResource{}
Expand All @@ -169,15 +169,15 @@ func (r *ResourceGroupResource) ResourceGroup() string {
return r.resourceGroup
}

func (r *ResourceGroupResource) Spec() ArmResourceSpec {
func (r *ResourceGroupResource) Spec() ARMResourceSpec {
return r.spec
}

// SubscriptionResource represents a resource which can be deployed to Azure directly
// in a subscription (not inside of a resource group).
type SubscriptionResource struct {
location string
spec ArmResourceSpec
spec ARMResourceSpec
}

var _ DeployableResource = &SubscriptionResource{}
Expand All @@ -186,6 +186,6 @@ func (r *SubscriptionResource) Location() string {
return r.location
}

func (r *SubscriptionResource) Spec() ArmResourceSpec {
func (r *SubscriptionResource) Spec() ARMResourceSpec {
return r.spec
}

0 comments on commit 8e6a7c8

Please sign in to comment.