Skip to content

Add DomainMapping CRUD commands - #1267

Merged
knative-prow-robot merged 6 commits into
knative:mainfrom
dsimansk:pr/domain-mapping
Apr 1, 2021
Merged

knative-prow-robot merged 6 commits into
knative:mainfrom
dsimansk:pr/domain-mapping

Conversation

@dsimansk

Copy link
Copy Markdown
Contributor

Description

This PR adds CRUD operations for DomainMapping resource.

TODO:

  • I've covered only Knative Service as the only target, but going through the updated docs I should probably reflect the other targets as well.
    knative/serving@8eee938

  • I'll take a look into Servings test, if we can do a real world domain E2E test.

Changes

  • 🎁 Add top-level cmd domain with create, update, describe, delete, list ops

Reference

Fixes #1197

@google-cla google-cla Bot added the cla: yes Indicates the PR's author has signed the CLA. label Mar 17, 2021

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dsimansk: 15 warnings.

Details

In response to this:

Description

This PR adds CRUD operations for DomainMapping resource.

TODO:

  • I've covered only Knative Service as the only target, but going through the updated docs I should probably reflect the other targets as well.
    knative/serving@8eee938

  • I'll take a look into Servings test, if we can do a real world domain E2E test.

Changes

  • 🎁 Add top-level cmd domain with create, update, describe, delete, list ops

Reference

Fixes #1197

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.

Comment thread pkg/kn/commands/domain/create.go Resolved
Comment thread pkg/serving/v1alpha1/client.go Resolved
Comment thread pkg/serving/v1alpha1/client.go Resolved
Comment thread pkg/serving/v1alpha1/client_mock.go Resolved
Comment thread pkg/serving/v1alpha1/client_mock.go Resolved
Comment thread pkg/serving/v1alpha1/client_mock.go Resolved
Comment thread pkg/serving/v1alpha1/client_mock.go Resolved
Comment thread pkg/serving/v1alpha1/client_mock.go Resolved
Comment thread pkg/serving/v1alpha1/client_mock.go Resolved
@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 17, 2021
@dsimansk

Copy link
Copy Markdown
Contributor Author

@julz FYI.

@dsimansk
dsimansk force-pushed the pr/domain-mapping branch from 113b513 to ff5f028 Compare March 18, 2021 09:49

@itsmurugappan itsmurugappan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I gave it a try and it looks good. Just a few nits.

