Skip to content

Commit

Permalink
Create horizon route and svc overrides
Browse files Browse the repository at this point in the history
Creates the route for the horizon, also allows to customize the
route via override.

Generats the service override for the env with what is configured in
the externalEndpoints, or specified in the service template override.

Depends-On: openstack-k8s-operators/lib-common#313
Depends-On: openstack-k8s-operators/keystone-operator#289
Depends-On: openstack-k8s-operators/horizon-operator#202

Jira: OSP-26690
  • Loading branch information
stuggi committed Aug 16, 2023
1 parent 361639f commit ebefd32
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 4 deletions.
105 changes: 103 additions & 2 deletions apis/bases/core.openstack.org_openstackcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3937,6 +3937,107 @@ spec:
type: object
horizon:
properties:
apiOverride:
properties:
route:
properties:
metadata:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
type: object
spec:
properties:
alternateBackends:
items:
properties:
kind:
enum:
- Service
- ""
type: string
name:
type: string
weight:
format: int32
maximum: 256
minimum: 0
type: integer
type: object
maxItems: 3
type: array
host:
maxLength: 253
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
type: string
path:
pattern: ^/
type: string
port:
properties:
targetPort:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- targetPort
type: object
subdomain:
maxLength: 253
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
type: string
tls:
properties:
caCertificate:
type: string
certificate:
type: string
destinationCACertificate:
type: string
insecureEdgeTerminationPolicy:
type: string
key:
type: string
termination:
enum:
- edge
- reencrypt
- passthrough
type: string
required:
- termination
type: object
to:
properties:
kind:
enum:
- Service
- ""
type: string
name:
type: string
weight:
format: int32
maximum: 256
minimum: 0
type: integer
type: object
wildcardPolicy:
enum:
- None
- Subdomain
- ""
type: string
type: object
type: object
type: object
enabled:
default: false
type: boolean
Expand Down Expand Up @@ -3967,7 +4068,7 @@ spec:
override:
properties:
service:
items:
additionalProperties:
properties:
endpointURL:
type: string
Expand Down Expand Up @@ -4013,7 +4114,7 @@ spec:
type: string
type: object
type: object
type: array
type: object
type: object
preserveJobs:
default: false
Expand Down
12 changes: 12 additions & 0 deletions apis/core/v1beta1/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,18 @@ type HorizonSection struct {
// +kubebuilder:validation:Optional
// Template - Overrides to use when creating the Horizon services
Template horizonv1.HorizonSpec `json:"template,omitempty"`

// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec
// APIOverride, provides the ability to override the generated manifest of several child resources.
APIOverride HorizonOverride `json:"apiOverride,omitempty"`
}

// HorizonOverride to override the generated manifest of several child resources.
type HorizonOverride struct {
// +kubebuilder:validation:Optional
// Route overrides to use when creating the public service endpoint
Route *route.OverrideSpec `json:"route,omitempty"`
}

// CeilometerSection defines the desired state of OpenStack Telemetry services
Expand Down
21 changes: 21 additions & 0 deletions apis/core/v1beta1/zz_generated.deepcopy.go

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

105 changes: 103 additions & 2 deletions config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3937,6 +3937,107 @@ spec:
type: object
horizon:
properties:
apiOverride:
properties:
route:
properties:
metadata:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
type: object
spec:
properties:
alternateBackends:
items:
properties:
kind:
enum:
- Service
- ""
type: string
name:
type: string
weight:
format: int32
maximum: 256
minimum: 0
type: integer
type: object
maxItems: 3
type: array
host:
maxLength: 253
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
type: string
path:
pattern: ^/
type: string
port:
properties:
targetPort:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- targetPort
type: object
subdomain:
maxLength: 253
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
type: string
tls:
properties:
caCertificate:
type: string
certificate:
type: string
destinationCACertificate:
type: string
insecureEdgeTerminationPolicy:
type: string
key:
type: string
termination:
enum:
- edge
- reencrypt
- passthrough
type: string
required:
- termination
type: object
to:
properties:
kind:
enum:
- Service
- ""
type: string
name:
type: string
weight:
format: int32
maximum: 256
minimum: 0
type: integer
type: object
wildcardPolicy:
enum:
- None
- Subdomain
- ""
type: string
type: object
type: object
type: object
enabled:
default: false
type: boolean
Expand Down Expand Up @@ -3967,7 +4068,7 @@ spec:
override:
properties:
service:
items:
additionalProperties:
properties:
endpointURL:
type: string
Expand Down Expand Up @@ -4013,7 +4114,7 @@ spec:
type: string
type: object
type: object
type: array
type: object
type: object
preserveJobs:
default: false
Expand Down
53 changes: 53 additions & 0 deletions pkg/openstack/horizon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"fmt"

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/service"

"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

Expand All @@ -31,9 +33,48 @@ func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackContro
instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneHorizonReadyCondition)
return ctrl.Result{}, nil
}

// Create service overrides to pass into the service CR
// and expose the public endpoint using a route per default.
// Any trailing path will be added on the service-operator level.
var endpoints = map[service.Endpoint]endpoint.Data{
service.EndpointPublic: {},
service.EndpointInternal: {},
}
serviceDetails := []ServiceDetails{}

serviceOverrides := map[string]service.OverrideSpec{}
for endpointType := range endpoints {

sd := ServiceDetails{
ServiceName: horizon.Name,
Namespace: instance.Namespace,
Endpoint: endpointType,
ServiceOverrideSpec: instance.Spec.Horizon.Template.Override.Service,
RouteOverrideSpec: instance.Spec.Horizon.APIOverride.Route,
}

svcOverride, ctrlResult, err := sd.CreateRouteAndServiceOverride(ctx, instance, helper)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

serviceDetails = append(
serviceDetails,
sd,
)
if svcOverride != nil {
serviceOverrides[string(endpointType)] = *svcOverride
}
}

helper.GetLogger().Info("Reconcile Horizon", "horizon.Namespace", instance.Namespace, "horizon.Name", "horizon")
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), horizon, func() error {
instance.Spec.Horizon.Template.DeepCopyInto(&horizon.Spec)
horizon.Spec.Override.Service = serviceOverrides

err := controllerutil.SetControllerReference(helper.GetBeforeObject(), horizon, helper.GetScheme())
if err != nil {
return err
Expand Down Expand Up @@ -64,5 +105,17 @@ func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackContro
corev1beta1.OpenStackControlPlaneHorizonReadyRunningMessage))
}

for _, sd := range serviceDetails {
// Add the service CR to the ownerRef list of the route to prevent the route being deleted
// before the service is deleted. Otherwise this can result cleanup issues which require
// the endpoint to be reachable.
// If ALL objects in the list have been deleted, this object will be garbage collected.
// https://github.com/kubernetes/apimachinery/blob/15d95c0b2af3f4fcf46dce24105e5fbb9379af5a/pkg/apis/meta/v1/types.go#L240-L247
err = sd.AddOwnerRef(ctx, helper, horizon)
if err != nil {
return ctrl.Result{}, err
}
}

return ctrl.Result{}, nil
}

0 comments on commit ebefd32

Please sign in to comment.