Commit Graph

51 Commits

Author SHA1 Message Date
Naomi Seyfer 4874b9a384 Human-readable revision describe (#475)
* Revision describe rebaseable

* Fix up for rebase

* Some tests

* moretests

* Forgot part of the refactor!

* Fix unit tests

* Change e2e tests and respond to feedback
2019-11-05 17:43:02 -08:00
Ying Chun Guo c5b3f7af0d add serviceaccount to service describe (#472) 2019-11-05 03:11:25 -08:00
Naomi Seyfer aafdb9a238 Refactor describe: printing levels and shared kn code (#430)
* Refactor describe: printing levels and shared kn code

* Test this refactor more

* Comments
2019-10-29 03:08:11 -07:00
Navid Shaikh a32f5666b5 Vendors serving v0.9.0 (#458)
* Vendors serving v0.9.0

* Updates references per serving v0.9.0 vendoring

 - Updates code and tests to refer the required data structure and method/function calls
 - duckv1beta1 -> duckv1 conditions
 - traffic percent value is now *int64
 - containerConcurrency validation method relocation

* fix(golint): exported function should have comment

 for NonReadyConditionReason function

* Updates check for removing null targets

 fixes the pointer value check

* Updates per review comments
2019-10-27 22:22:36 -07:00
Ying Chun Guo 492f1dce76 add revision information to service list (#441) 2019-10-25 02:40:35 -07:00
Roland Huß 6328a73c98 fix(service): Set default timeout for update to the same value as for create (#446)
Also, added accidentally removed seperator lines during create/update
2019-10-16 04:51:15 -07:00
Roland Huß 53125bcbdb chore: Some minor printout fixes (#442)
* chore: Some minor printout fixes

* test fixes
2019-10-11 09:51:31 -07:00
Roland Huß a2d1ef7d83 chore(service): Improvements for waiting on service readiness (#431)
* Increased default timeout to 600s. This timeout will be triggered
  only when the Ready condition stays in UNKNOWN for that long. If its
  True or False then the command will return anyway sooner.
  So it makes sense to go for a much longer timeout than 60s
* Enhanced output to indicate the progress

This change needs some updates to the API and introduces a 'MessageCallback'
type which is calle for each intermediate event with the "Ready" condition message.
2019-10-10 06:06:06 -07:00
Navid Shaikh 2f7fa6a7c2 feat(annotations): Adds annotation flag for service create and update (#422)
* feat(annotations): Adds annotation flag for service create and update

  - Adds specified annotations to service object meta and revision template meta
  - Adds --annotation / -a flag to service create and update options
  - User can specify '-' at the end of the annotation key to remove an annotation
  - Adds unit and e2e tests
  - Updates docs and changelog accordingly

* Adds example for service create with annotation

* Adds mock unit tests for service update with annotations

* Removes the short hand -a for annotation flag
2019-10-04 06:40:05 -07:00
Naomi Seyfer b27e366dcb Service describe: information about revision status, tags, latest [created, ready] revisions, and latest traffic (#379)
* Change symbols, add latest and latest ready

* More info on what is latest and tags. Filter annotations and labels.

* Make current tests pass

* More tests

* No longer require Annotations in test

* Add error

* Adjust tests to match adjusted output

* Respond to review comments

* one more

* Fix double printing of revisions + test for it

* Differentiate between latest traffic and latest ready w/o that being reason for traffic

* Re-build with go 1.12

* Rebased

* Limit non-verbose output to error and image

* Fix tests for new format
2019-10-03 11:33:08 -07:00
Roland Huß 6ffef8dd88 refactor(knclient): Moved KnClient -> KnServingClient (#420)
This is in preparation of introducting eventing and makes sense anyway.
Also, the GVK update handling has been moved to "util" so that it then
can be also reused by eventing.
2019-09-28 09:21:45 -07:00
Ingwon Song 14ec594e56 Add --service-account-name flag (#401)
* Add --service-account-name flag

* Change the flag --service-account-name to --service-account, and change its default value from "-" to an empty string. In addition, CHANGELOG.adoc is changed.

* Update docs with ./hack/build.sh
2019-09-23 04:45:13 -07:00
Toshinori Sugita 43f8386b82 fix analyzer warnings (#412)
* remove unused codes (structcheck)(varcheck)

* add error handling (errcheck)

* add error handling (ineffassign)

* fix lint errors (golint)
2019-09-23 03:03:12 -07:00
Tsubasa Nagasawa 9b52fc8345 Update EnvVars in alphabetical order of Env key name (#389) 2019-09-12 01:12:32 -07:00
Gong Zhang a607b16b0c Rename go files under command group dir (#245)
- Files under service dir
- Files under revision dir
- Files under plugin dir

[issue 229](https://github.com/knative/client/issues/229)
2019-09-06 00:13:03 -07:00
Gong Zhang b649b72694 Fill up test cases for files with low coverage (#399)
To get the test pass for https://github.com/knative/client/pull/245,
need to fill up test cases for files with low code coverage
2019-09-05 03:33:04 -07:00
Komal Dhull 679096194a Added --no-headers flag for resource listing (#262) 2019-09-03 00:31:00 -07:00
Naomi Seyfer 0ff537ad98 By default, set `Image` to the image of the prev. revision by digest (#373)
* Option to freeze revision to digest

* Tests pass. Checkpoint.

* Tests for env now check pinning to digest

* Bool flag using convention. Tweak usage.

* Describing the image carefully using the annotation and digest

* lint

* Test matrix of locking to digest behaviors

* Expose both flags, and rewrite help text again

* Unit tests.

* Removed unsed method

* Add tests for getting base revision

* Make tests actually test stuff better

* Make tests actually test stuff better

* A mergeout killed a returning of error. Restore it

* Help text again
2019-08-27 11:42:40 -07:00
Toshinori Sugita 699ac5e7cb fix lint errors (#388)
* fix typo (misspell)

* ineffectual assignment to err (ineffassign)

* if block ends with a return statement, so drop this else and outdent its block (golint)

* should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (golint)

* struct field LogHttp should be LogHTTP (golint)

* fix last typo
2019-08-24 22:46:13 -07:00
makocchi 04a55b27f2 Remove namespace from args (#386) 2019-08-22 18:00:12 -07:00
Roland Huß 9625b5f4c5 chore(plugins, services, routes): Aligned "Not found" messages (#359)
For the sake of consistency with out own service commands and for kubectl,

`kn plugin list` should print:

```
No plugins found.
```

`kn service list` should print:

```
No services found.
```

and not `No resources found.` like it does now.

Same for `kn routes list`.
2019-08-22 00:23:32 -07:00
Tsubasa Nagasawa d0dc3b75f3 feature(service list): Print NAMESPACE column as the first column when --all-namespaces is specified (#366)
* Make `kn service list --all-namespace` print namespace column

`kn service list` should print NAMESPACE column when specifying `--all-namespace` option, which follows the kubectl convention.

* Put services in default namespace at the top of the list

* Switch output of column definitions by priority field

A priority field is handled as follows:
- priority 0: print namespace column
- priority 1: print default columns
- priority 2: print additional columns for wide option

* Don't use AddFlags to bind all namespaces flag

* Update CHANGELOG

* Remove commented codes

* Fix import path

* Clean up

* Remove unnecessary return

* Swap the order of records
2019-08-21 23:57:33 -07:00
Naomi Seyfer 25c726453e Update serving dependency to 0.8; change all import paths (#368)
* Update serving to 0.8. Try building.

* Find the right serving version

* Change our own import path to knative.dev to match

* Remove dependency on old version of client

* Update yaml template

* Add sleep to test to deal with race

* fix merge conflict

* Update vendor modules
2019-08-15 18:09:08 -07:00
Naomi Seyfer b707702973 Always create in new format rather than old (#361)
* Always create in new format rather than old

* Rejigger tests and make them independent of filesytem

* Fix test on mergeout
2019-08-15 16:01:07 -07:00
Navid Shaikh 746dacc47c feature(service): Implements traffic splitting and tagging targets (#345)
- Add e2e tests
 - Use '=' for traffic and tag assignment instead of ':'
 - Use --tag and --untag flags for tagging traffic targets
 - Use --traffic flag for setting traffic portions
 - Allow --traffic portion to either take revisionName or tagName
 - Uses @latest identifier for referencing latest revision of service
 - Dont throw error if requested revision=tag pair is same
 - Support having multiple tags for a revision
	 - creates a new target in traffic block if revision present in traffic block with new tag requested
	 - creates N new targets in traffic block if revision absent in traffic block with Nxnew tags requested
 - Ensure updating tag of @latest requires --untag flag
	 - streamline updating tag for latestReadyRevision
	 - adds respective tests
	 - adds tests for ensuring given traffic sum to 100 on CLI and fail fast
 - Add note about preference of order in case where tagOfOneRevision == revisionOfAnother,
   first tags are checked and assigned traffic if any, as tags are supposed to be
   unique in traffic block and should be referenced in such scenario.
 - Remove the examples from flag description, moves it to service update command example section
 - Pass only traffic block to compute trffic, makes it better to consume.
 - Cover more error cases for invalid value format for assignments, covers a=b=c, a=, =b, or variants of them
 - Separate and improves the error messages
 - Add unit tests for traffic computing
 - Add sanity checks in dedicated function verifyInputSanity
 	  - traffic perents should sum to 100
          - individual percent should be in 0-100
          - repetition of @latest or tagName or revisionRef is disallowed
 - Verify traffic percents sum to 100 on client side and fail fast
 - Add e2e tests for traffic splitting
	 - create and update service, assign tags and set traffic to make an existing state
	 - run the scenario on existing state of service
	 - form the desired state traffic block
	 - extract the traffic block and form the traffic block struct actual state
	 - assert.DeepEqual actual and desired traffic blocks
 - Use logic to generate service name in the same way as namespace, use different service name per test case
 - Run e2e test for traffic splitting in parallel
 - Use timeout duration of 30m for e2e tests, use timeout parameter for go_test_e2e library function
 - Use tagName in flag description of --untag, avoiding conflict with --tag flag
 - Update CHANGELOG
2019-08-15 10:56:08 -07:00
Naomi Seyfer ffe80b9f87 Specify names on service update and generate names client-side. (#282)
* Groundwork for naming revisions automatically and deliberately

* Tests for name updates

* Add godoc comments

* Changelog entry for naming flags

* Error when trying to BYO revision name to an old-format service

* fix tests again

* Template the names

* Polsh, remove unused flags, generate helptext, add better helptext

* Decapitalize error msg

* Respond to Roland comments

* Forgot to add test file

* Be a good citizen, add more tests, try to get coverage happy.

* true dat

* Re-add implicit service prefix if one was not added.
2019-08-14 15:31:07 -07:00
Aaron Lerner 27d8f4330a Service and Revision labels (#342)
* Add support for service labels with --label or -l

* Add tests

* Fix typo

* Move MapToArray helper method to separate file

* Allow unsetting labels by passing empty value

* Fix test

* Add test case for label removal

* Wrap error message with flag

* Update docs to include --label

* Update labels on both services and revisions

* Add some test cases around weirder user input

* Change unset behavior and allow setting empty env and label

* Update docs for new unset behavior

* Make single keys to map to empty values

* Move helper to util

* Use assert.DeepEqual

* Use new mock test + check both service and revision

* Use new method and correct year
2019-08-13 17:07:06 -07:00
Ying Chun Guo 8c362f0363 list services sorted by alphabetical order (#330) 2019-08-09 01:00:04 -07:00
Roland Huß b4b254f64c feature(service describe): Output of service details (#252)
* feature(service describe): Output of service details

`kn service show` mimics `kubectl describe <sth>` as that it output detail information in human readable output.

A future extension should add machine readable output with `-o` to export
a single object in json/yaml (that is missing from `kn service list`)

This command shows information about the service itself, but also a summary about the associated revisions.

It also knows about scaling and concurrency options.

Options:

`--details`    : Print more information. By default only are shorter summary is shown

* chore: Cleanup up and refreshed dependencies

* fix(service describe): Integration test fix (revert "show" to "describe")

* fix: go.sum

* fix go.sum

* feature(service describe): Add printing of resources (requests/limits) + machine readable output with -o

* chore(service describe): Simplified digest handling

* chore(service describe): Sort maps by key when printed

* chore: Adapt mock framework

* chore(service describe): Test fixes

* chore: Added some tests

* more tests

* test: Moar tests

* chore: Even moar tests

* more, more tests

* changelog update

* fix(service describe): golint fixes
2019-08-08 08:23:56 -07:00
Doug Davis 6af3edb789 Add 'creator' annotation on create --force (#341)
Closes #340

Signed-off-by: Doug Davis <dug@us.ibm.com>
2019-08-06 13:25:55 -07:00
Gong Zhang 8fbb51f92a Report an error if no flag(s) set in service update (#318)
For now if no flag(s) set, service update will still try to
do an update, it should return an error instead.

[issue 286](https://github.com/knative/client/issues/286)
2019-07-31 13:49:44 -07:00
Roland Huß 71c39e822d feature(testing): Introduce a mock implementation for KnClient (#306)
* feature(testing): Introduce a Mock implementation for KnClient

Commands must only use the `KnClient` API and their unit tests should also
only use a mock implementation for this interface.

This commit introduces such a Mock implementation and works like in
the example below for creating a simple service in a synchronous
way

```
// New mock client
	client := knclient.NewMockKnClient(t)

	// Recording:
	r := client.Recorder()
	// Check for existing service --> no
	r.GetService("foo", nil, errors.NewNotFound(v1alpha1.Resource("service"), "foo"))
	// Create service (don't validate given service --> "Any()" arg is allowed)
	r.CreateService(knclient.Any(), nil)
	// Wait for service to become ready
	r.WaitForService("foo", knclient.Any(), nil)
	// Get for showing the URL
	r.GetService("foo", getServiceWithUrl("foo", "http://foo.example.com"), nil)

	// Testing:
	output, err := executeCommand(client, "create", "foo", "--image", "gcr.io/foo/bar:baz")
	assert.NilError(t, err)
	assert.Assert(t, util.ContainsAll(output, "created", "foo", "http://foo.example.com", "Waiting"))

	// Validate that all recorded API methods have been called
	r.Validate()
```

Such tests have three phases:

* A recording phase where the mock client is prepared. In this phase a
  recorder is called with the expected arguments and the return values
  it can return. The arguments can be also functions with
  signature `func (t *testing.T, actual interface{}, expected interface{})`
  and will be called to verify a given argument. Such a function should
  `t.Fail()` on its own if the validation fails.
  A convenient `Any()` method is added to allow no validation on an argument
  (see example below).
  Method can be called multiple times, but the order needs to reflect
  the actual calling order
* A playback phase where the test executed which in turn calls out to the
  Mocks
* A validation phase to check the expected output. The recorder can be
  also validated to verify that all recorded mock calls has been
  used during the test.

  See `service_create_mock_test.go` for a full example.

* chore: Test the mock client

* chore: Minor fixes

* chore: Cosmetic fixes
2019-07-30 17:51:42 -07:00
Tsubasa Nagasawa b7808b0fa2 Validate scale and container concurrency options when updating configuration resource (#279)
* Validate invalid container concurrency options

* Use assert package

* Use FlagSet.Changed and don't care about default values

* Update dependency

* Follow e2e test changes

* Return error if invalid value is specified by users

* Fix broken e2e test

* Add more unit tests

* Fix error message

* Fix comment statement

* Revert back unrelated changes

* Fix typo
2019-07-25 02:57:35 -07:00
Roland Huß 875e8da2a5 feature(service): Wait on update for service to become ready. (#271)
* feature(service): Wait on update for service to become ready.

The behaviour is now the same as for `kn service create`. This should also fix some flakiness in the tests again.

* chore: Fixed changelog

* chore(service): Adapt help message for update

* fix(test): Updated renamed method
2019-07-22 10:52:35 -07:00
Naomi Seyfer 8d7d227785 Rename accessors to be less like methods that get from the server (#275) 2019-07-18 23:19:28 -07:00
Roland Huß e1614f95e6 fix(service update): Retry an update in case of a conflict. (#240)
* fix(service update): Retry an update in case of a conflict.

Is related to #224 and should fix one flake.

* chore(service): Fixed retry-loop for kn service create/update
2019-07-10 11:18:10 -07:00
Roland Huß 26fb47c1d6 fix(service): Show URL (external) instead of Address (internal) when listing service (#247)
* fix(service): Pick up new field Address instead of Domain when listing service

Starting with 0.7.0 old fields are not populated anymore. Let's switch to the new fields then.

This fix should work with 0.6.0, too as the new fields already have been populated back then.

So we can unconditionally pick status.address.url which is accordance with
our policy to support the latest release and the release before.

Fixes #246.

* fix(service list): Use status.URL instead of status.Address in column

* chore: Rebase and update changelog

* chore: Rebase and test fix
2019-07-10 09:23:09 -07:00
savitaashture 3eb6e41751 get a particular service and revision based on name parameter (#150) 2019-07-10 02:39:05 -07:00
Roland Huß 2ae037f3be refactor(service): Removed io.writer from of KnClient.WaitForService() (#248)
This puts all the console output to the command, where it belongs too.
One could add a ProgressHandler for more fine granular feedback (like suggested in #234) but for now this is not needed.
2019-07-08 11:57:34 -07:00
Roland Huß 98184eafbc refactor(serving): KnClient interface for single point of cluster access (#134)
* fix(serving): Remove hardcoded GVK and look it up from schema

Fixes #133.

* chore(serving): Add test for "WaitForService()"

* refactor(service): Add listRoutes() to client + generic way for list options

* chore(serving): Fixing rebase conflicts
2019-07-08 10:08:34 -07:00
Navid Shaikh fc9b24c1e5 Add custom comparison for checking multiple substrings (#227)
* Adds custom comparison for checking multiple substrings

 This changeset introduces custom comparison for checking if a target
 string has given multiple substrings, namely `ContainsMultipleSubstrings`.

 Also removes `commands.TestContains` function and replaces all references
 of `commands.TestContains` with `gotest.tools/assert.Check` function and
 uses `ContainsMultipleSubstrings` as comparison function.

* Renames and makes the compare function variadic

 New name: ContainsAll
 New location: pkg/util/compare.go
 Also the function now takes target string as first arg,
 and accepts any number of substrings to check.
 Removed the message arg, the compare function composes the error message.
 For eg:
```
        Actual output: foo-abcd   foo       <unknown>   0 OK / 0     <unknown>   <unknown>
        Missing strings: foo-abcd1, foo1
```

* Adds tests for compare utility ContainsAll

* Update vendor/modules.txt
2019-07-05 10:07:32 -07:00
Roland Huß d51a3a8d91 fix(serving): Fix logic 'service create --force' and some bogus tests (#216)
* fix(servicing): Fix logic 'service create --force' and some bogus tests

Now a more meaningful error is returned when the user tries to create
a service that already exists. Until know the service is tried
to be created even if the client already knows that it exists.

Also some broken (broken in the sense that the test was nonsense) tests has been fixed.

* chore(serving): Use constant instead of string lateral in test
2019-07-02 12:19:32 -07:00
dr.max 43b37a6747 Fixes `limits-memory` and `requests-memory` descriptions (#198)
Erroneously showed ‘CPU’ for ‘memory’ in description strings
2019-06-28 12:04:08 -07:00
savitaashture 4cc5c84264 Added changes to support container port information while creating/updating service (#191) 2019-06-28 10:48:08 -07:00
Navid Shaikh 65f1c081ee Add kn revision delete command (#207)
* Adds kn revision delete command

* Adds unit tests for revision delete command

* Adds integration tests for revision delete command

 Added revision delete command tests in new workflow namely
 TestRevisionWorkflow.

* Removes extra line and renames an import alias

* Adds 10 seconds sleep between service create and revision delete

 Also adds check for 'No resources found' while grabbing revision name.

* Clean up imports

* Removes the pause after service create

* Updates testing output strings in unit and e2e

* Updates post goimports on hack and test dirs
2019-06-28 10:21:08 -07:00
Roland Huß a7d1bc9dc0 feat(service create): Wait for a service to be ready when its created (#156)
* feat(service create): Added --no-wait and --wait-timeout

By default, `kn service create` blocks until the service is either
created or an error occured during service creation.

With the option --no-wait the behaviour can be switched to an
async mode so that that kn returns immediately after the service is
created without waiting for a successful Ready status condition.

The timeout for how long to wait can be configured with --wait-timeout
If a timeout occur, that doesn't mean that the service is not created,
but the wait just returns. The default value is 60 seconds.

In wait mode, print out the service URL as a last line (so that it can be used together with `tail -1`) to extract the service URL after the service is created.

Fixes #54

* chore(service create): Tolerate if obeservedGeneration has not been set yet during startup

* chore(service create): Refactored based on review comments

* Introduced an --async flag (replacing --wait and --no-wait)
* Added proper retry handling on the list watch
* Updated help message

* chore(service wait): Added a new test for sync behaviour
2019-06-28 05:57:06 -07:00
Kenjiro Nakayama 13ff277095 Set current namespace from kubeconfig by default (#172)
* Set current namespace from kubeconfig by default

Currently kn command does not pick up namespace from kubeconfig but
hardcorded default namespace.

This patch fixes to get namespace from kubeconfig.

Fixes https://github.com/knative/client/issues/7

* Use NamespaceFactory to get current namespace

* Update unit tests

* Add nil check for ClientConfig
2019-06-24 11:23:05 -07:00
Roland Huß 8a1d412f52 fix(service update): Print success message after successful update (#169)
* fix(service update): Print success message after successful update

* chore(service update): Improve test, revert unneeded changes
2019-06-17 12:23:45 -07:00
Navid Shaikh d25ea5f1e7 Renames service 'get' to 'list' (#179)
* Renames service 'get' to 'list'

 As per title.

* Renames get references to list in e2e tests

* Replaces get to list in docs
2019-06-13 13:56:43 -07:00
Roland Huß b885e41974 feat(service create/update): Add support of minScale/maxScale/concurrency-target/concurrency-limit (#157)
Autoscaler concurrency annotations are added to the revision template if
--min-scale / --max-scale / --concurrency-target/--concurrency-limit
are provided to `kn service create` and `kn service update`

Fixes #151
2019-06-08 08:27:40 -07:00