@@ -3,8 +3,6 @@ package argus
33import  (
44	"time" 
55
6- 	"github.com/logicmonitor/k8s-argus/pkg/utilities" 
7- 
86	"github.com/logicmonitor/k8s-argus/pkg/watch/deployment" 
97
108	"github.com/logicmonitor/k8s-argus/pkg/config" 
@@ -23,7 +21,6 @@ import (
2321	"github.com/logicmonitor/lm-sdk-go/client" 
2422	log "github.com/sirupsen/logrus" 
2523	v1 "k8s.io/api/core/v1" 
26- 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
2724	"k8s.io/apimachinery/pkg/fields" 
2825	"k8s.io/client-go/kubernetes" 
2926	"k8s.io/client-go/rest" 
@@ -79,14 +76,11 @@ func NewArgus(base *types.Base, client api.CollectorSetControllerClient) (*Argus
7976		Base : base ,
8077	}
8178
82- 	hasDeploymentRbac  :=  checkHasDeploymentRbac (base )
83- 	log .Infof ("Has deployment rbac: %+v" , hasDeploymentRbac )
84- 
8579	// init sync to delete the non-exist resource devices through logicmonitor API 
8680	initSyncer  :=  sync.InitSyncer {
8781		DeviceManager : deviceManager ,
8882	}
89- 	initSyncer .InitSync (hasDeploymentRbac )
83+ 	initSyncer .InitSync ()
9084
9185	deviceGroups , err  :=  deviceTree .CreateDeviceTree ()
9286	if  err  !=  nil  {
@@ -119,34 +113,14 @@ func NewArgus(base *types.Base, client api.CollectorSetControllerClient) (*Argus
119113		& pod.Watcher {
120114			DeviceManager : deviceManager ,
121115		},
122- 	}
123- 
124- 	if  hasDeploymentRbac  {
125- 		argus .Watchers  =  append (argus .Watchers , & deployment.Watcher {
116+ 		& deployment.Watcher {
126117			DeviceManager : deviceManager ,
127- 		}) 
118+ 		}, 
128119	}
129120
130121	return  argus , nil 
131122}
132123
133- func  checkHasDeploymentRbac (base  * types.Base ) bool  {
134- 	clusterRole , err  :=  base .K8sClient .RbacV1beta1 ().ClusterRoles ().Get ("argus" , metav1.GetOptions {})
135- 	if  err  !=  nil  {
136- 		log .Errorf ("Get clusterRoles failed: %+v" , err )
137- 	} else  {
138- 		for  _ , rule  :=  range  clusterRole .Rules  {
139- 			if  len (rule .APIGroups ) ==  0  {
140- 				continue 
141- 			}
142- 			if  utilities .Contains ("apps" , rule .APIGroups ) &&  utilities .Contains ("deployments" , rule .Resources ) {
143- 				return  true 
144- 			}
145- 		}
146- 	}
147- 	return  false 
148- }
149- 
150124// NewBase instantiates and returns the base structure used throughout Argus. 
151125func  NewBase (config  * config.Config ) (* types.Base , error ) {
152126	// LogicMonitor API client. 
@@ -173,6 +147,10 @@ func NewBase(config *config.Config) (*types.Base, error) {
173147// Watch watches the API for events. 
174148func  (a  * Argus ) Watch () {
175149	for  _ , w  :=  range  a .Watchers  {
150+ 		if  ! w .CheckRBAC () {
151+ 			log .Warnf ("Resource %s has no rbac, ignore watch" , w .Resource ())
152+ 			continue 
153+ 		}
176154		watchlist  :=  cache .NewListWatchFromClient (getK8sRESTClient (a .K8sClient , w .APIVersion ()), w .Resource (), v1 .NamespaceAll , fields .Everything ())
177155		_ , controller  :=  cache .NewInformer (
178156			watchlist ,
0 commit comments