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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
338d253
Add ManagedZone to apis folder
danielinclouds Sep 10, 2022
e310293
Generate code and manifests
danielinclouds Sep 10, 2022
37c0da3
Add example
danielinclouds Sep 10, 2022
3e9783d
Add ManagedZone client and controller
danielinclouds Sep 10, 2022
4eadfc8
Don't late initialize Description and Visibility
danielinclouds Sep 14, 2022
094742a
Add missing test UpdateResourceSpecSuccess and fix test UpdateResourc…
danielinclouds Sep 17, 2022
7dceeb5
Changed ManagedZoneObservation parameters to non-pointers
danielinclouds Sep 17, 2022
bcb1704
Add TODO for missing Managed Zone parameters
danielinclouds Sep 17, 2022
07d3d5e
Improve consistency between error messages
danielinclouds Sep 25, 2022
1ae637d
Change variable to lower case
danielinclouds Sep 25, 2022
b7aa496
Remove description printer column
danielinclouds Sep 25, 2022
ccfd5f4
Remove redundant code in Delete function
danielinclouds Sep 25, 2022
5391d03
Simplify code
danielinclouds Sep 25, 2022
84aa3fa
Remove redundant code in Create function
danielinclouds Sep 25, 2022
b019391
Add description, visibility and networks to late initialization
danielinclouds Sep 25, 2022
cf88e93
Don't update k8s resource in Observe function
danielinclouds Oct 2, 2022
a404b3b
Merge branch 'crossplane-contrib:master' into add-managedzone
danielinclouds Oct 15, 2022
f8dd587
Add ability to reference networks
danielinclouds Oct 15, 2022
1234435
Update apis/dns/v1alpha1/managed_zone_types.go
danielinclouds Oct 20, 2022
d8ba224
Update apis/dns/v1alpha1/managed_zone_types.go
danielinclouds Oct 29, 2022
c8909a5
Fix infinite update loop
danielinclouds Oct 29, 2022
0a15715
Fix null pointer exception in managedzone referencers
danielinclouds Oct 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apis/compute/v1beta1/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ func NetworkURL() reference.ExtractValueFn {
}
}

// 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
}
}
Comment on lines +42 to +51
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"}


// SubnetworkURL extracts the partially qualified URL of a Subnetwork.
func SubnetworkURL() reference.ExtractValueFn {
return func(mg resource.Managed) string {
Expand Down
149 changes: 149 additions & 0 deletions apis/dns/v1alpha1/managed_zone_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
Copyright 2022 The Crossplane 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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// ManagedZoneParameters define the desired state of a ManagedZone
type ManagedZoneParameters struct {
Feggah marked this conversation as resolved.
Show resolved Hide resolved

// Description: A mutable string of at most 1024 characters associated
// with this resource for the user's convenience. Has no effect on the
// managed zone's function. Defaults to 'Managed by Crossplane'
// +optional
Description *string `json:"description,omitempty"`

// DNSName: The DNS name of this managed zone, for instance "example.com.".
// +immutable
DNSName string `json:"dnsName"`

// Labels: User labels.
// +optional
Labels map[string]string `json:"labels,omitempty"`

// PrivateVisibilityConfig: For privately visible zones, the set of
// Virtual Private Cloud resources that the zone is visible from.
// +optional
PrivateVisibilityConfig *ManagedZonePrivateVisibilityConfig `json:"privateVisibilityConfig,omitempty"`

// Visibility: The zone's visibility: public zones are exposed to the
// Internet, while private zones are visible only to Virtual Private
// Cloud resources. Defaults to 'public`
//
// Possible values:
// "public"
// "private"
// +optional
// +immutable
// +kubebuilder:validation:Enum=public;private
Visibility *string `json:"visibility,omitempty"`

// TODO(danielinclouds): support CloudLoggingConfig parameters
// TODO(danielinclouds): support DnssecConfig parameters
// TODO(danielinclouds): support ForwardingConfig parameters
// TODO(danielinclouds): support NameServerSet parameters
// TODO(danielinclouds): support PeeringConfig parameters
// TODO(danielinclouds): support ReverseLookupConfig parameters
// TODO(danielinclouds): support ServiceDirectoryConfig parameters
}

// ManagedZonePrivateVisibilityConfig the set of Virtual Private Cloud resources
// that the zone is visible from
type ManagedZonePrivateVisibilityConfig struct {

// Networks: The list of VPC networks that can see this zone.
// +optional
Networks []*ManagedZonePrivateVisibilityConfigNetwork `json:"networks,omitempty"`
}

// ManagedZonePrivateVisibilityConfigNetwork is a list of VPC networks
type ManagedZonePrivateVisibilityConfigNetwork struct {

// NetworkUrl: The fully qualified URL of the VPC network to bind to.
// Format this URL like
// https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}
// +optional
// +immutable
NetworkURL *string `json:"networkUrl,omitempty"`

// NetworkRef references to a Network and retrieves its URI
// +optional
// +immutable
NetworkRef *xpv1.Reference `json:"networkRef,omitempty"`

// NetworkSelector selects a reference to a Network and retrieves its URI
// +optional
// +immutable
NetworkSelector *xpv1.Selector `json:"networkSelector,omitempty"`
}

// ManagedZoneObservation is used to show the observed state of the ManagedZone
type ManagedZoneObservation struct {

// CreationTime: The time that this resource was created on the server.
// This is in RFC3339 text format. Output only.
CreationTime string `json:"creationTime,omitempty"`

// Id: Unique identifier for the resource; defined by the server (output only)
ID uint64 `json:"id,omitempty"`

// NameServers: Delegate your managed_zone to these virtual name
// servers; defined by the server (output only)
NameServers []string `json:"nameServers,omitempty"`
}

// ManagedZoneSpec defines the desired state of a ManagedZone.
type ManagedZoneSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider ManagedZoneParameters `json:"forProvider"`
}

// ManagedZoneStatus represents the observed state of a ManagedZone.
type ManagedZoneStatus struct {
xpv1.ResourceStatus `json:",inline"`
AtProvider ManagedZoneObservation `json:"atProvider,omitempty"`
}

// +kubebuilder:object:root=true

// ManagedZone is a managed resource that represents a Managed Zone in Cloud DNS
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="DNS NAME",type="string",JSONPath=".spec.forProvider.dnsName"
// +kubebuilder:printcolumn:name="VISIBILITY",type="string",JSONPath=".spec.forProvider.visibility"
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,gcp}
type ManagedZone struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ManagedZoneSpec `json:"spec"`
Status ManagedZoneStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// ManagedZoneList contains a list of ManagedZones
type ManagedZoneList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ManagedZone `json:"items"`
}
57 changes: 57 additions & 0 deletions apis/dns/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2022 The Crossplane 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 (
"context"

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/crossplane/crossplane-runtime/pkg/errors"

"github.com/crossplane/crossplane-runtime/pkg/reference"

computev1beta1 "github.com/crossplane-contrib/provider-gcp/apis/compute/v1beta1"
)

