From 5113e7c0e6a0aa46f028973857c8688bcb49a6fe Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Thu, 17 Oct 2024 17:45:22 +0000 Subject: [PATCH] Add types and mappers for compute target TCP proxy --- .../v1beta1/computeforwardingrule_types.go | 11 +- .../v1beta1/computetargettcpproxy_types.go | 118 +++++++++++ .../{register.go => groupversion_info.go} | 17 +- .../v1beta1/targettcpproxy_reference.go | 183 ++++++++++++++++ apis/compute/v1beta1/zz_generated.deepcopy.go | 200 ++++++++++++++++++ ...proxies.compute.cnrm.cloud.google.com.yaml | 73 ++++--- dev/tasks/find-missing-fields | 1 + .../controllerbuilder/template/apis/refs.go | 2 +- .../v1beta1/computetargettcpproxy_types.go | 19 +- .../compute/v1beta1/zz_generated.deepcopy.go | 14 +- .../v1alpha1/computeregiontargettcpproxy.go | 198 +++++++++++++++++ .../fake/fake_computeregiontargettcpproxy.go | 144 +++++++++++++ .../targettcpproxy/mapper.generated.go | 68 ++++++ .../direct/compute/targettcpproxy/mapper.go | 40 ++++ .../compute/targettcpproxy/roundtrip_test.go | 84 ++++++++ .../compute/computetargettcpproxy.md | 41 ++-- 16 files changed, 1154 insertions(+), 59 deletions(-) create mode 100644 apis/compute/v1beta1/computetargettcpproxy_types.go rename apis/compute/v1beta1/{register.go => groupversion_info.go} (50%) create mode 100644 apis/compute/v1beta1/targettcpproxy_reference.go create mode 100644 pkg/clients/generated/client/clientset/versioned/typed/compute/v1alpha1/computeregiontargettcpproxy.go create mode 100644 pkg/clients/generated/client/clientset/versioned/typed/compute/v1alpha1/fake/fake_computeregiontargettcpproxy.go create mode 100644 pkg/controller/direct/compute/targettcpproxy/mapper.generated.go create mode 100644 pkg/controller/direct/compute/targettcpproxy/mapper.go create mode 100644 pkg/controller/direct/compute/targettcpproxy/roundtrip_test.go diff --git a/apis/compute/v1beta1/computeforwardingrule_types.go b/apis/compute/v1beta1/computeforwardingrule_types.go index 2d8a307802..7933ba9b7d 100644 --- a/apis/compute/v1beta1/computeforwardingrule_types.go +++ b/apis/compute/v1beta1/computeforwardingrule_types.go @@ -21,19 +21,12 @@ import ( commonv1alpha1 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/common/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" ) var ( - // SchemeBuilder is used to add go types to the GroupVersionKind scheme. - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} - - // AddToScheme is a global function that registers this API group & version to a scheme - AddToScheme = SchemeBuilder.AddToScheme - ComputeForwardingRuleGVK = schema.GroupVersionKind{ - Group: SchemeGroupVersion.Group, - Version: SchemeGroupVersion.Version, + Group: GroupVersion.Group, + Version: GroupVersion.Version, Kind: "ComputeForwardingRule", } ) diff --git a/apis/compute/v1beta1/computetargettcpproxy_types.go b/apis/compute/v1beta1/computetargettcpproxy_types.go new file mode 100644 index 0000000000..4561746240 --- /dev/null +++ b/apis/compute/v1beta1/computetargettcpproxy_types.go @@ -0,0 +1,118 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1beta1 + +import ( + refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var ( + ComputeTargetTCPProxyGVK = schema.GroupVersionKind{ + Group: GroupVersion.Group, + Version: GroupVersion.Version, + Kind: "ComputeTargetTCPProxy", + } +) + +// ComputeTargetTCPProxySpec defines the desired state of ComputeTargetTCPProxy +// +kcc:proto=google.cloud.compute.v1.TargetTcpProxy +type ComputeTargetTCPProxySpec struct { + // A reference to the ComputeBackendService resource. + // +required + BackendServiceRef *refs.ComputeBackendServiceRef `json:"backendServiceRef"` + + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Description is immutable" + // Immutable. An optional description of this resource. + Description *string `json:"description,omitempty"` + + // The geographical location of the ComputeTargetTCPProxy. + // Reference: GCP definition of regions/zones (https://cloud.google.com/compute/docs/regions-zones/) + // +optional + Location *string `json:"location"` + + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ProxyBind is immutable" + // Immutable. This field only applies when the forwarding rule that references + // this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED. + ProxyBind *bool `json:"proxyBind,omitempty"` + + // Specifies the type of proxy header to append before sending data to + // the backend. Default value: "NONE" Possible values: ["NONE", "PROXY_V1"]. + ProxyHeader *string `json:"proxyHeader,omitempty"` + + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ResourceID is immutable" + // Immutable. The ComputeTargetTCPProxy name. If not given, the metadata.name will be used. + ResourceID *string `json:"resourceID,omitempty"` +} + +// ComputeTargetTCPProxyStatus defines the config connector machine state of ComputeTargetTCPProxy +type ComputeTargetTCPProxyStatus struct { + // Conditions represent the latest available observations of the object's current state. + Conditions []v1alpha1.Condition `json:"conditions,omitempty"` + + // ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource. + ObservedGeneration *int64 `json:"observedGeneration,omitempty"` + + // A unique specifier for the ComputeTargetTCPProxy resource in GCP. + ExternalRef *string `json:"externalRef,omitempty"` + + // Creation timestamp in RFC3339 text format. + CreationTimestamp *string `json:"creationTimestamp,omitempty"` + + // The unique identifier for the resource. + ProxyID *int64 `json:"proxyID,omitempty"` + + // The SelfLink for the resource. + SelfLink *string `json:"selfLink,omitempty"` +} + +// ComputeTargetTCPProxyObservedState is the state of the ComputeTargetTCPProxy resource as most recently observed in GCP. +type ComputeTargetTCPProxyObservedState struct { +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:resource:categories=gcp,shortName=gcpcomputetargettcpproxy;gcpcomputetargettcpproxies +// +kubebuilder:subresource:status +// +kubebuilder:metadata:labels="cnrm.cloud.google.com/tf2crd=true";"cnrm.cloud.google.com/stability-level=stable";"cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/system=true" +// +kubebuilder:printcolumn:name="Age",JSONPath=".metadata.creationTimestamp",type="date" +// +kubebuilder:printcolumn:name="Ready",JSONPath=".status.conditions[?(@.type=='Ready')].status",type="string",description="When 'True', the most recent reconcile of the resource succeeded" +// +kubebuilder:printcolumn:name="Status",JSONPath=".status.conditions[?(@.type=='Ready')].reason",type="string",description="The reason for the value in 'Ready'" +// +kubebuilder:printcolumn:name="Status Age",JSONPath=".status.conditions[?(@.type=='Ready')].lastTransitionTime",type="date",description="The last transition time for the value in 'Status'" + +// ComputeTargetTCPProxy is the Schema for the ComputeTargetTCPProxy API +// +k8s:openapi-gen=true +type ComputeTargetTCPProxy struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +required + Spec ComputeTargetTCPProxySpec `json:"spec,omitempty"` + Status ComputeTargetTCPProxyStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// ComputeTargetTCPProxyList contains a list of ComputeTargetTCPProxy +type ComputeTargetTCPProxyList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ComputeTargetTCPProxy `json:"items"` +} + +func init() { + SchemeBuilder.Register(&ComputeTargetTCPProxy{}, &ComputeTargetTCPProxyList{}) +} diff --git a/apis/compute/v1beta1/register.go b/apis/compute/v1beta1/groupversion_info.go similarity index 50% rename from apis/compute/v1beta1/register.go rename to apis/compute/v1beta1/groupversion_info.go index 7f328f8130..71321a9a87 100644 --- a/apis/compute/v1beta1/register.go +++ b/apis/compute/v1beta1/groupversion_info.go @@ -12,11 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +kubebuilder:object:generate=true +// +groupName=compute.cnrm.cloud.google.com package v1beta1 -import "k8s.io/apimachinery/pkg/runtime/schema" +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) var ( - // SchemeGroupVersion is the group version used to register these objects. - SchemeGroupVersion = schema.GroupVersion{Group: "compute.cnrm.cloud.google.com", Version: "v1beta1"} + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "compute.cnrm.cloud.google.com", Version: "v1beta1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme ) diff --git a/apis/compute/v1beta1/targettcpproxy_reference.go b/apis/compute/v1beta1/targettcpproxy_reference.go new file mode 100644 index 0000000000..2165c31394 --- /dev/null +++ b/apis/compute/v1beta1/targettcpproxy_reference.go @@ -0,0 +1,183 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1beta1 + +import ( + "context" + "fmt" + "strings" + + refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var _ refsv1beta1.ExternalNormalizer = &ComputeTargetTCPProxyRef{} + +// ComputeTargetTCPProxyRef defines the resource reference to ComputeTargetTCPProxy, which "External" field +// holds the GCP identifier for the KRM object. +type ComputeTargetTCPProxyRef struct { + // A reference to an externally managed ComputeTargetTCPProxy resource. + // Should be in the format "projects//regions//targetTcpProxies/". + External string `json:"external,omitempty"` + + // The name of a ComputeTargetTCPProxy resource. + Name string `json:"name,omitempty"` + + // The namespace of a ComputeTargetTCPProxy resource. + Namespace string `json:"namespace,omitempty"` + + parent *ComputeTargetTCPProxyParent +} + +// NormalizedExternal provision the "External" value for other resource that depends on ComputeTargetTCPProxy. +// If the "External" is given in the other resource's spec.ComputeTargetTCPProxyRef, the given value will be used. +// Otherwise, the "Name" and "Namespace" will be used to query the actual ComputeTargetTCPProxy object from the cluster. +func (r *ComputeTargetTCPProxyRef) NormalizedExternal(ctx context.Context, reader client.Reader, otherNamespace string) (string, error) { + if r.External != "" && r.Name != "" { + return "", fmt.Errorf("cannot specify both name and external on %s reference", ComputeTargetTCPProxyGVK.Kind) + } + // From given External + if r.External != "" { + if _, _, err := parseComputeTargetTCPProxyExternal(r.External); err != nil { + return "", err + } + return r.External, nil + } + + // From the Config Connector object + if r.Namespace == "" { + r.Namespace = otherNamespace + } + key := types.NamespacedName{Name: r.Name, Namespace: r.Namespace} + u := &unstructured.Unstructured{} + u.SetGroupVersionKind(ComputeTargetTCPProxyGVK) + if err := reader.Get(ctx, key, u); err != nil { + if apierrors.IsNotFound(err) { + return "", k8s.NewReferenceNotFoundError(u.GroupVersionKind(), key) + } + return "", fmt.Errorf("reading referenced %s %s: %w", ComputeTargetTCPProxyGVK, key, err) + } + // Get external from status.externalRef. This is the most trustworthy place. + actualExternalRef, _, err := unstructured.NestedString(u.Object, "status", "externalRef") + if err != nil { + return "", fmt.Errorf("reading status.externalRef: %w", err) + } + if actualExternalRef == "" { + return "", k8s.NewReferenceNotReadyError(u.GroupVersionKind(), key) + } + r.External = actualExternalRef + return r.External, nil +} + +// New builds a ComputeTargetTCPProxyRef from the Config Connector ComputeTargetTCPProxy object. +func NewComputeTargetTCPProxyRef(ctx context.Context, reader client.Reader, obj *ComputeTargetTCPProxy, u *unstructured.Unstructured) (*ComputeTargetTCPProxyRef, error) { + id := &ComputeTargetTCPProxyRef{} + + // Get Parent + projectID, err := refsv1beta1.ResolveProjectID(ctx, reader, u) + if projectID == "" { + return nil, fmt.Errorf("cannot resolve project") + } + region := valueOf(obj.Spec.Location) + id.parent = &ComputeTargetTCPProxyParent{ProjectID: projectID, Region: region} + + // Get desired ID + resourceID := valueOf(obj.Spec.ResourceID) + if resourceID == "" { + resourceID = obj.GetName() + } + if resourceID == "" { + return nil, fmt.Errorf("cannot resolve resource ID") + } + + // Use approved External + externalRef := valueOf(obj.Status.ExternalRef) + if externalRef == "" { + id.External = asComputeTargetTCPProxyExternal(id.parent, resourceID) + return id, nil + } + + // Validate desired with actual + actualParent, actualResourceID, err := parseComputeTargetTCPProxyExternal(externalRef) + if err != nil { + return nil, err + } + if actualParent.ProjectID != projectID { + return nil, fmt.Errorf("spec.projectRef changed, expect %s, got %s", actualParent.ProjectID, projectID) + } + if actualParent.Region != region { + return nil, fmt.Errorf("spec.location changed, expect %s, got %s", actualParent.Region, region) + } + if actualResourceID != resourceID { + return nil, fmt.Errorf("cannot reset `metadata.name` or `spec.resourceID` to %s, since it has already assigned to %s", + resourceID, actualResourceID) + } + id.External = externalRef + id.parent = &ComputeTargetTCPProxyParent{ProjectID: projectID, Region: region} + return id, nil +} + +func (r *ComputeTargetTCPProxyRef) Parent() (*ComputeTargetTCPProxyParent, error) { + if r.parent != nil { + return r.parent, nil + } + if r.External != "" { + parent, _, err := parseComputeTargetTCPProxyExternal(r.External) + if err != nil { + return nil, err + } + return parent, nil + } + return nil, fmt.Errorf("ComputeTargetTCPProxyRef not initialized from `NewComputeTargetTCPProxyRef` or `NormalizedExternal`") +} + +type ComputeTargetTCPProxyParent struct { + ProjectID string + Region string +} + +func (p *ComputeTargetTCPProxyParent) String() string { + return "projects/" + p.ProjectID + "/regions/" + p.Region +} + +func asComputeTargetTCPProxyExternal(parent *ComputeTargetTCPProxyParent, resourceID string) (external string) { + return parent.String() + "/targetTcpProxies/" + resourceID +} + +func parseComputeTargetTCPProxyExternal(external string) (parent *ComputeTargetTCPProxyParent, resourceID string, err error) { + external = strings.TrimPrefix(external, "/") + tokens := strings.Split(external, "/") + if len(tokens) != 6 || tokens[0] != "projects" || tokens[2] != "regions" || tokens[4] != "targetTcpProxies" { + return nil, "", fmt.Errorf("format of ComputeTargetTCPProxy external=%q was not known (use projects//regions//targetTcpProxies/)", external) + } + parent = &ComputeTargetTCPProxyParent{ + ProjectID: tokens[1], + Region: tokens[3], + } + resourceID = tokens[5] + return parent, resourceID, nil +} + +func valueOf[T any](t *T) T { + var zeroVal T + if t == nil { + return zeroVal + } + return *t +} diff --git a/apis/compute/v1beta1/zz_generated.deepcopy.go b/apis/compute/v1beta1/zz_generated.deepcopy.go index 2f8bd34bcf..74f287938e 100644 --- a/apis/compute/v1beta1/zz_generated.deepcopy.go +++ b/apis/compute/v1beta1/zz_generated.deepcopy.go @@ -20,6 +20,7 @@ package v1beta1 import ( refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -409,6 +410,205 @@ func (in *ComputeForwardingRuleStatus) DeepCopy() *ComputeForwardingRuleStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ComputeTargetTCPProxy) DeepCopyInto(out *ComputeTargetTCPProxy) { + *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 ComputeTargetTCPProxy. +func (in *ComputeTargetTCPProxy) DeepCopy() *ComputeTargetTCPProxy { + if in == nil { + return nil + } + out := new(ComputeTargetTCPProxy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ComputeTargetTCPProxy) 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 *ComputeTargetTCPProxyList) DeepCopyInto(out *ComputeTargetTCPProxyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ComputeTargetTCPProxy, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComputeTargetTCPProxyList. +func (in *ComputeTargetTCPProxyList) DeepCopy() *ComputeTargetTCPProxyList { + if in == nil { + return nil + } + out := new(ComputeTargetTCPProxyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ComputeTargetTCPProxyList) 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 *ComputeTargetTCPProxyObservedState) DeepCopyInto(out *ComputeTargetTCPProxyObservedState) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComputeTargetTCPProxyObservedState. +func (in *ComputeTargetTCPProxyObservedState) DeepCopy() *ComputeTargetTCPProxyObservedState { + if in == nil { + return nil + } + out := new(ComputeTargetTCPProxyObservedState) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ComputeTargetTCPProxyParent) DeepCopyInto(out *ComputeTargetTCPProxyParent) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComputeTargetTCPProxyParent. +func (in *ComputeTargetTCPProxyParent) DeepCopy() *ComputeTargetTCPProxyParent { + if in == nil { + return nil + } + out := new(ComputeTargetTCPProxyParent) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ComputeTargetTCPProxyRef) DeepCopyInto(out *ComputeTargetTCPProxyRef) { + *out = *in + if in.parent != nil { + in, out := &in.parent, &out.parent + *out = new(ComputeTargetTCPProxyParent) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComputeTargetTCPProxyRef. +func (in *ComputeTargetTCPProxyRef) DeepCopy() *ComputeTargetTCPProxyRef { + if in == nil { + return nil + } + out := new(ComputeTargetTCPProxyRef) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ComputeTargetTCPProxySpec) DeepCopyInto(out *ComputeTargetTCPProxySpec) { + *out = *in + if in.BackendServiceRef != nil { + in, out := &in.BackendServiceRef, &out.BackendServiceRef + *out = new(refsv1beta1.ComputeBackendServiceRef) + **out = **in + } + if in.Description != nil { + in, out := &in.Description, &out.Description + *out = new(string) + **out = **in + } + if in.Location != nil { + in, out := &in.Location, &out.Location + *out = new(string) + **out = **in + } + if in.ProxyBind != nil { + in, out := &in.ProxyBind, &out.ProxyBind + *out = new(bool) + **out = **in + } + if in.ProxyHeader != nil { + in, out := &in.ProxyHeader, &out.ProxyHeader + *out = new(string) + **out = **in + } + if in.ResourceID != nil { + in, out := &in.ResourceID, &out.ResourceID + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComputeTargetTCPProxySpec. +func (in *ComputeTargetTCPProxySpec) DeepCopy() *ComputeTargetTCPProxySpec { + if in == nil { + return nil + } + out := new(ComputeTargetTCPProxySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ComputeTargetTCPProxyStatus) DeepCopyInto(out *ComputeTargetTCPProxyStatus) { + *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]v1alpha1.Condition, len(*in)) + copy(*out, *in) + } + if in.ObservedGeneration != nil { + in, out := &in.ObservedGeneration, &out.ObservedGeneration + *out = new(int64) + **out = **in + } + if in.ExternalRef != nil { + in, out := &in.ExternalRef, &out.ExternalRef + *out = new(string) + **out = **in + } + if in.CreationTimestamp != nil { + in, out := &in.CreationTimestamp, &out.CreationTimestamp + *out = new(string) + **out = **in + } + if in.ProxyID != nil { + in, out := &in.ProxyID, &out.ProxyID + *out = new(int64) + **out = **in + } + if in.SelfLink != nil { + in, out := &in.SelfLink, &out.SelfLink + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComputeTargetTCPProxyStatus. +func (in *ComputeTargetTCPProxyStatus) DeepCopy() *ComputeTargetTCPProxyStatus { + if in == nil { + return nil + } + out := new(ComputeTargetTCPProxyStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FirewallPolicyRuleLayer4Configs) DeepCopyInto(out *FirewallPolicyRuleLayer4Configs) { *out = *in diff --git a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_computetargettcpproxies.compute.cnrm.cloud.google.com.yaml b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_computetargettcpproxies.compute.cnrm.cloud.google.com.yaml index af102e8e55..974d830520 100644 --- a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_computetargettcpproxies.compute.cnrm.cloud.google.com.yaml +++ b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_computetargettcpproxies.compute.cnrm.cloud.google.com.yaml @@ -16,6 +16,7 @@ spec: categories: - gcp kind: ComputeTargetTCPProxy + listKind: ComputeTargetTCPProxyList plural: computetargettcpproxies shortNames: - gcpcomputetargettcpproxy @@ -43,20 +44,23 @@ spec: name: v1beta1 schema: openAPIV3Schema: + description: ComputeTargetTCPProxy is the Schema for the ComputeTargetTCPProxy + API properties: apiVersion: - description: 'apiVersion defines the versioned schema of this representation + 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/api-conventions.md#resources' + 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 + 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/api-conventions.md#types-kinds' + 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: ComputeTargetTCPProxySpec defines the desired state of ComputeTargetTCPProxy properties: backendServiceRef: description: A reference to the ComputeBackendService resource. @@ -76,42 +80,58 @@ spec: - external properties: external: - description: 'Allowed value: The `selfLink` field of a `ComputeBackendService` - resource.' + description: The ComputeBackendService selflink in the form "projects/{{project}}/global/backendServices/{{name}}" + or "projects/{{project}}/regions/{{region}}/backendServices/{{name}}" + when not managed by Config Connector. type: string name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + description: The `name` field of a `ComputeBackendService` resource. type: string namespace: - description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + description: The `namespace` field of a `ComputeBackendService` + resource. type: string type: object description: description: Immutable. An optional description of this resource. type: string + x-kubernetes-validations: + - message: Description is immutable + rule: self == oldSelf + location: + description: 'The geographical location of the ComputeTargetTCPProxy. + Reference: GCP definition of regions/zones (https://cloud.google.com/compute/docs/regions-zones/)' + type: string proxyBind: - description: |- - Immutable. This field only applies when the forwarding rule that references - this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED. + description: Immutable. This field only applies when the forwarding + rule that references this target proxy has a loadBalancingScheme + set to INTERNAL_SELF_MANAGED. type: boolean + x-kubernetes-validations: + - message: ProxyBind is immutable + rule: self == oldSelf proxyHeader: - description: |- - Specifies the type of proxy header to append before sending data to - the backend. Default value: "NONE" Possible values: ["NONE", "PROXY_V1"]. + description: 'Specifies the type of proxy header to append before + sending data to the backend. Default value: "NONE" Possible values: + ["NONE", "PROXY_V1"].' type: string resourceID: - description: Immutable. Optional. The name of the resource. Used for - creation and acquisition. When unset, the value of `metadata.name` - is used as the default. + description: Immutable. The ComputeTargetTCPProxy name. If not given, + the metadata.name will be used. type: string + x-kubernetes-validations: + - message: ResourceID is immutable + rule: self == oldSelf required: - backendServiceRef type: object status: + description: ComputeTargetTCPProxyStatus defines the config connector + machine state of ComputeTargetTCPProxy properties: conditions: - description: Conditions represent the latest available observation - of the resource's current state. + description: Conditions represent the latest available observations + of the object's current state. items: properties: lastTransitionTime: @@ -138,17 +158,24 @@ spec: creationTimestamp: description: Creation timestamp in RFC3339 text format. type: string + externalRef: + description: A unique specifier for the ComputeTargetTCPProxy resource + in GCP. + type: string observedGeneration: description: ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource. + format: int64 type: integer - proxyId: + proxyID: description: The unique identifier for the resource. + format: int64 type: integer selfLink: + description: The SelfLink for the resource. type: string type: object required: @@ -158,9 +185,3 @@ spec: storage: true subresources: status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/dev/tasks/find-missing-fields b/dev/tasks/find-missing-fields index c258e6080d..a3f1dfa569 100755 --- a/dev/tasks/find-missing-fields +++ b/dev/tasks/find-missing-fields @@ -25,6 +25,7 @@ cd ${REPO_ROOT} go test -v ./pkg/controller/direct/compute/firewallpolicyrule -fuzz=FuzzComputeFirewallPolicyRuleSpec -fuzztime 60s go test -v ./pkg/controller/direct/compute/forwardingrule -fuzz=FuzzComputeForwardingRuleSpec -fuzztime 60s +go test -v ./pkg/controller/direct/compute/targettcpproxy -fuzz=FuzzComputeTargetTCPProxySpec -fuzztime 60s go test -v ./pkg/controller/direct/networkconnectivity/ -fuzz=FuzzServiceConnectionPolicySpec -fuzztime 60s go test -v ./pkg/controller/direct/networkconnectivity/ -fuzz=FuzzServiceConnectionPolicyObservedState -fuzztime 60s diff --git a/dev/tools/controllerbuilder/template/apis/refs.go b/dev/tools/controllerbuilder/template/apis/refs.go index 360f9a7b6a..729bac8c3f 100644 --- a/dev/tools/controllerbuilder/template/apis/refs.go +++ b/dev/tools/controllerbuilder/template/apis/refs.go @@ -96,7 +96,7 @@ func New{{.Kind}}Ref(ctx context.Context, reader client.Reader, obj *{{.Kind}}) if err != nil { return nil, err } - projectID := projectRef.ProjectID + projectID := projectRef.ProjectID if projectID == "" { return nil, fmt.Errorf("cannot resolve project") } diff --git a/pkg/clients/generated/apis/compute/v1beta1/computetargettcpproxy_types.go b/pkg/clients/generated/apis/compute/v1beta1/computetargettcpproxy_types.go index ebbececef5..a6dbe7aa06 100644 --- a/pkg/clients/generated/apis/compute/v1beta1/computetargettcpproxy_types.go +++ b/pkg/clients/generated/apis/compute/v1beta1/computetargettcpproxy_types.go @@ -43,17 +43,19 @@ type ComputeTargetTCPProxySpec struct { // +optional Description *string `json:"description,omitempty"` - /* Immutable. This field only applies when the forwarding rule that references - this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED. */ + /* The geographical location of the ComputeTargetTCPProxy. Reference: GCP definition of regions/zones (https://cloud.google.com/compute/docs/regions-zones/) */ + // +optional + Location *string `json:"location,omitempty"` + + /* Immutable. This field only applies when the forwarding rule that references this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED. */ // +optional ProxyBind *bool `json:"proxyBind,omitempty"` - /* Specifies the type of proxy header to append before sending data to - the backend. Default value: "NONE" Possible values: ["NONE", "PROXY_V1"]. */ + /* Specifies the type of proxy header to append before sending data to the backend. Default value: "NONE" Possible values: ["NONE", "PROXY_V1"]. */ // +optional ProxyHeader *string `json:"proxyHeader,omitempty"` - /* Immutable. Optional. The name of the resource. Used for creation and acquisition. When unset, the value of `metadata.name` is used as the default. */ + /* Immutable. The ComputeTargetTCPProxy name. If not given, the metadata.name will be used. */ // +optional ResourceID *string `json:"resourceID,omitempty"` } @@ -66,14 +68,19 @@ type ComputeTargetTCPProxyStatus struct { // +optional CreationTimestamp *string `json:"creationTimestamp,omitempty"` + /* A unique specifier for the ComputeTargetTCPProxy resource in GCP. */ + // +optional + ExternalRef *string `json:"externalRef,omitempty"` + /* ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource. */ // +optional ObservedGeneration *int64 `json:"observedGeneration,omitempty"` /* The unique identifier for the resource. */ // +optional - ProxyId *int64 `json:"proxyId,omitempty"` + ProxyID *int64 `json:"proxyID,omitempty"` + /* The SelfLink for the resource. */ // +optional SelfLink *string `json:"selfLink,omitempty"` } diff --git a/pkg/clients/generated/apis/compute/v1beta1/zz_generated.deepcopy.go b/pkg/clients/generated/apis/compute/v1beta1/zz_generated.deepcopy.go index c376fe0585..3b8a130ff8 100644 --- a/pkg/clients/generated/apis/compute/v1beta1/zz_generated.deepcopy.go +++ b/pkg/clients/generated/apis/compute/v1beta1/zz_generated.deepcopy.go @@ -9424,6 +9424,11 @@ func (in *ComputeTargetTCPProxySpec) DeepCopyInto(out *ComputeTargetTCPProxySpec *out = new(string) **out = **in } + if in.Location != nil { + in, out := &in.Location, &out.Location + *out = new(string) + **out = **in + } if in.ProxyBind != nil { in, out := &in.ProxyBind, &out.ProxyBind *out = new(bool) @@ -9465,13 +9470,18 @@ func (in *ComputeTargetTCPProxyStatus) DeepCopyInto(out *ComputeTargetTCPProxySt *out = new(string) **out = **in } + if in.ExternalRef != nil { + in, out := &in.ExternalRef, &out.ExternalRef + *out = new(string) + **out = **in + } if in.ObservedGeneration != nil { in, out := &in.ObservedGeneration, &out.ObservedGeneration *out = new(int64) **out = **in } - if in.ProxyId != nil { - in, out := &in.ProxyId, &out.ProxyId + if in.ProxyID != nil { + in, out := &in.ProxyID, &out.ProxyID *out = new(int64) **out = **in } diff --git a/pkg/clients/generated/client/clientset/versioned/typed/compute/v1alpha1/computeregiontargettcpproxy.go b/pkg/clients/generated/client/clientset/versioned/typed/compute/v1alpha1/computeregiontargettcpproxy.go new file mode 100644 index 0000000000..603f7779ca --- /dev/null +++ b/pkg/clients/generated/client/clientset/versioned/typed/compute/v1alpha1/computeregiontargettcpproxy.go @@ -0,0 +1,198 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// *** DISCLAIMER *** +// Config Connector's go-client for CRDs is currently in ALPHA, which means +// that future versions of the go-client may include breaking changes. +// Please try it out and give us feedback! + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/compute/v1alpha1" + scheme "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// ComputeRegionTargetTCPProxiesGetter has a method to return a ComputeRegionTargetTCPProxyInterface. +// A group's client should implement this interface. +type ComputeRegionTargetTCPProxiesGetter interface { + ComputeRegionTargetTCPProxies(namespace string) ComputeRegionTargetTCPProxyInterface +} + +// ComputeRegionTargetTCPProxyInterface has methods to work with ComputeRegionTargetTCPProxy resources. +type ComputeRegionTargetTCPProxyInterface interface { + Create(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.CreateOptions) (*v1alpha1.ComputeRegionTargetTCPProxy, error) + Update(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.UpdateOptions) (*v1alpha1.ComputeRegionTargetTCPProxy, error) + UpdateStatus(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.UpdateOptions) (*v1alpha1.ComputeRegionTargetTCPProxy, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.ComputeRegionTargetTCPProxy, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.ComputeRegionTargetTCPProxyList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) + ComputeRegionTargetTCPProxyExpansion +} + +// computeRegionTargetTCPProxies implements ComputeRegionTargetTCPProxyInterface +type computeRegionTargetTCPProxies struct { + client rest.Interface + ns string +} + +// newComputeRegionTargetTCPProxies returns a ComputeRegionTargetTCPProxies +func newComputeRegionTargetTCPProxies(c *ComputeV1alpha1Client, namespace string) *computeRegionTargetTCPProxies { + return &computeRegionTargetTCPProxies{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the computeRegionTargetTCPProxy, and returns the corresponding computeRegionTargetTCPProxy object, and an error if there is any. +func (c *computeRegionTargetTCPProxies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + result = &v1alpha1.ComputeRegionTargetTCPProxy{} + err = c.client.Get(). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of ComputeRegionTargetTCPProxies that match those selectors. +func (c *computeRegionTargetTCPProxies) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ComputeRegionTargetTCPProxyList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.ComputeRegionTargetTCPProxyList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested computeRegionTargetTCPProxies. +func (c *computeRegionTargetTCPProxies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a computeRegionTargetTCPProxy and creates it. Returns the server's representation of the computeRegionTargetTCPProxy, and an error, if there is any. +func (c *computeRegionTargetTCPProxies) Create(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.CreateOptions) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + result = &v1alpha1.ComputeRegionTargetTCPProxy{} + err = c.client.Post(). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(computeRegionTargetTCPProxy). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a computeRegionTargetTCPProxy and updates it. Returns the server's representation of the computeRegionTargetTCPProxy, and an error, if there is any. +func (c *computeRegionTargetTCPProxies) Update(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.UpdateOptions) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + result = &v1alpha1.ComputeRegionTargetTCPProxy{} + err = c.client.Put(). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + Name(computeRegionTargetTCPProxy.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(computeRegionTargetTCPProxy). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *computeRegionTargetTCPProxies) UpdateStatus(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.UpdateOptions) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + result = &v1alpha1.ComputeRegionTargetTCPProxy{} + err = c.client.Put(). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + Name(computeRegionTargetTCPProxy.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(computeRegionTargetTCPProxy). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the computeRegionTargetTCPProxy and deletes it. Returns an error if one occurs. +func (c *computeRegionTargetTCPProxies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *computeRegionTargetTCPProxies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched computeRegionTargetTCPProxy. +func (c *computeRegionTargetTCPProxies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + result = &v1alpha1.ComputeRegionTargetTCPProxy{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("computeregiontargettcpproxies"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/clients/generated/client/clientset/versioned/typed/compute/v1alpha1/fake/fake_computeregiontargettcpproxy.go b/pkg/clients/generated/client/clientset/versioned/typed/compute/v1alpha1/fake/fake_computeregiontargettcpproxy.go new file mode 100644 index 0000000000..bfa60ce466 --- /dev/null +++ b/pkg/clients/generated/client/clientset/versioned/typed/compute/v1alpha1/fake/fake_computeregiontargettcpproxy.go @@ -0,0 +1,144 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// *** DISCLAIMER *** +// Config Connector's go-client for CRDs is currently in ALPHA, which means +// that future versions of the go-client may include breaking changes. +// Please try it out and give us feedback! + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/compute/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeComputeRegionTargetTCPProxies implements ComputeRegionTargetTCPProxyInterface +type FakeComputeRegionTargetTCPProxies struct { + Fake *FakeComputeV1alpha1 + ns string +} + +var computeregiontargettcpproxiesResource = v1alpha1.SchemeGroupVersion.WithResource("computeregiontargettcpproxies") + +var computeregiontargettcpproxiesKind = v1alpha1.SchemeGroupVersion.WithKind("ComputeRegionTargetTCPProxy") + +// Get takes name of the computeRegionTargetTCPProxy, and returns the corresponding computeRegionTargetTCPProxy object, and an error if there is any. +func (c *FakeComputeRegionTargetTCPProxies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(computeregiontargettcpproxiesResource, c.ns, name), &v1alpha1.ComputeRegionTargetTCPProxy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ComputeRegionTargetTCPProxy), err +} + +// List takes label and field selectors, and returns the list of ComputeRegionTargetTCPProxies that match those selectors. +func (c *FakeComputeRegionTargetTCPProxies) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ComputeRegionTargetTCPProxyList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(computeregiontargettcpproxiesResource, computeregiontargettcpproxiesKind, c.ns, opts), &v1alpha1.ComputeRegionTargetTCPProxyList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.ComputeRegionTargetTCPProxyList{ListMeta: obj.(*v1alpha1.ComputeRegionTargetTCPProxyList).ListMeta} + for _, item := range obj.(*v1alpha1.ComputeRegionTargetTCPProxyList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested computeRegionTargetTCPProxies. +func (c *FakeComputeRegionTargetTCPProxies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(computeregiontargettcpproxiesResource, c.ns, opts)) + +} + +// Create takes the representation of a computeRegionTargetTCPProxy and creates it. Returns the server's representation of the computeRegionTargetTCPProxy, and an error, if there is any. +func (c *FakeComputeRegionTargetTCPProxies) Create(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.CreateOptions) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(computeregiontargettcpproxiesResource, c.ns, computeRegionTargetTCPProxy), &v1alpha1.ComputeRegionTargetTCPProxy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ComputeRegionTargetTCPProxy), err +} + +// Update takes the representation of a computeRegionTargetTCPProxy and updates it. Returns the server's representation of the computeRegionTargetTCPProxy, and an error, if there is any. +func (c *FakeComputeRegionTargetTCPProxies) Update(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.UpdateOptions) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(computeregiontargettcpproxiesResource, c.ns, computeRegionTargetTCPProxy), &v1alpha1.ComputeRegionTargetTCPProxy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ComputeRegionTargetTCPProxy), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeComputeRegionTargetTCPProxies) UpdateStatus(ctx context.Context, computeRegionTargetTCPProxy *v1alpha1.ComputeRegionTargetTCPProxy, opts v1.UpdateOptions) (*v1alpha1.ComputeRegionTargetTCPProxy, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(computeregiontargettcpproxiesResource, "status", c.ns, computeRegionTargetTCPProxy), &v1alpha1.ComputeRegionTargetTCPProxy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ComputeRegionTargetTCPProxy), err +} + +// Delete takes name of the computeRegionTargetTCPProxy and deletes it. Returns an error if one occurs. +func (c *FakeComputeRegionTargetTCPProxies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(computeregiontargettcpproxiesResource, c.ns, name, opts), &v1alpha1.ComputeRegionTargetTCPProxy{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeComputeRegionTargetTCPProxies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(computeregiontargettcpproxiesResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.ComputeRegionTargetTCPProxyList{}) + return err +} + +// Patch applies the patch and returns the patched computeRegionTargetTCPProxy. +func (c *FakeComputeRegionTargetTCPProxies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ComputeRegionTargetTCPProxy, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(computeregiontargettcpproxiesResource, c.ns, name, pt, data, subresources...), &v1alpha1.ComputeRegionTargetTCPProxy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ComputeRegionTargetTCPProxy), err +} diff --git a/pkg/controller/direct/compute/targettcpproxy/mapper.generated.go b/pkg/controller/direct/compute/targettcpproxy/mapper.generated.go new file mode 100644 index 0000000000..568d25ff81 --- /dev/null +++ b/pkg/controller/direct/compute/targettcpproxy/mapper.generated.go @@ -0,0 +1,68 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package targettcpproxy + +import ( + pb "cloud.google.com/go/compute/apiv1/computepb" + krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/compute/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" +) + +func ComputeTargetTCPProxySpec_FromProto(mapCtx *direct.MapContext, in *pb.TargetTcpProxy) *krm.ComputeTargetTCPProxySpec { + if in == nil { + return nil + } + out := &krm.ComputeTargetTCPProxySpec{} + out.Description = in.Description + out.ProxyBind = in.ProxyBind + out.ProxyHeader = in.ProxyHeader + out.Location = in.Region + out.BackendServiceRef = ComputeTargetTCPProxySpec_BackendServiceRef_FromProto(mapCtx, direct.ValueOf(in.Service)) + return out +} +func ComputeTargetTCPProxySpec_ToProto(mapCtx *direct.MapContext, in *krm.ComputeTargetTCPProxySpec) *pb.TargetTcpProxy { + if in == nil { + return nil + } + out := &pb.TargetTcpProxy{} + out.Description = in.Description + out.ProxyBind = in.ProxyBind + out.ProxyHeader = in.ProxyHeader + out.Region = in.Location + out.Service = ComputeTargetTCPProxySpec_BackendServiceRef_ToProto(mapCtx, in.BackendServiceRef) + return out +} +func ComputeTargetTCPProxyStatus_FromProto(mapCtx *direct.MapContext, in *pb.TargetTcpProxy) *krm.ComputeTargetTCPProxyStatus { + if in == nil { + return nil + } + out := &krm.ComputeTargetTCPProxyStatus{} + out.CreationTimestamp = in.CreationTimestamp + // Kind + out.ProxyID = direct.LazyPtr(int64(in.GetId())) + out.SelfLink = in.SelfLink + return out +} +func ComputeTargetTCPProxyStatus_ToProto(mapCtx *direct.MapContext, in *krm.ComputeTargetTCPProxyStatus) *pb.TargetTcpProxy { + if in == nil { + return nil + } + out := &pb.TargetTcpProxy{} + out.CreationTimestamp = in.CreationTimestamp + out.Id = direct.LazyPtr(uint64(*in.ProxyID)) + // Kind + out.SelfLink = in.SelfLink + return out +} diff --git a/pkg/controller/direct/compute/targettcpproxy/mapper.go b/pkg/controller/direct/compute/targettcpproxy/mapper.go new file mode 100644 index 0000000000..e0aea08ec6 --- /dev/null +++ b/pkg/controller/direct/compute/targettcpproxy/mapper.go @@ -0,0 +1,40 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package targettcpproxy + +import ( + refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" + + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" +) + +func ComputeTargetTCPProxySpec_BackendServiceRef_FromProto(mapCtx *direct.MapContext, in string) *refs.ComputeBackendServiceRef { + if in == "" { + return nil + } + return &refs.ComputeBackendServiceRef{ + External: in, + } +} + +func ComputeTargetTCPProxySpec_BackendServiceRef_ToProto(mapCtx *direct.MapContext, in *refs.ComputeBackendServiceRef) *string { + if in == nil { + return nil + } + if in.External == "" { + mapCtx.Errorf("reference %s was not pre-resolved", in.Name) + } + return direct.LazyPtr(in.External) +} diff --git a/pkg/controller/direct/compute/targettcpproxy/roundtrip_test.go b/pkg/controller/direct/compute/targettcpproxy/roundtrip_test.go new file mode 100644 index 0000000000..2f62344b55 --- /dev/null +++ b/pkg/controller/direct/compute/targettcpproxy/roundtrip_test.go @@ -0,0 +1,84 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package targettcpproxy + +import ( + "math/rand" + "testing" + + pb "cloud.google.com/go/compute/apiv1/computepb" + + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/fuzz" + "github.com/google/go-cmp/cmp" + "google.golang.org/protobuf/encoding/prototext" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/testing/protocmp" + "k8s.io/apimachinery/pkg/util/sets" +) + +func FuzzComputeTargetTCPProxySpec(f *testing.F) { + f.Fuzz(func(t *testing.T, seed int64) { + randStream := rand.New(rand.NewSource(seed)) + + p1 := &pb.TargetTcpProxy{} + fuzz.FillWithRandom(t, randStream, p1) + + // We don't expect output fields to round-trip + outputFields := sets.New(".etag") + + // A few fields are not implemented yet in KRM, don't test them + unimplementedFields := sets.New[string]() + + // Status fields + unimplementedFields.Insert(".creation_timestamp") + unimplementedFields.Insert(".id") + unimplementedFields.Insert(".self_link") + + // Not supported in KRM + unimplementedFields.Insert(".name") + unimplementedFields.Insert(".kind") + + // Remove any output only or known-unimplemented fields + clearFields := &fuzz.ClearFields{ + Paths: unimplementedFields.Union(outputFields), + } + fuzz.Visit("", p1.ProtoReflect(), nil, clearFields) + + r := &fuzz.ReplaceFields{} + r.Func = func(path string, val protoreflect.Value) (protoreflect.Value, bool) { + // TODO: Any values that must follow a pattern + return protoreflect.Value{}, false + } + fuzz.Visit("", p1.ProtoReflect(), nil, r) + + ctx := &direct.MapContext{} + k := ComputeTargetTCPProxySpec_FromProto(ctx, p1) + if ctx.Err() != nil { + t.Fatalf("error mapping from proto to krm: %v", ctx.Err()) + } + + p2 := ComputeTargetTCPProxySpec_ToProto(ctx, k) + if ctx.Err() != nil { + t.Fatalf("error mapping from krm to proto: %v", ctx.Err()) + } + + if diff := cmp.Diff(p1, p2, protocmp.Transform()); diff != "" { + t.Logf("p1 = %v", prototext.Format(p1)) + t.Logf("p2 = %v", prototext.Format(p2)) + t.Errorf("roundtrip failed; diff:\n%s", diff) + } + }) +} diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/compute/computetargettcpproxy.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/compute/computetargettcpproxy.md index 4e9c90ed6a..31b3b5fafb 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/compute/computetargettcpproxy.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/compute/computetargettcpproxy.md @@ -82,6 +82,7 @@ backendServiceRef: name: string namespace: string description: string +location: string proxyBind: boolean proxyHeader: string resourceID: string @@ -111,7 +112,7 @@ resourceID: string

string

-

{% verbatim %}Allowed value: The `selfLink` field of a `ComputeBackendService` resource.{% endverbatim %}

+

{% verbatim %}The ComputeBackendService selflink in the form "projects/{{project}}/global/backendServices/{{name}}" or "projects/{{project}}/regions/{{region}}/backendServices/{{name}}" when not managed by Config Connector.{% endverbatim %}

@@ -121,7 +122,7 @@ resourceID: string

string

-

{% verbatim %}Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names{% endverbatim %}

+

{% verbatim %}The `name` field of a `ComputeBackendService` resource.{% endverbatim %}

@@ -131,7 +132,7 @@ resourceID: string

string

-

{% verbatim %}Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/{% endverbatim %}

+

{% verbatim %}The `namespace` field of a `ComputeBackendService` resource.{% endverbatim %}

@@ -144,6 +145,16 @@ resourceID: string

{% verbatim %}Immutable. An optional description of this resource.{% endverbatim %}

+ + +

location

+

Optional

+ + +

string

+

{% verbatim %}The geographical location of the ComputeTargetTCPProxy. Reference: GCP definition of regions/zones (https://cloud.google.com/compute/docs/regions-zones/){% endverbatim %}

+ +

proxyBind

@@ -151,8 +162,7 @@ resourceID: string

boolean

-

{% verbatim %}Immutable. This field only applies when the forwarding rule that references -this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED.{% endverbatim %}

+

{% verbatim %}Immutable. This field only applies when the forwarding rule that references this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED.{% endverbatim %}

@@ -162,8 +172,7 @@ this target proxy has a loadBalancingScheme set to INTERNAL_SELF_MANAGED.{% endv

string

-

{% verbatim %}Specifies the type of proxy header to append before sending data to -the backend. Default value: "NONE" Possible values: ["NONE", "PROXY_V1"].{% endverbatim %}

+

{% verbatim %}Specifies the type of proxy header to append before sending data to the backend. Default value: "NONE" Possible values: ["NONE", "PROXY_V1"].{% endverbatim %}

@@ -173,7 +182,7 @@ the backend. Default value: "NONE" Possible values: ["NONE", "PROXY_V1"].{% endv

string

-

{% verbatim %}Immutable. Optional. The name of the resource. Used for creation and acquisition. When unset, the value of `metadata.name` is used as the default.{% endverbatim %}

+

{% verbatim %}Immutable. The ComputeTargetTCPProxy name. If not given, the metadata.name will be used.{% endverbatim %}

@@ -191,8 +200,9 @@ conditions: status: string type: string creationTimestamp: string +externalRef: string observedGeneration: integer -proxyId: integer +proxyID: integer selfLink: string ``` @@ -207,7 +217,7 @@ selfLink: string conditions

list (object)

-

{% verbatim %}Conditions represent the latest available observation of the resource's current state.{% endverbatim %}

+

{% verbatim %}Conditions represent the latest available observations of the object's current state.{% endverbatim %}

@@ -259,6 +269,13 @@ selfLink: string

{% verbatim %}Creation timestamp in RFC3339 text format.{% endverbatim %}

+ + externalRef + +

string

+

{% verbatim %}A unique specifier for the ComputeTargetTCPProxy resource in GCP.{% endverbatim %}

+ + observedGeneration @@ -267,7 +284,7 @@ selfLink: string - proxyId + proxyID

integer

{% verbatim %}The unique identifier for the resource.{% endverbatim %}

@@ -277,7 +294,7 @@ selfLink: string selfLink

string

-

{% verbatim %}{% endverbatim %}

+

{% verbatim %}The SelfLink for the resource.{% endverbatim %}