From e706fad7819a83ed5152d371e00df797760244e8 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Sat, 27 Apr 2024 02:50:04 -0400 Subject: [PATCH] feat: add digitalocean_reserved_ip resource (#13) Signed-off-by: Yordis Prieto --- README.md | 2 +- .../v1alpha1/zz_generated.deepcopy.go | 199 +++++++++ .../v1alpha1/zz_generated.managed.go | 60 +++ .../v1alpha1/zz_generated.managedlist.go | 9 + .../v1alpha1/zz_generated.resolvers.go | 26 ++ .../v1alpha1/zz_generated_terraformed.go | 84 ++++ apis/networking/v1alpha1/zz_ip_types.go | 130 ++++++ config/provider.go | 9 + examples-generated/networking/ip.yaml | 33 ++ .../controller/networking/ip/zz_controller.go | 63 +++ internal/controller/zz_setup.go | 2 + ...orking.digitalocean.crossplane.io_ips.yaml | 402 ++++++++++++++++++ 12 files changed, 1018 insertions(+), 1 deletion(-) create mode 100755 apis/networking/v1alpha1/zz_ip_types.go create mode 100644 examples-generated/networking/ip.yaml create mode 100755 internal/controller/networking/ip/zz_controller.go create mode 100644 package/crds/networking.digitalocean.crossplane.io_ips.yaml diff --git a/README.md b/README.md index f6569d4..a661a37 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ open an [issue](https://github.com/straw-hat-team/provider-digitalocean/issues). - [x] digitalocean_project - [ ] digitalocean_project_resources - [x] digitalocean_record -- [ ] digitalocean_reserved_ip +- [x] digitalocean_reserved_ip - [ ] digitalocean_reserved_ip_assignment - [x] digitalocean_spaces_bucket - [ ] digitalocean_spaces_bucket_cors_configuration diff --git a/apis/networking/v1alpha1/zz_generated.deepcopy.go b/apis/networking/v1alpha1/zz_generated.deepcopy.go index 68478de..4aa7775 100644 --- a/apis/networking/v1alpha1/zz_generated.deepcopy.go +++ b/apis/networking/v1alpha1/zz_generated.deepcopy.go @@ -782,6 +782,205 @@ func (in *HealthcheckParameters) DeepCopy() *HealthcheckParameters { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IP) DeepCopyInto(out *IP) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IP. +func (in *IP) DeepCopy() *IP { + if in == nil { + return nil + } + out := new(IP) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *IP) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPInitParameters) DeepCopyInto(out *IPInitParameters) { + *out = *in + if in.IPAddress != nil { + in, out := &in.IPAddress, &out.IPAddress + *out = new(string) + **out = **in + } + if in.Region != nil { + in, out := &in.Region, &out.Region + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPInitParameters. +func (in *IPInitParameters) DeepCopy() *IPInitParameters { + if in == nil { + return nil + } + out := new(IPInitParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPList) DeepCopyInto(out *IPList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]IP, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPList. +func (in *IPList) DeepCopy() *IPList { + if in == nil { + return nil + } + out := new(IPList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *IPList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPObservation) DeepCopyInto(out *IPObservation) { + *out = *in + if in.DropletID != nil { + in, out := &in.DropletID, &out.DropletID + *out = new(float64) + **out = **in + } + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(string) + **out = **in + } + if in.IPAddress != nil { + in, out := &in.IPAddress, &out.IPAddress + *out = new(string) + **out = **in + } + if in.Region != nil { + in, out := &in.Region, &out.Region + *out = new(string) + **out = **in + } + if in.Urn != nil { + in, out := &in.Urn, &out.Urn + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPObservation. +func (in *IPObservation) DeepCopy() *IPObservation { + if in == nil { + return nil + } + out := new(IPObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPParameters) DeepCopyInto(out *IPParameters) { + *out = *in + if in.DropletID != nil { + in, out := &in.DropletID, &out.DropletID + *out = new(float64) + **out = **in + } + if in.DropletIDRef != nil { + in, out := &in.DropletIDRef, &out.DropletIDRef + *out = new(v1.Reference) + (*in).DeepCopyInto(*out) + } + if in.DropletIDSelector != nil { + in, out := &in.DropletIDSelector, &out.DropletIDSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } + if in.IPAddress != nil { + in, out := &in.IPAddress, &out.IPAddress + *out = new(string) + **out = **in + } + if in.Region != nil { + in, out := &in.Region, &out.Region + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPParameters. +func (in *IPParameters) DeepCopy() *IPParameters { + if in == nil { + return nil + } + out := new(IPParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPSpec) DeepCopyInto(out *IPSpec) { + *out = *in + in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) + in.ForProvider.DeepCopyInto(&out.ForProvider) + in.InitProvider.DeepCopyInto(&out.InitProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPSpec. +func (in *IPSpec) DeepCopy() *IPSpec { + if in == nil { + return nil + } + out := new(IPSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPStatus) DeepCopyInto(out *IPStatus) { + *out = *in + in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) + in.AtProvider.DeepCopyInto(&out.AtProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPStatus. +func (in *IPStatus) DeepCopy() *IPStatus { + if in == nil { + return nil + } + out := new(IPStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *InboundRuleInitParameters) DeepCopyInto(out *InboundRuleInitParameters) { *out = *in diff --git a/apis/networking/v1alpha1/zz_generated.managed.go b/apis/networking/v1alpha1/zz_generated.managed.go index 200cf35..1e7dd68 100644 --- a/apis/networking/v1alpha1/zz_generated.managed.go +++ b/apis/networking/v1alpha1/zz_generated.managed.go @@ -127,6 +127,66 @@ func (mg *Firewall) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) mg.Spec.WriteConnectionSecretToReference = r } +// GetCondition of this IP. +func (mg *IP) GetCondition(ct xpv1.ConditionType) xpv1.Condition { + return mg.Status.GetCondition(ct) +} + +// GetDeletionPolicy of this IP. +func (mg *IP) GetDeletionPolicy() xpv1.DeletionPolicy { + return mg.Spec.DeletionPolicy +} + +// GetManagementPolicies of this IP. +func (mg *IP) GetManagementPolicies() xpv1.ManagementPolicies { + return mg.Spec.ManagementPolicies +} + +// GetProviderConfigReference of this IP. +func (mg *IP) GetProviderConfigReference() *xpv1.Reference { + return mg.Spec.ProviderConfigReference +} + +// GetPublishConnectionDetailsTo of this IP. +func (mg *IP) GetPublishConnectionDetailsTo() *xpv1.PublishConnectionDetailsTo { + return mg.Spec.PublishConnectionDetailsTo +} + +// GetWriteConnectionSecretToReference of this IP. +func (mg *IP) GetWriteConnectionSecretToReference() *xpv1.SecretReference { + return mg.Spec.WriteConnectionSecretToReference +} + +// SetConditions of this IP. +func (mg *IP) SetConditions(c ...xpv1.Condition) { + mg.Status.SetConditions(c...) +} + +// SetDeletionPolicy of this IP. +func (mg *IP) SetDeletionPolicy(r xpv1.DeletionPolicy) { + mg.Spec.DeletionPolicy = r +} + +// SetManagementPolicies of this IP. +func (mg *IP) SetManagementPolicies(r xpv1.ManagementPolicies) { + mg.Spec.ManagementPolicies = r +} + +// SetProviderConfigReference of this IP. +func (mg *IP) SetProviderConfigReference(r *xpv1.Reference) { + mg.Spec.ProviderConfigReference = r +} + +// SetPublishConnectionDetailsTo of this IP. +func (mg *IP) SetPublishConnectionDetailsTo(r *xpv1.PublishConnectionDetailsTo) { + mg.Spec.PublishConnectionDetailsTo = r +} + +// SetWriteConnectionSecretToReference of this IP. +func (mg *IP) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { + mg.Spec.WriteConnectionSecretToReference = r +} + // GetCondition of this Loadbalancer. func (mg *Loadbalancer) GetCondition(ct xpv1.ConditionType) xpv1.Condition { return mg.Status.GetCondition(ct) diff --git a/apis/networking/v1alpha1/zz_generated.managedlist.go b/apis/networking/v1alpha1/zz_generated.managedlist.go index 9ad13f9..15dc23b 100644 --- a/apis/networking/v1alpha1/zz_generated.managedlist.go +++ b/apis/networking/v1alpha1/zz_generated.managedlist.go @@ -25,6 +25,15 @@ func (l *FirewallList) GetItems() []resource.Managed { return items } +// GetItems of this IPList. +func (l *IPList) GetItems() []resource.Managed { + items := make([]resource.Managed, len(l.Items)) + for i := range l.Items { + items[i] = &l.Items[i] + } + return items +} + // GetItems of this LoadbalancerList. func (l *LoadbalancerList) GetItems() []resource.Managed { items := make([]resource.Managed, len(l.Items)) diff --git a/apis/networking/v1alpha1/zz_generated.resolvers.go b/apis/networking/v1alpha1/zz_generated.resolvers.go index a4d2124..bbada52 100644 --- a/apis/networking/v1alpha1/zz_generated.resolvers.go +++ b/apis/networking/v1alpha1/zz_generated.resolvers.go @@ -39,6 +39,32 @@ func (mg *Firewall) ResolveReferences(ctx context.Context, c client.Reader) erro return nil } +// ResolveReferences of this IP. +func (mg *IP) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromFloatPtrValue(mg.Spec.ForProvider.DropletID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.DropletIDRef, + Selector: mg.Spec.ForProvider.DropletIDSelector, + To: reference.To{ + List: &v1alpha1.DropletList{}, + Managed: &v1alpha1.Droplet{}, + }, + }) + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.DropletID") + } + mg.Spec.ForProvider.DropletID = reference.ToFloatPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.DropletIDRef = rsp.ResolvedReference + + return nil +} + // ResolveReferences of this Loadbalancer. func (mg *Loadbalancer) ResolveReferences(ctx context.Context, c client.Reader) error { r := reference.NewAPIResolver(c, mg) diff --git a/apis/networking/v1alpha1/zz_generated_terraformed.go b/apis/networking/v1alpha1/zz_generated_terraformed.go index d47907b..c0c1a7d 100755 --- a/apis/networking/v1alpha1/zz_generated_terraformed.go +++ b/apis/networking/v1alpha1/zz_generated_terraformed.go @@ -353,6 +353,90 @@ func (tr *Record) GetTerraformSchemaVersion() int { return 0 } +// GetTerraformResourceType returns Terraform resource type for this IP +func (mg *IP) GetTerraformResourceType() string { + return "digitalocean_reserved_ip" +} + +// GetConnectionDetailsMapping for this IP +func (tr *IP) GetConnectionDetailsMapping() map[string]string { + return nil +} + +// GetObservation of this IP +func (tr *IP) GetObservation() (map[string]any, error) { + o, err := json.TFParser.Marshal(tr.Status.AtProvider) + if err != nil { + return nil, err + } + base := map[string]any{} + return base, json.TFParser.Unmarshal(o, &base) +} + +// SetObservation for this IP +func (tr *IP) SetObservation(obs map[string]any) error { + p, err := json.TFParser.Marshal(obs) + if err != nil { + return err + } + return json.TFParser.Unmarshal(p, &tr.Status.AtProvider) +} + +// GetID returns ID of underlying Terraform resource of this IP +func (tr *IP) GetID() string { + if tr.Status.AtProvider.ID == nil { + return "" + } + return *tr.Status.AtProvider.ID +} + +// GetParameters of this IP +func (tr *IP) GetParameters() (map[string]any, error) { + p, err := json.TFParser.Marshal(tr.Spec.ForProvider) + if err != nil { + return nil, err + } + base := map[string]any{} + return base, json.TFParser.Unmarshal(p, &base) +} + +// SetParameters for this IP +func (tr *IP) SetParameters(params map[string]any) error { + p, err := json.TFParser.Marshal(params) + if err != nil { + return err + } + return json.TFParser.Unmarshal(p, &tr.Spec.ForProvider) +} + +// GetInitParameters of this IP +func (tr *IP) GetInitParameters() (map[string]any, error) { + p, err := json.TFParser.Marshal(tr.Spec.InitProvider) + if err != nil { + return nil, err + } + base := map[string]any{} + return base, json.TFParser.Unmarshal(p, &base) +} + +// LateInitialize this IP using its observed tfState. +// returns True if there are any spec changes for the resource. +func (tr *IP) LateInitialize(attrs []byte) (bool, error) { + params := &IPParameters{} + if err := json.TFParser.Unmarshal(attrs, params); err != nil { + return false, errors.Wrap(err, "failed to unmarshal Terraform state parameters for late-initialization") + } + opts := []resource.GenericLateInitializerOption{resource.WithZeroValueJSONOmitEmptyFilter(resource.CNameWildcard)} + + li := resource.NewGenericLateInitializer(opts...) + return li.LateInitialize(&tr.Spec.ForProvider, params) +} + +// GetTerraformSchemaVersion returns the associated Terraform schema version +func (tr *IP) GetTerraformSchemaVersion() int { + return 0 +} + // GetTerraformResourceType returns Terraform resource type for this VPC func (mg *VPC) GetTerraformResourceType() string { return "digitalocean_vpc" diff --git a/apis/networking/v1alpha1/zz_ip_types.go b/apis/networking/v1alpha1/zz_ip_types.go new file mode 100755 index 0000000..c19f7b2 --- /dev/null +++ b/apis/networking/v1alpha1/zz_ip_types.go @@ -0,0 +1,130 @@ +// SPDX-FileCopyrightText: 2023 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +/* +Copyright 2022 Upbound Inc. +*/ + +// Code generated by upjet. DO NOT EDIT. + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + + v1 "github.com/crossplane/crossplane-runtime/apis/common/v1" +) + +type IPInitParameters struct { + + // The IP Address of the resource + IPAddress *string `json:"ipAddress,omitempty" tf:"ip_address,omitempty"` + + // The region that the reserved IP is reserved to. + Region *string `json:"region,omitempty" tf:"region,omitempty"` +} + +type IPObservation struct { + + // The ID of Droplet that the reserved IP will be assigned to. + DropletID *float64 `json:"dropletId,omitempty" tf:"droplet_id,omitempty"` + + ID *string `json:"id,omitempty" tf:"id,omitempty"` + + // The IP Address of the resource + IPAddress *string `json:"ipAddress,omitempty" tf:"ip_address,omitempty"` + + // The region that the reserved IP is reserved to. + Region *string `json:"region,omitempty" tf:"region,omitempty"` + + // The uniform resource name of the reserved ip + // the uniform resource name for the reserved ip + Urn *string `json:"urn,omitempty" tf:"urn,omitempty"` +} + +type IPParameters struct { + + // The ID of Droplet that the reserved IP will be assigned to. + // +crossplane:generate:reference:type=github.com/straw-hat-team/provider-digitalocean/apis/compute/v1alpha1.Droplet + // +kubebuilder:validation:Optional + DropletID *float64 `json:"dropletId,omitempty" tf:"droplet_id,omitempty"` + + // Reference to a Droplet in compute to populate dropletId. + // +kubebuilder:validation:Optional + DropletIDRef *v1.Reference `json:"dropletIdRef,omitempty" tf:"-"` + + // Selector for a Droplet in compute to populate dropletId. + // +kubebuilder:validation:Optional + DropletIDSelector *v1.Selector `json:"dropletIdSelector,omitempty" tf:"-"` + + // The IP Address of the resource + // +kubebuilder:validation:Optional + IPAddress *string `json:"ipAddress,omitempty" tf:"ip_address,omitempty"` + + // The region that the reserved IP is reserved to. + // +kubebuilder:validation:Optional + Region *string `json:"region,omitempty" tf:"region,omitempty"` +} + +// IPSpec defines the desired state of IP +type IPSpec struct { + v1.ResourceSpec `json:",inline"` + ForProvider IPParameters `json:"forProvider"` + // THIS IS A BETA FIELD. It will be honored + // unless the Management Policies feature flag is disabled. + // InitProvider holds the same fields as ForProvider, with the exception + // of Identifier and other resource reference fields. The fields that are + // in InitProvider are merged into ForProvider when the resource is created. + // The same fields are also added to the terraform ignore_changes hook, to + // avoid updating them after creation. This is useful for fields that are + // required on creation, but we do not desire to update them after creation, + // for example because of an external controller is managing them, like an + // autoscaler. + InitProvider IPInitParameters `json:"initProvider,omitempty"` +} + +// IPStatus defines the observed state of IP. +type IPStatus struct { + v1.ResourceStatus `json:",inline"` + AtProvider IPObservation `json:"atProvider,omitempty"` +} + +// +kubebuilder:object:root=true + +// IP is the Schema for the IPs API. +// +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:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" +// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:subresource:status +// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,do} +type IP struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + // +kubebuilder:validation:XValidation:rule="!('*' in self.managementPolicies || 'Create' in self.managementPolicies || 'Update' in self.managementPolicies) || has(self.forProvider.region) || (has(self.initProvider) && has(self.initProvider.region))",message="spec.forProvider.region is a required parameter" + Spec IPSpec `json:"spec"` + Status IPStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// IPList contains a list of IPs +type IPList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []IP `json:"items"` +} + +// Repository type metadata. +var ( + IP_Kind = "IP" + IP_GroupKind = schema.GroupKind{Group: CRDGroup, Kind: IP_Kind}.String() + IP_KindAPIVersion = IP_Kind + "." + CRDGroupVersion.String() + IP_GroupVersionKind = CRDGroupVersion.WithKind(IP_Kind) +) + +func init() { + SchemeBuilder.Register(&IP{}, &IPList{}) +} diff --git a/config/provider.go b/config/provider.go index e518e76..b844a97 100644 --- a/config/provider.go +++ b/config/provider.go @@ -41,6 +41,7 @@ var ExternalNameConfigs = map[string]ujconfig.ExternalName{ "digitalocean_droplet_snapshot": ujconfig.IdentifierFromProvider, "digitalocean_tag": ujconfig.IdentifierFromProvider, "digitalocean_firewall": ujconfig.IdentifierFromProvider, + "digitalocean_reserved_ip": ujconfig.IdentifierFromProvider, } const networkingGroup = "networking" @@ -56,6 +57,14 @@ func GetProvider() *ujconfig.Provider { ExternalNameConfigurations(), )) + pc.AddResourceConfigurator("digitalocean_reserved_ip", func(r *ujconfig.Resource) { + r.ShortGroup = networkingGroup + r.UseAsync = false + r.References["droplet_id"] = ujconfig.Reference{ + Type: referenceType(pc, "compute", "v1alpha1", "Droplet"), + TerraformName: "digitalocean_droplet", + } + }) pc.AddResourceConfigurator("digitalocean_firewall", func(r *ujconfig.Resource) { r.ShortGroup = networkingGroup r.UseAsync = false diff --git a/examples-generated/networking/ip.yaml b/examples-generated/networking/ip.yaml new file mode 100644 index 0000000..d023573 --- /dev/null +++ b/examples-generated/networking/ip.yaml @@ -0,0 +1,33 @@ +apiVersion: networking.digitalocean.crossplane.io/v1alpha1 +kind: IP +metadata: + annotations: + meta.upbound.io/example-id: networking/v1alpha1/ip + labels: + testing.upbound.io/example-name: example + name: example +spec: + forProvider: + dropletIdSelector: + matchLabels: + testing.upbound.io/example-name: example + region: nyc2 + +--- + +apiVersion: compute.digitalocean.crossplane.io/v1alpha1 +kind: Droplet +metadata: + annotations: + meta.upbound.io/example-id: networking/v1alpha1/ip + labels: + testing.upbound.io/example-name: example + name: example +spec: + forProvider: + image: ubuntu-22-04-x64 + ipv6: true + name: example + privateNetworking: true + region: nyc3 + size: s-1vcpu-1gb diff --git a/internal/controller/networking/ip/zz_controller.go b/internal/controller/networking/ip/zz_controller.go new file mode 100755 index 0000000..204412e --- /dev/null +++ b/internal/controller/networking/ip/zz_controller.go @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: 2023 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +/* +Copyright 2022 Upbound Inc. +*/ + +// Code generated by upjet. DO NOT EDIT. + +package ip + +import ( + "time" + + "github.com/crossplane/crossplane-runtime/pkg/connection" + "github.com/crossplane/crossplane-runtime/pkg/event" + "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + xpresource "github.com/crossplane/crossplane-runtime/pkg/resource" + tjcontroller "github.com/crossplane/upjet/pkg/controller" + "github.com/crossplane/upjet/pkg/controller/handler" + "github.com/crossplane/upjet/pkg/terraform" + ctrl "sigs.k8s.io/controller-runtime" + + v1alpha1 "github.com/straw-hat-team/provider-digitalocean/apis/networking/v1alpha1" + features "github.com/straw-hat-team/provider-digitalocean/internal/features" +) + +// Setup adds a controller that reconciles IP managed resources. +func Setup(mgr ctrl.Manager, o tjcontroller.Options) error { + name := managed.ControllerName(v1alpha1.IP_GroupVersionKind.String()) + var initializers managed.InitializerChain + cps := []managed.ConnectionPublisher{managed.NewAPISecretPublisher(mgr.GetClient(), mgr.GetScheme())} + if o.SecretStoreConfigGVK != nil { + cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), *o.SecretStoreConfigGVK, connection.WithTLSConfig(o.ESSOptions.TLSConfig))) + } + eventHandler := handler.NewEventHandler(handler.WithLogger(o.Logger.WithValues("gvk", v1alpha1.IP_GroupVersionKind))) + opts := []managed.ReconcilerOption{ + managed.WithExternalConnecter(tjcontroller.NewConnector(mgr.GetClient(), o.WorkspaceStore, o.SetupFn, o.Provider.Resources["digitalocean_reserved_ip"], tjcontroller.WithLogger(o.Logger), tjcontroller.WithConnectorEventHandler(eventHandler))), + managed.WithLogger(o.Logger.WithValues("controller", name)), + managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))), + managed.WithFinalizer(terraform.NewWorkspaceFinalizer(o.WorkspaceStore, xpresource.NewAPIFinalizer(mgr.GetClient(), managed.FinalizerName))), + managed.WithTimeout(3 * time.Minute), + managed.WithInitializers(initializers), + managed.WithConnectionPublishers(cps...), + managed.WithPollInterval(o.PollInterval), + } + if o.PollJitter != 0 { + opts = append(opts, managed.WithPollJitterHook(o.PollJitter)) + } + if o.Features.Enabled(features.EnableBetaManagementPolicies) { + opts = append(opts, managed.WithManagementPolicies()) + } + r := managed.NewReconciler(mgr, xpresource.ManagedKind(v1alpha1.IP_GroupVersionKind), opts...) + + return ctrl.NewControllerManagedBy(mgr). + Named(name). + WithOptions(o.ForControllerRuntime()). + WithEventFilter(xpresource.DesiredStateChanged()). + Watches(&v1alpha1.IP{}, eventHandler). + Complete(ratelimiter.NewReconciler(name, r, o.GlobalRateLimiter)) +} diff --git a/internal/controller/zz_setup.go b/internal/controller/zz_setup.go index eb70ce0..e4a7209 100755 --- a/internal/controller/zz_setup.go +++ b/internal/controller/zz_setup.go @@ -19,6 +19,7 @@ import ( nodepool "github.com/straw-hat-team/provider-digitalocean/internal/controller/kubernetes/nodepool" domain "github.com/straw-hat-team/provider-digitalocean/internal/controller/networking/domain" firewall "github.com/straw-hat-team/provider-digitalocean/internal/controller/networking/firewall" + ip "github.com/straw-hat-team/provider-digitalocean/internal/controller/networking/ip" loadbalancer "github.com/straw-hat-team/provider-digitalocean/internal/controller/networking/loadbalancer" record "github.com/straw-hat-team/provider-digitalocean/internal/controller/networking/record" vpc "github.com/straw-hat-team/provider-digitalocean/internal/controller/networking/vpc" @@ -41,6 +42,7 @@ func Setup(mgr ctrl.Manager, o controller.Options) error { nodepool.Setup, domain.Setup, firewall.Setup, + ip.Setup, loadbalancer.Setup, record.Setup, vpc.Setup, diff --git a/package/crds/networking.digitalocean.crossplane.io_ips.yaml b/package/crds/networking.digitalocean.crossplane.io_ips.yaml new file mode 100644 index 0000000..4f4ac62 --- /dev/null +++ b/package/crds/networking.digitalocean.crossplane.io_ips.yaml @@ -0,0 +1,402 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.13.0 + name: ips.networking.digitalocean.crossplane.io +spec: + group: networking.digitalocean.crossplane.io + names: + categories: + - crossplane + - managed + - do + kind: IP + listKind: IPList + plural: ips + singular: ip + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .status.conditions[?(@.type=='Ready')].status + name: READY + type: string + - jsonPath: .status.conditions[?(@.type=='Synced')].status + name: SYNCED + type: string + - jsonPath: .metadata.annotations.crossplane\.io/external-name + name: EXTERNAL-NAME + type: string + - jsonPath: .metadata.creationTimestamp + name: AGE + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: IP is the Schema for the IPs API. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: IPSpec defines the desired state of IP + properties: + deletionPolicy: + default: Delete + description: 'DeletionPolicy specifies what will happen to the underlying + external when this managed resource is deleted - either "Delete" + or "Orphan" the external resource. This field is planned to be deprecated + in favor of the ManagementPolicies field in a future release. Currently, + both could be set independently and non-default values would be + honored if the feature flag is enabled. See the design doc for more + information: https://github.com/crossplane/crossplane/blob/499895a25d1a1a0ba1604944ef98ac7a1a71f197/design/design-doc-observe-only-resources.md?plain=1#L223' + enum: + - Orphan + - Delete + type: string + forProvider: + properties: + dropletId: + description: The ID of Droplet that the reserved IP will be assigned + to. + type: number + dropletIdRef: + description: Reference to a Droplet in compute to populate dropletId. + properties: + name: + description: Name of the referenced object. + type: string + policy: + description: Policies for referencing. + properties: + resolution: + default: Required + description: Resolution specifies whether resolution of + this reference is required. The default is 'Required', + which means the reconcile will fail if the reference + cannot be resolved. 'Optional' means this reference + will be a no-op if it cannot be resolved. + enum: + - Required + - Optional + type: string + resolve: + description: Resolve specifies when this reference should + be resolved. The default is 'IfNotPresent', which will + attempt to resolve the reference only when the corresponding + field is not present. Use 'Always' to resolve the reference + on every reconcile. + enum: + - Always + - IfNotPresent + type: string + type: object + required: + - name + type: object + dropletIdSelector: + description: Selector for a Droplet in compute to populate dropletId. + properties: + matchControllerRef: + description: MatchControllerRef ensures an object with the + same controller reference as the selecting object is selected. + type: boolean + matchLabels: + additionalProperties: + type: string + description: MatchLabels ensures an object with matching labels + is selected. + type: object + policy: + description: Policies for selection. + properties: + resolution: + default: Required + description: Resolution specifies whether resolution of + this reference is required. The default is 'Required', + which means the reconcile will fail if the reference + cannot be resolved. 'Optional' means this reference + will be a no-op if it cannot be resolved. + enum: + - Required + - Optional + type: string + resolve: + description: Resolve specifies when this reference should + be resolved. The default is 'IfNotPresent', which will + attempt to resolve the reference only when the corresponding + field is not present. Use 'Always' to resolve the reference + on every reconcile. + enum: + - Always + - IfNotPresent + type: string + type: object + type: object + ipAddress: + description: The IP Address of the resource + type: string + region: + description: The region that the reserved IP is reserved to. + type: string + type: object + initProvider: + description: THIS IS A BETA FIELD. It will be honored unless the Management + Policies feature flag is disabled. InitProvider holds the same fields + as ForProvider, with the exception of Identifier and other resource + reference fields. The fields that are in InitProvider are merged + into ForProvider when the resource is created. The same fields are + also added to the terraform ignore_changes hook, to avoid updating + them after creation. This is useful for fields that are required + on creation, but we do not desire to update them after creation, + for example because of an external controller is managing them, + like an autoscaler. + properties: + ipAddress: + description: The IP Address of the resource + type: string + region: + description: The region that the reserved IP is reserved to. + type: string + type: object + managementPolicies: + default: + - '*' + description: 'THIS IS A BETA FIELD. It is on by default but can be + opted out through a Crossplane feature flag. ManagementPolicies + specify the array of actions Crossplane is allowed to take on the + managed and external resources. This field is planned to replace + the DeletionPolicy field in a future release. Currently, both could + be set independently and non-default values would be honored if + the feature flag is enabled. If both are custom, the DeletionPolicy + field will be ignored. See the design doc for more information: + https://github.com/crossplane/crossplane/blob/499895a25d1a1a0ba1604944ef98ac7a1a71f197/design/design-doc-observe-only-resources.md?plain=1#L223 + and this one: https://github.com/crossplane/crossplane/blob/444267e84783136daa93568b364a5f01228cacbe/design/one-pager-ignore-changes.md' + items: + description: A ManagementAction represents an action that the Crossplane + controllers can take on an external resource. + enum: + - Observe + - Create + - Update + - Delete + - LateInitialize + - '*' + type: string + type: array + providerConfigRef: + default: + name: default + description: ProviderConfigReference specifies how the provider that + will be used to create, observe, update, and delete this managed + resource should be configured. + properties: + name: + description: Name of the referenced object. + type: string + policy: + description: Policies for referencing. + properties: + resolution: + default: Required + description: Resolution specifies whether resolution of this + reference is required. The default is 'Required', which + means the reconcile will fail if the reference cannot be + resolved. 'Optional' means this reference will be a no-op + if it cannot be resolved. + enum: + - Required + - Optional + type: string + resolve: + description: Resolve specifies when this reference should + be resolved. The default is 'IfNotPresent', which will attempt + to resolve the reference only when the corresponding field + is not present. Use 'Always' to resolve the reference on + every reconcile. + enum: + - Always + - IfNotPresent + type: string + type: object + required: + - name + type: object + publishConnectionDetailsTo: + description: PublishConnectionDetailsTo specifies the connection secret + config which contains a name, metadata and a reference to secret + store config to which any connection details for this managed resource + should be written. Connection details frequently include the endpoint, + username, and password required to connect to the managed resource. + properties: + configRef: + default: + name: default + description: SecretStoreConfigRef specifies which secret store + config should be used for this ConnectionSecret. + properties: + name: + description: Name of the referenced object. + type: string + policy: + description: Policies for referencing. + properties: + resolution: + default: Required + description: Resolution specifies whether resolution of + this reference is required. The default is 'Required', + which means the reconcile will fail if the reference + cannot be resolved. 'Optional' means this reference + will be a no-op if it cannot be resolved. + enum: + - Required + - Optional + type: string + resolve: + description: Resolve specifies when this reference should + be resolved. The default is 'IfNotPresent', which will + attempt to resolve the reference only when the corresponding + field is not present. Use 'Always' to resolve the reference + on every reconcile. + enum: + - Always + - IfNotPresent + type: string + type: object + required: + - name + type: object + metadata: + description: Metadata is the metadata for connection secret. + properties: + annotations: + additionalProperties: + type: string + description: Annotations are the annotations to be added to + connection secret. - For Kubernetes secrets, this will be + used as "metadata.annotations". - It is up to Secret Store + implementation for others store types. + type: object + labels: + additionalProperties: + type: string + description: Labels are the labels/tags to be added to connection + secret. - For Kubernetes secrets, this will be used as "metadata.labels". + - It is up to Secret Store implementation for others store + types. + type: object + type: + description: Type is the SecretType for the connection secret. + - Only valid for Kubernetes Secret Stores. + type: string + type: object + name: + description: Name is the name of the connection secret. + type: string + required: + - name + type: object + writeConnectionSecretToRef: + description: WriteConnectionSecretToReference specifies the namespace + and name of a Secret to which any connection details for this managed + resource should be written. Connection details frequently include + the endpoint, username, and password required to connect to the + managed resource. This field is planned to be replaced in a future + release in favor of PublishConnectionDetailsTo. Currently, both + could be set independently and connection details would be published + to both without affecting each other. + properties: + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - name + - namespace + type: object + required: + - forProvider + type: object + x-kubernetes-validations: + - message: spec.forProvider.region is a required parameter + rule: '!(''*'' in self.managementPolicies || ''Create'' in self.managementPolicies + || ''Update'' in self.managementPolicies) || has(self.forProvider.region) + || (has(self.initProvider) && has(self.initProvider.region))' + status: + description: IPStatus defines the observed state of IP. + properties: + atProvider: + properties: + dropletId: + description: The ID of Droplet that the reserved IP will be assigned + to. + type: number + id: + type: string + ipAddress: + description: The IP Address of the resource + type: string + region: + description: The region that the reserved IP is reserved to. + type: string + urn: + description: The uniform resource name of the reserved ip the + uniform resource name for the reserved ip + type: string + type: object + conditions: + description: Conditions of the resource. + items: + description: A Condition that may apply to a resource. + properties: + lastTransitionTime: + description: LastTransitionTime is the last time this condition + transitioned from one status to another. + format: date-time + type: string + message: + description: A Message containing details about this condition's + last transition from one status to another, if any. + type: string + reason: + description: A Reason for this condition's last transition from + one status to another. + type: string + status: + description: Status of this condition; is it currently True, + False, or Unknown? + type: string + type: + description: Type of this condition. At most one of each condition + type may apply to a resource at any point in time. + type: string + required: + - lastTransitionTime + - reason + - status + - type + type: object + type: array + x-kubernetes-list-map-keys: + - type + x-kubernetes-list-type: map + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {}