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

Fix user http tls certificate watch leak #2975

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/controller/apmserver/apmserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ func (r *ReconcileApmServer) validate(ctx context.Context, as *apmv1.ApmServer)
func (r *ReconcileApmServer) onDelete(obj types.NamespacedName) {
// Clean up watches set on secure settings
r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj))
// Clean up watches set on custom http tls certificates
r.dynamicWatches.Secrets.RemoveHandlerForKey(certificates.CertificateWatchKey(apmname.APMNamer, obj.Name))
}

// reconcileApmServerToken reconciles a Secret containing the APM Server token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ func (r *ReconcileEnterpriseSearch) Reconcile(request reconcile.Request) (reconc
func (r *ReconcileEnterpriseSearch) onDelete(obj types.NamespacedName) {
// Clean up watches
r.dynamicWatches.Secrets.RemoveHandlerForKey(configRefWatchName(obj))
// Clean up watches set on custom http tls certificates
r.dynamicWatches.Secrets.RemoveHandlerForKey(certificates.CertificateWatchKey(entName.EntNamer, obj.Name))
}

func (r *ReconcileEnterpriseSearch) isCompatible(ctx context.Context, ent *entv1beta1.EnterpriseSearch) (bool, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ func TestReconcileEnterpriseSearch_Reconcile_NotFound(t *testing.T) {
}
// simulate existing watches
nsn := types.NamespacedName{Name: "sample", Namespace: "ns"}
err := watches.WatchUserProvidedSecrets(nsn, r.DynamicWatches(), configRefWatchName(nsn), []string{"watched-secret"})
require.NoError(t, err)
require.NoError(t, watches.WatchUserProvidedSecrets(nsn, r.DynamicWatches(), configRefWatchName(nsn), []string{"watched-secret"}))
// simulate a custom http tls secret
require.NoError(t, watches.WatchUserProvidedSecrets(nsn, r.dynamicWatches, "sample-ent-http-certificate", []string{"user-tls-secret"}))
require.NotEmpty(t, r.dynamicWatches.Secrets.Registrations())

result, err := r.Reconcile(reconcile.Request{NamespacedName: nsn})
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/kibana/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/elastic/cloud-on-k8s/pkg/controller/association"
"github.com/elastic/cloud-on-k8s/pkg/controller/common"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/events"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/finalizer"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore"
Expand Down Expand Up @@ -240,6 +241,8 @@ func (r *ReconcileKibana) updateStatus(ctx context.Context, state State) error {
func (r *ReconcileKibana) onDelete(obj types.NamespacedName) {
// Clean up watches set on secure settings
r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj))
// Clean up watches set on custom http tls certificates
r.dynamicWatches.Secrets.RemoveHandlerForKey(certificates.CertificateWatchKey(Namer, obj.Name))
}

// State holds the accumulated state during the reconcile loop including the response and a pointer to a Kibana
Expand Down