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

Introduce ack-generate webhooks sub command #122

Closed

Conversation

a-hilaly
Copy link
Member

@a-hilaly a-hilaly commented Jul 6, 2021

Part of aws-controllers-k8s/community#835

This patch brings in a new sub command that can be used to generate
webhook functions. For now it can only generate conversion webhook
functions, but it can be extended to generate defaulting and validating
functions.

This patch also introduces a new function that generates conversion
functions. It can be used to generate ConvertTo and ConvertFrom
functions.

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 jaypipes and vijtrip2 July 6, 2021 14:56
@ack-bot
Copy link
Collaborator

ack-bot commented Jul 6, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly

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:

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

@a-hilaly
Copy link
Member Author

a-hilaly commented Jul 6, 2021

NOTE to reviews: This will need a rebase after #120 and #121 merge.
/hold

@ack-bot ack-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 6, 2021
@a-hilaly a-hilaly force-pushed the ackgenerate-webhooks branch 3 times, most recently from 2d48795 to 2dcad55 Compare July 12, 2021 23:03
@RedbackThomson
Copy link
Contributor

Could we hold off on this command until after I propose the metadata configuration? Options such as deprecated versions, etc. will all be available in that configuration file and it will not be necessary to pass them as command line arguments.

@a-hilaly
Copy link
Member Author

Could we hold off on this command until after I propose the metadata configuration? Options such as deprecated versions, etc. will all be available in that configuration file and it will not be necessary to pass them as command line arguments.

Sure. I will rebase on top of your work once it's available.

@a-hilaly a-hilaly force-pushed the ackgenerate-webhooks branch 4 times, most recently from c149eb8 to 78c343c Compare July 13, 2021 15:01
Comment on lines 148 to 164
// LoadGenerationMetadata read the generation metadata for a given api version and
// apis path.
func LoadGenerationMetadata(apisPath, apiVersion string) (*GenerationMetadata, error) {
filePath := filepath.Join(apisPath, apiVersion, outputFileName)
b, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}

var generationMetadata GenerationMetadata
err = yaml.Unmarshal(b, &generationMetadata)
if err != nil {
return nil, err
}
return &generationMetadata, nil
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@RedbackThomson If you can implement a similar function in your PR, i'm taking it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

These have been moved to pkg/metadata

@a-hilaly a-hilaly force-pushed the ackgenerate-webhooks branch 3 times, most recently from d91e0ae to a36d4d1 Compare July 15, 2021 16:12
@a-hilaly
Copy link
Member Author

Need to be rebased, now that #126 is merged
/hold

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.

@a-hilaly wonderful start on this! You will need to make a number of changes, however, in order to properly deal with nested complex types. See inline for an explanation of why your variable-naming schema needs to be adapted.

cmd/ack-generate/command/webhook.go Outdated Show resolved Hide resolved
cmd/ack-generate/command/webhook.go Outdated Show resolved Hide resolved
cmd/ack-generate/command/webhook.go Show resolved Hide resolved
cmd/ack-generate/command/webhook.go Outdated Show resolved Hide resolved
pkg/generate/ack/webhook.go Show resolved Hide resolved
pkg/generate/code/converter/converter.go Show resolved Hide resolved
pkg/generate/code/converter/converter.go Show resolved Hide resolved
Comment on lines +335 to +336
// elementCopy := make([]*v1alpha2.WebhookFilter, 0, len(element))
varElementCopy := "element" + "Copy"
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are going to run into problems with nested list types here, because you will have variable name shadowing in effect. This is why the code generation that sets CR fields from an Output shape (the pkg/generate/code.SetOutput stuff) generates a variable name that represents the field's numeric index within the Shape. For instance, if I had a Shape like this:

type Bar struct {
     Baz string
}

type Foo struct {
  Bars []*Bar
}

type MyShape struct {
  Foos []*Foo
}

The variable referring to MyShape.Foos.Bars would be called f0f0 and the iterator over elements in that list of Bar structs would be called f0f0iter, with the element variable name of f0f0elem.

The way you are naming things here means that you would end up producing Go code like this:

elementCopy := make([]*Foo, 0, len(src.Foos))
for _, element := range src.Foos {
    fooCopy := &Foo{}
    elementCopy := make([]*Bar, 0, len(element.Bars)
    for _, element := range element.Bars {
        barCopy := &Bar{}
        barCopy.Baz = element.Baz
        elementCopy = append(elementCopy, barCopy)
    }
    elementCopy = append(elementCopy, fooCopy)
}

which would be invalid since the variable name elementCopy is shadowed/hidden by the inner declaration of itself.

)

memberShape := shape.ValueRef.Shape
varElementCopy := "element" + "Copy"
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment as above :) you are going to run into variable naming conflicts.

return out
}

// storeVariableIn retruns go code that stores a value in a given variable.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/retruns go/returns Go

a-hilaly added 3 commits July 22, 2021 17:25
functions

This patch introduces a new function that generates conversion
functions. It can be used to generate `ConvertTo` and `ConvertFrom`
functions.
This patch brings in a new sub command that can be used to generate
webhook functions. For now it can only generate conversion webhook
functions, but it can be used to generate defaulting and validating
functions.

This patch also introduces a new function to load existing ack-generate
metadata for a given api version.
@a-hilaly a-hilaly force-pushed the ackgenerate-webhooks branch 2 times, most recently from 282df9a to 3a3f2f0 Compare August 24, 2021 08:56
@a-hilaly
Copy link
Member Author

/do-not-merge needs-rebase

@ack-bot
Copy link
Collaborator

ack-bot commented Nov 22, 2021

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 Nov 22, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Dec 22, 2021

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 Dec 22, 2021
@a-hilaly
Copy link
Member Author

/remove-lifecycle rotten

@ack-bot ack-bot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Dec 22, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Mar 22, 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

@a-hilaly
Copy link
Member Author

/lifecycle frozen

@ack-bot ack-bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 22, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Mar 22, 2022

@a-hilaly: The lifecycle/frozen label cannot be applied to Pull Requests.

In response to this:

/lifecycle frozen

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.

@ack-bot
Copy link
Collaborator

ack-bot commented Apr 21, 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 Apr 21, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented May 22, 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
Copy link
Collaborator

ack-bot commented May 22, 2022

@ack-bot: Closed this PR.

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.

@ack-bot ack-bot closed this May 22, 2022
@a-hilaly
Copy link
Member Author

/reopen
/lifecycle frozen

@ack-bot ack-bot reopened this May 23, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented May 23, 2022

@a-hilaly: Reopened this PR.

In response to this:

/reopen
/lifecycle frozen

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.

@ack-bot
Copy link
Collaborator

ack-bot commented May 23, 2022

@a-hilaly: The lifecycle/frozen label cannot be applied to Pull Requests.

In response to this:

/reopen
/lifecycle frozen

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.

@ack-bot
Copy link
Collaborator

ack-bot commented May 23, 2022

@a-hilaly: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
s3-olm-test 3a3f2f0 link /test s3-olm-test
dynamodb-controller-test 3a3f2f0 link /test dynamodb-controller-test
s3-controller-test 3a3f2f0 link /test s3-controller-test
ecr-controller-test 3a3f2f0 link /test ecr-controller-test
unit-test 3a3f2f0 link /test unit-test

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@ack-bot
Copy link
Collaborator

ack-bot commented Jun 22, 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 Jun 22, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Jun 22, 2022

@ack-bot: Closed this PR.

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
approved do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants