Skip to content

Commit

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

Jira: OSP-26690
  • Loading branch information
stuggi committed Aug 17, 2023
1 parent 880de4a commit 0338bca
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 20 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 @@ -4906,6 +4906,107 @@ spec:
type: object
manila:
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
5 changes: 5 additions & 0 deletions apis/core/v1beta1/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ type ManilaSection struct {
// +kubebuilder:validation:Optional
// Template - Overrides to use when creating Manila Resources
Template manilav1.ManilaSpec `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"`
}

// HorizonSection defines the desired state of Horizon 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 @@ -4906,6 +4906,107 @@ spec:
type: object
manila:
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 @@ -121,14 +121,15 @@ spec:
template:
secret: osp-secret
manila:
apiOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
template:
manilaAPI:
replicas: 1
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
networkAttachments:
- internalapi
manilaScheduler:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ spec:
template:
secret: osp-secret
manila:
apiOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
template:
manilaAPI:
replicas: 1
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
networkAttachments:
- internalapi
manilaScheduler:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ spec:
template:
secret: osp-secret
manila:
apiOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
template:
manilaAPI:
replicas: 1
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
networkAttachments:
- internalapi
manilaScheduler:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,15 @@ spec:
template:
secret: osp-secret
manila:
apiOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
template:
manilaAPI:
replicas: 1
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
networkAttachments:
- internalapi
manilaScheduler:
Expand Down
46 changes: 46 additions & 0 deletions pkg/openstack/manila.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"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"

Expand All @@ -32,9 +33,42 @@ func ReconcileManila(ctx context.Context, instance *corev1beta1.OpenStackControl
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.
serviceOverrides := map[string]service.OverrideSpec{}
serviceDetails := []ServiceDetails{}
for _, endpointType := range []service.Endpoint{service.EndpointPublic, service.EndpointInternal} {

sd := ServiceDetails{
ServiceName: manila.Name,
Namespace: instance.Namespace,
Endpoint: endpointType,
ServiceOverrideSpec: instance.Spec.Manila.Template.ManilaAPI.Override.Service,
RouteOverrideSpec: instance.Spec.Manila.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,
)

serviceOverrides[string(endpointType)] = *svcOverride
}
instance.Status.Conditions.MarkTrue(corev1beta1.OpenStackControlPlaneServiceOverrideReadyCondition, corev1beta1.OpenStackControlPlaneServiceOverrideReadyMessage)

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

if manila.Spec.Secret == "" {
manila.Spec.Secret = instance.Spec.Secret
}
Expand Down Expand Up @@ -90,5 +124,17 @@ func ReconcileManila(ctx context.Context, instance *corev1beta1.OpenStackControl
corev1beta1.OpenStackControlPlaneManilaReadyRunningMessage))
}

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, manila)
if err != nil {
return ctrl.Result{}, err
}
}

return ctrl.Result{}, nil
}

0 comments on commit 0338bca

Please sign in to comment.