Skip to content

Commit

Permalink
Fix some small casing issues (#1561)
Browse files Browse the repository at this point in the history
* Rename ApiVersion to APIVersion

* Rename GetId to GetID
  • Loading branch information
matthchr authored Jun 14, 2021
1 parent cc87f74 commit a261848
Show file tree
Hide file tree
Showing 44 changed files with 295 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ type ResourceGroupStatusPropertiesArm struct {

type ResourceGroupSpecArm struct {

//ApiVersion: API Version of the resource type, optional when apiProfile is used
//APIVersion: API Version of the resource type, optional when apiProfile is used
//on the template
ApiVersion string `json:"apiVersion"`
APIVersion string `json:"apiVersion"`

//Name: Name of the resource
Name string `json:"name"`
Expand All @@ -47,9 +47,9 @@ type ResourceGroupSpecArm struct {

var _ genruntime.ARMResourceSpec = &ResourceGroupSpecArm{}

// GetApiVersion returns the ApiVersion of the resource
func (spec ResourceGroupSpecArm) GetApiVersion() string {
return string(spec.ApiVersion)
// GetAPIVersion returns the APIVersion of the resource
func (spec ResourceGroupSpecArm) GetAPIVersion() string {
return string(spec.APIVersion)
}

// GetName returns the Name of the resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (spec *ResourceGroupSpec) ConvertToARM(name string, resolvedReferences genr
return nil, nil
}
result := ResourceGroupSpecArm{}
result.ApiVersion = "2020-06-01" // TODO: Update this to match what the codegenerated resources do with APIVersion eventually
result.APIVersion = "2020-06-01" // TODO: Update this to match what the codegenerated resources do with APIVersion eventually
result.Location = spec.Location
result.Name = name
result.ManagedBy = spec.ManagedBy
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 @@ -60,11 +60,11 @@ func Test_NewResourceGroupDeployment(t *testing.T) {
log.Printf("Created resource: %s\n", id)

// Delete the RG
_, err = testContext.AzureClient.BeginDeleteResource(ctx, id, typedResourceGroupSpec.ApiVersion, nil)
_, err = testContext.AzureClient.BeginDeleteResource(ctx, id, typedResourceGroupSpec.APIVersion, nil)
g.Expect(err).ToNot(HaveOccurred())

// Ensure that the resource group is deleted
g.Eventually([]string{id, typedResourceGroupSpec.ApiVersion}).Should(testContext.AzureMatch.BeDeleted(ctx))
g.Eventually([]string{id, typedResourceGroupSpec.APIVersion}).Should(testContext.AzureMatch.BeDeleted(ctx))
}

func Test_NewResourceGroupDeployment_Error(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions hack/generated/pkg/genruntime/base_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func AddAnnotation(obj MetaObject, k string, v string) {
// methods to access properties common to all ARM Resource Specs. An Azure
// Deployment is made of these.
type ARMResourceSpec interface {
GetApiVersion() string
GetAPIVersion() string

GetType() string

Expand All @@ -107,7 +107,7 @@ type ARMResource interface {
Status() ARMResourceStatus

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

func NewArmResource(spec ARMResourceSpec, status ARMResourceStatus, id string) ARMResource {
Expand All @@ -134,7 +134,7 @@ func (resource *armResourceImpl) Status() ARMResourceStatus {
return resource.status
}

func (resource *armResourceImpl) GetId() string {
func (resource *armResourceImpl) GetID() string {
return resource.Id
}

Expand Down
8 changes: 4 additions & 4 deletions hack/generated/pkg/reconcilers/azure_deployment_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ func (r *AzureDeploymentReconciler) StartDeleteOfResource(ctx context.Context) (

emptyStatus, err := reflecthelpers.NewEmptyArmResourceStatus(r.obj)
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "creating empty status for %q", resource.GetId())
return ctrl.Result{}, errors.Wrapf(err, "creating empty status for %q", resource.GetID())
}

// retryAfter = ARM can tell us how long to wait for a DELETE
retryAfter, err := r.ARMClient.BeginDeleteResource(ctx, resource.GetId(), resource.Spec().GetApiVersion(), emptyStatus)
retryAfter, err := r.ARMClient.BeginDeleteResource(ctx, resource.GetID(), resource.Spec().GetAPIVersion(), emptyStatus)
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "deleting resource %q", resource.Spec().GetType())
}
Expand Down Expand Up @@ -424,7 +424,7 @@ func (r *AzureDeploymentReconciler) MonitorDelete(ctx context.Context) (ctrl.Res
}

// already deleting, just check to see if it still exists and if it's gone, remove finalizer
found, retryAfter, err := r.ARMClient.HeadResource(ctx, resource.GetId(), resource.Spec().GetApiVersion())
found, retryAfter, err := r.ARMClient.HeadResource(ctx, resource.GetID(), resource.Spec().GetAPIVersion())
if err != nil {
if retryAfter != 0 {
r.log.V(3).Info("Error performing HEAD on resource, will retry", "delaySec", retryAfter/time.Second)
Expand Down Expand Up @@ -657,7 +657,7 @@ func (r *AzureDeploymentReconciler) getStatus(ctx context.Context, id string) (g
}

// Get the resource
retryAfter, err := r.ARMClient.GetResource(ctx, id, deployableSpec.Spec().GetApiVersion(), armStatus)
retryAfter, err := r.ARMClient.GetResource(ctx, id, deployableSpec.Spec().GetAPIVersion(), armStatus)
if r.log.V(4).Enabled() {
statusBytes, marshalErr := json.Marshal(armStatus)
if marshalErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion hack/generated/pkg/reflecthelpers/reflect_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func Test_ConvertResourceToDeployableResource(t *testing.T) {
g.Expect(ok).To(BeTrue())
g.Expect("myrg").To(Equal(rgResource.ResourceGroup()))
g.Expect("azureName").To(Equal(rgResource.Spec().GetName()))
g.Expect("2017-09-01").To(Equal(rgResource.Spec().GetApiVersion()))
g.Expect("2017-09-01").To(Equal(rgResource.Spec().GetAPIVersion()))
g.Expect(string(batch.BatchAccountsSpecTypeMicrosoftBatchBatchAccounts)).To(Equal(rgResource.Spec().GetType()))
}

Expand Down
20 changes: 10 additions & 10 deletions hack/generator/pkg/astmodel/arm_spec_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
ApiVersionProperty = "ApiVersion"
APIVersionProperty = "APIVersion"
TypeProperty = "Type"
NameProperty = "Name"
)
Expand All @@ -36,7 +36,7 @@ func NewARMSpecInterfaceImpl(
spec *ObjectType) (*InterfaceImplementation, error) {

// Check the spec first to ensure it looks how we expect
apiVersionProperty := idFactory.CreatePropertyName(ApiVersionProperty, Exported)
apiVersionProperty := idFactory.CreatePropertyName(APIVersionProperty, Exported)
err := checkPropertyPresence(spec, apiVersionProperty)
if err != nil {
return nil, err
Expand All @@ -53,34 +53,34 @@ func NewARMSpecInterfaceImpl(
}

getNameFunc := &objectFunction{
name: "GetName",
name: "Get" + NameProperty,
o: spec,
idFactory: idFactory,
asFunc: getNameFunction,
requiredPackages: NewPackageReferenceSet(GenRuntimeReference),
}

getTypeFunc := &objectFunction{
name: "GetType",
name: "Get" + TypeProperty,
o: spec,
idFactory: idFactory,
asFunc: getTypeFunction,
requiredPackages: NewPackageReferenceSet(GenRuntimeReference),
}

getApiVersionFunc := &objectFunction{
name: "GetApiVersion",
getAPIVersionFunc := &objectFunction{
name: "Get" + APIVersionProperty,
o: spec,
idFactory: idFactory,
asFunc: getApiVersionFunction,
asFunc: getAPIVersionFunction,
requiredPackages: NewPackageReferenceSet(GenRuntimeReference),
}

result := NewInterfaceImplementation(
MakeTypeName(GenRuntimeReference, "ARMResourceSpec"),
getNameFunc,
getTypeFunc,
getApiVersionFunc)
getAPIVersionFunc)

return result, nil
}
Expand All @@ -105,13 +105,13 @@ func getTypeFunction(k *objectFunction, codeGenerationContext *CodeGenerationCon
true)
}

func getApiVersionFunction(k *objectFunction, codeGenerationContext *CodeGenerationContext, receiver TypeName, methodName string) *dst.FuncDecl {
func getAPIVersionFunction(k *objectFunction, codeGenerationContext *CodeGenerationContext, receiver TypeName, methodName string) *dst.FuncDecl {
return armSpecInterfaceSimpleGetFunction(
k,
codeGenerationContext,
receiver,
methodName,
"ApiVersion",
APIVersionProperty,
true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func newConvertToARMFunctionBuilder(
result.propertyConversionHandlers = []propertyConversionHandler{
result.namePropertyHandler,
result.referencePropertyHandler,
result.fixedValuePropertyHandler("Type"),
result.fixedValuePropertyHandler("ApiVersion"),
result.fixedValuePropertyHandler(astmodel.TypeProperty),
result.fixedValuePropertyHandler(astmodel.APIVersionProperty),
result.propertiesWithSameNameHandler,
}

Expand Down
5 changes: 3 additions & 2 deletions hack/generator/pkg/astmodel/identifier_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ func (factory *identifierFactory) CreatePropertyName(propertyName string, visibi

func createRenames() map[string]string {
return map[string]string{
"$schema": "Schema",
"*": "Star", // This happens mostly in enums
"$schema": "Schema",
"*": "Star", // This happens mostly in enums
"apiVersion": "APIVersion",
}
}

Expand Down
2 changes: 1 addition & 1 deletion hack/generator/pkg/astmodel/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewAzureResourceType(specType Type, statusType Type, typeName TypeName) *Re
}
}

if property.HasName(ApiVersionProperty) {
if property.HasName(APIVersionProperty) {
apiVersionProperty = property
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,19 @@ func (c *armConversionApplier) transformSpec(resourceType *astmodel.ResourceType
// TODO: https://github.com/kubernetes-sigs/controller-tools/issues/461 is fixed

// drop Type property
t = t.WithoutProperty("Type")
t = t.WithoutProperty(astmodel.TypeProperty)

// drop ApiVersion property
t = t.WithoutProperty("ApiVersion")
// drop APIVersion property
t = t.WithoutProperty(astmodel.APIVersionProperty)

nameProp, hasName := t.Property("Name")
nameProp, hasName := t.Property(astmodel.NameProperty)
if !hasName {
return t, nil
}

// rename Name to AzureName
azureNameProp := armconversion.GetAzureNameProperty(c.idFactory).WithType(nameProp.PropertyType())
return t.WithoutProperty("Name").WithProperty(azureNameProp), nil
return t.WithoutProperty(astmodel.NameProperty).WithProperty(azureNameProp), nil
}

kubernetesDef, err := resourceSpecDef.ApplyObjectTransformations(remapProperties, injectOwnerProperty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ type FakeResourceList struct {
}

type FakeResource_SpecARM struct {
ApiVersion FakeResourceSpecApiVersion `json:"apiVersion"`
APIVersion FakeResourceSpecAPIVersion `json:"apiVersion"`
Name string `json:"name"`
Properties *PropertiesARM `json:"properties,omitempty"`
Type FakeResourceSpecType `json:"type"`
}

var _ genruntime.ARMResourceSpec = &FakeResource_SpecARM{}

// GetApiVersion returns the ApiVersion of the resource
func (fakeResourceSpecARM FakeResource_SpecARM) GetApiVersion() string {
return string(fakeResourceSpecARM.ApiVersion)
// GetAPIVersion returns the APIVersion of the resource
func (fakeResourceSpecARM FakeResource_SpecARM) GetAPIVersion() string {
return string(fakeResourceSpecARM.APIVersion)
}

// GetName returns the Name of the resource
Expand All @@ -178,9 +178,9 @@ func (fakeResourceSpecARM FakeResource_SpecARM) GetType() string {
}

// +kubebuilder:validation:Enum={"2020-06-01"}
type FakeResourceSpecApiVersion string
type FakeResourceSpecAPIVersion string

const FakeResourceSpecApiVersion20200601 = FakeResourceSpecApiVersion("2020-06-01")
const FakeResourceSpecAPIVersion20200601 = FakeResourceSpecAPIVersion("2020-06-01")

// +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"}
type FakeResourceSpecType string
Expand All @@ -205,7 +205,7 @@ func (fakeResourceSpec *FakeResource_Spec) ConvertToARM(name string, resolvedRef
return nil, nil
}
var result FakeResource_SpecARM
result.ApiVersion = FakeResourceSpecApiVersion20200601
result.APIVersion = FakeResourceSpecAPIVersion20200601
result.Name = name
if fakeResourceSpec.Properties != nil {
propertiesARM, err := (*fakeResourceSpec.Properties).ConvertToARM(name, resolvedReferences)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type FakeResource_Spec struct {

type FakeResourceParameters struct {
// +kubebuilder:validation:Required
ApiVersion FakeResourceSpecApiVersion `json:"apiVersion"`
APIVersion FakeResourceSpecAPIVersion `json:"apiVersion"`

// +kubebuilder:validation:Required
Name string `json:"name"`
Expand All @@ -54,9 +54,9 @@ type FakeResourceParameters struct {
}

// +kubebuilder:validation:Enum={"2020-06-01"}
type FakeResourceSpecApiVersion string
type FakeResourceSpecAPIVersion string

const FakeResourceSpecApiVersion20200601 = FakeResourceSpecApiVersion("2020-06-01")
const FakeResourceSpecAPIVersion20200601 = FakeResourceSpecAPIVersion("2020-06-01")

// +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"}
type FakeResourceSpecType string
Expand Down
Loading

0 comments on commit a261848

Please sign in to comment.