Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Issue #364 Add Support to Kafka Source for Resource spec #399

Merged
merged 8 commits into from
May 31, 2019

Conversation

lberk
Copy link
Member

@lberk lberk commented May 7, 2019

As mentioned in Issue #364 , this is experimenting adding resource spec for

  • resources.limits.cpu
  • resources.limits.memory
  • resources.requests.cpu
  • resources.requests.memory

As part of this change, we've moved the cmp test to kmp (was hitting errors similar to those seen in Serving 2622), Matching the approach in the serving repo.

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label May 7, 2019
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 7, 2019
@knative-prow-robot
Copy link
Contributor

Hi @lberk. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 7, 2019
@matzew
Copy link
Member

matzew commented May 7, 2019

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 7, 2019
@matzew
Copy link
Member

matzew commented May 7, 2019

In the config/300-kafkasource.yaml, let's add this:

            resources:
              properties:
                limits:
                  properties:
                    cpu:
                      type: string
                    memory:
                      type: string
                  type: object
                requests:
                  properties:
                    cpu:
                      type: string
                    memory:
                      type: string
                  type: object
              type: object

you can generate that file (but CAUTION) with:

cd contrib/kafka
go run ../../vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all 
mv config/crds/sources_v1alpha1_kafkasource.yaml config/300-kafkasource.yaml

but only ... pick the relevant diff ...

I'd also suggest adding this new feature to the samples, to make it a little bit more visible

@matzew
Copy link
Member

matzew commented May 7, 2019

Regarding the coverage - let's add a test that does NOT specify the Resource Limits, so that we can test if the actual defaults are applied:

							Resources: corev1.ResourceRequirements{
								Limits: corev1.ResourceList{
									corev1.ResourceCPU:    resource.MustParse("100m"),
									corev1.ResourceMemory: resource.MustParse("500Mi"),
								},
								Requests: corev1.ResourceList{
									corev1.ResourceCPU:    resource.MustParse("10m"),
									corev1.ResourceMemory: resource.MustParse("10Mi"),
								},
							},

than we get back to 100% :)

@matzew
Copy link
Member

matzew commented May 7, 2019

I deployed a source, no specific setting (assuming defaults), doing k get kafkasources kafka-source -oyaml gives me:

apiVersion: sources.eventing.knative.dev/v1alpha1
kind: KafkaSource
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"sources.eventing.knative.dev/v1alpha1","kind":"KafkaSource","metadata":{"annotations":{},"name":"kafka-source","namespace":"default"},"spec":{"bootstrapServers":"my-cluster-kafka-bootstrap.kafka:9092","consumerGroup":"my-group","sink":{"apiVersion":"serving.knative.dev/v1alpha1","kind":"Service","name":"event-display"},"topics":"my-topic"}}
  creationTimestamp: "2019-05-07T09:11:12Z"
  generation: 2
  name: kafka-source
  namespace: default
  resourceVersion: "21585"
  selfLink: /apis/sources.eventing.knative.dev/v1alpha1/namespaces/default/kafkasources/kafka-source
  uid: 0f203a34-70a8-11e9-9cdb-e452b3720906
spec:
  bootstrapServers: my-cluster-kafka-bootstrap.kafka:9092
  consumerGroup: my-group
  net:
    sasl:
      password: {}
      user: {}
    tls: {}
  resources:
    limits: {}
    requests: {}
  sink:
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    name: event-display
  topics: my-topic

Expected ?

@matzew
Copy link
Member

matzew commented May 7, 2019

looking in the underlying deployment, I do indeed see the defaults:

...
        resources:
          limits:
            cpu: 100m
            memory: 100M
          requests:
            cpu: 10m
            memory: 10M
...

@matzew
Copy link
Member

matzew commented May 7, 2019

Now, updating/changing a running source (by explicitly adding NON-DEFAULT settings) and runningk get kafkasources kafka-source -oyaml

gives me:

apiVersion: sources.eventing.knative.dev/v1alpha1
kind: KafkaSource
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"sources.eventing.knative.dev/v1alpha1","kind":"KafkaSource","metadata":{"annotations":{},"name":"kafka-source","namespace":"default"},"spec":{"bootstrapServers":"my-cluster-kafka-bootstrap.kafka:9092","consumerGroup":"my-group","resources":{"limits":{"cpu":"200m","memory":"200M"},"requests":{"cpu":"20m","memory":"20M"}},"sink":{"apiVersion":"serving.knative.dev/v1alpha1","kind":"Service","name":"event-display"},"topics":"my-topic"}}
  creationTimestamp: "2019-05-07T09:11:12Z"
  generation: 3
  name: kafka-source
  namespace: default
  resourceVersion: "22294"
  selfLink: /apis/sources.eventing.knative.dev/v1alpha1/namespaces/default/kafkasources/kafka-source
  uid: 0f203a34-70a8-11e9-9cdb-e452b3720906
