Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes(#606): adds --cluster-local / --no-cluster-local flags #629

Merged
merged 12 commits into from
Mar 10, 2020

Conversation

maximilien
Copy link
Contributor

@maximilien maximilien commented Feb 1, 2020

When specified on 'service create' the --cluster-local flag will
make the created service 'private' by setting its config visibility
to cluster-local. This is done with label:

serving.knative.dev/visibility: cluster-local

The --no-cluster-local will remove the label.

Fixes #606

Proposed Changes

  • add --cluster-local and --no-cluster-local
  • when --cluster-local is specified then create service and add label: serving.knative.dev/visibility: cluster-local
  • add unit test for creating service with --cluster-local

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Feb 1, 2020
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 1, 2020
When specified on 'service create' the '--cluster-local' flag will
make the created service 'private' by setting its config visibility
to 'cluster-local'. This is done with label:

serving.knative.dev/visibility: cluster-local

The --no-cluster-local will remove the label.
@maximilien
Copy link
Contributor Author

/ok-to-test

@knative-prow-robot knative-prow-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Feb 1, 2020
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.

Thanks ! I one minor suggestion, see below.

Also, I think it would be cool if we could add already an E2E test to this functionality. would you mind to add a simpe one (or extend an existing one ?)

CHANGELOG.adoc Show resolved Hide resolved
}

_, present := template.Labels[config.VisibilityLabelKey]
assert.Assert(t, !present)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we please also check for the proper value of the annotation ? Maybe also in update_test.go that the annotation gets removed when using --no-cluster-local to complete the scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, slight problem adding the update_test.go. Seems like removing that label causes an API error:

Internal error occurred: admission webhook "webhook.serving.knative.dev" denied the request: mutation failed: Saw the following changes without a name change (-old +new): spec.configuration.template
{*v1alpha1.RevisionTemplateSpec}.ObjectMeta.Labels:
	-: "map[serving.knative.dev/visibility:cluster-local]"
	+: "map[]"

Let me know if you see something obvious. Unless my cluster is not up to date. Digging more.

Copy link
Contributor

Choose a reason for hiding this comment

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

The issue is, that the test uses the BYO feature for revision ("Bring your own" revision name). This means you need to to change the revision name to something unique on your own (like increasing a counter). Alternatively, you can use the auto revision name generation feature from Knative serving (which results in this random prefixes, like for pods of a deployment). You can servers side name generation with -revision-name "" (which might arguable not be the best option to use). Not sure anymore why we have settled on client side provided names by default.

However, I would expect that kn update deals with percularity. Could you show me how you did the test ? Also, have you set the proper flag that the flag that you set also creates a new revision ? (look in the flags file how other do it)

@duglin
Copy link
Contributor

duglin commented Feb 1, 2020

Just a minor comment on the help text, but otherwise LGTM

@rhuss
Copy link
Contributor

rhuss commented Feb 1, 2020

@maximilien there is a compile error in the tests:

# knative.dev/client/pkg/kn/commands/service [knative.dev/client/pkg/kn/commands/service.test]
pkg/kn/commands/service/create_test.go:514:32: undefined: config

@maximilien
Copy link
Contributor Author

/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 Feb 3, 2020
@maximilien
Copy link
Contributor Author

@maximilien there is a compile error in the tests:

# knative.dev/client/pkg/kn/commands/service [knative.dev/client/pkg/kn/commands/service.test]
pkg/kn/commands/service/create_test.go:514:32: undefined: config

Yup. Surprised did not see this locally. Must be lost in the test output. Thanks for pasting the location.

@navidshaikh
Copy link
Collaborator

/retest

Failed to successfully execute 'kn service create echo0 --image gcr.io/knative-samples/helloworld-go -n kne2etests6': Execution error: stderr: 'timeout: service 'echo0' not ready after 600 seconds

Copy link
Collaborator

@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.

Created a private service and subsequent update to service with only --cluster-local flag generates
new revisions (while the service was already private). It should see that service is already private and consider configuration change as nil?

➜  client git:(issue606) ./kn service create private --image gcr.io/knative-samples/helloworld-go --cluster-local
Creating service 'private' in namespace 'default':

  0.298s Configuration "private" is waiting for a Revision to become ready.
  9.714s ...
  9.769s Ingress has not yet been reconciled.
 50.790s Ready to serve.

Service 'private' created to latest revision 'private-lpcgx-1' is available at URL:
http://private.default.svc.cluster.local

➜  client git:(issue606) ./kn revision list
NAME              SERVICE   TRAFFIC   TAGS   GENERATION   AGE   CONDITIONS   READY   REASON
private-lpcgx-1   private   100%             1            69s   4 OK / 4     True    

➜  client git:(issue606) ./kn service update private --cluster-local
Updating Service 'private' in namespace 'default':

  9.866s Traffic is not yet migrated to the latest revision.
  9.894s Ingress has not yet been reconciled.
 11.257s Ready to serve.

Service 'private' updated to latest revision 'private-vygmw-2' is available at URL:
http://private.default.svc.cluster.local

➜  client git:(issue606) ./kn revision list                         
NAME              SERVICE   TRAFFIC   TAGS   GENERATION   AGE   CONDITIONS   READY   REASON
private-vygmw-2   private   100%             2            16s   4 OK / 4     True    
private-lpcgx-1   private                    1            97s   3 OK / 4     True    

➜  client git:(issue606) ./kn service update private --cluster-local
Updating Service 'private' in namespace 'default':

  9.883s Traffic is not yet migrated to the latest revision.
  9.919s Ingress has not yet been reconciled.
 11.278s Ready to serve.

