-
Notifications
You must be signed in to change notification settings - Fork 101
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
danielinclouds
wants to merge
22
commits into
crossplane-contrib:master
Choose a base branch
from
danielinclouds:add-managedzone
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 e310293
Generate code and manifests
danielinclouds 37c0da3
Add example
danielinclouds 3e9783d
Add ManagedZone client and controller
danielinclouds 4eadfc8
Don't late initialize Description and Visibility
danielinclouds 094742a
Add missing test UpdateResourceSpecSuccess and fix test UpdateResourc…
danielinclouds 7dceeb5
Changed ManagedZoneObservation parameters to non-pointers
danielinclouds bcb1704
Add TODO for missing Managed Zone parameters
danielinclouds 07d3d5e
Improve consistency between error messages
danielinclouds 1ae637d
Change variable to lower case
danielinclouds b7aa496
Remove description printer column
danielinclouds ccfd5f4
Remove redundant code in Delete function
danielinclouds 5391d03
Simplify code
danielinclouds 84aa3fa
Remove redundant code in Create function
danielinclouds b019391
Add description, visibility and networks to late initialization
danielinclouds cf88e93
Don't update k8s resource in Observe function
danielinclouds a404b3b
Merge branch 'crossplane-contrib:master' into add-managedzone
danielinclouds f8dd587
Add ability to reference networks
danielinclouds 1234435
Update apis/dns/v1alpha1/managed_zone_types.go
danielinclouds d8ba224
Update apis/dns/v1alpha1/managed_zone_types.go
danielinclouds c8909a5
Fix infinite update loop
danielinclouds 0a15715
Fix null pointer exception in managedzone referencers
danielinclouds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 byNetworkURL()
because theExtract
field expects a value of typereference.ExtractValueFn
.Here is an error I'm getting when I'm using
NetworkURL()
instead ofNetworkSelfLink()