Skip to content

Commit

Permalink
feat(api): add ExternalHost property for routes (backport #877) (#878)
Browse files Browse the repository at this point in the history
* feat(api): add ExternalHost property for routes (#877)

* feat(api): add ExternalHost property for routes

* Handle reverting hostname to default

* Host is immutable after creation

(cherry picked from commit 2fc2faa)

# Conflicts:
#	bundle/manifests/cryostat-operator.clusterserviceversion.yaml

* Fix conflicts

---------

Co-authored-by: Elliott Baron <[email protected]>
  • Loading branch information
mergify[bot] and ebaron authored Jun 7, 2024
1 parent 1bf4a2c commit 1c85ed6
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/v1beta2/cryostat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ type ServiceConfigList struct {
// On OpenShift, a Route is created by default. On Kubernetes, an Ingress will
// be created if the IngressSpec is defined within this NetworkConfiguration.
type NetworkConfiguration struct {
// Externally routable host to be used to reach this
// Cryostat service. Used to define a Route's host on
// OpenShift when it is first created.
// On Kubernetes, define this using "spec.ingressSpec".
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
ExternalHost *string `json:"externalHost,omitempty"`
// Configuration for an Ingress object.
// Currently subpaths are not supported, so unique hosts must be specified
// (if a single external IP is being used) to differentiate between ingresses/services.
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

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 @@ -30,7 +30,7 @@ metadata:
capabilities: Seamless Upgrades
categories: Monitoring, Developer Tools
containerImage: quay.io/cryostat/cryostat-operator:3.0.0-dev
createdAt: "2024-06-07T18:04:27Z"
createdAt: "2024-06-07T20:23:16Z"
description: JVM monitoring and profiling tool
operatorframework.io/initialization-resource: |-
{
Expand Down Expand Up @@ -151,6 +151,9 @@ spec:
- description: Annotations to add to the Ingress or Route during its creation.
displayName: Annotations
path: networkOptions.coreConfig.annotations
- description: Externally routable host to be used to reach this Cryostat service. Used to define a Route's host on OpenShift when it is first created. On Kubernetes, define this using "spec.ingressSpec".
displayName: External Host
path: networkOptions.coreConfig.externalHost
- description: Configuration for an Ingress object. Currently subpaths are not supported, so unique hosts must be specified (if a single external IP is being used) to differentiate between ingresses/services.
displayName: Ingress Spec
path: networkOptions.coreConfig.ingressSpec
Expand Down
7 changes: 7 additions & 0 deletions bundle/manifests/operator.cryostat.io_cryostats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4991,6 +4991,13 @@ spec:
description: Annotations to add to the Ingress or Route during
its creation.
type: object
externalHost:
description: |-
Externally routable host to be used to reach this
Cryostat service. Used to define a Route's host on
OpenShift when it is first created.
On Kubernetes, define this using "spec.ingressSpec".
type: string
ingressSpec:
description: |-
Configuration for an Ingress object.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/operator.cryostat.io_cryostats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4980,6 +4980,13 @@ spec:
description: Annotations to add to the Ingress or Route during
its creation.
type: object
externalHost:
description: |-
Externally routable host to be used to reach this
Cryostat service. Used to define a Route's host on
OpenShift when it is first created.
On Kubernetes, define this using "spec.ingressSpec".
type: string
ingressSpec:
description: |-
Configuration for an Ingress object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ spec:
- description: Annotations to add to the Ingress or Route during its creation.
displayName: Annotations
path: networkOptions.coreConfig.annotations
- description: Externally routable host to be used to reach this Cryostat service.
Used to define a Route's host on OpenShift when it is first created. On
Kubernetes, define this using "spec.ingressSpec".
displayName: External Host
path: networkOptions.coreConfig.externalHost
- description: Configuration for an Ingress object. Currently subpaths are not
supported, so unique hosts must be specified (if a single external IP is
being used) to differentiate between ingresses/services.
Expand Down
23 changes: 23 additions & 0 deletions internal/controllers/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,28 @@ func (c *controllerTest) commonTests() {
t.checkRoute(t.NewCustomCoreRoute())
})
})
Context("containing core route host", func() {
BeforeEach(func() {
t.objs = append(t.objs, t.NewCryostatWithCoreRouteHost().Object)
})
It("should create the route as described", func() {
t.checkRoute(t.NewCustomHostCoreRoute())
})
Context("changing host after creation", func() {
JustBeforeEach(func() {
// Remove custom route host from CR
cr := t.getCryostatInstance()
cr.Spec.NetworkOptions = t.NewCryostat().Spec.NetworkOptions
t.updateCryostatInstance(cr)

// Reconcile again
t.reconcileCryostatFully()
})
It("should leave the route as-is", func() {
t.checkRoute(t.NewCustomHostCoreRoute())
})
})
})
})
Context("with security options", func() {
JustBeforeEach(func() {
Expand Down Expand Up @@ -2113,6 +2135,7 @@ func (t *cryostatTestInput) checkRoute(expected *openshiftv1.Route) *openshiftv1
Expect(err).ToNot(HaveOccurred())

t.checkMetadata(route, expected)
Expect(route.Spec.Host).To(Equal(expected.Spec.Host))
Expect(route.Spec.To).To(Equal(expected.Spec.To))
Expect(route.Spec.Port).To(Equal(expected.Spec.Port))
Expect(route.Spec.TLS).To(Equal(expected.Spec.TLS))
Expand Down
6 changes: 6 additions & 0 deletions internal/controllers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func (r *Reconciler) createOrUpdateRoute(ctx context.Context, route *routev1.Rou
route.Spec.To.Name = svc.Name
route.Spec.Port = &routev1.RoutePort{TargetPort: exposePort.TargetPort}
route.Spec.TLS = routeTLS

// If a custom host has been provided, specify that in the route.
// Modifying the route's host after creation appears to have no effect
if route.CreationTimestamp.IsZero() && config.ExternalHost != nil {
route.Spec.Host = *config.ExternalHost
}
return nil
})
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions internal/test/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ func (r *TestResources) NewCryostatWithCoreNetworkOptions() *model.CryostatInsta
return cr
}

func (r *TestResources) NewCryostatWithCoreRouteHost() *model.CryostatInstance {
cr := r.NewCryostat()
cr.Spec.NetworkOptions = &operatorv1beta2.NetworkConfigurationList{
CoreConfig: &operatorv1beta2.NetworkConfiguration{
ExternalHost: &[]string{"cryostat.example.com"}[0],
},
}
return cr
}

func (r *TestResources) NewCryostatWithReportsResources() *model.CryostatInstance {
cr := r.NewCryostat()
cr.Spec.ReportOptions = &operatorv1beta2.ReportConfiguration{
Expand Down Expand Up @@ -2311,6 +2321,12 @@ func (r *TestResources) NewCustomCoreRoute() *routev1.Route {
return route
}

func (r *TestResources) NewCustomHostCoreRoute() *routev1.Route {
route := r.NewCoreRoute()
route.Spec.Host = "cryostat.example.com"
return route
}

func (r *TestResources) newRoute(name string, port int) *routev1.Route {
var routeTLS *routev1.TLSConfig
if !r.TLS {
Expand Down

0 comments on commit 1c85ed6

Please sign in to comment.