Skip to content

add AWS SQS event source#328

Closed
rootfs wants to merge 2 commits into
knative:masterfrom
rootfs:sqs-src
Closed

add AWS SQS event source#328
rootfs wants to merge 2 commits into
knative:masterfrom
rootfs:sqs-src

Conversation

@rootfs
Copy link
Copy Markdown
Contributor

@rootfs rootfs commented Aug 7, 2018

Fixes #

Proposed Changes

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 7, 2018
@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 7, 2018
@rootfs
Copy link
Copy Markdown
Contributor Author

rootfs commented Aug 7, 2018

/assign @scothis

@rootfs rootfs force-pushed the sqs-src branch 2 times, most recently from ba2e056 to 636b2e4 Compare August 8, 2018 18:38
@evankanderson
Copy link
Copy Markdown
Member

/assign @n3wscott

Copy link
Copy Markdown
Contributor

@n3wscott n3wscott left a comment

Choose a reason for hiding this comment

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

Will look again when not WIP

Comment thread pkg/sources/awssqs/awssqs.go Outdated
}

func NewAWSSQSEventSource(kubeclientset kubernetes.Interface, feedNamespace string, feedServiceAccountName string, image string) sources.EventSource {
glog.Infof("Image: %q", image)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note we have been moving away from glog. We are moving to either zap for controller logging and log for jobs logging.

Comment thread pkg/sources/awssqs/awssqs.go Outdated

err := a.deleteAWSSQSDeployment(deploymentName)
if err != nil {
glog.Warningf("Failed to delete deployment: %s", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

%s should be %v

glog.Infof("creating awssqs feed context")
// create aws sqs deployment
awsToken := ""
awsId := trigger.Parameters["AWS_ACCESS_KEY_ID"].(string)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

magic keys should be moved to a string const block at top.

awsToken := ""
awsId := trigger.Parameters["AWS_ACCESS_KEY_ID"].(string)
awsKey := trigger.Parameters["AWS_SECRET_ACCESS_KEY"].(string)
if token, ok := trigger.Parameters["AWS_SESSION_TOKEN"].(string); ok {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would assign awsToken directly and then ...; !ok || len(awsToken) == 0 {

I have a few examples of pulling params out of contexts and objects here: https://github.com/knative/eventing/pull/276/files#diff-15c4ba004c85a3abc13efbe47a731b58R391

if len(resource) != 2 {
return nil, fmt.Errorf("invalid resource: must be region/queue-name")
}
region := resource[0]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if err != nil {
return nil, err
}
deploymentName := "awssqs-" + queueName + "-" + uuid.String()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

uuid is a very large number. Paul had a better method by using k8s generate name. @pmorie can you link to that api to get the short random name?

Comment thread pkg/sources/awssqs/awssqs.go Outdated
var p parameters
err := json.Unmarshal(decodedParameters, &p)
if err != nil {
panic(fmt.Sprintf("can not unmarshal %q : %v", decodedParameters, err))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I moved from panic to os.Exit(0) with a log above

@rootfs rootfs changed the title [WIP] add AWS SQS event source add AWS SQS event source Aug 14, 2018
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 14, 2018
Comment thread sample/awssqs/flow.yaml
resource: us-east-1/knative-demo
service: aws-sqs
parametersFrom:
- secretKeyRef:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should consider the case that cluster is running on AWS, and use KIAM to do IAM role delegation. This is how people access AWS resources from a k8s cluster running on EC2 instances without using any credentials.

The implementation can support both cases, with credential, or KIAM delegated Role. For the latter case, the IAM role configuration would be like:

  1. Kubernetes cluster master nodes IAM role (This should already be existing after the cluster is created), this role should have the policy to assume-role

  2. An IAM role which is assigned to a namespace (and will be used by the POD), this role is set to trust cluster master node IAM role, with KIAM, your pod can get temp credential to this IAM role by calling AWS metadata API, without using any credential. This Role also needs the policy to assume-role.

  3. A third role to be able to operate SQS, and it trusts the 2nd IAM role.

  4. In flow configuration, the 2nd and 3rd IAM role ARNs are needed, so that in your receive_adaptor you can use the 2nd role credential to assume 3rd role, and then read messages.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I didn't see this PR until this afternoon. Before that, I implemented a SQS event source about 1 week ago, which was very similar to this. The major difference is, my k8s cluster is running on EC2 instances, and I use KIAM, so I don't use any explicit credentials to access AWS SQS. So I gave above comments, it would be better if this case can be considered in the PR.

@rootfs
Copy link
Copy Markdown
Contributor Author

rootfs commented Sep 24, 2018

@whynowy thanks, i ran my tests locally, IAM is a good idea, I'll get this here after eventing core is settled.

Huamin Chen added 2 commits October 4, 2018 13:38
Signed-off-by: Huamin Chen <hchen@redhat.com>
Signed-off-by: Huamin Chen <hchen@redhat.com>
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rootfs
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: scothis

If they are not already assigned, you can assign the PR to them by writing /assign @scothis in a comment when ready.

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

The pull request process is described here

Details 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

@knative-prow-robot
Copy link
Copy Markdown
Contributor

@rootfs: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-knative-eventing-unit-tests 099adfc link /test pull-knative-eventing-unit-tests

Full PR test history. Your PR dashboard.

Details

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.

@matzew
Copy link
Copy Markdown
Member

matzew commented Nov 7, 2018

@rootfs @n3wscott @scothis IMO we could close this... since this should be PR'd on the new repo (eventing-sources), following the new model

@rootfs rootfs closed this Nov 7, 2018
matzew pushed a commit to matzew/eventing that referenced this pull request Oct 12, 2023
Co-authored-by: pierDipi <pierDipi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants