Skip to content

Conversation

RedbackThomson
Copy link
Contributor

@RedbackThomson RedbackThomson commented Jun 23, 2021

Issue #, if available: aws-controllers-k8s/community#842

Description of changes:
This pull request introduces a smarter system for detecting resource primary identifiers by using the fields from the ReadOne (or optionally ReadMany) operations.
It detects if a field is attempting to use the resource ARN and will set the status metadata to the corresponding identifier element. Otherwise, it will search through each of the required fields in the operation to attempt to identify the "primary" identifier field (such as *Name, Name, *ID). All other fields in the operation can be configured through the use of the new AdditionalKeys map (https://github.com/aws-controllers-k8s/runtime/pull/13/files). Optionally, the primary identifier field can be configured in the generator under operations.<operation>.primary_identifier_field_name if one cannot be (or is incorrectly) identified.

Example output from applicationautoscaling ScalingPolicy:

func (r *resource) SetIdentifiers(identifier *ackv1alpha1.AWSIdentifiers) error {
	if identifier.NameOrID == nil {
		return ackerrors.MissingNameIdentifier
	}
	r.ko.Spec.ResourceID = identifier.NameOrID

	f0, f0ok := identifier.AdditionalKeys["scalableDimension"]
	if f0ok {
		r.ko.Spec.ScalableDimension = f0
	}
	f1, f1ok := identifier.AdditionalKeys["serviceNamespace"]
	if f1ok {
		r.ko.Spec.ServiceNamespace = f1
	}

	return nil
}

Example output from mq Broker:

func (r *resource) SetIdentifiers(identifier *ackv1alpha1.AWSIdentifiers) error {
	if identifier.NameOrID == nil {
		return ackerrors.MissingNameIdentifier
	}
	r.ko.Status.BrokerID = identifier.NameOrID

	return nil
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-bot ack-bot requested review from a-hilaly and vijtrip2 June 23, 2021 19:18
@RedbackThomson RedbackThomson requested review from jaypipes and removed request for a-hilaly and vijtrip2 June 23, 2021 19:18
@RedbackThomson
Copy link
Contributor Author

/assign @jaypipes @a-hilaly

@RedbackThomson
Copy link
Contributor Author

/retest

Copy link
Contributor

@vijtrip2 vijtrip2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just one comment above about secret.

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Over all!

Left few comments bellow

@a-hilaly
Copy link
Member

Nice! 👍
/approve

// r.ko.Status.BrokerID = identifier.NameOrID
primaryKeyOut += fmt.Sprintf("%s%s.%s.%s = %s.NameOrID\n", indent, targetVarName, memberPath, cleanMemberName, sourceVarName)
} else {
// f0, f0ok := identifier.AdditionalKeys["scalableDimension"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we plan to support case-insensitive lookups? Because if the Spec or Status field is PascalCased, per Go export rules, and we're asking users to use lowerCamelCased, things might get confusing here.

I think we should probably support case-insensitive key lookups here.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other fields in the k8s spec are lowerCamelCased, I am trying to make the additionalKeys map feel more "k8s native".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RedbackThomson yeah, I guess that's a fair point. I just worry that without the TODO below on line 953 being implemented, that simple typos here will be quite difficult to detect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah totally understandable. A typo in an additionalKeys key would not be detectable and would not produce any error statements at the moment. It would be interesting to pop values out of the additionalKeys map as they are consumed and return error conditions for any remaining values.

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm good with this. @vijtrip2 @a-hilaly can you do one more once-over and lgtm if good with you?

// r.ko.Status.BrokerID = identifier.NameOrID
primaryKeyOut += fmt.Sprintf("%s%s.%s.%s = %s.NameOrID\n", indent, targetVarName, memberPath, cleanMemberName, sourceVarName)
} else {
// f0, f0ok := identifier.AdditionalKeys["scalableDimension"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RedbackThomson yeah, I guess that's a fair point. I just worry that without the TODO below on line 953 being implemented, that simple typos here will be quite difficult to detect.

@a-hilaly
Copy link
Member

LGTM
/approve

@a-hilaly
Copy link
Member

a-hilaly commented Jul 1, 2021

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 1, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Jul 1, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, jaypipes, RedbackThomson, vijtrip2

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [A-Hilaly,RedbackThomson,jaypipes,vijtrip2]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-bot ack-bot merged commit 316cbcb into aws-controllers-k8s:main Jul 1, 2021
ack-bot pushed a commit that referenced this pull request Jul 2, 2021
…de (#115)

Related to #105 and aws-controllers-k8s/runtime#13

Description of changes:
- replace nil pointer checks with string zero value checks
- replace `string` value assignment with `string` ptr assignments

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
a-hilaly added a commit to a-hilaly/ack-code-generator that referenced this pull request Jul 6, 2021
…de (aws-controllers-k8s#115)

Related to aws-controllers-k8s#105 and aws-controllers-k8s/runtime#13

Description of changes:
- replace nil pointer checks with string zero value checks
- replace `string` value assignment with `string` ptr assignments

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
RedbackThomson added a commit to RedbackThomson/ack-code-generator that referenced this pull request Jul 8, 2021
…ollers-k8s#105)

Issue #, if available: aws-controllers-k8s/community#842

Description of changes:
This pull request introduces a smarter system for detecting resource primary identifiers by using the fields from the `ReadOne` (or optionally `ReadMany`) operations.
It detects if a field is attempting to use the resource ARN and will set the status metadata to the corresponding identifier element. Otherwise, it will search through each of the required fields in the operation to attempt to identify the "primary" identifier field (such as `*Name`, `Name`, `*ID`). All other fields in the operation can be configured through the use of the new `AdditionalKeys` map (https://github.com/aws-controllers-k8s/runtime/pull/13/files). Optionally, the primary identifier field can be configured in the generator under `operations.<operation>.primary_identifier_field_name` if one cannot be (or is incorrectly) identified.

Example output from `applicationautoscaling` `ScalingPolicy`:
```golang
func (r *resource) SetIdentifiers(identifier *ackv1alpha1.AWSIdentifiers) error {
	if identifier.NameOrID == nil {
		return ackerrors.MissingNameIdentifier
	}
	r.ko.Spec.ResourceID = identifier.NameOrID

	f0, f0ok := identifier.AdditionalKeys["scalableDimension"]
	if f0ok {
		r.ko.Spec.ScalableDimension = f0
	}
	f1, f1ok := identifier.AdditionalKeys["serviceNamespace"]
	if f1ok {
		r.ko.Spec.ServiceNamespace = f1
	}

	return nil
}
```

Example output from `mq` `Broker`:
```golang
func (r *resource) SetIdentifiers(identifier *ackv1alpha1.AWSIdentifiers) error {
	if identifier.NameOrID == nil {
		return ackerrors.MissingNameIdentifier
	}
	r.ko.Status.BrokerID = identifier.NameOrID

	return nil
}
```

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
RedbackThomson pushed a commit to RedbackThomson/ack-code-generator that referenced this pull request Jul 8, 2021
…de (aws-controllers-k8s#115)

Related to aws-controllers-k8s#105 and aws-controllers-k8s/runtime#13

Description of changes:
- replace nil pointer checks with string zero value checks
- replace `string` value assignment with `string` ptr assignments

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants