github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/cmd/ndm_daemonset/filter/filter.go (about) 1 /* 2 Copyright 2018 The OpenEBS Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package filter 18 19 import ( 20 "github.com/openebs/node-disk-manager/cmd/ndm_daemonset/controller" 21 "k8s.io/klog/v2" 22 ) 23 24 const ( 25 defaultEnabled = true // use in each filter to make it enable. 26 defaultDisabled = false // use in each filter to make it disable. 27 ) 28 29 // RegisteredFilters contains register function of filters which we want to register 30 var RegisteredFilters = []func(){ 31 oSDiskExcludeFilterRegister, 32 vendorFilterRegister, 33 pathFilterRegister, 34 deviceValidityFilterRegister, 35 } 36 37 type registerFilter struct { 38 name string 39 state bool 40 fi controller.FilterInterface 41 controller *controller.Controller 42 } 43 44 // register called by register function of each filter it will check for filter 45 // status if it is enabled then it will call Start() of that filter. 46 func (rf *registerFilter) register() { 47 newFilter := &controller.Filter{ 48 Name: rf.name, 49 State: rf.state, 50 Interface: rf.fi, 51 } 52 rf.controller.AddNewFilter(newFilter) 53 if rf.state { 54 rf.fi.Start() 55 } 56 } 57 58 // Start starts registration of filters present in RegisteredFilters 59 func Start(registeredFilters []func()) { 60 klog.Info("registering filters") 61 for _, filter := range registeredFilters { 62 filter() 63 } 64 }