Skip to content

Commit

Permalink
Create octaviaapi route and svc endpoint overrides
Browse files Browse the repository at this point in the history
Creates the route for the octaviaapi, 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/octavia-operator#171

Jira: OSP-26690
  • Loading branch information
stuggi committed Sep 26, 2023
1 parent 0975f61 commit f2a34af
Show file tree
Hide file tree
Showing 7 changed files with 924 additions and 0 deletions.
429 changes: 429 additions & 0 deletions apis/bases/core.openstack.org_openstackcontrolplanes.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions apis/core/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ const (

// OpenStackControlPlaneRedisReadyCondition Status=True condition which indicates if Redis is configured and operational
OpenStackControlPlaneRedisReadyCondition condition.Type = "OpenStackControlPlaneRedisReady"

// OpenStackControlPlaneExposeOctaviaReadyCondition Status=True condition which indicates if Octavia is exposed via a route
OpenStackControlPlaneExposeOctaviaReadyCondition condition.Type = "OpenStackControlPlaneExposeOctaviaReady"
)

// OpenStackControlPlane Reasons used by API objects.
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 @@ -540,6 +540,11 @@ type OctaviaSection struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// Template - Overrides to use when creating Octavia Resources
Template octaviav1.OctaviaSpec `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"`
}

// RedisSection defines the desired state of the Redis service
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.

429 changes: 429 additions & 0 deletions config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ spec:
- description: Template - Overrides to use when creating the Nova services
displayName: Template
path: nova.template
- description: APIOverride, provides the ability to override the generated manifest
of several child resources.
displayName: APIOverride
path: octavia.apiOverride
- description: Enabled - Whether the Octavia service should be deployed and
managed
displayName: Enabled
Expand Down
53 changes: 53 additions & 0 deletions pkg/openstack/octavia.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ 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"

octaviav1 "github.com/openstack-k8s-operators/octavia-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"
ctrl "sigs.k8s.io/controller-runtime"
)

Expand All @@ -45,9 +50,57 @@ func ReconcileOctavia(ctx context.Context, instance *corev1beta1.OpenStackContro
return res, err
}
instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneOctaviaReadyCondition)
instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneExposeOctaviaReadyCondition)
return ctrl.Result{}, nil
}

// add selector to service overrides
for _, endpointType := range []service.Endpoint{service.EndpointPublic, service.EndpointInternal} {
if instance.Spec.Octavia.Template.OctaviaAPI.Override.Service == nil {
instance.Spec.Octavia.Template.OctaviaAPI.Override.Service = map[service.Endpoint]service.RoutedOverrideSpec{}
}
instance.Spec.Octavia.Template.OctaviaAPI.Override.Service[endpointType] =
AddServiceComponentLabel(
instance.Spec.Octavia.Template.OctaviaAPI.Override.Service[endpointType],
octavia.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: "octavia", Namespace: instance.Namespace}, octavia); err != nil {
if !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
}

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

var ctrlResult reconcile.Result
instance.Spec.Octavia.Template.OctaviaAPI.Override.Service, ctrlResult, err = EnsureRoute(
ctx,
instance,
helper,
octavia,
svcs,
instance.Spec.Octavia.Template.OctaviaAPI.Override.Service,
instance.Spec.Octavia.APIOverride.Route,
corev1beta1.OpenStackControlPlaneExposeOctaviaReadyCondition,
)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}
}

helper.GetLogger().Info("Reconciling Octavia", "Octavia.Namespace", instance.Namespace, "Octavia.Name", octavia.Name)
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), octavia, func() error {
instance.Spec.Octavia.Template.DeepCopyInto(&octavia.Spec)
Expand Down

0 comments on commit f2a34af

Please sign in to comment.