Service 'private' updated to latest revision 'private-dgtsx-3' is available at URL:
http://private.default.svc.cluster.local

➜  client git:(issue606) ./kn revision list                         
NAME              SERVICE   TRAFFIC   TAGS   GENERATION   AGE    CONDITIONS   READY   REASON
private-dgtsx-3   private   100%             3            15s    4 OK / 4     True    
private-vygmw-2   private                    2            36s    4 OK / 4     True    
private-lpcgx-1   private                    1            117s   3 OK / 4     True    

CHANGELOG.adoc Outdated Show resolved Hide resolved
CHANGELOG.adoc Outdated Show resolved Hide resolved
pkg/kn/commands/service/configuration_edit_flags.go Outdated Show resolved Hide resolved
@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 Feb 4, 2020
@maximilien
Copy link
Contributor Author

maximilien commented Feb 4, 2020

/unhold

@maximilien
Copy link
Contributor Author

/hold cancel

@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 Feb 4, 2020
@maximilien
Copy link
Contributor Author

/test pull-knative-client-integration-tests

1 similar comment
@maximilien
Copy link
Contributor Author

/test pull-knative-client-integration-tests

@maximilien
Copy link
Contributor Author

maximilien commented Feb 4, 2020

Looks like we are getting errors in e2e tests and it seems to consistently failing. Should not be my doing (I hope) since the commend does not use --cluster-local or --no-cluster-local:

Running 'kn service create testsvc0 --image gcr.io/knative-samples/helloworld-go -n kne2etests4'...
--- PASS: TestSourceListTypes (8.02s)
    --- PASS: TestSourceListTypes/List_available_source_types (0.22s)
    --- PASS: TestSourceListTypes/List_available_source_types_in_YAML_format (0.14s)
Failed to successfully execute 'kn service create testsvc0 --image gcr.io/knative-samples/helloworld-go -n kne2etests8': Execution error: stderr: 'timeout: service 'testsvc0' not ready after 600 seconds
' error: 'exit status 1'FAIL	knative.dev/client/test/e2e	602.359s
FAIL
Finished run, return code is 1

cc: @navidshaikh @rhuss

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 9, 2020
Copy link
Collaborator

@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.

requested for few changes; those are causing e2e failures

@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 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)

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)

@rhuss
Copy link
Contributor

rhuss commented Mar 10, 2020

@maximilien I resolved the conflict, but as @navidshaikh points out the E2E issues are rooted within this PR. I suggest that we either fix or comment out the affected E2E test for now so that we can get in this feature for 0.13.0 right now and fix the E2E afterwards.

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/configuration_edit_flags.go 84.1% 84.6% 0.5

@rhuss
Copy link
Contributor

rhuss commented Mar 10, 2020

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

@mattmoor we are using gofmt with the same options with

find $(echo $source_dirs) -name "*.go" -print0 | xargs -0 gofmt -s -w

So, identical to your approach but more robust when it comes to file names which contains spaces.

Formatting is part of our regular build and also checked in CI that it has been called. It is performed via these functions (which also add goimports to the mix):

client/hack/build.sh

Lines 108 to 129 in 8dbf439

go_fmt() {
echo "🧹 ${S}Format"
find $(echo $source_dirs) -name "*.go" -print0 | xargs -0 gofmt -s -w
}
source_format() {
set +e
which goimports >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "✋ No 'goimports' found. Please use"
echo "✋ go install golang.org/x/tools/cmd/goimports"
echo "✋ to enable import cleanup. Import cleanup skipped."
# Run go fmt instead
go_fmt
else
echo "🧽 ${X}Format"
goimports -w $(echo $source_dirs)
find $(echo $source_dirs) -name "*.go" -print0 | xargs -0 gofmt -s -w
fi
set -e
}

I suggest to switch off the format-check for the client repo as it leads to bogus suggestions as in #629 (comment)

@rhuss
Copy link
Contributor

rhuss commented Mar 10, 2020

@maximilien there's a unit test error which you also should get with a hack/build.sh -t 👍

--- FAIL: TestServiceCreateWithClusterLocal (0.02s)
    create_test.go:560: assertion failed: expression is false: present

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)

pkg/kn/commands/service/create_test.go Outdated Show resolved Hide resolved
@rhuss
Copy link
Contributor

rhuss commented Mar 10, 2020

I think the integration test fails for the same reason as the unit test, i.e. that the label is not properly set on the service.

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/configuration_edit_flags.go 84.1% 84.7% 0.7

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/configuration_edit_flags.go 84.1% 84.7% 0.7

@maximilien
Copy link
Contributor Author

I think the integration test fails for the same reason as the unit test, i.e. that the label is not properly set on the service.

Yup. I see there is a case when labels are nil on service. Should be good on last update.

@maximilien
Copy link
Contributor Author

@maximilien there's a unit test error which you also should get with a hack/build.sh -t 👍

--- FAIL: TestServiceCreateWithClusterLocal (0.02s)
    create_test.go:560: assertion failed: expression is false: present

Yeah, optimistically pushed and went to lunch. It's all passing locally now (at least).

@maximilien
Copy link
Contributor Author

Yeah, finally all green @rhuss :)

@rhuss
Copy link
Contributor

rhuss commented Mar 10, 2020

Thanks !

/approve
/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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 merged commit 2b9377d into knative:master Mar 10, 2020
@rhuss rhuss mentioned this pull request Mar 13, 2020
@maximilien maximilien deleted the issue606 branch March 27, 2020 03:18
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. 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.

Add support for private KnServices
8 participants