From 82ea712b7f50defb77f2c3006db5d5fc833c3af1 Mon Sep 17 00:00:00 2001 From: Konrad Ferdinand Heimel Date: Tue, 28 Jul 2026 22:02:02 +0200 Subject: [PATCH 1/6] :sparkles: feat(publicnetwork): add PublicNetwork CRD and observe-only controller E8-S03 --- .../gridscale/v1alpha1/publicnetwork_types.go | 81 ++++++ .../v1alpha1/zz_generated.deepcopy.go | 183 +++++++++++++ .../v1alpha1/zz_generated.managed.go | 50 ++++ .../v1alpha1/zz_generated.managedlist.go | 9 + .../gridscale/v1alpha1/publicnetwork_types.go | 82 ++++++ .../v1alpha1/zz_generated.deepcopy.go | 183 +++++++++++++ .../v1alpha1/zz_generated.managed.go | 40 +++ .../v1alpha1/zz_generated.managedlist.go | 9 + .../e8_s03_publicnetwork_crd_exists_test.sh | 9 + .../gridscale/publicnetwork/controller.go | 173 ++++++++++++ .../publicnetwork/controller_test.go | 110 ++++++++ .../gridscale/publicnetwork/controller.go | 172 ++++++++++++ ...ale.m.platformrelay.io_publicnetworks.yaml | 214 +++++++++++++++ ...scale.platformrelay.io_publicnetworks.yaml | 256 ++++++++++++++++++ 14 files changed, 1571 insertions(+) create mode 100644 apis/cluster/gridscale/v1alpha1/publicnetwork_types.go create mode 100644 apis/namespaced/gridscale/v1alpha1/publicnetwork_types.go create mode 100755 hack/test/e8_s03_publicnetwork_crd_exists_test.sh create mode 100644 internal/controller/cluster/gridscale/publicnetwork/controller.go create mode 100644 internal/controller/cluster/gridscale/publicnetwork/controller_test.go create mode 100644 internal/controller/namespaced/gridscale/publicnetwork/controller.go create mode 100644 package/crds/gridscale.gridscale.m.platformrelay.io_publicnetworks.yaml create mode 100644 package/crds/gridscale.gridscale.platformrelay.io_publicnetworks.yaml diff --git a/apis/cluster/gridscale/v1alpha1/publicnetwork_types.go b/apis/cluster/gridscale/v1alpha1/publicnetwork_types.go new file mode 100644 index 0000000..4fe3fac --- /dev/null +++ b/apis/cluster/gridscale/v1alpha1/publicnetwork_types.go @@ -0,0 +1,81 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + + v1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1" +) + +// PublicNetworkParameters are the configurable fields of a PublicNetwork. +// No inputs are required — the controller discovers the public network automatically. +type PublicNetworkParameters struct{} + +// PublicNetworkObservation are the observable fields of a PublicNetwork. +type PublicNetworkObservation struct { + Name *string `json:"name,omitempty"` + Status *string `json:"status,omitempty"` + NetworkType *string `json:"networkType,omitempty"` + LocationUUID *string `json:"locationUUID,omitempty"` + LocationName *string `json:"locationName,omitempty"` + LocationCountry *string `json:"locationCountry,omitempty"` + LocationIATA *string `json:"locationIATA,omitempty"` + L2Security *bool `json:"l2Security,omitempty"` + DeleteBlock *bool `json:"deleteBlock,omitempty"` + Labels []string `json:"labels,omitempty"` + CreateTime *string `json:"createTime,omitempty"` + ChangeTime *string `json:"changeTime,omitempty"` +} + +// PublicNetworkSpec defines the desired state of PublicNetwork. +type PublicNetworkSpec struct { + v1.ResourceSpec `json:",inline"` + ForProvider PublicNetworkParameters `json:"forProvider"` +} + +// PublicNetworkStatus defines the observed state of PublicNetwork. +type PublicNetworkStatus struct { + v1.ResourceStatus `json:",inline"` + AtProvider PublicNetworkObservation `json:"atProvider,omitempty"` +} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion +// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" +// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" +// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,gridscale} + +// PublicNetwork is the Schema for the PublicNetworks API. Returns the account's public network details. +type PublicNetwork struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec PublicNetworkSpec `json:"spec"` + Status PublicNetworkStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// PublicNetworkList contains a list of PublicNetwork. +type PublicNetworkList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []PublicNetwork `json:"items"` +} + +// Repository type metadata. +var ( + PublicNetwork_Kind = "PublicNetwork" + PublicNetwork_GroupKind = schema.GroupKind{Group: CRDGroup, Kind: PublicNetwork_Kind}.String() + PublicNetwork_KindAPIVersion = PublicNetwork_Kind + "." + CRDGroupVersion.String() + PublicNetwork_GroupVersionKind = CRDGroupVersion.WithKind(PublicNetwork_Kind) +) + +func init() { + SchemeBuilder.Register(&PublicNetwork{}, &PublicNetworkList{}) +} diff --git a/apis/cluster/gridscale/v1alpha1/zz_generated.deepcopy.go b/apis/cluster/gridscale/v1alpha1/zz_generated.deepcopy.go index adf3792..6ebc09c 100644 --- a/apis/cluster/gridscale/v1alpha1/zz_generated.deepcopy.go +++ b/apis/cluster/gridscale/v1alpha1/zz_generated.deepcopy.go @@ -7338,6 +7338,189 @@ func (in *PostgresqlStatus) DeepCopy() *PostgresqlStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PublicNetwork) DeepCopyInto(out *PublicNetwork) { + *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 PublicNetwork. +func (in *PublicNetwork) DeepCopy() *PublicNetwork { + if in == nil { + return nil + } + out := new(PublicNetwork) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PublicNetwork) 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 *PublicNetworkList) DeepCopyInto(out *PublicNetworkList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PublicNetwork, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkList. +func (in *PublicNetworkList) DeepCopy() *PublicNetworkList { + if in == nil { + return nil + } + out := new(PublicNetworkList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PublicNetworkList) 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 *PublicNetworkObservation) DeepCopyInto(out *PublicNetworkObservation) { + *out = *in + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + if in.Status != nil { + in, out := &in.Status, &out.Status + *out = new(string) + **out = **in + } + if in.NetworkType != nil { + in, out := &in.NetworkType, &out.NetworkType + *out = new(string) + **out = **in + } + if in.LocationUUID != nil { + in, out := &in.LocationUUID, &out.LocationUUID + *out = new(string) + **out = **in + } + if in.LocationName != nil { + in, out := &in.LocationName, &out.LocationName + *out = new(string) + **out = **in + } + if in.LocationCountry != nil { + in, out := &in.LocationCountry, &out.LocationCountry + *out = new(string) + **out = **in + } + if in.LocationIATA != nil { + in, out := &in.LocationIATA, &out.LocationIATA + *out = new(string) + **out = **in + } + if in.L2Security != nil { + in, out := &in.L2Security, &out.L2Security + *out = new(bool) + **out = **in + } + if in.DeleteBlock != nil { + in, out := &in.DeleteBlock, &out.DeleteBlock + *out = new(bool) + **out = **in + } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.CreateTime != nil { + in, out := &in.CreateTime, &out.CreateTime + *out = new(string) + **out = **in + } + if in.ChangeTime != nil { + in, out := &in.ChangeTime, &out.ChangeTime + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkObservation. +func (in *PublicNetworkObservation) DeepCopy() *PublicNetworkObservation { + if in == nil { + return nil + } + out := new(PublicNetworkObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PublicNetworkParameters) DeepCopyInto(out *PublicNetworkParameters) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkParameters. +func (in *PublicNetworkParameters) DeepCopy() *PublicNetworkParameters { + if in == nil { + return nil + } + out := new(PublicNetworkParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PublicNetworkSpec) DeepCopyInto(out *PublicNetworkSpec) { + *out = *in + in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) + out.ForProvider = in.ForProvider +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkSpec. +func (in *PublicNetworkSpec) DeepCopy() *PublicNetworkSpec { + if in == nil { + return nil + } + out := new(PublicNetworkSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PublicNetworkStatus) DeepCopyInto(out *PublicNetworkStatus) { + *out = *in + in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) + in.AtProvider.DeepCopyInto(&out.AtProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkStatus. +func (in *PublicNetworkStatus) DeepCopy() *PublicNetworkStatus { + if in == nil { + return nil + } + out := new(PublicNetworkStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResourceLimitInitParameters) DeepCopyInto(out *ResourceLimitInitParameters) { *out = *in diff --git a/apis/cluster/gridscale/v1alpha1/zz_generated.managed.go b/apis/cluster/gridscale/v1alpha1/zz_generated.managed.go index f94bd45..30c6dee 100644 --- a/apis/cluster/gridscale/v1alpha1/zz_generated.managed.go +++ b/apis/cluster/gridscale/v1alpha1/zz_generated.managed.go @@ -708,6 +708,56 @@ func (mg *Postgresql) SetWriteConnectionSecretToReference(r *xpv1.SecretReferenc mg.Spec.WriteConnectionSecretToReference = r } +// GetCondition of this PublicNetwork. +func (mg *PublicNetwork) GetCondition(ct xpv1.ConditionType) xpv1.Condition { + return mg.Status.GetCondition(ct) +} + +// GetDeletionPolicy of this PublicNetwork. +func (mg *PublicNetwork) GetDeletionPolicy() xpv1.DeletionPolicy { + return mg.Spec.DeletionPolicy +} + +// GetManagementPolicies of this PublicNetwork. +func (mg *PublicNetwork) GetManagementPolicies() xpv1.ManagementPolicies { + return mg.Spec.ManagementPolicies +} + +// GetProviderConfigReference of this PublicNetwork. +func (mg *PublicNetwork) GetProviderConfigReference() *xpv1.Reference { + return mg.Spec.ProviderConfigReference +} + +// GetWriteConnectionSecretToReference of this PublicNetwork. +func (mg *PublicNetwork) GetWriteConnectionSecretToReference() *xpv1.SecretReference { + return mg.Spec.WriteConnectionSecretToReference +} + +// SetConditions of this PublicNetwork. +func (mg *PublicNetwork) SetConditions(c ...xpv1.Condition) { + mg.Status.SetConditions(c...) +} + +// SetDeletionPolicy of this PublicNetwork. +func (mg *PublicNetwork) SetDeletionPolicy(r xpv1.DeletionPolicy) { + mg.Spec.DeletionPolicy = r +} + +// SetManagementPolicies of this PublicNetwork. +func (mg *PublicNetwork) SetManagementPolicies(r xpv1.ManagementPolicies) { + mg.Spec.ManagementPolicies = r +} + +// SetProviderConfigReference of this PublicNetwork. +func (mg *PublicNetwork) SetProviderConfigReference(r *xpv1.Reference) { + mg.Spec.ProviderConfigReference = r +} + +// SetWriteConnectionSecretToReference of this PublicNetwork. +func (mg *PublicNetwork) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { + mg.Spec.WriteConnectionSecretToReference = r +} + // GetCondition of this Server. func (mg *Server) GetCondition(ct xpv1.ConditionType) xpv1.Condition { return mg.Status.GetCondition(ct) diff --git a/apis/cluster/gridscale/v1alpha1/zz_generated.managedlist.go b/apis/cluster/gridscale/v1alpha1/zz_generated.managedlist.go index bcec653..c15ced3 100644 --- a/apis/cluster/gridscale/v1alpha1/zz_generated.managedlist.go +++ b/apis/cluster/gridscale/v1alpha1/zz_generated.managedlist.go @@ -134,6 +134,15 @@ func (l *PostgresqlList) GetItems() []resource.Managed { return items } +// GetItems of this PublicNetworkList. +func (l *PublicNetworkList) 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 ServerList. func (l *ServerList) GetItems() []resource.Managed { items := make([]resource.Managed, len(l.Items)) diff --git a/apis/namespaced/gridscale/v1alpha1/publicnetwork_types.go b/apis/namespaced/gridscale/v1alpha1/publicnetwork_types.go new file mode 100644 index 0000000..76b89c2 --- /dev/null +++ b/apis/namespaced/gridscale/v1alpha1/publicnetwork_types.go @@ -0,0 +1,82 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + + v1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1" + v2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2" +) + +// PublicNetworkParameters are the configurable fields of a PublicNetwork. +// No inputs are required — the controller discovers the public network automatically. +type PublicNetworkParameters struct{} + +// PublicNetworkObservation are the observable fields of a PublicNetwork. +type PublicNetworkObservation struct { + Name *string `json:"name,omitempty"` + Status *string `json:"status,omitempty"` + NetworkType *string `json:"networkType,omitempty"` + LocationUUID *string `json:"locationUUID,omitempty"` + LocationName *string `json:"locationName,omitempty"` + LocationCountry *string `json:"locationCountry,omitempty"` + LocationIATA *string `json:"locationIATA,omitempty"` + L2Security *bool `json:"l2Security,omitempty"` + DeleteBlock *bool `json:"deleteBlock,omitempty"` + Labels []string `json:"labels,omitempty"` + CreateTime *string `json:"createTime,omitempty"` + ChangeTime *string `json:"changeTime,omitempty"` +} + +// PublicNetworkSpec defines the desired state of PublicNetwork. +type PublicNetworkSpec struct { + v2.ManagedResourceSpec `json:",inline"` + ForProvider PublicNetworkParameters `json:"forProvider"` +} + +// PublicNetworkStatus defines the observed state of PublicNetwork. +type PublicNetworkStatus struct { + v1.ResourceStatus `json:",inline"` + AtProvider PublicNetworkObservation `json:"atProvider,omitempty"` +} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion +// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" +// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" +// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:resource:scope=Namespaced,categories={crossplane,managed,gridscale} + +// PublicNetwork is the Schema for the PublicNetworks API. Returns the account's public network details. +type PublicNetwork struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec PublicNetworkSpec `json:"spec"` + Status PublicNetworkStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// PublicNetworkList contains a list of PublicNetwork. +type PublicNetworkList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []PublicNetwork `json:"items"` +} + +// Repository type metadata. +var ( + PublicNetwork_Kind = "PublicNetwork" + PublicNetwork_GroupKind = schema.GroupKind{Group: CRDGroup, Kind: PublicNetwork_Kind}.String() + PublicNetwork_KindAPIVersion = PublicNetwork_Kind + "." + CRDGroupVersion.String() + PublicNetwork_GroupVersionKind = CRDGroupVersion.WithKind(PublicNetwork_Kind) +) + +func init() { + SchemeBuilder.Register(&PublicNetwork{}, &PublicNetworkList{}) +} diff --git a/apis/namespaced/gridscale/v1alpha1/zz_generated.deepcopy.go b/apis/namespaced/gridscale/v1alpha1/zz_generated.deepcopy.go index ba42d35..4833c5f 100644 --- a/apis/namespaced/gridscale/v1alpha1/zz_generated.deepcopy.go +++ b/apis/namespaced/gridscale/v1alpha1/zz_generated.deepcopy.go @@ -7338,6 +7338,189 @@ func (in *PostgresqlStatus) DeepCopy() *PostgresqlStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PublicNetwork) DeepCopyInto(out *PublicNetwork) { + *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 PublicNetwork. +func (in *PublicNetwork) DeepCopy() *PublicNetwork { + if in == nil { + return nil + } + out := new(PublicNetwork) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PublicNetwork) 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 *PublicNetworkList) DeepCopyInto(out *PublicNetworkList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PublicNetwork, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkList. +func (in *PublicNetworkList) DeepCopy() *PublicNetworkList { + if in == nil { + return nil + } + out := new(PublicNetworkList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PublicNetworkList) 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 *PublicNetworkObservation) DeepCopyInto(out *PublicNetworkObservation) { + *out = *in + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + if in.Status != nil { + in, out := &in.Status, &out.Status + *out = new(string) + **out = **in + } + if in.NetworkType != nil { + in, out := &in.NetworkType, &out.NetworkType + *out = new(string) + **out = **in + } + if in.LocationUUID != nil { + in, out := &in.LocationUUID, &out.LocationUUID + *out = new(string) + **out = **in + } + if in.LocationName != nil { + in, out := &in.LocationName, &out.LocationName + *out = new(string) + **out = **in + } + if in.LocationCountry != nil { + in, out := &in.LocationCountry, &out.LocationCountry + *out = new(string) + **out = **in + } + if in.LocationIATA != nil { + in, out := &in.LocationIATA, &out.LocationIATA + *out = new(string) + **out = **in + } + if in.L2Security != nil { + in, out := &in.L2Security, &out.L2Security + *out = new(bool) + **out = **in + } + if in.DeleteBlock != nil { + in, out := &in.DeleteBlock, &out.DeleteBlock + *out = new(bool) + **out = **in + } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.CreateTime != nil { + in, out := &in.CreateTime, &out.CreateTime + *out = new(string) + **out = **in + } + if in.ChangeTime != nil { + in, out := &in.ChangeTime, &out.ChangeTime + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkObservation. +func (in *PublicNetworkObservation) DeepCopy() *PublicNetworkObservation { + if in == nil { + return nil + } + out := new(PublicNetworkObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PublicNetworkParameters) DeepCopyInto(out *PublicNetworkParameters) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkParameters. +func (in *PublicNetworkParameters) DeepCopy() *PublicNetworkParameters { + if in == nil { + return nil + } + out := new(PublicNetworkParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PublicNetworkSpec) DeepCopyInto(out *PublicNetworkSpec) { + *out = *in + in.ManagedResourceSpec.DeepCopyInto(&out.ManagedResourceSpec) + out.ForProvider = in.ForProvider +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkSpec. +func (in *PublicNetworkSpec) DeepCopy() *PublicNetworkSpec { + if in == nil { + return nil + } + out := new(PublicNetworkSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PublicNetworkStatus) DeepCopyInto(out *PublicNetworkStatus) { + *out = *in + in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) + in.AtProvider.DeepCopyInto(&out.AtProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PublicNetworkStatus. +func (in *PublicNetworkStatus) DeepCopy() *PublicNetworkStatus { + if in == nil { + return nil + } + out := new(PublicNetworkStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResourceLimitInitParameters) DeepCopyInto(out *ResourceLimitInitParameters) { *out = *in diff --git a/apis/namespaced/gridscale/v1alpha1/zz_generated.managed.go b/apis/namespaced/gridscale/v1alpha1/zz_generated.managed.go index a969f20..30c7efe 100644 --- a/apis/namespaced/gridscale/v1alpha1/zz_generated.managed.go +++ b/apis/namespaced/gridscale/v1alpha1/zz_generated.managed.go @@ -568,6 +568,46 @@ func (mg *Postgresql) SetWriteConnectionSecretToReference(r *xpv1.LocalSecretRef mg.Spec.WriteConnectionSecretToReference = r } +// GetCondition of this PublicNetwork. +func (mg *PublicNetwork) GetCondition(ct xpv1.ConditionType) xpv1.Condition { + return mg.Status.GetCondition(ct) +} + +// GetManagementPolicies of this PublicNetwork. +func (mg *PublicNetwork) GetManagementPolicies() xpv1.ManagementPolicies { + return mg.Spec.ManagementPolicies +} + +// GetProviderConfigReference of this PublicNetwork. +func (mg *PublicNetwork) GetProviderConfigReference() *xpv1.ProviderConfigReference { + return mg.Spec.ProviderConfigReference +} + +// GetWriteConnectionSecretToReference of this PublicNetwork. +func (mg *PublicNetwork) GetWriteConnectionSecretToReference() *xpv1.LocalSecretReference { + return mg.Spec.WriteConnectionSecretToReference +} + +// SetConditions of this PublicNetwork. +func (mg *PublicNetwork) SetConditions(c ...xpv1.Condition) { + mg.Status.SetConditions(c...) +} + +// SetManagementPolicies of this PublicNetwork. +func (mg *PublicNetwork) SetManagementPolicies(r xpv1.ManagementPolicies) { + mg.Spec.ManagementPolicies = r +} + +// SetProviderConfigReference of this PublicNetwork. +func (mg *PublicNetwork) SetProviderConfigReference(r *xpv1.ProviderConfigReference) { + mg.Spec.ProviderConfigReference = r +} + +// SetWriteConnectionSecretToReference of this PublicNetwork. +func (mg *PublicNetwork) SetWriteConnectionSecretToReference(r *xpv1.LocalSecretReference) { + mg.Spec.WriteConnectionSecretToReference = r +} + // GetCondition of this Server. func (mg *Server) GetCondition(ct xpv1.ConditionType) xpv1.Condition { return mg.Status.GetCondition(ct) diff --git a/apis/namespaced/gridscale/v1alpha1/zz_generated.managedlist.go b/apis/namespaced/gridscale/v1alpha1/zz_generated.managedlist.go index bcec653..c15ced3 100644 --- a/apis/namespaced/gridscale/v1alpha1/zz_generated.managedlist.go +++ b/apis/namespaced/gridscale/v1alpha1/zz_generated.managedlist.go @@ -134,6 +134,15 @@ func (l *PostgresqlList) GetItems() []resource.Managed { return items } +// GetItems of this PublicNetworkList. +func (l *PublicNetworkList) 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 ServerList. func (l *ServerList) GetItems() []resource.Managed { items := make([]resource.Managed, len(l.Items)) diff --git a/hack/test/e8_s03_publicnetwork_crd_exists_test.sh b/hack/test/e8_s03_publicnetwork_crd_exists_test.sh new file mode 100755 index 0000000..db9cecf --- /dev/null +++ b/hack/test/e8_s03_publicnetwork_crd_exists_test.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail +CLUSTER=package/crds/gridscale.gridscale.platformrelay.io_publicnetworks.yaml +NAMESPACED=package/crds/gridscale.gridscale.m.platformrelay.io_publicnetworks.yaml +[ -f "$CLUSTER" ] || { echo "FAIL: missing $CLUSTER"; exit 1; } +[ -f "$NAMESPACED" ] || { echo "FAIL: missing $NAMESPACED"; exit 1; } +grep -q "kind: CustomResourceDefinition" "$CLUSTER" || { echo "FAIL: not a CRD: $CLUSTER"; exit 1; } +grep -q "kind: CustomResourceDefinition" "$NAMESPACED" || { echo "FAIL: not a CRD: $NAMESPACED"; exit 1; } +echo "PASS: PublicNetwork CRD YAMLs exist" diff --git a/internal/controller/cluster/gridscale/publicnetwork/controller.go b/internal/controller/cluster/gridscale/publicnetwork/controller.go new file mode 100644 index 0000000..8ade589 --- /dev/null +++ b/internal/controller/cluster/gridscale/publicnetwork/controller.go @@ -0,0 +1,173 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +package publicnetwork + +import ( + "context" + "time" + + "github.com/pkg/errors" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + + xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1" + "github.com/crossplane/crossplane-runtime/v2/pkg/event" + "github.com/crossplane/crossplane-runtime/v2/pkg/ratelimiter" + "github.com/crossplane/crossplane-runtime/v2/pkg/reconciler/managed" + xpresource "github.com/crossplane/crossplane-runtime/v2/pkg/resource" + tjcontroller "github.com/crossplane/upjet/v2/pkg/controller" + "github.com/crossplane/upjet/v2/pkg/terraform" + + v1alpha1 "github.com/PlatformRelay/provider-gridscale/apis/cluster/gridscale/v1alpha1" + "github.com/PlatformRelay/provider-gridscale/internal/clients" +) + +const ( + errNotPublicNetwork = "managed resource is not a PublicNetwork" + errGetNetworks = "cannot get networks" + errNoPublicNetwork = "no public network found in account" +) + +type connector struct { + kube client.Client + setupFn terraform.SetupFn +} + +func (c *connector) Connect(ctx context.Context, mg xpresource.Managed) (managed.ExternalClient, error) { + pn, ok := mg.(*v1alpha1.PublicNetwork) + if !ok { + return nil, errors.New(errNotPublicNetwork) + } + setup, err := c.setupFn(ctx, c.kube, pn) + if err != nil { + return nil, errors.Wrap(err, "cannot get provider setup") + } + userUUID, _ := setup.Configuration["uuid"].(string) + token, _ := setup.Configuration["token"].(string) + apiURL, _ := setup.Configuration["api_url"].(string) + return &external{ + client: clients.NewGridscaleClient(userUUID, token, apiURL), + }, nil +} + +type external struct { + client *clients.GridscaleClient +} + +// networkEntry models a single network in the gridscale API response. +type networkEntry struct { + Name string `json:"name"` + Status string `json:"status"` + NetworkType string `json:"network_type"` + LocationUUID string `json:"location_uuid"` + LocationName string `json:"location_name"` + LocationCountry string `json:"location_country"` + LocationIATA string `json:"location_iata"` + L2Security bool `json:"l2security"` + DeleteBlock bool `json:"delete_block"` + Labels []string `json:"labels"` + CreateTime string `json:"create_time"` + ChangeTime string `json:"change_time"` +} + +// networksResponse models the gridscale API response for GET /objects/networks. +type networksResponse struct { + Networks map[string]networkEntry `json:"networks"` +} + +func strPtr(s string) *string { return &s } +func boolPtr(b bool) *bool { return &b } + +func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed.ExternalObservation, error) { + pn, ok := mg.(*v1alpha1.PublicNetwork) + if !ok { + return managed.ExternalObservation{}, errors.New(errNotPublicNetwork) + } + + var resp networksResponse + if err := e.client.Get(ctx, "/objects/networks", &resp); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, errGetNetworks) + } + + for _, net := range resp.Networks { + if net.NetworkType != "public" { + continue + } + obs := &pn.Status.AtProvider + obs.Name = strPtr(net.Name) + obs.Status = strPtr(net.Status) + obs.NetworkType = strPtr(net.NetworkType) + obs.LocationUUID = strPtr(net.LocationUUID) + obs.LocationName = strPtr(net.LocationName) + obs.LocationCountry = strPtr(net.LocationCountry) + obs.LocationIATA = strPtr(net.LocationIATA) + obs.L2Security = boolPtr(net.L2Security) + obs.DeleteBlock = boolPtr(net.DeleteBlock) + obs.Labels = net.Labels + obs.CreateTime = strPtr(net.CreateTime) + obs.ChangeTime = strPtr(net.ChangeTime) + pn.SetConditions(xpv1.Available()) + return managed.ExternalObservation{ + ResourceExists: true, + ResourceUpToDate: true, + }, nil + } + + return managed.ExternalObservation{ResourceExists: false}, nil +} + +func (e *external) Create(_ context.Context, _ xpresource.Managed) (managed.ExternalCreation, error) { + return managed.ExternalCreation{}, errors.New("PublicNetwork is observe-only and does not support Create") +} + +func (e *external) Update(_ context.Context, _ xpresource.Managed) (managed.ExternalUpdate, error) { + return managed.ExternalUpdate{}, errors.New("PublicNetwork is observe-only and does not support Update") +} + +func (e *external) Delete(_ context.Context, _ xpresource.Managed) (managed.ExternalDelete, error) { + // observe-only: nothing to delete remotely. + return managed.ExternalDelete{}, nil +} + +func (e *external) Disconnect(_ context.Context) error { + return nil +} + +// Setup adds a controller that reconciles PublicNetwork resources. +func Setup(mgr ctrl.Manager, o tjcontroller.Options) error { + name := managed.ControllerName(v1alpha1.PublicNetwork_GroupVersionKind.String()) + opts := []managed.ReconcilerOption{ + managed.WithExternalConnector(&connector{ + kube: mgr.GetClient(), + setupFn: o.SetupFn, + }), + managed.WithLogger(o.Logger.WithValues("controller", name)), + managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))), //nolint:staticcheck // suppress until crossplane-runtime offers the new recorder api + managed.WithTimeout(1 * time.Minute), + managed.WithPollInterval(o.PollInterval), + managed.WithManagementPolicies(), + } + if o.PollJitter != 0 { + opts = append(opts, managed.WithPollJitterHook(o.PollJitter)) + } + + r := managed.NewReconciler(mgr, xpresource.ManagedKind(v1alpha1.PublicNetwork_GroupVersionKind), opts...) + return ctrl.NewControllerManagedBy(mgr). + Named(name). + WithOptions(o.ForControllerRuntime()). + WithEventFilter(xpresource.DesiredStateChanged()). + For(&v1alpha1.PublicNetwork{}). + Complete(ratelimiter.NewReconciler(name, r, o.GlobalRateLimiter)) +} + +// SetupGated registers the controller behind a CRD-existence gate. +func SetupGated(mgr ctrl.Manager, o tjcontroller.Options) error { + o.Gate.Register(func() { + if err := Setup(mgr, o); err != nil { + mgr.GetLogger().Error(err, "unable to setup reconciler", "gvk", v1alpha1.PublicNetwork_GroupVersionKind.String()) + } + }, v1alpha1.PublicNetwork_GroupVersionKind) + return nil +} diff --git a/internal/controller/cluster/gridscale/publicnetwork/controller_test.go b/internal/controller/cluster/gridscale/publicnetwork/controller_test.go new file mode 100644 index 0000000..a2cf1b6 --- /dev/null +++ b/internal/controller/cluster/gridscale/publicnetwork/controller_test.go @@ -0,0 +1,110 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +package publicnetwork + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + v1alpha1 "github.com/PlatformRelay/provider-gridscale/apis/cluster/gridscale/v1alpha1" + "github.com/PlatformRelay/provider-gridscale/internal/clients" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func newTestExternal(t *testing.T, handler http.HandlerFunc) (*external, func()) { + t.Helper() + srv := httptest.NewServer(handler) + c := clients.NewGridscaleClient("uuid", "token", srv.URL) + return &external{client: c}, srv.Close +} + +func TestObserve_PublicNetworkFound(t *testing.T) { + resp := networksResponse{ + Networks: map[string]networkEntry{ + "abc": { + Name: "public-net", + NetworkType: "public", + Status: "active", + LocationUUID: "loc-uuid", + }, + }, + } + ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(resp) + }) + defer cleanup() + + pn := &v1alpha1.PublicNetwork{ObjectMeta: metav1.ObjectMeta{Name: "test"}} + obs, err := ext.Observe(context.Background(), pn) + if err != nil { + t.Fatalf("Observe error: %v", err) + } + if !obs.ResourceExists { + t.Error("ResourceExists should be true") + } + if pn.Status.AtProvider.Name == nil || *pn.Status.AtProvider.Name != "public-net" { + t.Errorf("unexpected name: %v", pn.Status.AtProvider.Name) + } + if pn.Status.AtProvider.NetworkType == nil || *pn.Status.AtProvider.NetworkType != "public" { + t.Errorf("unexpected network type: %v", pn.Status.AtProvider.NetworkType) + } +} + +func TestObserve_OnlyPrivateNetworks(t *testing.T) { + resp := networksResponse{ + Networks: map[string]networkEntry{ + "xyz": {Name: "private-net", NetworkType: "private"}, + }, + } + ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(resp) + }) + defer cleanup() + + pn := &v1alpha1.PublicNetwork{ObjectMeta: metav1.ObjectMeta{Name: "test"}} + obs, err := ext.Observe(context.Background(), pn) + if err != nil { + t.Fatalf("Observe error: %v", err) + } + if obs.ResourceExists { + t.Error("ResourceExists should be false when no public network found") + } +} + +func TestObserve_EmptyNetworkList(t *testing.T) { + resp := networksResponse{Networks: map[string]networkEntry{}} + ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(resp) + }) + defer cleanup() + + pn := &v1alpha1.PublicNetwork{ObjectMeta: metav1.ObjectMeta{Name: "test"}} + obs, err := ext.Observe(context.Background(), pn) + if err != nil { + t.Fatalf("Observe error: %v", err) + } + if obs.ResourceExists { + t.Error("ResourceExists should be false for empty network list") + } +} + +func TestCreate_ReturnsError(t *testing.T) { + ext := &external{client: clients.NewGridscaleClient("u", "t", "http://localhost:1")} + _, err := ext.Create(context.Background(), &v1alpha1.PublicNetwork{}) + if err == nil { + t.Fatal("Create should return observe-only error") + } +} + +func TestUpdate_ReturnsError(t *testing.T) { + ext := &external{client: clients.NewGridscaleClient("u", "t", "http://localhost:1")} + _, err := ext.Update(context.Background(), &v1alpha1.PublicNetwork{}) + if err == nil { + t.Fatal("Update should return observe-only error") + } +} diff --git a/internal/controller/namespaced/gridscale/publicnetwork/controller.go b/internal/controller/namespaced/gridscale/publicnetwork/controller.go new file mode 100644 index 0000000..a52065a --- /dev/null +++ b/internal/controller/namespaced/gridscale/publicnetwork/controller.go @@ -0,0 +1,172 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +package publicnetwork + +import ( + "context" + "time" + + "github.com/pkg/errors" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + + xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1" + "github.com/crossplane/crossplane-runtime/v2/pkg/event" + "github.com/crossplane/crossplane-runtime/v2/pkg/ratelimiter" + "github.com/crossplane/crossplane-runtime/v2/pkg/reconciler/managed" + xpresource "github.com/crossplane/crossplane-runtime/v2/pkg/resource" + tjcontroller "github.com/crossplane/upjet/v2/pkg/controller" + "github.com/crossplane/upjet/v2/pkg/terraform" + + v1alpha1 "github.com/PlatformRelay/provider-gridscale/apis/namespaced/gridscale/v1alpha1" + "github.com/PlatformRelay/provider-gridscale/internal/clients" +) + +const ( + errNotPublicNetwork = "managed resource is not a PublicNetwork" + errGetNetworks = "cannot get networks" +) + +type connector struct { + kube client.Client + setupFn terraform.SetupFn +} + +func (c *connector) Connect(ctx context.Context, mg xpresource.Managed) (managed.ExternalClient, error) { + pn, ok := mg.(*v1alpha1.PublicNetwork) + if !ok { + return nil, errors.New(errNotPublicNetwork) + } + setup, err := c.setupFn(ctx, c.kube, pn) + if err != nil { + return nil, errors.Wrap(err, "cannot get provider setup") + } + userUUID, _ := setup.Configuration["uuid"].(string) + token, _ := setup.Configuration["token"].(string) + apiURL, _ := setup.Configuration["api_url"].(string) + return &external{ + client: clients.NewGridscaleClient(userUUID, token, apiURL), + }, nil +} + +type external struct { + client *clients.GridscaleClient +} + +// networkEntry models a single network in the gridscale API response. +type networkEntry struct { + Name string `json:"name"` + Status string `json:"status"` + NetworkType string `json:"network_type"` + LocationUUID string `json:"location_uuid"` + LocationName string `json:"location_name"` + LocationCountry string `json:"location_country"` + LocationIATA string `json:"location_iata"` + L2Security bool `json:"l2security"` + DeleteBlock bool `json:"delete_block"` + Labels []string `json:"labels"` + CreateTime string `json:"create_time"` + ChangeTime string `json:"change_time"` +} + +// networksResponse models the gridscale API response for GET /objects/networks. +type networksResponse struct { + Networks map[string]networkEntry `json:"networks"` +} + +func strPtr(s string) *string { return &s } +func boolPtr(b bool) *bool { return &b } + +func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed.ExternalObservation, error) { + pn, ok := mg.(*v1alpha1.PublicNetwork) + if !ok { + return managed.ExternalObservation{}, errors.New(errNotPublicNetwork) + } + + var resp networksResponse + if err := e.client.Get(ctx, "/objects/networks", &resp); err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, errGetNetworks) + } + + for _, net := range resp.Networks { + if net.NetworkType != "public" { + continue + } + obs := &pn.Status.AtProvider + obs.Name = strPtr(net.Name) + obs.Status = strPtr(net.Status) + obs.NetworkType = strPtr(net.NetworkType) + obs.LocationUUID = strPtr(net.LocationUUID) + obs.LocationName = strPtr(net.LocationName) + obs.LocationCountry = strPtr(net.LocationCountry) + obs.LocationIATA = strPtr(net.LocationIATA) + obs.L2Security = boolPtr(net.L2Security) + obs.DeleteBlock = boolPtr(net.DeleteBlock) + obs.Labels = net.Labels + obs.CreateTime = strPtr(net.CreateTime) + obs.ChangeTime = strPtr(net.ChangeTime) + pn.SetConditions(xpv1.Available()) + return managed.ExternalObservation{ + ResourceExists: true, + ResourceUpToDate: true, + }, nil + } + + return managed.ExternalObservation{ResourceExists: false}, nil +} + +func (e *external) Create(_ context.Context, _ xpresource.Managed) (managed.ExternalCreation, error) { + return managed.ExternalCreation{}, errors.New("PublicNetwork is observe-only and does not support Create") +} + +func (e *external) Update(_ context.Context, _ xpresource.Managed) (managed.ExternalUpdate, error) { + return managed.ExternalUpdate{}, errors.New("PublicNetwork is observe-only and does not support Update") +} + +func (e *external) Delete(_ context.Context, _ xpresource.Managed) (managed.ExternalDelete, error) { + // observe-only: nothing to delete remotely. + return managed.ExternalDelete{}, nil +} + +func (e *external) Disconnect(_ context.Context) error { + return nil +} + +// Setup adds a controller that reconciles PublicNetwork resources. +func Setup(mgr ctrl.Manager, o tjcontroller.Options) error { + name := managed.ControllerName(v1alpha1.PublicNetwork_GroupVersionKind.String()) + opts := []managed.ReconcilerOption{ + managed.WithExternalConnector(&connector{ + kube: mgr.GetClient(), + setupFn: o.SetupFn, + }), + managed.WithLogger(o.Logger.WithValues("controller", name)), + managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))), //nolint:staticcheck // suppress until crossplane-runtime offers the new recorder api + managed.WithTimeout(1 * time.Minute), + managed.WithPollInterval(o.PollInterval), + managed.WithManagementPolicies(), + } + if o.PollJitter != 0 { + opts = append(opts, managed.WithPollJitterHook(o.PollJitter)) + } + + r := managed.NewReconciler(mgr, xpresource.ManagedKind(v1alpha1.PublicNetwork_GroupVersionKind), opts...) + return ctrl.NewControllerManagedBy(mgr). + Named(name). + WithOptions(o.ForControllerRuntime()). + WithEventFilter(xpresource.DesiredStateChanged()). + For(&v1alpha1.PublicNetwork{}). + Complete(ratelimiter.NewReconciler(name, r, o.GlobalRateLimiter)) +} + +// SetupGated registers the controller behind a CRD-existence gate. +func SetupGated(mgr ctrl.Manager, o tjcontroller.Options) error { + o.Gate.Register(func() { + if err := Setup(mgr, o); err != nil { + mgr.GetLogger().Error(err, "unable to setup reconciler", "gvk", v1alpha1.PublicNetwork_GroupVersionKind.String()) + } + }, v1alpha1.PublicNetwork_GroupVersionKind) + return nil +} diff --git a/package/crds/gridscale.gridscale.m.platformrelay.io_publicnetworks.yaml b/package/crds/gridscale.gridscale.m.platformrelay.io_publicnetworks.yaml new file mode 100644 index 0000000..68619ad --- /dev/null +++ b/package/crds/gridscale.gridscale.m.platformrelay.io_publicnetworks.yaml @@ -0,0 +1,214 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.20.1 + name: publicnetworks.gridscale.gridscale.m.platformrelay.io +spec: + group: gridscale.gridscale.m.platformrelay.io + names: + categories: + - crossplane + - managed + - gridscale + kind: PublicNetwork + listKind: PublicNetworkList + plural: publicnetworks + singular: publicnetwork + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .status.conditions[?(@.type=='Synced')].status + name: SYNCED + type: string + - jsonPath: .status.conditions[?(@.type=='Ready')].status + name: READY + type: string + - jsonPath: .metadata.creationTimestamp + name: AGE + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: PublicNetwork is the Schema for the PublicNetworks API. Returns + the account's public network details. + 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: PublicNetworkSpec defines the desired state of PublicNetwork. + properties: + forProvider: + description: |- + PublicNetworkParameters are the configurable fields of a PublicNetwork. + No inputs are required — the controller discovers the public network automatically. + 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. + 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: + kind: ClusterProviderConfig + 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: + kind: + description: Kind of the referenced object. + type: string + name: + description: Name of the referenced object. + type: string + required: + - kind + - 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. + properties: + name: + description: Name of the secret. + type: string + required: + - name + type: object + required: + - forProvider + type: object + status: + description: PublicNetworkStatus defines the observed state of PublicNetwork. + properties: + atProvider: + description: PublicNetworkObservation are the observable fields of + a PublicNetwork. + properties: + changeTime: + type: string + createTime: + type: string + deleteBlock: + type: boolean + l2Security: + type: boolean + labels: + items: + type: string + type: array + locationCountry: + type: string + locationIATA: + type: string + locationName: + type: string + locationUUID: + type: string + name: + type: string + networkType: + type: string + status: + 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 + observedGeneration: + description: |- + ObservedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + type: integer + 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 + observedGeneration: + description: |- + ObservedGeneration is the latest metadata.generation + which resulted in either a ready state, or stalled due to error + it can not recover from without human intervention. + format: int64 + type: integer + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} diff --git a/package/crds/gridscale.gridscale.platformrelay.io_publicnetworks.yaml b/package/crds/gridscale.gridscale.platformrelay.io_publicnetworks.yaml new file mode 100644 index 0000000..cf3de1d --- /dev/null +++ b/package/crds/gridscale.gridscale.platformrelay.io_publicnetworks.yaml @@ -0,0 +1,256 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.20.1 + name: publicnetworks.gridscale.gridscale.platformrelay.io +spec: + group: gridscale.gridscale.platformrelay.io + names: + categories: + - crossplane + - managed + - gridscale + kind: PublicNetwork + listKind: PublicNetworkList + plural: publicnetworks + singular: publicnetwork + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .status.conditions[?(@.type=='Synced')].status + name: SYNCED + type: string + - jsonPath: .status.conditions[?(@.type=='Ready')].status + name: READY + type: string + - jsonPath: .metadata.creationTimestamp + name: AGE + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: PublicNetwork is the Schema for the PublicNetworks API. Returns + the account's public network details. + 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: PublicNetworkSpec defines the desired state of PublicNetwork. + 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: + description: |- + PublicNetworkParameters are the configurable fields of a PublicNetwork. + No inputs are required — the controller discovers the public network automatically. + 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 + 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. + 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 + status: + description: PublicNetworkStatus defines the observed state of PublicNetwork. + properties: + atProvider: + description: PublicNetworkObservation are the observable fields of + a PublicNetwork. + properties: + changeTime: + type: string + createTime: + type: string + deleteBlock: + type: boolean + l2Security: + type: boolean + labels: + items: + type: string + type: array + locationCountry: + type: string + locationIATA: + type: string + locationName: + type: string + locationUUID: + type: string + name: + type: string + networkType: + type: string + status: + 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 + observedGeneration: + description: |- + ObservedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + type: integer + 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 + observedGeneration: + description: |- + ObservedGeneration is the latest metadata.generation + which resulted in either a ready state, or stalled due to error + it can not recover from without human intervention. + format: int64 + type: integer + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} From 4d55ebce6fd2c6a20b09db968877631e7b9b0724 Mon Sep 17 00:00:00 2001 From: Konrad Ferdinand Heimel Date: Tue, 28 Jul 2026 22:02:12 +0200 Subject: [PATCH 2/6] docs(changelog): regenerate for E8-S03 publicnetwork branch --- CHANGELOG.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc2a34f..eb82807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,16 +12,16 @@ Release notes are generated from [Conventional Commits](https://www.conventional ### Bug Fixes -- **observe:** Move YAMLs to examples/, update grpc, refresh changelog [6a9b19f](https://github.com/platformrelay/provider-gridscale/commit/6a9b19fc67c57cb2e0a01b096733f04e8633d525) +- **backuplist:** Fix deprecated API, goimports, regenerate managed/deepcopy files [64a5f5c](https://github.com/platformrelay/provider-gridscale/commit/64a5f5c6c2f78dee4ba7a468f327f1e365ce9cdd) -- **backuplist:** Fix deprecated API, goimports, regenerate managed/deepcopy files [5d9a3a4](https://github.com/platformrelay/provider-gridscale/commit/5d9a3a445d759c791d41727f48f8847bf88b257f) +- **backuplist:** Gofmt, README count 33, API docs, grpc v1.82.1, changelog [99a0d12](https://github.com/platformrelay/provider-gridscale/commit/99a0d12a4bbab55983393faf79c8e05cd641e09e) -- **backuplist:** Gofmt, README count 33, API docs, grpc v1.82.1, changelog [d2ff5a3](https://github.com/platformrelay/provider-gridscale/commit/d2ff5a3e09cc95a4227d64e2af7ed3cfee3ed593) +- **observe:** Move YAMLs to examples/, update grpc, refresh changelog [80107f1](https://github.com/platformrelay/provider-gridscale/commit/80107f12349b2e42f92af29566d8ecce411fa4af) ### Documentation -- **observe:** Add 38 observe-only example YAMLs and docs E8-S01 [f8a3884](https://github.com/platformrelay/provider-gridscale/commit/f8a3884bf50cf75bdf9b90b4403ea242c0437f5e) +- **observe:** Add 38 observe-only example YAMLs and docs E8-S01 [e92f89e](https://github.com/platformrelay/provider-gridscale/commit/e92f89e051884187ec9c33e6cb9d2f9f8ee3cfa6) - **backlog:** Mark backlog exhausted (U-1/LB-1/D-020-FU/E5 all landed) ([#29](https://github.com/platformrelay/provider-gridscale/pull/29))[ec942b9](https://github.com/platformrelay/provider-gridscale/commit/ec942b96cf443609fa53ecf52182f5a3bc3d515a) @@ -30,7 +30,9 @@ Release notes are generated from [Conventional Commits](https://www.conventional ### Features -- **backuplist:** Add BackupList CRD and observe-only controller E8-S02 [73d9201](https://github.com/platformrelay/provider-gridscale/commit/73d9201b756ca3cf81888311a6661017b743ac0d) +- **publicnetwork:** Add PublicNetwork CRD and observe-only controller E8-S03 [82ea712](https://github.com/platformrelay/provider-gridscale/commit/82ea712b7f50defb77f2c3006db5d5fc833c3af1) + +- **backuplist:** Add BackupList CRD and observe-only controller E8-S02 [643d488](https://github.com/platformrelay/provider-gridscale/commit/643d488f87f98ea538886e5b42b02a12902d92cd) ## [0.2.2](https://github.com/platformrelay/provider-gridscale/compare/v0.2.1..v0.2.2) - 2026-07-25 From 4070c5f8439e818c1a33a6f566a7384f899b9c85 Mon Sep 17 00:00:00 2001 From: Konrad Ferdinand Heimel Date: Tue, 28 Jul 2026 22:07:48 +0200 Subject: [PATCH 3/6] :memo: docs(api): regenerate CRD reference docs and README for PublicNetwork E8-S03 --- README.md | 8 +- docs/api/out.md | 233 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 237 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 762414c..47c31ee 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ clusters in YAML — Crossplane reconciles them against - **Cluster *and* namespaced APIs** — `gridscale.platformrelay.io` (cluster) and `gridscale.m.platformrelay.io` (namespaced) so multi-tenant teams can own their own `ProviderConfig`. -- **33 managed resources / 8 API groups** — servers, storage, networking, PaaS +- **34 managed resources / 8 API groups** — servers, storage, networking, PaaS databases, K8s, object storage, marketplace apps, and more. - **Signed packages** — GHCR + Upbound Marketplace publishes are keyless-cosign signed with an SBOM (from `v0.2.0` onward). @@ -113,20 +113,20 @@ Namespaced `ProviderConfig` / `ClusterProviderConfig` live under ## Supported resources -33 managed resources across 8 API groups, each served under both the +34 managed resources across 8 API groups, each served under both the cluster-scoped and namespaced families. Kind names below are the exact API server values (Upjet casing) — copy straight into `kind:`. | API group | Managed resources (`Kind`) | | --- | --- | -| `gridscale` | `Backupschedule`, `Filesystem`, `Firewall`, `IPv4`, `IPv6`, `Isoimage`, `K8S`, `Loadbalancer`, `Mariadb`, `Memcached` †, `MySQL` †, `Network`, `Paas`, `Postgresql`, `Server`, `Snapshot`, `Snapshotschedule`, `Sqlserver`, `Sshkey`, `Storage`, `Template` | +| `gridscale` | `Backupschedule`, `Filesystem`, `Firewall`, `IPv4`, `IPv6`, `Isoimage`, `K8S`, `Loadbalancer`, `Mariadb`, `Memcached` †, `MySQL` †, `Network`, `Paas`, `Postgresql`, `PublicNetwork`, `Server`, `Snapshot`, `Snapshotschedule`, `Sqlserver`, `Sshkey`, `Storage`, `Template` | | `marketplace` | `Application`, `ApplicationImport` | | `mysql8` | `MySQL8` | | `object` | `StorageAccesskey`, `StorageBucket` | | `paas` | `Securityzone` | | `redis` | `Cache`, `Store` | | `ssl` | `Certificate` | -| `storage` | `Clone`, `StorageImport` | +| `storage` | `BackupList`, `Clone`, `StorageImport` | † Upstream-deprecated — see [Deprecations](#deprecations). diff --git a/docs/api/out.md b/docs/api/out.md index 41a3429..6cbd75d 100644 --- a/docs/api/out.md +++ b/docs/api/out.md @@ -55,6 +55,8 @@ - [PaasList](#paaslist) - [Postgresql](#postgresql) - [PostgresqlList](#postgresqllist) +- [PublicNetwork](#publicnetwork) +- [PublicNetworkList](#publicnetworklist) - [Server](#server) - [ServerList](#serverlist) - [Snapshot](#snapshot) @@ -3241,6 +3243,120 @@ _Appears in:_ | `atProvider` _[PostgresqlObservation](#postgresqlobservation)_ | | | | +#### PublicNetwork + + + +PublicNetwork is the Schema for the PublicNetworks API. Returns the account's public network details. + + + +_Appears in:_ +- [PublicNetworkList](#publicnetworklist) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `apiVersion` _string_ | `gridscale.gridscale.m.platformrelay.io/v1alpha1` | | | +| `kind` _string_ | `PublicNetwork` | | | +| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | | +| `spec` _[PublicNetworkSpec](#publicnetworkspec)_ | | | | +| `status` _[PublicNetworkStatus](#publicnetworkstatus)_ | | | | + + +#### PublicNetworkList + + + +PublicNetworkList contains a list of PublicNetwork. + + + + + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `apiVersion` _string_ | `gridscale.gridscale.m.platformrelay.io/v1alpha1` | | | +| `kind` _string_ | `PublicNetworkList` | | | +| `metadata` _[ListMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#listmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | | +| `items` _[PublicNetwork](#publicnetwork) array_ | | | | + + +#### PublicNetworkObservation + + + +PublicNetworkObservation are the observable fields of a PublicNetwork. + + + +_Appears in:_ +- [PublicNetworkStatus](#publicnetworkstatus) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `name` _string_ | | | | +| `status` _string_ | | | | +| `networkType` _string_ | | | | +| `locationUUID` _string_ | | | | +| `locationName` _string_ | | | | +| `locationCountry` _string_ | | | | +| `locationIATA` _string_ | | | | +| `l2Security` _boolean_ | | | | +| `deleteBlock` _boolean_ | | | | +| `labels` _string array_ | | | | +| `createTime` _string_ | | | | +| `changeTime` _string_ | | | | + + +#### PublicNetworkParameters + + + +PublicNetworkParameters are the configurable fields of a PublicNetwork. +No inputs are required — the controller discovers the public network automatically. + + + +_Appears in:_ +- [PublicNetworkSpec](#publicnetworkspec) + + + +#### PublicNetworkSpec + + + +PublicNetworkSpec defines the desired state of PublicNetwork. + + + +_Appears in:_ +- [PublicNetwork](#publicnetwork) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `writeConnectionSecretToRef` _[LocalSecretReference](#localsecretreference)_ | 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. | | | +| `providerConfigRef` _[ProviderConfigReference](#providerconfigreference)_ | ProviderConfigReference specifies how the provider that will be used to
create, observe, update, and delete this managed resource should be
configured. | \{ kind:ClusterProviderConfig name:default \} | | +| `managementPolicies` _[ManagementPolicies](#managementpolicies)_ | 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.
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 | [*] | Enum: [Observe Create Update Delete LateInitialize *]
| +| `forProvider` _[PublicNetworkParameters](#publicnetworkparameters)_ | | | | + + +#### PublicNetworkStatus + + + +PublicNetworkStatus defines the observed state of PublicNetwork. + + + +_Appears in:_ +- [PublicNetwork](#publicnetwork) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `atProvider` _[PublicNetworkObservation](#publicnetworkobservation)_ | | | | + + #### ResourceLimitInitParameters @@ -5127,6 +5243,8 @@ _Appears in:_ - [PaasList](#paaslist) - [Postgresql](#postgresql) - [PostgresqlList](#postgresqllist) +- [PublicNetwork](#publicnetwork) +- [PublicNetworkList](#publicnetworklist) - [Server](#server) - [ServerList](#serverlist) - [Snapshot](#snapshot) @@ -8327,6 +8445,121 @@ _Appears in:_ | `atProvider` _[PostgresqlObservation](#postgresqlobservation)_ | | | | +#### PublicNetwork + + + +PublicNetwork is the Schema for the PublicNetworks API. Returns the account's public network details. + + + +_Appears in:_ +- [PublicNetworkList](#publicnetworklist) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `apiVersion` _string_ | `gridscale.gridscale.platformrelay.io/v1alpha1` | | | +| `kind` _string_ | `PublicNetwork` | | | +| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | | +| `spec` _[PublicNetworkSpec](#publicnetworkspec)_ | | | | +| `status` _[PublicNetworkStatus](#publicnetworkstatus)_ | | | | + + +#### PublicNetworkList + + + +PublicNetworkList contains a list of PublicNetwork. + + + + + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `apiVersion` _string_ | `gridscale.gridscale.platformrelay.io/v1alpha1` | | | +| `kind` _string_ | `PublicNetworkList` | | | +| `metadata` _[ListMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#listmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | | +| `items` _[PublicNetwork](#publicnetwork) array_ | | | | + + +#### PublicNetworkObservation + + + +PublicNetworkObservation are the observable fields of a PublicNetwork. + + + +_Appears in:_ +- [PublicNetworkStatus](#publicnetworkstatus) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `name` _string_ | | | | +| `status` _string_ | | | | +| `networkType` _string_ | | | | +| `locationUUID` _string_ | | | | +| `locationName` _string_ | | | | +| `locationCountry` _string_ | | | | +| `locationIATA` _string_ | | | | +| `l2Security` _boolean_ | | | | +| `deleteBlock` _boolean_ | | | | +| `labels` _string array_ | | | | +| `createTime` _string_ | | | | +| `changeTime` _string_ | | | | + + +#### PublicNetworkParameters + + + +PublicNetworkParameters are the configurable fields of a PublicNetwork. +No inputs are required — the controller discovers the public network automatically. + + + +_Appears in:_ +- [PublicNetworkSpec](#publicnetworkspec) + + + +#### PublicNetworkSpec + + + +PublicNetworkSpec defines the desired state of PublicNetwork. + + + +_Appears in:_ +- [PublicNetwork](#publicnetwork) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `writeConnectionSecretToRef` _[SecretReference](#secretreference)_ | 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. | | | +| `providerConfigRef` _[Reference](#reference)_ | ProviderConfigReference specifies how the provider that will be used to
create, observe, update, and delete this managed resource should be
configured. | \{ name:default \} | | +| `managementPolicies` _[ManagementPolicies](#managementpolicies)_ | 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 | [*] | | +| `deletionPolicy` _[DeletionPolicy](#deletionpolicy)_ | 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 | Delete | Enum: [Orphan Delete]
| +| `forProvider` _[PublicNetworkParameters](#publicnetworkparameters)_ | | | | + + +#### PublicNetworkStatus + + + +PublicNetworkStatus defines the observed state of PublicNetwork. + + + +_Appears in:_ +- [PublicNetwork](#publicnetwork) + +| Field | Description | Default | Validation | +| --- | --- | --- | --- | +| `atProvider` _[PublicNetworkObservation](#publicnetworkobservation)_ | | | | + + #### ResourceLimitInitParameters From f9a3f1feb531cd35bd58bd73b484e73d5eade022 Mon Sep 17 00:00:00 2001 From: Konrad Ferdinand Heimel Date: Tue, 28 Jul 2026 22:08:08 +0200 Subject: [PATCH 4/6] docs(changelog): regenerate for E8-S03 publicnetwork branch --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb82807..19158b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ Release notes are generated from [Conventional Commits](https://www.conventional ### Documentation +- **api:** Regenerate CRD reference docs and README for PublicNetwork E8-S03 [4070c5f](https://github.com/platformrelay/provider-gridscale/commit/4070c5f8439e818c1a33a6f566a7384f899b9c85) + - **observe:** Add 38 observe-only example YAMLs and docs E8-S01 [e92f89e](https://github.com/platformrelay/provider-gridscale/commit/e92f89e051884187ec9c33e6cb9d2f9f8ee3cfa6) - **backlog:** Mark backlog exhausted (U-1/LB-1/D-020-FU/E5 all landed) ([#29](https://github.com/platformrelay/provider-gridscale/pull/29))[ec942b9](https://github.com/platformrelay/provider-gridscale/commit/ec942b96cf443609fa53ecf52182f5a3bc3d515a) From 4a6df9ac46fbbfda45b93c01df1a86b247af07f3 Mon Sep 17 00:00:00 2001 From: Konrad Ferdinand Heimel Date: Tue, 28 Jul 2026 22:19:21 +0200 Subject: [PATCH 5/6] :white_check_mark: test(publicnetwork): add namespaced tests and fix errObserveOnly sentinel E8-S03 - Add var errObserveOnly sentinel in both cluster and namespaced controllers - Update Create/Update to return the sentinel (enables errors.Is assertions) - Remove dead errNoPublicNetwork constant from cluster controller - Rename controller_test.go -> publicnetwork_test.go in cluster package - Add publicnetwork_test.go to namespaced package (was missing) - Fix import grouping in test files (stdlib / k8s / PlatformRelay) - All tests use errors.Is(err, errObserveOnly) for precise assertions --- .../gridscale/publicnetwork/controller.go | 7 +- ...ntroller_test.go => publicnetwork_test.go} | 18 +-- .../gridscale/publicnetwork/controller.go | 6 +- .../publicnetwork/publicnetwork_test.go | 112 ++++++++++++++++++ 4 files changed, 130 insertions(+), 13 deletions(-) rename internal/controller/cluster/gridscale/publicnetwork/{controller_test.go => publicnetwork_test.go} (89%) create mode 100644 internal/controller/namespaced/gridscale/publicnetwork/publicnetwork_test.go diff --git a/internal/controller/cluster/gridscale/publicnetwork/controller.go b/internal/controller/cluster/gridscale/publicnetwork/controller.go index 8ade589..24cdd0b 100644 --- a/internal/controller/cluster/gridscale/publicnetwork/controller.go +++ b/internal/controller/cluster/gridscale/publicnetwork/controller.go @@ -27,9 +27,10 @@ import ( const ( errNotPublicNetwork = "managed resource is not a PublicNetwork" errGetNetworks = "cannot get networks" - errNoPublicNetwork = "no public network found in account" ) +var errObserveOnly = errors.New("publicnetwork is observe-only: use managementPolicies: [Observe]") + type connector struct { kube client.Client setupFn terraform.SetupFn @@ -119,11 +120,11 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed. } func (e *external) Create(_ context.Context, _ xpresource.Managed) (managed.ExternalCreation, error) { - return managed.ExternalCreation{}, errors.New("PublicNetwork is observe-only and does not support Create") + return managed.ExternalCreation{}, errObserveOnly } func (e *external) Update(_ context.Context, _ xpresource.Managed) (managed.ExternalUpdate, error) { - return managed.ExternalUpdate{}, errors.New("PublicNetwork is observe-only and does not support Update") + return managed.ExternalUpdate{}, errObserveOnly } func (e *external) Delete(_ context.Context, _ xpresource.Managed) (managed.ExternalDelete, error) { diff --git a/internal/controller/cluster/gridscale/publicnetwork/controller_test.go b/internal/controller/cluster/gridscale/publicnetwork/publicnetwork_test.go similarity index 89% rename from internal/controller/cluster/gridscale/publicnetwork/controller_test.go rename to internal/controller/cluster/gridscale/publicnetwork/publicnetwork_test.go index a2cf1b6..a0d433d 100644 --- a/internal/controller/cluster/gridscale/publicnetwork/controller_test.go +++ b/internal/controller/cluster/gridscale/publicnetwork/publicnetwork_test.go @@ -7,13 +7,15 @@ package publicnetwork import ( "context" "encoding/json" + "errors" "net/http" "net/http/httptest" "testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1alpha1 "github.com/PlatformRelay/provider-gridscale/apis/cluster/gridscale/v1alpha1" "github.com/PlatformRelay/provider-gridscale/internal/clients" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func newTestExternal(t *testing.T, handler http.HandlerFunc) (*external, func()) { @@ -35,7 +37,7 @@ func TestObserve_PublicNetworkFound(t *testing.T) { }, } ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(resp) + json.NewEncoder(w).Encode(resp) //nolint:errcheck }) defer cleanup() @@ -62,7 +64,7 @@ func TestObserve_OnlyPrivateNetworks(t *testing.T) { }, } ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(resp) + json.NewEncoder(w).Encode(resp) //nolint:errcheck }) defer cleanup() @@ -79,7 +81,7 @@ func TestObserve_OnlyPrivateNetworks(t *testing.T) { func TestObserve_EmptyNetworkList(t *testing.T) { resp := networksResponse{Networks: map[string]networkEntry{}} ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(resp) + json.NewEncoder(w).Encode(resp) //nolint:errcheck }) defer cleanup() @@ -96,15 +98,15 @@ func TestObserve_EmptyNetworkList(t *testing.T) { func TestCreate_ReturnsError(t *testing.T) { ext := &external{client: clients.NewGridscaleClient("u", "t", "http://localhost:1")} _, err := ext.Create(context.Background(), &v1alpha1.PublicNetwork{}) - if err == nil { - t.Fatal("Create should return observe-only error") + if !errors.Is(err, errObserveOnly) { + t.Fatalf("Create: want errObserveOnly, got %v", err) } } func TestUpdate_ReturnsError(t *testing.T) { ext := &external{client: clients.NewGridscaleClient("u", "t", "http://localhost:1")} _, err := ext.Update(context.Background(), &v1alpha1.PublicNetwork{}) - if err == nil { - t.Fatal("Update should return observe-only error") + if !errors.Is(err, errObserveOnly) { + t.Fatalf("Update: want errObserveOnly, got %v", err) } } diff --git a/internal/controller/namespaced/gridscale/publicnetwork/controller.go b/internal/controller/namespaced/gridscale/publicnetwork/controller.go index a52065a..8cbf3e9 100644 --- a/internal/controller/namespaced/gridscale/publicnetwork/controller.go +++ b/internal/controller/namespaced/gridscale/publicnetwork/controller.go @@ -29,6 +29,8 @@ const ( errGetNetworks = "cannot get networks" ) +var errObserveOnly = errors.New("publicnetwork is observe-only: use managementPolicies: [Observe]") + type connector struct { kube client.Client setupFn terraform.SetupFn @@ -118,11 +120,11 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed. } func (e *external) Create(_ context.Context, _ xpresource.Managed) (managed.ExternalCreation, error) { - return managed.ExternalCreation{}, errors.New("PublicNetwork is observe-only and does not support Create") + return managed.ExternalCreation{}, errObserveOnly } func (e *external) Update(_ context.Context, _ xpresource.Managed) (managed.ExternalUpdate, error) { - return managed.ExternalUpdate{}, errors.New("PublicNetwork is observe-only and does not support Update") + return managed.ExternalUpdate{}, errObserveOnly } func (e *external) Delete(_ context.Context, _ xpresource.Managed) (managed.ExternalDelete, error) { diff --git a/internal/controller/namespaced/gridscale/publicnetwork/publicnetwork_test.go b/internal/controller/namespaced/gridscale/publicnetwork/publicnetwork_test.go new file mode 100644 index 0000000..f32a24f --- /dev/null +++ b/internal/controller/namespaced/gridscale/publicnetwork/publicnetwork_test.go @@ -0,0 +1,112 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +package publicnetwork + +import ( + "context" + "encoding/json" + "errors" + "net/http" + "net/http/httptest" + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + v1alpha1 "github.com/PlatformRelay/provider-gridscale/apis/namespaced/gridscale/v1alpha1" + "github.com/PlatformRelay/provider-gridscale/internal/clients" +) + +func newTestExternal(t *testing.T, handler http.HandlerFunc) (*external, func()) { + t.Helper() + srv := httptest.NewServer(handler) + c := clients.NewGridscaleClient("uuid", "token", srv.URL) + return &external{client: c}, srv.Close +} + +func TestObserve_PublicNetworkFound(t *testing.T) { + resp := networksResponse{ + Networks: map[string]networkEntry{ + "abc": { + Name: "public-net", + NetworkType: "public", + Status: "active", + LocationUUID: "loc-uuid", + }, + }, + } + ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(resp) //nolint:errcheck + }) + defer cleanup() + + pn := &v1alpha1.PublicNetwork{ObjectMeta: metav1.ObjectMeta{Name: "test"}} + obs, err := ext.Observe(context.Background(), pn) + if err != nil { + t.Fatalf("Observe error: %v", err) + } + if !obs.ResourceExists { + t.Error("ResourceExists should be true") + } + if pn.Status.AtProvider.Name == nil || *pn.Status.AtProvider.Name != "public-net" { + t.Errorf("unexpected name: %v", pn.Status.AtProvider.Name) + } + if pn.Status.AtProvider.NetworkType == nil || *pn.Status.AtProvider.NetworkType != "public" { + t.Errorf("unexpected network type: %v", pn.Status.AtProvider.NetworkType) + } +} + +func TestObserve_OnlyPrivateNetworks(t *testing.T) { + resp := networksResponse{ + Networks: map[string]networkEntry{ + "xyz": {Name: "private-net", NetworkType: "private"}, + }, + } + ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(resp) //nolint:errcheck + }) + defer cleanup() + + pn := &v1alpha1.PublicNetwork{ObjectMeta: metav1.ObjectMeta{Name: "test"}} + obs, err := ext.Observe(context.Background(), pn) + if err != nil { + t.Fatalf("Observe error: %v", err) + } + if obs.ResourceExists { + t.Error("ResourceExists should be false when no public network found") + } +} + +func TestObserve_EmptyNetworkList(t *testing.T) { + resp := networksResponse{Networks: map[string]networkEntry{}} + ext, cleanup := newTestExternal(t, func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(resp) //nolint:errcheck + }) + defer cleanup() + + pn := &v1alpha1.PublicNetwork{ObjectMeta: metav1.ObjectMeta{Name: "test"}} + obs, err := ext.Observe(context.Background(), pn) + if err != nil { + t.Fatalf("Observe error: %v", err) + } + if obs.ResourceExists { + t.Error("ResourceExists should be false for empty network list") + } +} + +func TestCreate_ReturnsError(t *testing.T) { + ext := &external{client: clients.NewGridscaleClient("u", "t", "http://localhost:1")} + _, err := ext.Create(context.Background(), &v1alpha1.PublicNetwork{}) + if !errors.Is(err, errObserveOnly) { + t.Fatalf("Create: want errObserveOnly, got %v", err) + } +} + +func TestUpdate_ReturnsError(t *testing.T) { + ext := &external{client: clients.NewGridscaleClient("u", "t", "http://localhost:1")} + _, err := ext.Update(context.Background(), &v1alpha1.PublicNetwork{}) + if !errors.Is(err, errObserveOnly) { + t.Fatalf("Update: want errObserveOnly, got %v", err) + } +} From d34a42292daf3a051d53427fe00aa85765470689 Mon Sep 17 00:00:00 2001 From: Konrad Ferdinand Heimel Date: Tue, 28 Jul 2026 22:19:38 +0200 Subject: [PATCH 6/6] docs(changelog): regenerate for E8-S03 publicnetwork branch --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19158b8..57ad5bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,11 @@ Release notes are generated from [Conventional Commits](https://www.conventional - **backuplist:** Add BackupList CRD and observe-only controller E8-S02 [643d488](https://github.com/platformrelay/provider-gridscale/commit/643d488f87f98ea538886e5b42b02a12902d92cd) + +### Tests + +- **publicnetwork:** Add namespaced tests and fix errObserveOnly sentinel E8-S03 [4a6df9a](https://github.com/platformrelay/provider-gridscale/commit/4a6df9ac46fbbfda45b93c01df1a86b247af07f3) + ## [0.2.2](https://github.com/platformrelay/provider-gridscale/compare/v0.2.1..v0.2.2) - 2026-07-25 ### Bug Fixes