Comment thread pkg/kn/commands/domain/create.go Outdated
Comment on lines +65 to +67
err = client.CreateDomainMapping(builder.Build())
if err != nil {
return knerrors.GetError(err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
err = client.CreateDomainMapping(builder.Build())
if err != nil {
return knerrors.GetError(err)
}
if err := client.CreateDomainMapping(builder.Build()); err != nil {
return knerrors.GetError(err)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. However, I recall from some previous PRs that if-s with inline declarations aren't very popular in client's code.
@maximilien or @rhuss wdyt?

@maximilien maximilien Mar 30, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I like the simpler none if err := ... but that's just me :)

Comment thread pkg/kn/commands/domain/delete.go Outdated
Comment on lines +50 to +54
err = client.DeleteDomainMapping(name)
if err != nil {
return knerrors.GetError(err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
err = client.DeleteDomainMapping(name)
if err != nil {
return knerrors.GetError(err)
}
if err := client.DeleteDomainMapping(name); err != nil {
return knerrors.GetError(err)
}

Comment thread pkg/kn/commands/domain/delete_test.go Resolved
Comment thread pkg/serving/v1alpha1/client.go Outdated
Comment on lines +82 to +88
_, err := cl.client.DomainMappings(cl.namespace).Create(context.TODO(), domainMapping, v1.CreateOptions{})
if err != nil {
return knerrors.GetError(err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
_, err := cl.client.DomainMappings(cl.namespace).Create(context.TODO(), domainMapping, v1.CreateOptions{})
if err != nil {
return knerrors.GetError(err)
}
if _, err := cl.client.DomainMappings(cl.namespace).Create(context.TODO(), domainMapping, v1.CreateOptions{}); err != nil {
return knerrors.GetError(err)
}

@itsmurugappan

Copy link
Copy Markdown
Contributor

Few suggestions

  1. While creation, can ksvc be made the owner of this domain mapping, so that when ksvc is deleted this also gc'ed
  2. AutoTLS can be disabled per route based on annotations, in follow up PR we can support annotations to domain mapping
apiVersion: serving.knative.dev/v1alpha1
kind: DomainMapping
metadata:
 annotations:
  networking.knative.dev/disableAutoTLS: "true"
 name: domainmapping.example.com
spec:
 ref:
   name: domain-mapping-svc
   kind: Service
   apiVersion: serving.knative.dev/v1

@julz

julz commented Mar 19, 2021

Copy link
Copy Markdown

While creation, can ksvc be made the owner of this domain mapping, so that when ksvc is deleted this also gc'ed

FWIW I'm not sure this is what we should do. If the DM is deleted when the ksvc is deleted then it's possible for someone to swoop in and grab a domain mapping that you want to reuse for another ksvc later. I would understand doing this more if we created the ksvc and domain at the same time (eg if we added a field to ksvc to spit out a domainmapping), but it seems a bit surprising to me at first glance for us to do this implicitly. OTOH if this matches the behaviour for things like --sink that'd probably change my mind.. do we automatically set the ksvc as the owner of a source when you pass --sink?

@dsimansk

dsimansk commented Mar 19, 2021 •

Copy link
Copy Markdown
Contributor Author
  • While creation, can ksvc be made the owner of this domain mapping, so that when ksvc is deleted this also gc'ed

I have the same concern as @julz that it'd break the reuse use case. In addition to --sink handling question kn isn't adding any OwnerRef wiring for sources, channels etc., except very specific case in service import that's trying to recreate the relationship.

However, such flag can still optional per explicit request to add OwenerRef to the resource. It might prove to be useful elsewhere as well.

  • AutoTLS can be disabled per route based on annotations, in follow up PR we can support annotations to domain mapping

Thanks, that's good point I haven't checked the annotations yet.

@maximilien maximilien left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Various comments... please address. Great contribution BTW

CC: @julz who did the work on serving side as FYI

Comment thread docs/cmd/kn_domain_delete.md Outdated
Delete a domain mapping

```
kn domain delete FQDN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What’s “FQDN”? Can we use something simpler, e.g., ‘hello’

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I intended to promote that fully qualified domain name is expected. It'd be better to explain in the example description probably.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thx clearer the better

Comment thread pkg/kn/commands/domain/create.go Outdated
if err != nil {
return err
}
destination, err := refFlags.ResolveSink(dynamicClient, namespace)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A bit confuse here. Why are we resolving the destination as an event sink?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've reused the sink flag handling here, but it's not entirely correct. I'll come up with something better. :)

Comment thread pkg/kn/commands/domain/delete.go Resolved
Comment thread pkg/kn/commands/domain/domain.go Resolved
Comment thread pkg/kn/commands/domain/domain_test.go Resolved
Comment thread pkg/kn/commands/domain/domain_test.go Resolved
Comment thread pkg/kn/commands/domain/list.go Resolved
Comment thread pkg/kn/commands/domain/list_test.go Resolved
Comment thread pkg/kn/commands/domain/update.go Resolved
Comment thread pkg/serving/v1alpha1/client.go Resolved
@dsimansk

dsimansk commented Mar 23, 2021 •

Copy link
Copy Markdown
Contributor Author

I've updated target reference resolution with df9c889.

Do we want to support type:name:namespace resolution as was added for --sink flag? Or rather have something like --ref-namespace.
I lean more towards the first option.

@navidshaikh

Copy link
Copy Markdown
Contributor

Do we want to support type:name:namespace resolution as was added for --sink flag?

+1

@dsimansk

Copy link
Copy Markdown
Contributor Author

From the DomainMapping docs:

// Ref specifies the target of the Domain Mapping.
//
// The object identified by the Ref must be an Addressable with a URL of the
// form {name}.{namespace}.{domain} where {domain} is the cluster domain,
// and {name} and {namespace} are the name and namespace of a Kubernetes
// Service.
//
// This contract is satisfied by Knative types such as Knative Services and
// Knative Routes, and by Kubernetes Services.

Therefore I've added the following handling for 3 reference types.

Addressable target reference for Domain Mapping. You can specify a Knative service, a Knative soute or a Kubernetes service.Examples: '--ref ksvc:hello' or simply '--ref hello' for a Knative service 'hello', '--ref kroute:hello' for a Knative route 'hello', '--ref svc:hello' for a Kubernetes service 'hello'. If a prefix is not provided, it is considered as a Knative service.

However, per discussion with @navidshaikh and @itsmurugappan yesterday there're some doubts. The addition of Kubernetes Service wtih svc: prefix breaks our previous convention for --sink flag, that doesn't support K8s Service. Even though there're 3 types that satisfy the contract, probably Knative Service is the most popular in our context.

Should we only support reference as Knative Service for now to keep it simple. And add additional support if there's request for it? Wdyt? @rhuss @maximilien

@navidshaikh

Copy link
Copy Markdown
Contributor

Should we only support reference as Knative Service for now to keep it simple. And add additional support if there's request for it?

@dsimansk : Let's support knative resources, ksvc and kroute ?

If we're planning to support prefix for k8s service, let's do it for sink flag as well? This way we've consistent prefix across flags.

@dsimansk
dsimansk force-pushed the pr/domain-mapping branch 2 times, most recently from c7fbd6d to db96581 Compare March 26, 2021 13:44
@dsimansk
dsimansk force-pushed the pr/domain-mapping branch from db96581 to b57b7e3 Compare March 26, 2021 19:21
@dsimansk

Copy link
Copy Markdown
Contributor Author

Should we only support reference as Knative Service for now to keep it simple. And add additional support if there's request for it?

@dsimansk : Let's support knative resources, ksvc and kroute ?

If we're planning to support prefix for k8s service, let's do it for sink flag as well? This way we've consistent prefix across flags.

Update the resolve func accordingly. In addition the PR is rebased and context param added.

@knative-metrics-robot

Copy link
Copy Markdown

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/domain/create.go Do not exist 85.2%
pkg/kn/commands/domain/delete.go Do not exist 88.2%
pkg/kn/commands/domain/describe.go Do not exist 85.4%
pkg/kn/commands/domain/domain.go Do not exist 96.4%
pkg/kn/commands/domain/human_readable_flags.go Do not exist 90.0%
pkg/kn/commands/domain/list.go Do not exist 80.0%
pkg/kn/commands/domain/update.go Do not exist 81.2%
pkg/kn/commands/types.go 53.6% 55.1% 1.5
pkg/serving/v1alpha1/client.go Do not exist 88.4%
pkg/serving/v1alpha1/client_mock.go Do not exist 90.9%

@maximilien

Copy link
Copy Markdown
Contributor

/lgtm
/approve
/hold to let others complete their feedback

@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 Mar 30, 2021
@knative-prow-robot knative-prow-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 30, 2021
@rhuss

rhuss commented Apr 1, 2021

Copy link
Copy Markdown
Contributor

Let's get that merged now, if now one objects (we can clean up later, but we need to get this in before the release)

/approve
/lgtm
/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 Apr 1, 2021
@knative-prow-robot

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

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 10ea0df into knative:main Apr 1, 2021
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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for DomainMapping resource

8 participants