spec:
  bootstrapServers: my-cluster-kafka-bootstrap.kafka:9092
  consumerGroup: my-group
  net:
    sasl:
      password: {}
      user: {}
    tls: {}
  resources:
    limits:
      cpu: 200m
      memory: 200M
    requests:
      cpu: 20m
      memory: 20M
  sink:

But looking at the underlying deployment I still see:

        resources:
          limits:
            cpu: 100m
            memory: 100M
          requests:
            cpu: 10m
            memory: 10M

related: #400

@matzew
Copy link
Member

matzew commented May 7, 2019

Now, creating a new source, where I set values, like:

  resources:
    limits:
      cpu: 200m
      memory: 200Mi
    requests:
      cpu: 200m
      memory: 200Mi

It's all correct in the kafkasource AND the underlying deployment

@matzew
Copy link
Member

matzew commented May 7, 2019 via email

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 7, 2019
@lberk
Copy link
Member Author

lberk commented May 7, 2019

Updated as requested, and rebased on master

  • config/300-kafkasource.yaml - add in resource properties
  • pkg/reconcilier/resources/receive_adapter.go - increase the defaults to proper values
  • pkg/reconcilier/resources/receive_adapter_test.go - add second testcase (we should probably create a proper test struct in the future)
  • samples/event-sources.yaml - add in an example resource specification

@lberk lberk changed the title Issue #365 Add Support to Kafka Source for Resource spec Issue #364 Add Support to Kafka Source for Resource spec May 7, 2019
@matzew
Copy link
Member

matzew commented May 8, 2019

deploying a source, without the resource config, I still see it empty, when running k get kafkasources kafka-source -oyaml I am getting:

...
spec:
  bootstrapServers: my-cluster-kafka-bootstrap.kafka:9092
  consumerGroup: new
  net:
    sasl:
      password: {}
      user: {}
    tls: {}
  resources:
    limits: {}
    requests: {}
  sink:
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    name: event-display
  topics: my-topic

I'd expect the sepc.resources would tell the actual defaults

@matzew
Copy link
Member

matzew commented May 22, 2019

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 22, 2019
Copy link
Contributor

@Harwayne Harwayne left a comment

Choose a reason for hiding this comment

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

deploying a source, without the resource config, I still see it empty, ... I'd expect the sepc.resources would tell the actual defaults

I think we normally achieve that through Webhook defaulting. I don't think I've seen a reconciler manipulate the spec of the resource it is reconciling (although I'm sure someone somewhere does it).

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label May 24, 2019
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-sources-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
contrib/kafka/pkg/reconciler/kafkasource.go 89.1% 87.3% -1.7

lberk added 7 commits May 29, 2019 19:46
Add the kafka_types for resources requests and limits (cpu, memory)
which will translate to the deployment template as
resources.limits.cpu
resources.limits.memory
resources.requests.cpu
resources.requests.memory

Use kmp for testing intead of cmp.
As seen in serving issue #2622, we should use knative/pkg/kmp
(otherwise we get unit test errors)

Update the Gopkg.lock file accordingly
config/300-kafkasource.yaml - add in resource properties
pkg/reconcilier/resources/receive_adapter.go - increase the defaults
to proper values
pkg/reconcilier/resources/receive_adapter_test.go - add second
testcase (we should probably create a proper test struct in the
future)
samples/event-sources.yaml - add in an example resource specification
pkg/apis/sources/v1alpha1/kafka_types - Fix spelling mistake caught by sockpuppet
Readd cmp for testing/building
As per feedback, `kubectl get kafkasource -oyaml` should show some
status regarding the correctness of the resources supplied, and if
they were correctly parsed.  Add this, as well as a description/error
message for which resource failed (and why).

Update kafkasource_test accordingly
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-sources-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
contrib/kafka/pkg/apis/sources/v1alpha1/kafka_types.go 93.3% 82.4% -11.0
contrib/kafka/pkg/reconciler/kafkasource.go 89.1% 83.8% -5.3

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-sources-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
contrib/kafka/pkg/apis/sources/v1alpha1/kafka_types.go 93.3% 82.4% -11.0
contrib/kafka/pkg/reconciler/kafkasource.go 89.1% 83.8% -5.3

Copy link
Contributor

@Harwayne Harwayne left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 30, 2019
@matzew
Copy link
Member

matzew commented May 31, 2019

/approve

@matzew
Copy link
Member

matzew commented May 31, 2019

@n3wscott or @grantr This PR was /lgtm'd by @Harwayne, and I could, in theory, approve it.

However, since it also updates non Kafka file (Gopkg.lock), my /approve is not good enough :-(

Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/approve

Thanks to @Harwayne and @danp for asking the question I was going to ask.

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, lberk, matzew

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 31, 2019
@knative-prow-robot knative-prow-robot merged commit 0743eb4 into knative:master May 31, 2019
@matzew matzew mentioned this pull request Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants