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

[kn-admin]Added utils to update configmap #40

Merged
merged 1 commit into from
Jun 25, 2020

Conversation

zhanggbj
Copy link

@zhanggbj zhanggbj commented Jun 4, 2020

  • Added utils to update configmp, as this is very common for kn-admin operations
  • Chores to refine vars or logs

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 4, 2020
@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 4, 2020
@zhanggbj zhanggbj changed the title Added utils to update configmap [kn-admin]Added utils to update configmap Jun 4, 2020
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@zhanggbj
Copy link
Author

zhanggbj commented Jun 4, 2020

@rhuss @maximilien
The integration test failed due to incompatible packages, looks like it is not one of kn-admin, woudl you please help to take a look?

# k8s.io/client-go/rest
../../../pkg/mod/k8s.io/[email protected]+incompatible/rest/request.go:598:31: not enough arguments in call to watch.NewStreamWatcher
	have (*versioned.Decoder)
	want (watch.Decoder, watch.Reporter)
ERROR: cluster setup failed

@rhuss
Copy link
Contributor

rhuss commented Jun 4, 2020

Yep, I will give a look later today (have some meetings soon)

Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

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

Missing unit tests and integration tests. Thanks.

@@ -120,15 +120,15 @@ Use "kn admin autoscaling [command] --help" for more information about a comman
====
----
$ kn admin domain set --custom-domain mydomain.com
Updated Knative route domain mydomain.com
Set Knative route domain mydomain.com
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to “... route to domain ...”

Copy link
Author

Choose a reason for hiding this comment

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

Same question as below.

----
====

.Update a custom domain with --selector and Service with a label app=v1 will use test.com
====
----
$ kn admin domain set --custom-domain test.com --selector app=v1
Updated Knative route domain test.com
Set Knative route domain test.com with selector [app=v1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above add “to”

Copy link
Author

Choose a reason for hiding this comment

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

@maximilien
As Knative supports multiple domains, I'm wondering if set route domain to is more like Knative only support one domain?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO if use "set" it implies setting the single value. Otherwise, I would expect an "Add route".

How would one manage multiple routes here ? If this is only about a 'default' route maybe "Set default Knative route domain ..." is better choice.

Also, I wonder whether the "Knative" is not redundant and maybe we should talk about a "service" instead of a "route" here, as route is an internal concept mostly hidden in kn. We are always talking about a service's or revsion's URL.

Copy link
Author

Choose a reason for hiding this comment

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

@rhuss
In fact, I think in this context it is more about domain other than route.

Knative support to have multiple domains as below, in kn-admin we want to help with add and remove domains. I'm thinking maybe kn admin domain add is more proper here and perhaps also change route domain to domain as it may be a little bit confusing with the Knative Route resource.

@rhuss @maximilien what do you think? Thanks!

data:
  # example.org will be used for routes having app=prod.
  example.org: |
    selector:
      app: prod
  # Default value for domain, for routes that does not have app=prod labels.
  # Although it will match all routes, it is the least-specific rule so it
  # will only be used if no other domain matches.
  example.com: ""

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the "route" confused me a bit. Maybe just referring to the domain without any revision/service prefix makes more sense.

For this example, "Add" makes more sense as it also emphasises that you add a domain with the selector.

For general wording of the command itself (set/unset), it's a bit tricky.
As you can have multiple things that can be identified, having "create/delete" is typically a better wording for commands than "set/unset" as this more implies a single entity to manage. This is how we do it for the Knative entities like service or sources.

However, as you also can override with "set" then "add" would be misleading. Not sure if an "create/update/delete" makes sense, as this would add a possibly too fine-grained workflow (and would require the user to know whether a domain already is adder).

I hope we can implement the knative story that introduces an "apply" verb soon, which would be useful here, too: "apply" essentially mean, create-or-update and is idempotent (you can call it with the same argument many times, but only get a single result). This is the case for you command here.

So, if this were a core kn command, I probably would suggest a

# Add or update the given domain with the given selector
kn admin domain apply ....

# Remove the domain
kn admin domain remove ....

as this aligns with the other verbs used in kn.

Copy link
Author

@zhanggbj zhanggbj Jun 19, 2020

Choose a reason for hiding this comment

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

@rhuss I feel the same way. kn-admin itself should be consistent, now we have add/update/etc. This need refine and perhaps this change can wait for and follow kn client story you mentioned.
How about I open another chore item to follow it (#53) and we can complete this PR first.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, set/unset suit better for properties like domain,
while create/update/apply/deploy operates on the actual resources.

Copy link
Author

Choose a reason for hiding this comment

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

@navidshaikh thanks and we can continue subcommand wording in #53

plugins/admin/pkg/command/autoscaling/update.go Outdated Show resolved Hide resolved
plugins/admin/pkg/command/domain/set.go Outdated Show resolved Hide resolved
plugins/admin/pkg/command/registry/add.go Outdated Show resolved Hide resolved
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

@zhanggbj
Copy link
Author

zhanggbj commented Jun 7, 2020

@maximilien
I addressed your comments, and would you please help to take a look? Thanks!

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Change looks good to, thanks !

Only a small question about the wording and also I'm not clear how multiple domains can be managed (e.g also be deleted)

@zhanggbj
Copy link
Author

@rhuss
Thanks! As the example here, kn-admin will also add the domains with/without the selector. When users need to remove a domain, they only need to provide the domain name.
And kn admin domain list is working in progress, to list all the added domains and with selectors if any.

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)

- Added utils to update configmp
- Chores to refine vars or logs
@@ -0,0 +1,19 @@
/*
Copyright 2014 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Incorrect copyright year:

Suggested change
Copyright 2014 The Kubernetes Authors.
Copyright 2020 The Kubernetes Authors.

@@ -0,0 +1,512 @@
/*
Copyright 2014 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Incorrect copyright year:

Suggested change
Copyright 2014 The Kubernetes Authors.
Copyright 2020 The Kubernetes Authors.

@@ -0,0 +1,105 @@
/*
Copyright 2016 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Incorrect copyright year:

Suggested change
Copyright 2016 The Kubernetes Authors.
Copyright 2020 The Kubernetes Authors.

@zhanggbj
Copy link
Author

zhanggbj commented Jun 21, 2020

@rhuss As discussed in #40 (comment), I opened another chore item to follow command wording create/apply/update (#53).

@rhuss @maximilien Please help to review again and hope we can merge this first before the vendor pkg change. thanks!

@zhanggbj zhanggbj requested review from maximilien and rhuss June 22, 2020 13:59
Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

looks good for me, let's check in a follow PR about the concrete wording.

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 23, 2020
@rhuss
Copy link
Contributor

rhuss commented Jun 23, 2020

/hold

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 23, 2020
@rhuss
Copy link
Contributor

rhuss commented Jun 23, 2020

@maximilien please unhold if this looks ok for you, so that it gets merged.

Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

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

LGTM let me ask @navidshaikh if he has not seen this before.

I also don’t see tests for registry/add. Please address and let me know and I can do final pass.

@knative-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maximilien, rhuss, zhanggbj

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

@zhanggbj
Copy link
Author

@maximilien Thanks Max. For test, we have UT for each command and also for registry/add
e2e test is still working in progress by #14

Copy link
Contributor

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

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

suggested a few nits.

Unrelated to the changes in PR, noticed error returned by splitByEqualSign is not handled.
If incorrect selector is given, the error is reported from configmap update API call instead of plugin flag handling (can be fixed in a separate PR).

k, v, _ := splitByEqualSign(label)

Comment on lines +47 to +48
kn admin autoscaling update --scale-to-zero
# To disable scale-to-zero
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
kn admin autoscaling update --scale-to-zero
# To disable scale-to-zero
kn admin autoscaling update --scale-to-zero
# To disable scale-to-zero

Copy link
Author

Choose a reason for hiding this comment

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

@navidshaikh yes, I agree, this is a known issue and will be handled #41

kn admin domain set - to set Knative route domain

kn admin domain unset - to unset Knative route domain`,
Long: `Manage default route domain or custom route domain for Service with selectors.`,
Copy link
Contributor

@navidshaikh navidshaikh Jun 24, 2020

Choose a reason for hiding this comment

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

Suggested change
Long: `Manage default route domain or custom route domain for Service with selectors.`,
Long: `Manage default route domain or custom route domain for service(s) with selectors`,

# To set a default route domain
kn admin domain set --custom-domain mydomain.com

# To set a route domain for service having label app=v1
Copy link
Contributor

@navidshaikh navidshaikh Jun 24, 2020

Choose a reason for hiding this comment

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

Suggested change
# To set a route domain for service having label app=v1
# To set a route domain for service(s) having label 'app=v1'

Copy link
Author

Choose a reason for hiding this comment

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

@navidshaikh Thanks for the suggestion. Will update in another PR to refine #41

Comment on lines +21 to 23
"knative.dev/client-contrib/plugins/admin/pkg/command/utils"

"knative.dev/client-contrib/plugins/admin/pkg"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"knative.dev/client-contrib/plugins/admin/pkg/command/utils"
"knative.dev/client-contrib/plugins/admin/pkg"
"knative.dev/client-contrib/plugins/admin/pkg/command/utils"
"knative.dev/client-contrib/plugins/admin/pkg"

Long: `Manage autoscaling provided by Knative Pod Autoscaler (KPA). For example:

kn admin autoscaling update - to manage autoscaling config`,
Long: `Manage autoscaling provided by Knative Pod Autoscaler (KPA).`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Long: `Manage autoscaling provided by Knative Pod Autoscaler (KPA).`,
Long: `Manage autoscaling provided by Knative Pod Autoscaler (KPA)`,

--username=[REGISTRY_USER] \
--password=[REGISTRY_PASSWORD]`,
Short: "Add registry with credentials",
Long: `Add registry with credentials to enable Service deployment from it`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Long: `Add registry with credentials to enable Service deployment from it`,
Long: `Add registry with credentials to enable service deployment from it`,

--email=[REGISTRY_EMAIL] \
--username=[REGISTRY_USER] \
--password=[REGISTRY_PASSWORD]`,
Long: `Manage Service deployment from a registry with credentials`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Long: `Manage Service deployment from a registry with credentials`,
Long: `Manage service deployment from a registry with credentials`,

"k8s.io/client-go/util/retry"
)

func UpdateConfigMap(client kubernetes.Interface, desiredCm *corev1.ConfigMap) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

/lint

----
====

.Update a custom domain with --selector and Service with a label app=v1 will use test.com
====
----
$ kn admin domain set --custom-domain test.com --selector app=v1
Updated Knative route domain test.com
Set Knative route domain test.com with selector [app=v1]
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, set/unset suit better for properties like domain,
while create/update/apply/deploy operates on the actual resources.

Copy link

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@navidshaikh: 6 warnings.

In response to this:

/lint

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.

"k8s.io/apimachinery/pkg/util/runtime"
)

// For any test of the style:

Choose a reason for hiding this comment

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

Golint comments: comment on exported var ForeverTestTimeout should be of the form "ForeverTestTimeout ...". More info.

wg sync.WaitGroup
}

func (g *Group) Wait() {

Choose a reason for hiding this comment

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

Golint comments: exported method Group.Wait should have comment or be unexported. More info.


// WaitFunc creates a channel that receives an item every time a test
// should be executed and is closed when the last test should be invoked.
type WaitFunc func(done <-chan struct{}) <-chan struct{}

Choose a reason for hiding this comment

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

Suggested change
type WaitFunc func(done <-chan struct{}) <-chan struct{}
type Func func(done <-chan struct{}) <-chan struct{}

Golint naming: type name will be used as wait.WaitFunc by other packages, and that stutters; consider calling this Func. More info.

// When the done channel is closed, because the golang `select` statement is
// "uniform pseudo-random", the `fn` might still run one or multiple time,
// though eventually `WaitFor` will return.
func WaitFor(wait WaitFunc, fn ConditionFunc, done <-chan struct{}) error {

Choose a reason for hiding this comment

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

Suggested change
func WaitFor(wait WaitFunc, fn ConditionFunc, done <-chan struct{}) error {
func For(wait WaitFunc, fn ConditionFunc, done <-chan struct{}) error {

Golint naming: func name will be used as wait.WaitFor by other packages, and that stutters; consider calling this For. More info.

// ...
//
// TODO: Make Backoff an interface?
func RetryOnConflict(backoff wait.Backoff, fn func() error) error {

Choose a reason for hiding this comment

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

Suggested change
func RetryOnConflict(backoff wait.Backoff, fn func() error) error {
func OnConflict(backoff wait.Backoff, fn func() error) error {

Golint naming: func name will be used as retry.RetryOnConflict by other packages, and that stutters; consider calling this OnConflict. More info.

"k8s.io/client-go/util/retry"
)

func UpdateConfigMap(client kubernetes.Interface, desiredCm *corev1.ConfigMap) error {

Choose a reason for hiding this comment

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

Golint comments: exported function UpdateConfigMap should have comment or be unexported. More info.

@maximilien
Copy link
Contributor

@maximilien Thanks Max. For test, we have UT for each command and also for registry/add
e2e test is still working in progress by #14

OK cool. Let me know when you address the last comments from @navidshaikh and we can merge this. Thx.

@rhuss
Copy link
Contributor

rhuss commented Jun 25, 2020

/unhold

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 25, 2020
@knative-prow-robot knative-prow-robot merged commit 969cebc into knative:master Jun 25, 2020
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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants