Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetResource does not handle String Pointers properly in GenerateCrawler #1078

Closed
AaronME opened this issue Nov 24, 2021 · 13 comments
Closed
Assignees
Labels
area/code-generation Issues or PRs as related to controllers or docs code generation kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.

Comments

@AaronME
Copy link

AaronME commented Nov 24, 2021

Describe the bug
aws-controllers-k8s/code-generator#232 introduced the ability to support different goTypes for input/output shapes with the same name. This code is not working for all fields on all resources.

The Crawler Resource on the Glue API exposes a field "Schedule."

In CreateCrawlerInput, "Schedule" is a string.
In GetCrawlerOutput's Crawler, "Schedule" is a type Schedule.

When running this through the latest code-generator, we get the following on the GenerateCrawler method:

	if resp.Crawler.Schedule != nil {
		var f13 string
		cr.Spec.ForProvider.Schedule = f13
	} else {
		cr.Spec.ForProvider.Schedule = nil
	}

Because Schedule is a *string and not a string, this code does not compile.

Steps to reproduce
See generated code in https://github.com/crossplane/provider-aws/blob/2212c0919ed36e8d10f7829ef939d69322766b7e/pkg/controller/glue/crawler/zz_conversions.go#L92

Expected outcome
I would expect the generator to initialize this value as nil for a pointer:

	if resp.Crawler.Schedule != nil {
		cr.Spec.ForProvider.Schedule = resp.Crawler.Schedule
	} else {
		cr.Spec.ForProvider.Schedule = nil
	}

Environment

  • Kubernetes version N/A
  • Using EKS (yes/no), if so version? N/A
  • AWS service targeted (S3, RDS, etc.) glue
@AaronME AaronME added the kind/bug Categorizes issue or PR as related to a bug. label Nov 24, 2021
@vijtrip2
Copy link
Contributor

Hi @AaronME , thanks for pointing this out.

This issue of different go types for same named field was recently fixed. Please take a look at this fix

You'll need to update generator.yaml to provide code-generator the instructions on how to handle this field. See the above mentioned fix's commit message for reference.

@AaronME
Copy link
Author

AaronME commented Nov 24, 2021

@vijtrip2 Thank you for the fast reply.

I had already tried running generation with the following:

resources:
  Crawler:
    fields:
      Schedule:
        set:
          - on: Create
            from: ScheduleExpression
          - on: Update
            from: ScheduleExpression
          - on: ReadOne
            from: ScheduleExpression
          - on: ReadMany
            from: ScheduleExpression

This did not change any generated code.

I have two theories about this:

  1. This is a known issue with nested fields, since the Schedule field needs to be set from ScheduleExpression, which is an attribute of Schedule.
  2. allow different Go types for input/output shapes code-generator#232 does not affect setResourceReadMany (which is where GenerateCrawler is being generated).

@jaypipes
Copy link
Collaborator

2. allow different Go types for input/output shapes code-generator#232 does not affect setResourceReadMany (which is where GenerateCrawler is being generated).

Hi @AaronME! It's this second one. I will try to push a fix for this ASAP.

@jaypipes jaypipes added the area/code-generation Issues or PRs as related to controllers or docs code generation label Nov 29, 2021
@jaypipes jaypipes self-assigned this Nov 29, 2021
@jaypipes jaypipes added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Nov 29, 2021
@jaypipes jaypipes added this to To do in ACK Core Team Nov 29, 2021
@jaypipes
Copy link
Collaborator

  1. allow different Go types for input/output shapes code-generator#232 does not affect setResourceReadMany (which is where GenerateCrawler is being generated).

Hi @AaronME! It's this second one. I will try to push a fix for this ASAP.

Actually, it turns out that Glue's GetCrawler (Singular form/ReadOne) is used and not the list form of GetCrawlers (ReadMany) so this must be some other problem. Looking further into it...

@jaypipes
Copy link
Collaborator

Yeah, it's the lack of nested struct support (list item 1 above). I'm working on a fix now.

@AaronME
Copy link
Author

AaronME commented Nov 29, 2021

@jaypipes I appreciate you taking a look at it.

ack-bot pushed a commit to aws-controllers-k8s/code-generator that referenced this issue Dec 1, 2021
In attempting to implement the nested field path support for different
source and target field Go types, I realized I needed a support package
that made working with field paths easier, including taking a field path
and finding a ShapeRef within an Output shape that matched the field
path.

This patch introduces a new `pkg/fieldpath` package with a simple `Path`
struct containing a variety of utility methods, as shown in this example
Go code snippet:

```go
import (
        "fmt"

	awssdkmodel "github.com/aws/aws-sdk-go/private/model/api"
        "github.com/aws-controllers-k8s/code-generator/pkg/fieldpath"
        "github.com/aws-controllers-k8s/code-generator/pkg/sdk"
)

...

p := fieldpath.FromString("Crawler.Schedule.ScheduleExpression")

// Will print "true"
fmt.Println(p.HasPrefix("Crawler.Schedule"))

// Will print "false"
fmt.Println(p.HasPrefix("crawler.Schedule"))

// Will print "true"
fmt.Println(p.HasPrefixFold("crawler.Schedule"))

// Will print "ScheduleExpression"
fmt.Println(p.Back())

// Will print "Crawler"
fmt.Println(p.Front())

// Find the shape within the GetCrawlerResponse shape that contains the
// field referred to by the path...
helper := sdk.NewHelper("/path/to/apis", genCfg)
api := helper.API("glue")
crawlerOutputShape := api.Shapes["GetCrawlerResponse"]

schedExpressionShape := p.ShapeRef(crawlerOutputShape)
// Will print "ScheduleExpression"
fmt.Println(schedExpressionShape.ShapeName)
```
Note that we support list and map type field paths using a single-dot
notation since we are only looking at field types and not **values**
within the list or map.

Signed-off-by: Jay Pipes <jaypipes@gmail.com>

Related: aws-controllers-k8s/community#1078

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

muvaf commented Dec 7, 2021

We have similar situation in lambda.Function where Layers field is []*string in CreateFunctionInput but []*Layer in FunctionConfiguration which is the struct returned by CreateFunctionWithContext.

@a-hilaly
Copy link
Member

a-hilaly commented Dec 8, 2021

We have similar situation in lambda.Function where Layers field is []*string in CreateFunctionInput but []*Layer in FunctionConfiguration which is the struct returned by CreateFunctionWithContext.

I am aware of this issue. For now our lambda controller is ignoring the Layers field. Will /cc you one the PR fixing that once it's open

@jaypipes
Copy link
Collaborator

jaypipes commented Jan 5, 2022

@AaronME Sorry for the long delay in addressing this. I have pushed up aws-controllers-k8s/code-generator#255 to address the issue.

@ack-bot
Copy link
Collaborator

ack-bot commented Apr 5, 2022

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Provide feedback via https://github.com/aws-controllers-k8s/community.
/lifecycle stale

@ack-bot ack-bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 5, 2022
@RedbackThomson RedbackThomson added this to To do in ACK Core Team Apr 8, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented May 5, 2022

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.
Provide feedback via https://github.com/aws-controllers-k8s/community.
/lifecycle rotten

@ack-bot ack-bot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 5, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Jun 4, 2022

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Provide feedback via https://github.com/aws-controllers-k8s/community.
/close

@ack-bot ack-bot closed this as completed Jun 4, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Jun 4, 2022

@ack-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Provide feedback via https://github.com/aws-controllers-k8s/community.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code-generation Issues or PRs as related to controllers or docs code generation kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Projects
No open projects
Status: Done
Development

No branches or pull requests

6 participants