-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ApiServer source update and describe commands (#556)
* Dont return created ApiServer source object but only error - After ApiServer source object is created, we don't need it to pass around in caller function. * Align creating ApiServer source client, removes unit tests * Add ApiServer source update command * Rename TestMockKnClient to TestMockKnCronJobSourceClient * Add mock client for ApiServer Source and its tests * Add mock unit tests for create, delete and update * Add e2e tests for apiserver source update - Add a test for apiserver source sink update - Verify the updated sink name after the apiserver source is created - Update resource names in existing tests * Uses builder pattern for ApiServer source create command * Update ApiServer source create/update flags and required config * Uses builder pattern for ApiServer source update command * Align create/update/delete description and error messages * Add unit tests for get/create/update/delete in apiserver_client.go * Update e2e tests expected output per change in commands output * Golint fixes, Api -> API and add exported method docs * Rename a test method and source update command description * Add ApiServer source describe command - Add command and unit tests - TODO for later: Add 'Controller Selector' section for --verbose
- Loading branch information
1 parent
7def9f4
commit 6ac25cd
Showing
26 changed files
with
1,070 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## kn source apiserver describe | ||
|
||
Describe an ApiServer source. | ||
|
||
### Synopsis | ||
|
||
Describe an ApiServer source. | ||
|
||
``` | ||
kn source apiserver describe NAME [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Describe an ApiServer source with name 'k8sevents' | ||
kn source apiserver describe k8sevents | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for describe | ||
-n, --namespace string Specify the namespace to operate in. | ||
-v, --verbose More output. | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string kn config file (default is $HOME/.kn/config.yaml) | ||
--kubeconfig string kubectl config file (default is $HOME/.kube/config) | ||
--log-http log http traffic | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kn source apiserver](kn_source_apiserver.md) - Kubernetes API Server Event Source command group | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## kn source apiserver update | ||
|
||
Update an ApiServer source. | ||
|
||
### Synopsis | ||
|
||
Update an ApiServer source. | ||
|
||
``` | ||
kn source apiserver update NAME --resource RESOURCE --service-account ACCOUNTNAME --sink SINK --mode MODE [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Update an ApiServerSource 'k8sevents' with different service account and sink service | ||
kn source apiserver update k8sevents --service-account newsa --sink svc:newsvc | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for update | ||
--mode string The mode the receive adapter controller runs under:, | ||
"Ref" sends only the reference to the resource, | ||
"Resource" send the full resource. (default "Ref") | ||
-n, --namespace string Specify the namespace to operate in. | ||
--resource strings Comma seperate Kind:APIVersion:isController list, e.g. Event:v1:true. | ||
"APIVersion" and "isControler" can be omitted. | ||
"APIVersion" is "v1" by default, "isController" is "false" by default. | ||
--service-account string Name of the service account to use to run this source | ||
-s, --sink string Addressable sink for events | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string kn config file (default is $HOME/.kn/config.yaml) | ||
--kubeconfig string kubectl config file (default is $HOME/.kube/config) | ||
--log-http log http traffic | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kn source apiserver](kn_source_apiserver.md) - Kubernetes API Server Event Source command group | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright © 2019 The Knative Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"knative.dev/eventing/pkg/apis/sources/v1alpha1" | ||
|
||
"knative.dev/client/pkg/util/mock" | ||
) | ||
|
||
// MockKnAPIServerSourceClient for mocking the client | ||
type MockKnAPIServerSourceClient struct { | ||
t *testing.T | ||
recorder *APIServerSourcesRecorder | ||
namespace string | ||
} | ||
|
||
// NewMockKnAPIServerSourceClient returns a new mock instance which you need to record for | ||
func NewMockKnAPIServerSourceClient(t *testing.T, ns ...string) *MockKnAPIServerSourceClient { | ||
namespace := "default" | ||
if len(ns) > 0 { | ||
namespace = ns[0] | ||
} | ||
return &MockKnAPIServerSourceClient{ | ||
t: t, | ||
recorder: &APIServerSourcesRecorder{mock.NewRecorder(t, namespace)}, | ||
} | ||
} | ||
|
||
// Ensure that the interface is implemented | ||
var _ KnAPIServerSourcesClient = &MockKnAPIServerSourceClient{} | ||
|
||
// APIServerSourcesRecorder for recording actions on source | ||
type APIServerSourcesRecorder struct { | ||
r *mock.Recorder | ||
} | ||
|
||
// Recorder returns the recorder for registering API calls | ||
func (c *MockKnAPIServerSourceClient) Recorder() *APIServerSourcesRecorder { | ||
return c.recorder | ||
} | ||
|
||
// Namespace of this client | ||
func (c *MockKnAPIServerSourceClient) Namespace() string { | ||
return c.recorder.r.Namespace() | ||
} | ||
|
||
// GetAPIServerSource records a call for GetApiServerSource with the expected object or error. Either apiServerSource or err should be nil | ||
func (sr *APIServerSourcesRecorder) GetAPIServerSource(name interface{}, apiServerSource *v1alpha1.ApiServerSource, err error) { | ||
sr.r.Add("GetApiServerSource", []interface{}{name}, []interface{}{apiServerSource, err}) | ||
} | ||
|
||
// GetAPIServerSource performs a previously recorded action, failing if non has been registered | ||
func (c *MockKnAPIServerSourceClient) GetAPIServerSource(name string) (*v1alpha1.ApiServerSource, error) { | ||
call := c.recorder.r.VerifyCall("GetApiServerSource", name) | ||
return call.Result[0].(*v1alpha1.ApiServerSource), mock.ErrorOrNil(call.Result[1]) | ||
} | ||
|
||
// CreateAPIServerSource records a call for CreateApiServerSource with the expected error | ||
func (sr *APIServerSourcesRecorder) CreateAPIServerSource(apiServerSource interface{}, err error) { | ||
sr.r.Add("CreateApiServerSource", []interface{}{apiServerSource}, []interface{}{err}) | ||
} | ||
|
||
// CreateAPIServerSource performs a previously recorded action, failing if non has been registered | ||
func (c *MockKnAPIServerSourceClient) CreateAPIServerSource(apiServerSource *v1alpha1.ApiServerSource) error { | ||
call := c.recorder.r.VerifyCall("CreateApiServerSource", apiServerSource) | ||
return mock.ErrorOrNil(call.Result[0]) | ||
} | ||
|
||
// UpdateAPIServerSource records a call for UpdateAPIServerSource with the expected error (nil if none) | ||
func (sr *APIServerSourcesRecorder) UpdateAPIServerSource(apiServerSource interface{}, err error) { | ||
sr.r.Add("UpdateAPIServerSource", []interface{}{apiServerSource}, []interface{}{err}) | ||
} | ||
|
||
// UpdateAPIServerSource performs a previously recorded action, failing if non has been registered | ||
func (c *MockKnAPIServerSourceClient) UpdateAPIServerSource(apiServerSource *v1alpha1.ApiServerSource) error { | ||
call := c.recorder.r.VerifyCall("UpdateAPIServerSource", apiServerSource) | ||
return mock.ErrorOrNil(call.Result[0]) | ||
} | ||
|
||
// DeleteAPIServerSource records a call for DeleteAPIServerSource with the expected error (nil if none) | ||
func (sr *APIServerSourcesRecorder) DeleteAPIServerSource(name interface{}, err error) { | ||
sr.r.Add("DeleteAPIServerSource", []interface{}{name}, []interface{}{err}) | ||
} | ||
|
||
// DeleteAPIServerSource performs a previously recorded action, failing if non has been registered | ||
func (c *MockKnAPIServerSourceClient) DeleteAPIServerSource(name string) error { | ||
call := c.recorder.r.VerifyCall("DeleteAPIServerSource", name) | ||
return mock.ErrorOrNil(call.Result[0]) | ||
} | ||
|
||
// Validate validates whether every recorded action has been called | ||
func (sr *APIServerSourcesRecorder) Validate() { | ||
sr.r.CheckThatAllRecordedMethodsHaveBeenCalled() | ||
} |
Oops, something went wrong.