Skip to content

Commit

Permalink
Get the controlplane object to read some TLS parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
cescgina committed Jan 31, 2025
1 parent 04433af commit 71111be
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 70 deletions.
10 changes: 0 additions & 10 deletions api/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -652,16 +652,6 @@ spec:
description: ServiceUser - optional username used for this service
to register in keystone
type: string
tlsLevel:
default: PodLevel
description: |-
TLSLevel choose until what level should use TLS (terminate at the route,
at the pod or no TLS at all)
enum:
- Ingress
- PodLevel
- None
type: string
required:
- apiContainerImageURL
- apiServiceTemplate
Expand Down
7 changes: 0 additions & 7 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ type WatcherTemplate struct {
// APIOverride, provides the ability to override the generated
// manifest of several child resources.
APIOverride Override `json:"apiOverride,omitempty"`

// +kubebuilder:validation:Enum=Ingress;PodLevel;None
// +kubebuilder:validation:Optional
// +kubebuilder:default=PodLevel
// TLSLevel choose until what level should use TLS (terminate at the route,
// at the pod or no TLS at all)
TLSLevel string `json:"tlsLevel"`
}

// Override to override the generated manifest of several child resources.
Expand Down
10 changes: 0 additions & 10 deletions config/crd/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -652,16 +652,6 @@ spec:
description: ServiceUser - optional username used for this service
to register in keystone
type: string
tlsLevel:
default: PodLevel
description: |-
TLSLevel choose until what level should use TLS (terminate at the route,
at the pod or no TLS at all)
enum:
- Ingress
- PodLevel
- None
type: string
required:
- apiContainerImageURL
- apiServiceTemplate
Expand Down
7 changes: 7 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ rules:
- patch
- update
- watch
- apiGroups:
- core.openstack.org
resources:
- openstackcontrolplanes
verbs:
- get
- list
- apiGroups:
- keystone.openstack.org
resources:
Expand Down
70 changes: 52 additions & 18 deletions controllers/watcher_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

