Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NETOBSERV-773 Copy certificates across namespaces #283

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1alpha1/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ type CertificateReference struct {
// name of the config map or secret containing certificates
Name string `json:"name,omitempty"`

// namespace of the config map or secret containing certificates. If omitted, assumes same namespace as where NetObserv is deployed.
// If the namespace is different, the config map or the secret will be copied so that it can be mounted as required.
// +optional
Namespace string `json:"namespace,omitempty"`

// certFile defines the path to the certificate file name within the config map or secret
CertFile string `json:"certFile,omitempty"`

Expand Down
52 changes: 52 additions & 0 deletions bundle/manifests/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,14 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret
containing certificates. If omitted, assumes same
namespace as where NetObserv is deployed. If the
namespace is different, the config map or the
secret will be copied so that it can be mounted
as required.
type: string
type:
description: 'type for the certificate reference:
"configmap" or "secret"'
Expand Down Expand Up @@ -1050,6 +1058,14 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret
containing certificates. If omitted, assumes same
namespace as where NetObserv is deployed. If the
namespace is different, the config map or the
secret will be copied so that it can be mounted
as required.
type: string
type:
description: 'type for the certificate reference:
"configmap" or "secret"'
Expand Down Expand Up @@ -1110,6 +1126,13 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret containing
certificates. If omitted, assumes same namespace as
where NetObserv is deployed. If the namespace is different,
the config map or the secret will be copied so that
it can be mounted as required.
type: string
type:
description: 'type for the certificate reference: "configmap"
or "secret"'
Expand Down Expand Up @@ -1146,6 +1169,13 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret containing
certificates. If omitted, assumes same namespace as
where NetObserv is deployed. If the namespace is different,
the config map or the secret will be copied so that
it can be mounted as required.
type: string
type:
description: 'type for the certificate reference: "configmap"
or "secret"'
Expand Down Expand Up @@ -1264,6 +1294,13 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret containing
certificates. If omitted, assumes same namespace as
where NetObserv is deployed. If the namespace is different,
the config map or the secret will be copied so that
it can be mounted as required.
type: string
type:
description: 'type for the certificate reference: "configmap"
or "secret"'
Expand Down Expand Up @@ -1300,6 +1337,13 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret containing
certificates. If omitted, assumes same namespace as
where NetObserv is deployed. If the namespace is different,
the config map or the secret will be copied so that
it can be mounted as required.
type: string
type:
description: 'type for the certificate reference: "configmap"
or "secret"'
Expand Down Expand Up @@ -1978,6 +2022,14 @@ spec:
description: name of the config map or secret
containing certificates
type: string
namespace:
description: namespace of the config map or secret
containing certificates. If omitted, assumes
same namespace as where NetObserv is deployed.
If the namespace is different, the config map
or the secret will be copied so that it can
be mounted as required.
type: string
type:
description: 'type for the certificate reference:
"configmap" or "secret"'
Expand Down
52 changes: 52 additions & 0 deletions config/crd/bases/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,14 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret
containing certificates. If omitted, assumes same
namespace as where NetObserv is deployed. If the
namespace is different, the config map or the
secret will be copied so that it can be mounted
as required.
type: string
type:
description: 'type for the certificate reference:
"configmap" or "secret"'
Expand Down Expand Up @@ -1048,6 +1056,14 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret
containing certificates. If omitted, assumes same
namespace as where NetObserv is deployed. If the
namespace is different, the config map or the
secret will be copied so that it can be mounted
as required.
type: string
type:
description: 'type for the certificate reference:
"configmap" or "secret"'
Expand Down Expand Up @@ -1108,6 +1124,13 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret containing
certificates. If omitted, assumes same namespace as
where NetObserv is deployed. If the namespace is different,
the config map or the secret will be copied so that
it can be mounted as required.
type: string
type:
description: 'type for the certificate reference: "configmap"
or "secret"'
Expand Down Expand Up @@ -1144,6 +1167,13 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret containing
certificates. If omitted, assumes same namespace as
where NetObserv is deployed. If the namespace is different,
the config map or the secret will be copied so that
it can be mounted as required.
type: string
type:
description: 'type for the certificate reference: "configmap"
or "secret"'
Expand Down Expand Up @@ -1262,6 +1292,13 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret containing
certificates. If omitted, assumes same namespace as
where NetObserv is deployed. If the namespace is different,
the config map or the secret will be copied so that
it can be mounted as required.
type: string
type:
description: 'type for the certificate reference: "configmap"
or "secret"'
Expand Down Expand Up @@ -1298,6 +1335,13 @@ spec:
description: name of the config map or secret containing
certificates
type: string
namespace:
description: namespace of the config map or secret containing
certificates. If omitted, assumes same namespace as
where NetObserv is deployed. If the namespace is different,
the config map or the secret will be copied so that
it can be mounted as required.
type: string
type:
description: 'type for the certificate reference: "configmap"
or "secret"'
Expand Down Expand Up @@ -1976,6 +2020,14 @@ spec:
description: name of the config map or secret
containing certificates
type: string
namespace:
description: namespace of the config map or secret
containing certificates. If omitted, assumes
same namespace as where NetObserv is deployed.
If the namespace is different, the config map
or the secret will be copied so that it can
be mounted as required.
type: string
type:
description: 'type for the certificate reference:
"configmap" or "secret"'
Expand Down
2 changes: 1 addition & 1 deletion controllers/consoleplugin/consoleplugin_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (b *builder) podTemplate(cmDigest string) *corev1.PodTemplateSpec {

args := buildArgs(b.desired, b.desiredLoki)
if b.desiredLoki != nil && b.desiredLoki.TLS.Enable && !b.desiredLoki.TLS.InsecureSkipVerify {
volumes, volumeMounts = helper.AppendCertVolumes(volumes, volumeMounts, &b.desiredLoki.TLS, lokiCerts, b.cWatcher)
volumes, volumeMounts = helper.AppendCertVolumes(volumes, volumeMounts, &b.desiredLoki.TLS, lokiCerts, b.cWatcher.SetWatchedCertificate)
}

if b.desiredLoki.UseHostToken() {
Expand Down
10 changes: 5 additions & 5 deletions controllers/consoleplugin/consoleplugin_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type pluginSpec = flowsv1alpha1.FlowCollectorConsolePlugin

// CPReconciler reconciles the current console plugin state with the desired configuration
type CPReconciler struct {
reconcilers.ClientHelper
reconcilers.Common
nobjMngr *reconcilers.NamespacedObjectManager
owned ownedObjects
image string
Expand All @@ -42,7 +42,7 @@ type ownedObjects struct {
serviceMonitor *monitoringv1.ServiceMonitor
}

func NewReconciler(cl reconcilers.ClientHelper, ns, prevNS, imageName string, availableAPIs *discover.AvailableAPIs) CPReconciler {
func NewReconciler(cmn reconcilers.Common, ns, prevNS, imageName string, availableAPIs *discover.AvailableAPIs) CPReconciler {
owned := ownedObjects{
deployment: &appsv1.Deployment{},
service: &corev1.Service{},
Expand All @@ -51,7 +51,7 @@ func NewReconciler(cl reconcilers.ClientHelper, ns, prevNS, imageName string, av
configMap: &corev1.ConfigMap{},
serviceMonitor: &monitoringv1.ServiceMonitor{},
}
nobjMngr := reconcilers.NewNamespacedObjectManager(cl, ns, prevNS)
nobjMngr := reconcilers.NewNamespacedObjectManager(cmn, ns, prevNS)
nobjMngr.AddManagedObject(constants.PluginName, owned.deployment)
nobjMngr.AddManagedObject(constants.PluginName, owned.service)
nobjMngr.AddManagedObject(constants.PluginName, owned.hpa)
Expand All @@ -61,7 +61,7 @@ func NewReconciler(cl reconcilers.ClientHelper, ns, prevNS, imageName string, av
nobjMngr.AddManagedObject(constants.PluginName, owned.serviceMonitor)
}

return CPReconciler{ClientHelper: cl, nobjMngr: nobjMngr, owned: owned, image: imageName, availableAPIs: availableAPIs}
return CPReconciler{Common: cmn, nobjMngr: nobjMngr, owned: owned, image: imageName, availableAPIs: availableAPIs}
}

// InitStaticResources inits some "static" / one-shot resources, usually not subject to reconciliation
Expand Down Expand Up @@ -180,7 +180,7 @@ func (r *CPReconciler) reconcileConfigMap(ctx context.Context, builder builder,
func (r *CPReconciler) reconcileDeployment(ctx context.Context, builder builder, desired *flowsv1alpha1.FlowCollectorSpec, cmDigest string) error {
newDepl := builder.deployment(cmDigest)
// Annotate pod with certificate reference so that it is reloaded if modified
if err := r.CertWatcher.AnnotatePod(ctx, r.Client, &newDepl.Spec.Template, lokiCerts); err != nil {
if err := r.CertWatcher.PrepareForPod(ctx, r.ClientHelper, &newDepl.Spec.Template, r.nobjMngr.Namespace, lokiCerts); err != nil {
return err
}
if !r.nobjMngr.Exists(r.owned.deployment) {
Expand Down