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

Add DNS ManagedZone managed resource #457

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

danielinclouds
Copy link

Description of your changes

Add DNS ManagedZone managed resource.

Fixes #455

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

  • Manually tested creating, updating and deleting Managed Zone in GCP.
  • Developed unit tests

Notes

This resource is based on ManagedZone but is missing DnssecConfig, ForwardingConfig, NameServerSet, PeeringConfig, ServiceDirectoryConfig, ReverseLookupConfig parameters. The idea behind this implementation is to satisfy the most common use of GCP DNS Managed Zone.

Copy link
Collaborator

@Feggah Feggah left a comment

Choose a reason for hiding this comment

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

Hey @danielinclouds, thanks for opening this PR!

You just need to rebase your commits signing each of them (git commit -s), otherwise the DCO CI check will fail.

I've added some small comments in the code.

pkg/clients/managedzone/managed_zone.go Show resolved Hide resolved
apis/dns/v1alpha1/managed_zone_types.go Outdated Show resolved Hide resolved
apis/dns/v1alpha1/managed_zone_types.go Show resolved Hide resolved
@danielinclouds danielinclouds force-pushed the add-managedzone branch 3 times, most recently from ff28de4 to 35bb96b Compare September 18, 2022 00:06
@danielinclouds
Copy link
Author

@Feggah I made all requested changes. Do I resolve your comments or leave them to you?

Copy link
Collaborator

@Feggah Feggah left a comment

Choose a reason for hiding this comment

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

I did some testing running the code and that's what I think should be fixed:

  • Import is not working.
  • Import isn't importing the private networks.

I think the one of the errors are occurring because I told you in the last review to remove some fields from the LateInitialize method. I'm sorry if this is the cause, I didn't predict it.


The first error you can reproduce with this test case:

  1. Create a DNS zone in the GCP interface

image

  1. Create a ManagedZone managed resource only with required fields with the same name as created in the step 1.
apiVersion: dns.gcp.crossplane.io/v1alpha1
kind: ManagedZone
metadata:
  name: test
spec:
  forProvider:
    dnsName: test.com.
  providerConfigRef:
    name: default
  1. Results in a error, because it is trying to update the visibility to public (it was created as private in the interface). The expected behavior would be importing the values from the API and not updating the resource at all (because that would be nothing to update, as we are importing the fields from the API.
1.6639251312905607e+09	DEBUG	provider-gcp	Reconciling	{"controller": "managed/managedzone.dns.gcp.crossplane.io", "request": "/test"}
1.6639251331243162e+09	DEBUG	provider-gcp	Cannot update external resource	{"controller": "managed/managedzone.dns.gcp.crossplane.io", "request": "/test", "uid": "ad15a248-58ca-47d1-90f3-22a51a8062e6", "version": "53015", "external-name": "test"}
1.663925133124595e+09	DEBUG	events	Warning	{"object": {"kind":"ManagedZone","name":"test","uid":"ad15a248-58ca-47d1-90f3-22a51a8062e6","apiVersion":"dns.gcp.crossplane.io/v1alpha1","resourceVersion":"53015"}, "reason": "CannotUpdateExternalResource", "message": "googleapi: Error 400: The field 'entity.managedZone.visibility' cannot be modified., immutableField"}

To see the second error, you can create an ManagedZone without specifying the networks, and then you specify it in the GCP interface.

What happens is that the controller isn't considering this field, and the controller is behaving as it is already up to date with the external state (and it isn't).

The expected behavior would be: after specifying in the GCP interface, in the next reconciliation loop the network would be filled when kubectl describe the resource.

