Skip to content

Commit

Permalink
Include Gateway info in GenericResourceService
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Aug 31, 2024
1 parent 23baf7a commit d9204dd
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 22 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
44 changes: 27 additions & 17 deletions pkg/registry/core/resourceservice/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
<alias>-<db-name>
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:
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d9204dd

Please sign in to comment.