Skip to content

add conformance test for labels#2039

Merged
knative-prow-robot merged 3 commits into
knative:masterfrom
nader-ziada:labels-test
Sep 20, 2018
Merged

add conformance test for labels#2039
knative-prow-robot merged 3 commits into
knative:masterfrom
nader-ziada:labels-test

Conversation

@nader-ziada
Copy link
Copy Markdown
Member

Fixes #2021

Proposed Changes

  • Add new conformance test to check labels propagation in serving objects

Release Note

NONE

@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 17, 2018
@nader-ziada
Copy link
Copy Markdown
Member Author

any comments about this test? anything else we need to cover?
@dprotaso @mattmoor @evankanderson @shashwathi

@nader-ziada
Copy link
Copy Markdown
Member Author

/assign @mattmoor

@evankanderson
Copy link
Copy Markdown
Member

/assign @evankanderson

I'll take a look shortly. Do you want to also write up a change to the spec, or do you want me to try to write that up? I'd be happy to help with wordsmithing if you want to make the spec change (Probably https://github.com/knative/serving/blob/master/docs/spec/spec.md and maybe https://github.com/knative/serving/blob/master/docs/runtime-contract.md#process).

Copy link
Copy Markdown
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.

Looking further at this test, this should be spelled out better in the spec document: we have a completely different set of labels on the object right now. (And the "type" label can probably go, as it was advisory rather than mandatory.)

It may also be worth adding a small amount of text above the sample YAML explaining how each objects labels are derived from its relations.

Comment thread test/conformance/labels_test.go Outdated
var imagePath = test.ImagePath("helloworld")

var names test.ResourceNames
names.Service = test.AppendRandomString("pizzaplanet-service", logger)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Prefer:

names := test.ResourceNames{Service: test.AppendRandomString("pizzaplanet-service", logger)

// Add test case specific name to its own logger.
logger := logging.GetContextLogger("TestLabelsPropagation")

var imagePath = test.ImagePath("helloworld")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move this below the initialization of "names" so that the setup of clients and names are as close as possible to the deferred tearDown.

Comment thread test/conformance/labels_test.go Outdated
names.Config = serviceresourcenames.Configuration(svc)

logger.Info("The Service will be updated with the name of the Revision once it is created")
var revisionName string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we need this revisionName here, since we overwrite it on line 62?

Comment thread test/conformance/labels_test.go Outdated
}
return false, nil
}, "ServiceUpdatedWithRevision")
revisionName, err = waitForServiceLatestCreatedRevision(clients, names)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we have both WaitForServiceState and waitForServiceLatestCreatedRevision?

Comment thread test/conformance/labels_test.go Outdated
revisionName = s.Status.LatestCreatedRevisionName
return true, nil
}
return false, nil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you don't need to capture revisionName, this can be:

return s.Status.LatestCreatedRevisionname != names.Revision, nil

Comment thread test/conformance/labels_test.go Outdated
if err != nil {
t.Fatalf("Service %s was not updated with the new revision: %v", names.Service, err)
}
names.Revision = revisionName
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not assign to names.Revision on line 62?

t.Fatalf("The Service %s was not marked as Ready to serve traffic to Revision %s: %v", names.Service, names.Revision, err)
}

logger.Info("Validate Labels on Revision Object")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a comment here that the setup is complete, and what we're intending to test (possibly as a reference to the spec)?

}
} else {
t.Fatalf("Failed to get configuration name from Revision label")
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Totally optional: golang will return a empty value from a map lookup if you use the single-assignment form. Assuming that you know that names.Config is non-empty, you could write this as:

if revision.Labels["serving.knative.dev/configuration"] != names.Config {
  t.Fatalf(...)
} 

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, I'd suggest using t.Errorf() here, to fail the test but allow it to keep executing. This will allow additional conditions to be tested and debugged at one time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might also be an opportunity for a table-driven test; ala:

struct TestCase {
  Name string
  Fetcher func(string, metav1.Options) (interface, error)  // Must be an object 
  Labels map[string]string
}

expectedLabels := []TestCase{
  {
    Name: names.Revision,
    Fetcher: clients.ServingClient.Revisions.Get,
    Labels: {
        "serving.knative.dev/configuration": names.Config,
        "serving.knative.dev/service": names.Service,
    },
  },
  ...
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@evankanderson

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, I'd missed that the conversion between clients.ServingClient.Revisions.Get and the Fetcher wouldn't work. Given that, I agree that this is the most reasonable formulation.

@evankanderson evankanderson changed the title add conformance test for lables add conformance test for labels Sep 18, 2018
@mattmoor mattmoor removed their assignment Sep 19, 2018
@nader-ziada
Copy link
Copy Markdown
Member Author

@evankanderson addressed comments

Copy link
Copy Markdown
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

A few small corrections, but this looks good. Thanks!

Comment thread docs/spec/spec.md Outdated
namespace: default
labels:
knative.dev/type: ... # +optional convention: function|app
knative.dev/service: ... # name of the service
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mention this is filled in automatically.

Comment thread docs/spec/spec.md Outdated
namespace: default

labels:
knative.dev/service: ... # name of the service
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto

Comment thread test/conformance/labels_test.go Outdated
t.Fatalf("The Service %s was not marked as Ready to serve traffic to Revision %s: %v", names.Service, names.Revision, err)
}

// Now that the serive is ready, we can validate the Labels on the Revision, Configuration
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"serive" -> Service.

Comment thread test/conformance/labels_test.go Outdated
}

if revision.Labels["serving.knative.dev/configuration"] != names.Config {
t.Errorf("Expect confguration name in revision label %q but got %q ", names.Config, revision.Labels["serving.knative.dev/configuration"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"Configuration"

Comment thread test/conformance/labels_test.go Outdated
}

if route.Labels["serving.knative.dev/service"] != names.Service {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Extra line here.

}
} else {
t.Fatalf("Failed to get configuration name from Revision label")
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, I'd missed that the conversion between clients.ServingClient.Revisions.Get and the Fetcher wouldn't work. Given that, I agree that this is the most reasonable formulation.

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 20, 2018
@nader-ziada
Copy link
Copy Markdown
Member Author

@evankanderson addressed comments

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 20, 2018
Copy link
Copy Markdown
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.

/lgtm
/approve

Thanks for doing this, and your patience with my reviews!

@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, pivotal-nader-ziada

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 knative-prow-robot merged commit 984c181 into knative:master Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. 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.

4 participants