From 1be47ea0b81cf203c2ef1c278da7f113a06ceb2e Mon Sep 17 00:00:00 2001 From: Satoru Takeuchi Date: Thu, 14 Jan 2021 15:15:47 +0000 Subject: [PATCH] ceph: delete discovery daemon if it is disabled discovery-daemon still exists even if it's disabled. Closes: https://github.com/rook/rook/issues/6936 Signed-off-by: Satoru Takeuchi --- pkg/operator/ceph/operator.go | 19 ++++++++++++------- pkg/operator/discover/discover.go | 9 +++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/operator/ceph/operator.go b/pkg/operator/ceph/operator.go index 22f4c48d7..9d74b122b 100644 --- a/pkg/operator/ceph/operator.go +++ b/pkg/operator/ceph/operator.go @@ -114,16 +114,21 @@ func (o *Operator) Run() error { return errors.Errorf("rook operator namespace is not provided. expose it via downward API in the rook operator manifest file using environment variable %q", k8sutil.PodNamespaceEnvVar) } - if EnableDiscoveryDaemon { - rookDiscover := discover.New(o.context.Clientset) - if err := rookDiscover.Start(o.operatorNamespace, o.rookImage, o.securityAccount, true); err != nil { - return errors.Wrap(err, "failed to start device discovery daemonset") - } - } - // creating a context stopContext, stopFunc := context.WithCancel(context.Background()) defer stopFunc() + + rookDiscover := discover.New(o.context.Clientset) + if EnableDiscoveryDaemon { + if err := rookDiscover.Start(o.operatorNamespace, o.rookImage, o.securityAccount, true); err != nil { + return errors.Wrap(err, "failed to start device discovery daemonset") + } + } else { + if err := rookDiscover.Stop(stopContext, o.operatorNamespace); err != nil { + return errors.Wrap(err, "failed to stop device discovery daemonset") + } + } + logger.Debug("checking for admission controller secrets") err := StartControllerIfSecretPresent(stopContext, o.context, o.rookImage) if err != nil { diff --git a/pkg/operator/discover/discover.go b/pkg/operator/discover/discover.go index a0b0f7f2e..4abb01edf 100644 --- a/pkg/operator/discover/discover.go +++ b/pkg/operator/discover/discover.go @@ -472,3 +472,12 @@ func GetAvailableDevices(clusterdContext *clusterd.Context, nodeName, clusterNam } return results, nil } + +// Stop the discover +func (d *Discover) Stop(ctx context.Context, namespace string) error { + err := d.clientset.AppsV1().DaemonSets(namespace).Delete(ctx, discoverDaemonsetName, metav1.DeleteOptions{}) + if err != nil && !k8serrors.IsNotFound(err) { + return err + } + return nil +}