// ResolveReferences of ManagedZone
func (mg *ManagedZone) ResolveReferences(ctx context.Context, c client.Reader) error {

if mg.Spec.ForProvider.PrivateVisibilityConfig == nil {
return nil
}

r := reference.NewAPIResolver(c, mg)

// Resolve spec.forProvider.privateVisibilityConfig.networks[*].NetworkURL
for i := range mg.Spec.ForProvider.PrivateVisibilityConfig.Networks {
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.PrivateVisibilityConfig.Networks[i].NetworkURL),
Reference: mg.Spec.ForProvider.PrivateVisibilityConfig.Networks[i].NetworkRef,
Selector: mg.Spec.ForProvider.PrivateVisibilityConfig.Networks[i].NetworkSelector,
To: reference.To{Managed: &computev1beta1.Network{}, List: &computev1beta1.NetworkList{}},
Extract: computev1beta1.NetworkSelfLink(),
})
if err != nil {
return errors.Wrapf(err, "spec.forProvider.PrivateVisibilityConfig.Networks[%d].NetworkURL", i)
}
mg.Spec.ForProvider.PrivateVisibilityConfig.Networks[i].NetworkURL = reference.ToPtrValue(rsp.ResolvedValue)
mg.Spec.ForProvider.PrivateVisibilityConfig.Networks[i].NetworkRef = rsp.ResolvedReference
}

return nil
}
12 changes: 10 additions & 2 deletions apis/dns/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Crossplane Authors.
Copyright 2022 The Crossplane Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,15 @@ var (
PolicyGroupVersionKind = SchemeGroupVersion.WithKind(PolicyKind)
)

// ManagedZone type metadata
var (
ManagedZoneKind = reflect.TypeOf(ManagedZone{}).Name()
ManagedZoneGroupKind = schema.GroupKind{Group: Group, Kind: ManagedZoneKind}.String()
ManagedZoneKindAPIVersion = ManagedZoneKind + "." + SchemeGroupVersion.String()
ManagedZoneGroupVersionKind = SchemeGroupVersion.WithKind(ManagedZoneKind)
)

func init() {
SchemeBuilder.Register(&ResourceRecordSet{}, &ResourceRecordSetList{},
&Policy{}, &PolicyList{})
&Policy{}, &PolicyList{}, &ManagedZone{}, &ManagedZoneList{})
}
Loading