Skip to content

Commit

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

Jira: OSP-26690
  • Loading branch information
stuggi committed Aug 14, 2023
1 parent 8f2cd68 commit 7fe8ae1
Show file tree
Hide file tree
Showing 9 changed files with 898 additions and 0 deletions.
370 changes: 370 additions & 0 deletions apis/bases/core.openstack.org_openstackcontrolplanes.yaml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions apis/core/v1beta1/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,16 @@ type HeatSection struct {
//+operator-sdk:csv:customresourcedefinitions:type=spec
// Template - Overrides to use when creating the Heat services
Template heatv1.HeatSpec `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"`

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

// IronicSection defines the desired state of Ironic services
Expand Down
2 changes: 2 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.

370 changes: 370 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 @@ -184,6 +184,18 @@ spec:
ipAddressPool: internalapi
sharedIP: false
heat:
apiOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
cnfAPIOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
enabled: false
template:
databaseInstance: openstack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ spec:
ipAddressPool: internalapi
sharedIP: false
heat:
apiOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
cnfAPIOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
enabled: false
template:
databaseInstance: openstack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ spec:
ipAddressPool: internalapi
sharedIP: false
heat:
apiOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
cnfAPIOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
enabled: false
template:
databaseInstance: openstack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ spec:
ipAddressPool: internalapi
sharedIP: false
heat:
apiOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
cnfAPIOverride:
externalEndpoints:
- endpoint: internal
ipAddressPool: internalapi
loadBalancerIPs:
- 172.17.0.80
enabled: false
template:
databaseInstance: openstack
Expand Down
98 changes: 98 additions & 0 deletions pkg/openstack/heat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ 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"

heatv1 "github.com/openstack-k8s-operators/heat-operator/api/v1beta1"
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
ctrl "sigs.k8s.io/controller-runtime"
)

Expand All @@ -31,9 +35,81 @@ func ReconcileHeat(ctx context.Context, instance *corev1beta1.OpenStackControlPl
instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneHeatReadyCondition)
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{}

// HeatAPI
apiServiceOverrides := []service.OverrideSpec{}
for endpointType := range endpoints {

sd := ServiceDetails{
ServiceName: heat.Name + "-api",
Namespace: instance.Namespace,
Endpoint: endpointType,
ExternalEndpoints: instance.Spec.Heat.APIOverride.ExternalEndpoints,
ServiceOverrideSpec: instance.Spec.Heat.Template.HeatAPI.Override.Service,
RouteOverrideSpec: instance.Spec.Heat.APIOverride.Route,
}

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

serviceDetails = append(
serviceDetails,
sd,
)
if svcOverride != nil {
apiServiceOverrides = append(apiServiceOverrides, *svcOverride)
}
}

// HeatCfnAPI
cfnAPIServiceOverrides := []service.OverrideSpec{}
for endpointType := range endpoints {

sd := ServiceDetails{
ServiceName: heat.Name + "-cfnapi",
Namespace: instance.Namespace,
Endpoint: endpointType,
ExternalEndpoints: instance.Spec.Heat.APIOverride.ExternalEndpoints,
ServiceOverrideSpec: instance.Spec.Heat.Template.HeatAPI.Override.Service,
RouteOverrideSpec: instance.Spec.Heat.APIOverride.Route,
}

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

serviceDetails = append(
serviceDetails,
sd,
)
if svcOverride != nil {
cfnAPIServiceOverrides = append(cfnAPIServiceOverrides, *svcOverride)
}
}
instance.Status.Conditions.MarkTrue(corev1beta1.OpenStackControlPlaneServiceOverrideReadyCondition, corev1beta1.OpenStackControlPlaneServiceOverrideReadyMessage)

helper.GetLogger().Info("Reconcile heat", "heat.Namespace", instance.Namespace, "heat.Name", "heat")
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), heat, func() error {
instance.Spec.Heat.Template.DeepCopyInto(&heat.Spec)
heat.Spec.HeatAPI.Override.Service = apiServiceOverrides
heat.Spec.HeatCfnAPI.Override.Service = cfnAPIServiceOverrides

err := controllerutil.SetControllerReference(helper.GetBeforeObject(), heat, helper.GetScheme())
if err != nil {
return err
Expand Down Expand Up @@ -64,5 +140,27 @@ func ReconcileHeat(ctx context.Context, instance *corev1beta1.OpenStackControlPl
corev1beta1.OpenStackControlPlaneHeatReadyRunningMessage))
}

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
scheme := runtime.NewScheme()
gvk := schema.GroupVersionKind{
Group: heatv1.GroupVersion.Group,
Version: heatv1.GroupVersion.Version,
Kind: heat.Kind,
}

// Add the GVK to the scheme
scheme.AddKnownTypeWithName(gvk, &heatv1.Heat{})

err = sd.AddOwnerRef(ctx, helper, heat, scheme)
if err != nil {
return ctrl.Result{}, err
}
}

return ctrl.Result{}, nil
}

0 comments on commit 7fe8ae1

Please sign in to comment.