watcherv1beta1 "github.com/openstack-k8s-operators/watcher-operator/api/v1beta1"
Expand Down Expand Up @@ -144,13 +145,14 @@ func (e *Endpoints) GetEndptCertSecret(endpt service.Endpoint) *string {
func (ed *EndpointDetail) ensureRoute(
ctx context.Context,
helper *helper.Helper,
controlPlane *corev1beta1.OpenStackControlPlane,
) (ctrl.Result, error) {
if ed.Route.Create {
if ed.Service.OverrideSpec.EmbeddedLabelsAnnotations == nil {
ed.Service.OverrideSpec.EmbeddedLabelsAnnotations = &service.EmbeddedLabelsAnnotations{}
}

ctrlResult, err := ed.CreateRoute(ctx, helper)
ctrlResult, err := ed.CreateRoute(ctx, helper, controlPlane)
return ctrlResult, err
}

Expand All @@ -160,6 +162,7 @@ func (ed *EndpointDetail) ensureRoute(
func (ed *EndpointDetail) CreateRoute(
ctx context.Context,
helper *helper.Helper,
controlPlane *corev1beta1.OpenStackControlPlane,
) (ctrl.Result, error) {
// initialize the route with any custom provided route override
// per default use the service name as targetPortName if we don't have the annotation.
Expand Down Expand Up @@ -241,6 +244,12 @@ func (ed *EndpointDetail) CreateRoute(
Labels: util.MergeMaps(ed.Labels, map[string]string{serviceCertSelector: ""}),
Usages: nil,
}
if controlPlane.Spec.TLS.Ingress.Cert.Duration != nil {
certRequest.Duration = &controlPlane.Spec.TLS.Ingress.Cert.Duration.Duration
}
if controlPlane.Spec.TLS.Ingress.Cert.RenewBefore != nil {
certRequest.Duration = &controlPlane.Spec.TLS.Ingress.Cert.RenewBefore.Duration
}

// create the cert using the default issue for the endpointSpec
certSecret, ctrlResult, err = certmanager.EnsureCert(
Expand Down Expand Up @@ -338,14 +347,6 @@ const (
// serviceCertSelector selector passed to cert-manager to set on the
// service cert secret
serviceCertSelector = "service-cert"

// publicIssuerName name of the default public issuer name used in
// openstack-operator
publicIssuerName = "rootca-public"

// internalIssuerName name of the default internal issuer name used in
// openstack-operator
internalIssuerName = "rootca-public"
)

// end of helper types to expose services
Expand Down Expand Up @@ -389,6 +390,10 @@ func (r *WatcherReconciler) GetLogger(ctx context.Context) logr.Logger {
//+kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=rolebindings,verbs=get;list;watch;create;update;patch
//+kubebuilder:rbac:groups="security.openshift.io",resourceNames=anyuid,resources=securitycontextconstraints,verbs=use

// controlplane, should only be needed until watcher-operator is integrated
// into openstack-operator
// +kubebuilder:rbac:groups=core.openstack.org,resources=openstackcontrolplanes,verbs=get;list

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
//
Expand Down Expand Up @@ -632,11 +637,29 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
return ctrl.Result{}, err
}

controlPlaneLists := &corev1beta1.OpenStackControlPlaneList{}

listOps := []client.ListOption{
client.InNamespace(instance.Namespace),
}
err = r.Client.List(ctx, controlPlaneLists, listOps...)
if err != nil {
return ctrl.Result{}, err
}
if len(controlPlaneLists.Items) > 1 {
return ctrl.Result{}, fmt.Errorf("more than one OpenStackControlPlane found in namespace %s", instance.Namespace)
}
if len(controlPlaneLists.Items) == 0 {
// no control plane found
return ctrl.Result{}, fmt.Errorf("No OpenStackControlPlane found in namespace %s", instance.Namespace)
}
controlPlane := &controlPlaneLists.Items[0]
oldSpec := instance.DeepCopy().Spec.APIServiceTemplate
ctrlResult, err = r.exposeEndpoints(
ctx,
helper,
instance,
controlPlane,
)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
Expand Down Expand Up @@ -1263,6 +1286,7 @@ func (r *WatcherReconciler) exposeEndpoints(
ctx context.Context,
helper *helper.Helper,
instance *watcherv1beta1.Watcher,
controlPlane *corev1beta1.OpenStackControlPlane,

) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Expand Down Expand Up @@ -1292,7 +1316,8 @@ func (r *WatcherReconciler) exposeEndpoints(
}

ed.Service.OverrideSpec = instance.Spec.APIServiceTemplate.Override.Service[ed.Type]
if instance.Spec.TLSLevel == "PodLevel" {

if controlPlane.Spec.TLS.PodLevel.Enabled {
ed.Service.TLS.Enabled = true
ed.Service.TLS.CertName = fmt.Sprintf("%s-svc", ed.Name)
} else {
Expand All @@ -1311,7 +1336,7 @@ func (r *WatcherReconciler) exposeEndpoints(

// we have TLS termination at the ingress if any of PodLevel or
// Ingress tlslevels are selected
if instance.Spec.TLSLevel != "None" {
if controlPlane.Spec.TLS.Ingress.Enabled {
// TLS for route enabled if public endpoint TLS is true
ed.Route.TLS.Enabled = true
ed.Route.TLS.CertName = fmt.Sprintf("%s-route", ed.Name)
Expand All @@ -1330,11 +1355,8 @@ func (r *WatcherReconciler) exposeEndpoints(
return ctrl.Result{}, err
}
} else {
// we don't support custom cert issuers for now, just rely
// on the default ones from the openstack-operator
ed.Route.TLS.IssuerName = publicIssuerName
ed.Route.TLS.IssuerName = controlPlane.GetPublicIssuer()
}

}

if ed.Service.TLS.Enabled {
Expand Down Expand Up @@ -1369,7 +1391,7 @@ func (r *WatcherReconciler) exposeEndpoints(
} else {
// issue a certificate for public pod virthost
certRequest := certmanager.CertificateRequest{
IssuerName: publicIssuerName,
IssuerName: controlPlane.GetPublicIssuer(),
CertName: ed.Service.TLS.CertName,
Hostnames: []string{
fmt.Sprintf("%s.%s.svc", ed.Name, instance.Namespace),
Expand All @@ -1384,6 +1406,12 @@ func (r *WatcherReconciler) exposeEndpoints(
if len(addSubjNames) > 0 {
certRequest.Hostnames = append(certRequest.Hostnames, addSubjNames...)
}
if controlPlane.Spec.TLS.Ingress.Cert.Duration != nil {
certRequest.Duration = &controlPlane.Spec.TLS.Ingress.Cert.Duration.Duration
}
if controlPlane.Spec.TLS.Ingress.Cert.RenewBefore != nil {
certRequest.RenewBefore = &controlPlane.Spec.TLS.Ingress.Cert.RenewBefore.Duration
}

certSecret, ctrlResult, err := certmanager.EnsureCert(
ctx,
Expand All @@ -1398,7 +1426,7 @@ func (r *WatcherReconciler) exposeEndpoints(
}
}

ctrlResult, err := ed.ensureRoute(ctx, helper)
ctrlResult, err := ed.ensureRoute(ctx, helper, controlPlane)
if err != nil || (ctrlResult != ctrl.Result{}) {
return ctrlResult, err
}
Expand All @@ -1408,7 +1436,7 @@ func (r *WatcherReconciler) exposeEndpoints(
// create certificate for internal pod virthost
// request certificate
certRequest := certmanager.CertificateRequest{
IssuerName: internalIssuerName,
IssuerName: controlPlane.GetInternalIssuer(),
CertName: ed.Service.TLS.CertName,
Hostnames: []string{
fmt.Sprintf("%s.%s.svc", ed.Name, instance.Namespace),
Expand All @@ -1423,6 +1451,12 @@ func (r *WatcherReconciler) exposeEndpoints(
if len(addSubjNames) > 0 {
certRequest.Hostnames = append(certRequest.Hostnames, addSubjNames...)
}
if controlPlane.Spec.TLS.PodLevel.Internal.Cert.Duration != nil {
certRequest.Duration = &controlPlane.Spec.TLS.PodLevel.Internal.Cert.Duration.Duration
}
if controlPlane.Spec.TLS.PodLevel.Internal.Cert.RenewBefore != nil {
certRequest.RenewBefore = &controlPlane.Spec.TLS.PodLevel.Internal.Cert.RenewBefore.Duration
}

certSecret, ctrlResult, err := certmanager.EnsureCert(
ctx,
Expand Down
44 changes: 35 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241029151503-4878b3fa3333
github.com/openstack-k8s-operators/mariadb-operator/api v0.5.0
github.com/openstack-k8s-operators/openstack-operator/apis v0.5.0
go.uber.org/zap v1.27.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.29.10
Expand All @@ -23,7 +24,29 @@ require (
sigs.k8s.io/controller-runtime v0.17.6
)

require sigs.k8s.io/gateway-api v1.0.0 // indirect
require (
github.com/openstack-k8s-operators/barbican-operator/api v0.4.1-0.20241016144515-afdcc747d15d // indirect
github.com/openstack-k8s-operators/cinder-operator/api v0.4.1-0.20241016131023-405a20c57587 // indirect
github.com/openstack-k8s-operators/designate-operator/api v0.1.1-0.20241017142748-ba17591a0731 // indirect
github.com/openstack-k8s-operators/glance-operator/api v0.4.1-0.20241018102005-b38ee106b37d // indirect
github.com/openstack-k8s-operators/heat-operator/api v0.4.1-0.20241018100621-bfd90678fca0 // indirect
github.com/openstack-k8s-operators/horizon-operator/api v0.4.1-0.20241017085952-cdfbe98abf09 // indirect
github.com/openstack-k8s-operators/ironic-operator/api v0.4.1-0.20241016184335-60fb2a3ccf1a // indirect
github.com/openstack-k8s-operators/lib-common/modules/storage v0.4.1-0.20241014140317-e5c35d28f3af // indirect
github.com/openstack-k8s-operators/manila-operator/api v0.4.1-0.20241016213652-f06ae482a4bf // indirect
github.com/openstack-k8s-operators/neutron-operator/api v0.4.1-0.20241018124837-82fbf3bc498e // indirect
github.com/openstack-k8s-operators/nova-operator/api v0.4.1-0.20241017115306-c3ef3bef3be5 // indirect
github.com/openstack-k8s-operators/octavia-operator/api v0.4.1-0.20241017154659-930f3479c2e4 // indirect
github.com/openstack-k8s-operators/ovn-operator/api v0.4.1-0.20241018052304-b2f1022e67a0 // indirect
github.com/openstack-k8s-operators/placement-operator/api v0.4.1-0.20241016073632-718abf1faec1 // indirect
github.com/openstack-k8s-operators/swift-operator/api v0.4.1-0.20241016113221-7b5e6572638c // indirect
github.com/openstack-k8s-operators/telemetry-operator/api v0.4.1-0.20241018110953-a5889858101b // indirect
github.com/rabbitmq/cluster-operator/v2 v2.11.0 // indirect
github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring v0.71.0-rhobs1 // indirect
github.com/rhobs/observability-operator v0.3.1 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
sigs.k8s.io/gateway-api v1.0.0 // indirect
)

require (
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -41,7 +64,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
Expand All @@ -56,19 +79,19 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241029151503-4878b3fa3333 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
Expand All @@ -90,3 +113,6 @@ replace github.com/openstack-k8s-operators/watcher-operator/api => ./api
// mschuppert: map to latest commit from release-4.16 tag
// must consistent within modules and service operators
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging

// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.9.0_patches_tag)
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20241017142550-a3524acedd49 //allow-merging
Loading

0 comments on commit 71111be

Please sign in to comment.