diff --git a/go.mod b/go.mod index 74e191b47..ee3f7e93e 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( kmodules.xyz/custom-resources v0.30.0 kmodules.xyz/go-containerregistry v0.0.12 kmodules.xyz/monitoring-agent-api v0.29.0 - kmodules.xyz/resource-metadata v0.18.13-0.20240830120231-189258047c19 + kmodules.xyz/resource-metadata v0.18.13-0.20240831011752-f53d8b2924e9 kmodules.xyz/resource-metrics v0.30.4 kmodules.xyz/resource-metrics/utils v0.30.4 kmodules.xyz/sets v0.29.0 diff --git a/go.sum b/go.sum index 8a026e606..ec22dfdbb 100644 --- a/go.sum +++ b/go.sum @@ -922,8 +922,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9 kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI= kmodules.xyz/offshoot-api v0.30.0 h1:dq9F93pu4Q8rL9oTcCk+vGGy8vpS7RNt0GSwx7Bvhec= kmodules.xyz/offshoot-api v0.30.0/go.mod h1:o9VoA3ImZMDBp3lpLb8+kc2d/KBxioRwCpaKDfLIyDw= -kmodules.xyz/resource-metadata v0.18.13-0.20240830120231-189258047c19 h1:zBMWyBhdUlOMDrH5uFvUw3MoyE4VX+AsEK57EJRmQsk= -kmodules.xyz/resource-metadata v0.18.13-0.20240830120231-189258047c19/go.mod h1:cP78KvHOSrtPRPeQAyzmrkZQSXPYO5gQdd5DrUDAk1Y= +kmodules.xyz/resource-metadata v0.18.13-0.20240831011752-f53d8b2924e9 h1:iajL2aPvVZPVabUxALrmMBAGjVQJ2iJ2mGQjT3Ye1xM= +kmodules.xyz/resource-metadata v0.18.13-0.20240831011752-f53d8b2924e9/go.mod h1:bRVan42dRX/6FOb1Z4qK3s9o8M9q5I3XPakKbEGAHi4= kmodules.xyz/resource-metrics v0.30.4 h1:8HBPtYmo9ETY91gsc55JE8Z986+3ZuRq57M0wZ9npqI= kmodules.xyz/resource-metrics v0.30.4/go.mod h1:w9+rz7/s/kGP1GWzYSuRdCn+l7EwpesmESSEHkLBnIQ= kmodules.xyz/resource-metrics/utils v0.30.4 h1:bJS/x0Qr7N1FFdxugFbzZ/Es6HVs4ptsFlhkmgj3jac= diff --git a/pkg/registry/core/resourceservice/storage.go b/pkg/registry/core/resourceservice/storage.go index dc5b5e062..f75658e14 100644 --- a/pkg/registry/core/resourceservice/storage.go +++ b/pkg/registry/core/resourceservice/storage.go @@ -386,7 +386,7 @@ func (r *Storage) toGenericResourceService(item unstructured.Unstructured, apiTy genres.Spec.Facilities.Exposed.Usage = rscoreapi.FacilityUnused } } - if apiType.Group == "kubedb.com" && genres.Spec.Facilities.Exposed.Usage == rscoreapi.FacilityUnused { + if apiType.Group == "kubedb.com" { rid, objs, err := graph.ExecQuery(r.kc, oid, sharedapi.ResourceLocator{ Ref: metav1.GroupKind{ Group: "catalog.appscode.com", @@ -398,27 +398,37 @@ func (r *Storage) toGenericResourceService(item unstructured.Unstructured, apiTy }, }) if err == nil { - var isExposed bool - var refs []kmapi.ObjectReference + var gw *catalogapi.Gateway for _, obj := range objs { - var binding catalogapi.GenericBinding - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), &binding); err != nil { - return nil, err - } - if binding.Status.Gateway != nil && - (binding.Status.Gateway.Hostname != "" || binding.Status.Gateway.IP != "") { - isExposed = true - refs = append(refs, kmapi.ObjectReference{ - Namespace: binding.Status.Gateway.Namespace, - Name: binding.Status.Gateway.Name, - }) - break + if gw == nil || obj.GetNamespace() == item.GetNamespace() { + var binding catalogapi.GenericBinding + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), &binding); err != nil { + return nil, err + } + + if binding.Status.Gateway != nil { + // prefer root binding + if obj.GetNamespace() == item.GetNamespace() { + gw = binding.Status.Gateway + break + } + // otherwise keep the first not nil gateway + gw = binding.Status.Gateway + } } } - if isExposed { + if gw != nil && + (gw.Hostname != "" || gw.IP != "") && + genres.Spec.Facilities.Exposed.Usage == rscoreapi.FacilityUnused { + genres.Spec.Facilities.Exposed.Usage = rscoreapi.FacilityUsed genres.Spec.Facilities.Exposed.Resource = rid - genres.Spec.Facilities.Exposed.Refs = refs + genres.Spec.Facilities.Exposed.Refs = []kmapi.ObjectReference{ + { + Namespace: gw.Namespace, + Name: gw.Name, + }, + } } } else if !meta.IsNoMatchError(err) { return nil, err diff --git a/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/generic_resource_service_types.go b/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/generic_resource_service_types.go index 20435663a..dcdd324dd 100644 --- a/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/generic_resource_service_types.go +++ b/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/generic_resource_service_types.go @@ -20,6 +20,7 @@ import ( kmapi "kmodules.xyz/client-go/api/v1" "kmodules.xyz/resource-metadata/apis/shared" + catalogapi "go.bytebuilders.dev/catalog/api/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -57,6 +58,8 @@ type GenericResourceServiceFacilities struct { Backup GenericResourceServiceFacilitator `json:"backup,omitempty"` Monitoring GenericResourceServiceFacilitator `json:"monitoring,omitempty"` Exec []ExecServiceFacilitator `json:"exec,omitempty"` + // +optional + Gateway *catalogapi.Gateway `json:"gateway,omitempty"` } type GenericResourceServiceFacilitator struct { diff --git a/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/openapi_generated.go b/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/openapi_generated.go index fd50b147a..b74c644b8 100644 --- a/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/openapi_generated.go +++ b/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/openapi_generated.go @@ -17594,11 +17594,16 @@ func schema_resource_metadata_apis_core_v1alpha1_GenericResourceServiceFacilitie }, }, }, + "gateway": { + SchemaProps: spec.SchemaProps{ + Ref: ref("go.bytebuilders.dev/catalog/api/v1alpha1.Gateway"), + }, + }, }, }, }, Dependencies: []string{ - "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ExecServiceFacilitator", "kmodules.xyz/resource-metadata/apis/core/v1alpha1.GenericResourceServiceFacilitator"}, + "go.bytebuilders.dev/catalog/api/v1alpha1.Gateway", "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ExecServiceFacilitator", "kmodules.xyz/resource-metadata/apis/core/v1alpha1.GenericResourceServiceFacilitator"}, } } diff --git a/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/zz_generated.deepcopy.go b/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/zz_generated.deepcopy.go index c6672a102..600800135 100644 --- a/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/zz_generated.deepcopy.go @@ -26,6 +26,7 @@ import ( shared "kmodules.xyz/resource-metadata/apis/shared" api "kmodules.xyz/resource-metrics/api" + apiv1alpha1 "go.bytebuilders.dev/catalog/api/v1alpha1" v1 "k8s.io/api/core/v1" resource "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -313,6 +314,11 @@ func (in *GenericResourceServiceFacilities) DeepCopyInto(out *GenericResourceSer (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Gateway != nil { + in, out := &in.Gateway, &out.Gateway + *out = new(apiv1alpha1.Gateway) + (*in).DeepCopyInto(*out) + } return } diff --git a/vendor/kmodules.xyz/resource-metadata/crds/core.k8s.appscode.com_genericresourceservices.yaml b/vendor/kmodules.xyz/resource-metadata/crds/core.k8s.appscode.com_genericresourceservices.yaml index 259665f25..70c8746e5 100644 --- a/vendor/kmodules.xyz/resource-metadata/crds/core.k8s.appscode.com_genericresourceservices.yaml +++ b/vendor/kmodules.xyz/resource-metadata/crds/core.k8s.appscode.com_genericresourceservices.yaml @@ -222,6 +222,125 @@ spec: required: - usage type: object + gateway: + properties: + hostname: + type: string + ip: + type: string + name: + type: string + namespace: + type: string + services: + description: Services is an optional configuration for services + used to expose database + items: + properties: + alias: + description: Alias represents the identifier of the + service. + type: string + ports: + items: + description: GatewayPort contains information on Gateway + service's port. + properties: + backendServicePort: + description: Number of the port to access the + backend service. + format: int32 + type: integer + name: + description: The name of this port within the + gateway service. + type: string + nodePort: + description: The port on each node on which this + gateway service is exposed when type is NodePort + or LoadBalancer. + format: int32 + type: integer + port: + description: The port that will be exposed by + the gateway service. + format: int32 + type: integer + required: + - port + type: object + type: array + required: + - alias + - ports + type: object + type: array + ui: + description: UI is an optional list of database web uis + items: + properties: + alias: + description: Alias represents the identifier of the + service. This should match the db ui chart name + type: string + helmRelease: + description: HelmRelease is the name of the helm release + used to deploy this ui The name format is typically + - + properties: + name: + default: "" + description: 'Name of the referent. This field is + effectively required, but due to backwards compatibility + is allowed to be empty. Instances of this type + with an empty value here are almost certainly + wrong. TODO: Add other useful fields. apiVersion, + kind, uid? More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Drop `kubebuilder:default` when controller-gen + doesn''t need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.' + type: string + type: object + x-kubernetes-map-type: atomic + port: + description: GatewayPort contains information on Gateway + service's port. + properties: + backendServicePort: + description: Number of the port to access the backend + service. + format: int32 + type: integer + name: + description: The name of this port within the gateway + service. + type: string + nodePort: + description: The port on each node on which this + gateway service is exposed when type is NodePort + or LoadBalancer. + format: int32 + type: integer + port: + description: The port that will be exposed by the + gateway service. + format: int32 + type: integer + required: + - port + type: object + url: + description: URL of the database ui + type: string + required: + - alias + - port + - url + type: object + type: array + required: + - name + - namespace + type: object monitoring: properties: refs: diff --git a/vendor/modules.txt b/vendor/modules.txt index a6e674ed7..75bcc58d1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2011,7 +2011,7 @@ kmodules.xyz/monitoring-agent-api/client ## explicit; go 1.22.0 kmodules.xyz/offshoot-api/api/v1 kmodules.xyz/offshoot-api/api/v2 -# kmodules.xyz/resource-metadata v0.18.13-0.20240830120231-189258047c19 +# kmodules.xyz/resource-metadata v0.18.13-0.20240831011752-f53d8b2924e9 ## explicit; go 1.22.1 kmodules.xyz/resource-metadata/apis/core/install kmodules.xyz/resource-metadata/apis/core/v1alpha1