pkg/clients/managedzone/managed_zone.go Outdated Show resolved Hide resolved
apis/dns/v1alpha1/managed_zone_types.go Outdated Show resolved Hide resolved
pkg/controller/dns/managed_zone.go Outdated Show resolved Hide resolved
pkg/controller/dns/managed_zone.go Outdated Show resolved Hide resolved
pkg/controller/dns/managed_zone.go Outdated Show resolved Hide resolved
pkg/controller/dns/managed_zone.go Outdated Show resolved Hide resolved
pkg/controller/dns/managed_zone.go Outdated Show resolved Hide resolved
pkg/controller/dns/managed_zone.go Outdated Show resolved Hide resolved
pkg/controller/dns/managed_zone.go Outdated Show resolved Hide resolved
apis/dns/v1alpha1/managed_zone_types.go Outdated Show resolved Hide resolved
@danielinclouds danielinclouds force-pushed the add-managedzone branch 6 times, most recently from 202d79d to fcca94c Compare October 3, 2022 00:01
danielinclouds and others added 16 commits October 3, 2022 01:06
Signed-off-by: Daniel Kozlowski <[email protected]>
Signed-off-by: Daniel Kozlowski <[email protected]>
Signed-off-by: Daniel Kozlowski <[email protected]>
Co-authored-by: Gabriel Ferreira <[email protected]>
Signed-off-by: Daniel Kozlowski <[email protected]>
Signed-off-by: Daniel Kozlowski <[email protected]>
Signed-off-by: Daniel Kozlowski <[email protected]>
Signed-off-by: Daniel Kozlowski <[email protected]>
@danielinclouds
Copy link
Author

@Feggah Please look again, I think all problems should be addressed now.

Signed-off-by: Daniel Kozlowski <[email protected]>
Copy link
Collaborator

@Feggah Feggah left a comment

Choose a reason for hiding this comment

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

Looks great! We are pretty close to merge, thanks for your effort!


I created the manifest:

apiVersion: compute.gcp.crossplane.io/v1beta1
kind: Network
metadata:
  name: example
spec:
  forProvider:
    autoCreateSubnetworks: false
    routingConfig:
      routingMode: REGIONAL

---
apiVersion: dns.gcp.crossplane.io/v1alpha1
kind: ManagedZone
metadata:
  name: test
spec:
  forProvider:
    dnsName: test.com.
    visibility: private
    privateVisibilityConfig:
      networks:
      - networkRef: 
          name: example

And I got an update loop in the managed resource. Every reconciliation it was updating, even if not needed.

image

Besides that, I added some small comments in the code.

Comment on lines +42 to +51
// NetworkSelfLink extracts the SelfLink of a Network.
func NetworkSelfLink() reference.ExtractValueFn {
return func(mg resource.Managed) string {
n, ok := mg.(*Network)
if !ok {
return ""
}
return n.Status.AtProvider.SelfLink
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't the above function enough for this referencer?

image

Copy link
Author

Choose a reason for hiding this comment

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

Unfortunately NetworkURL function is not enough because I need a full SelfLink not a trimmed version of the link. I also can't just add a prefix to the string returned by NetworkURL() because the Extract field expects a value of type reference.ExtractValueFn.

Here is an error I'm getting when I'm using NetworkURL() instead of NetworkSelfLink()

1.667036804796583e+09	DEBUG	provider-gcp	Cannot create external resource	{"controller": "managed/managedzone.dns.gcp.crossplane.io", "request": "/test", "uid": "6f5ba5ef-dcd2-488f-b5bc-48e3cbad11fd", "version": "800", "external-name": "test", "error": "cannot create DNS ManagedZone: googleapi: Error 400: Invalid value for 'entity.managedZone.privateVisibilityConfig.networks[0].networkUrl': 'projects/po-test-314912/global/networks/example', invalid"}

apis/dns/v1alpha1/managed_zone_types.go Outdated Show resolved Hide resolved
apis/dns/v1alpha1/managed_zone_types.go Outdated Show resolved Hide resolved
Co-authored-by: Gabriel Ferreira <[email protected]>
Signed-off-by: Daniel Kozlowski <[email protected]>
Co-authored-by: Gabriel Ferreira <[email protected]>
Signed-off-by: Daniel Kozlowski <[email protected]>
@danielinclouds
Copy link
Author

@Feggah Let's try again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DNS Managed Zone resource
2 participants