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 Sep 21, 2023
1 parent 41ca569 commit 4c7b7bb
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 0 deletions.
101 changes: 101 additions & 0 deletions apis/bases/core.openstack.org_openstackcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,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
3 changes: 3 additions & 0 deletions apis/core/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const (
// OpenStackControlPlaneHorizonReadyCondition Status=True condition which indicates if Horizon is configured and operational
OpenStackControlPlaneHorizonReadyCondition condition.Type = "OpenStackControlPlaneHorizonReady"

// OpenStackControlPlaneExposeHorizonReadyCondition Status=True condition which indicates if Horizon is exposed via a route
OpenStackControlPlaneExposeHorizonReadyCondition condition.Type = "OpenStackControlPlaneExposeHorizonReady"

// OpenStackControlPlaneClientReadyCondition Status=True condition which indicates if OpenStackClient is configured and operational
OpenStackControlPlaneClientReadyCondition condition.Type = "OpenStackControlPlaneClientReady"

Expand Down
5 changes: 5 additions & 0 deletions apis/core/v1beta1/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ 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 Override `json:"apiOverride,omitempty"`
}

// CeilometerSection defines the desired state of OpenStack Telemetry services
Expand Down
1 change: 1 addition & 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.

101 changes: 101 additions & 0 deletions config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,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
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ spec:
networkAttachments:
- internalapi
horizon:
apiOverride:
route: {}
template:
replicas: 1
secret: osp-secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ spec:
networkAttachments:
- internalapi
horizon:
apiOverride:
route: {}
template:
replicas: 1
secret: osp-secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ spec:
networkAttachments:
- internalapi
horizon:
apiOverride:
route: {}
template:
replicas: 1
secret: osp-secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ spec:
networkAttachments:
- internalapi
horizon:
apiOverride:
route: {}
template:
replicas: 1
secret: osp-secret
Expand Down
67 changes: 67 additions & 0 deletions pkg/openstack/horizon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import (
"context"
"fmt"

"github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"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"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

horizonv1 "github.com/openstack-k8s-operators/horizon-operator/api/v1beta1"
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
)

Expand All @@ -29,11 +35,72 @@ func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackContro
return res, err
}
instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneHorizonReadyCondition)
instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneExposeHorizonReadyCondition)
return ctrl.Result{}, nil
}

// add selector to service overrides
/*
for _, endpointType := range []service.Endpoint{service.EndpointPublic, service.EndpointInternal} {
if instance.Spec.Horizon.Template.Override.Service == nil {
instance.Spec.Horizon.Template.Override.Service = map[string]service.RoutedOverrideSpec{}
}
instance.Spec.Horizon.Template.Override.Service[string(endpointType)] =
AddServiceComponentLabel(
ptr.To(instance.Spec.Horizon.Template.Override.Service[string(endpointType)]),
horizon.Name)
*/
serviceOverrides := map[service.Endpoint]service.RoutedOverrideSpec{}
if instance.Spec.Horizon.Template.Override.Service != nil {
serviceOverrides[service.EndpointPublic] = *instance.Spec.Horizon.Template.Override.Service
}

// add selector to service overrides
serviceOverrides[service.EndpointPublic] = AddServiceComponentLabel(
serviceOverrides[service.EndpointPublic],
horizon.Name)

// When component services got created check if there is the need to create a route
if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: "horizon", Namespace: instance.Namespace}, horizon); err != nil {
if !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
}

if horizon.Status.Conditions.IsTrue(condition.ExposeServiceReadyCondition) {
svcs, err := service.GetServicesListWithLabel(
ctx,
helper,
instance.Namespace,
map[string]string{common.AppSelector: horizon.Name},
)
if err != nil {
return ctrl.Result{}, err
}

var ctrlResult reconcile.Result
serviceOverrides, ctrlResult, err = EnsureRoute(
ctx,
instance,
helper,
horizon,
svcs,
serviceOverrides,
instance.Spec.Horizon.APIOverride.Route,
corev1beta1.OpenStackControlPlaneExposeHorizonReadyCondition,
)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}
}

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 = ptr.To(serviceOverrides[service.EndpointPublic])

err := controllerutil.SetControllerReference(helper.GetBeforeObject(), horizon, helper.GetScheme())
if err != nil {
return err
Expand Down

0 comments on commit 4c7b7bb

Please sign in to comment.