Skip to content

Commit

Permalink
Filter pdb, daemonset and deployment by namespace
Browse files Browse the repository at this point in the history
Longhorn 6954

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit authored and David Ko committed Oct 26, 2023
1 parent f291376 commit 9fa7892
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion controller/engine_image_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (s *TestSuite) TestEngineImage(c *C) {

informerFactories := util.NewInformerFactories(TestNamespace, kubeClient, lhClient, controller.NoResyncPeriodFunc())

dsIndexer := informerFactories.KubeInformerFactory.Apps().V1().DaemonSets().Informer().GetIndexer()
dsIndexer := informerFactories.KubeNamespaceFilteredInformerFactory.Apps().V1().DaemonSets().Informer().GetIndexer()
podIndexer := informerFactories.KubeInformerFactory.Core().V1().Pods().Informer().GetIndexer()

nodeIndexer := informerFactories.LhInformerFactory.Longhorn().V1beta2().Nodes().Informer().GetIndexer()
Expand Down
8 changes: 4 additions & 4 deletions controller/system_rollout_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,8 @@ func (s *TestSuite) TestSystemRollout(c *C) {
fakeSystemRolloutClusterRoles(tc.backupClusterRoles, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutClusterRoleBindings(tc.backupClusterRoleBindings, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutConfigMaps(tc.backupConfigMaps, c, informerFactories.KubeNamespaceFilteredInformerFactory, kubeClient)
fakeSystemRolloutDaemonSets(tc.backupDaemonSets, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutDeployments(tc.backupDeployments, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutDaemonSets(tc.backupDaemonSets, c, informerFactories.KubeNamespaceFilteredInformerFactory, kubeClient)
fakeSystemRolloutDeployments(tc.backupDeployments, c, informerFactories.KubeNamespaceFilteredInformerFactory, kubeClient)
fakeSystemRolloutEngineImages(tc.backupEngineImages, c, informerFactories.LhInformerFactory, lhClient)
fakeSystemRolloutPersistentVolumes(tc.backupPersistentVolumes, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutPersistentVolumeClaims(tc.backupPersistentVolumeClaims, c, informerFactories.KubeInformerFactory, kubeClient)
Expand Down Expand Up @@ -1026,8 +1026,8 @@ func (s *TestSuite) TestSystemRollout(c *C) {
fakeSystemRolloutClusterRoleBindings(tc.existClusterRoleBindings, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutConfigMaps(tc.existConfigMaps, c, informerFactories.KubeNamespaceFilteredInformerFactory, kubeClient)
fakeSystemRolloutCustomResourceDefinitions(tc.existCRDVersions, c, extensionsInformerFactory, extensionsClient)
fakeSystemRolloutDaemonSets(tc.existDaemonSets, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutDeployments(tc.existDeployments, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutDaemonSets(tc.existDaemonSets, c, informerFactories.KubeNamespaceFilteredInformerFactory, kubeClient)
fakeSystemRolloutDeployments(tc.existDeployments, c, informerFactories.KubeNamespaceFilteredInformerFactory, kubeClient)
fakeSystemRolloutEngineImages(tc.existEngineImages, c, informerFactories.LhInformerFactory, lhClient)
fakeSystemRolloutPersistentVolumes(tc.existPersistentVolumes, c, informerFactories.KubeInformerFactory, kubeClient)
fakeSystemRolloutPersistentVolumeClaims(tc.existPersistentVolumeClaims, c, informerFactories.KubeInformerFactory, kubeClient)
Expand Down
44 changes: 22 additions & 22 deletions datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,10 @@ func NewDataStore(namespace string, lhClient lhclientset.Interface, kubeClient c
cacheSyncs = append(cacheSyncs, persistentVolumeClaimInformer.Informer().HasSynced)
volumeAttachmentInformer := informerFactories.KubeInformerFactory.Storage().V1().VolumeAttachments()
cacheSyncs = append(cacheSyncs, volumeAttachmentInformer.Informer().HasSynced)
daemonSetInformer := informerFactories.KubeInformerFactory.Apps().V1().DaemonSets()
cacheSyncs = append(cacheSyncs, daemonSetInformer.Informer().HasSynced)
deploymentInformer := informerFactories.KubeInformerFactory.Apps().V1().Deployments()
cacheSyncs = append(cacheSyncs, deploymentInformer.Informer().HasSynced)
csiDriverInformer := informerFactories.KubeInformerFactory.Storage().V1().CSIDrivers()
cacheSyncs = append(cacheSyncs, csiDriverInformer.Informer().HasSynced)
storageclassInformer := informerFactories.KubeInformerFactory.Storage().V1().StorageClasses()
cacheSyncs = append(cacheSyncs, storageclassInformer.Informer().HasSynced)
podDisruptionBudgetInformer := kubeInformerFactory.Policy().V1().PodDisruptionBudgets()
cacheSyncs = append(cacheSyncs, podDisruptionBudgetInformer.Informer().HasSynced)

// Filtered kube Informers by longhorn-system namespace
cronJobInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Batch().V1().CronJobs()
Expand All @@ -201,6 +195,12 @@ func NewDataStore(namespace string, lhClient lhclientset.Interface, kubeClient c
cacheSyncs = append(cacheSyncs, priorityClassInformer.Informer().HasSynced)
serviceInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Core().V1().Services()
cacheSyncs = append(cacheSyncs, serviceInformer.Informer().HasSynced)
podDisruptionBudgetInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Policy().V1().PodDisruptionBudgets()
cacheSyncs = append(cacheSyncs, podDisruptionBudgetInformer.Informer().HasSynced)
daemonSetInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Apps().V1().DaemonSets()
cacheSyncs = append(cacheSyncs, daemonSetInformer.Informer().HasSynced)
deploymentInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Apps().V1().Deployments()
cacheSyncs = append(cacheSyncs, deploymentInformer.Informer().HasSynced)

return &DataStore{
namespace: namespace,
Expand Down Expand Up @@ -254,10 +254,6 @@ func NewDataStore(namespace string, lhClient lhclientset.Interface, kubeClient c
kubeClient: kubeClient,
podLister: podInformer.Lister(),
PodInformer: podInformer.Informer(),
daemonSetLister: daemonSetInformer.Lister(),
DaemonSetInformer: daemonSetInformer.Informer(),
deploymentLister: deploymentInformer.Lister(),
DeploymentInformer: deploymentInformer.Informer(),
persistentVolumeLister: persistentVolumeInformer.Lister(),
PersistentVolumeInformer: persistentVolumeInformer.Informer(),
persistentVolumeClaimLister: persistentVolumeClaimInformer.Lister(),
Expand All @@ -270,19 +266,23 @@ func NewDataStore(namespace string, lhClient lhclientset.Interface, kubeClient c
CSIDriverInformer: csiDriverInformer.Informer(),
storageclassLister: storageclassInformer.Lister(),
StorageClassInformer: storageclassInformer.Informer(),
podDisruptionBudgetLister: podDisruptionBudgetInformer.Lister(),
PodDisruptionBudgetInformer: podDisruptionBudgetInformer.Informer(),

cronJobLister: cronJobInformer.Lister(),
CronJobInformer: cronJobInformer.Informer(),
configMapLister: configMapInformer.Lister(),
ConfigMapInformer: configMapInformer.Informer(),
secretLister: secretInformer.Lister(),
SecretInformer: secretInformer.Informer(),
priorityClassLister: priorityClassInformer.Lister(),
PriorityClassInformer: priorityClassInformer.Informer(),
serviceLister: serviceInformer.Lister(),
ServiceInformer: serviceInformer.Informer(),
cronJobLister: cronJobInformer.Lister(),
CronJobInformer: cronJobInformer.Informer(),
configMapLister: configMapInformer.Lister(),
ConfigMapInformer: configMapInformer.Informer(),
secretLister: secretInformer.Lister(),
SecretInformer: secretInformer.Informer(),
priorityClassLister: priorityClassInformer.Lister(),
PriorityClassInformer: priorityClassInformer.Informer(),
serviceLister: serviceInformer.Lister(),
ServiceInformer: serviceInformer.Informer(),
podDisruptionBudgetLister: podDisruptionBudgetInformer.Lister(),
PodDisruptionBudgetInformer: podDisruptionBudgetInformer.Informer(),
daemonSetLister: daemonSetInformer.Lister(),
DaemonSetInformer: daemonSetInformer.Informer(),
deploymentLister: deploymentInformer.Lister(),
DeploymentInformer: deploymentInformer.Informer(),

extensionsClient: extensionsClient,
}
Expand Down
10 changes: 5 additions & 5 deletions datastore/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3079,20 +3079,20 @@ func verifyCreation(name, kind string, getMethod func(name string) (runtime.Obje
func verifyUpdate(name string, obj runtime.Object, getMethod func(name string) (runtime.Object, error)) {
accessor, err := meta.Accessor(obj)
if err != nil {
logrus.Errorf("BUG: datastore: cannot verify update for %v (%+v) because cannot get accessor: %v", name, obj, err)
logrus.WithError(err).Errorf("BUG: datastore: cannot verify update for %v (%+v) because cannot get accessor", name, obj)
return
}
minimalResourceVersion := accessor.GetResourceVersion()
verified := false
for i := 0; i < VerificationRetryCounts; i++ {
ret, err := getMethod(name)
if err != nil {
logrus.Errorf("datastore: failed to get updated object %v", name)
logrus.WithError(err).Errorf("datastore: failed to get updated object %v", name)
return
}
accessor, err := meta.Accessor(ret)
if err != nil {
logrus.Errorf("BUG: datastore: cannot verify update for %v because cannot get accessor for updated object: %v", name, err)
logrus.WithError(err).Errorf("BUG: datastore: cannot verify update for %v because cannot get accessor for updated object", name)
return
}
if resourceVersionAtLeast(accessor.GetResourceVersion(), minimalResourceVersion) {
Expand All @@ -3115,12 +3115,12 @@ func resourceVersionAtLeast(curr, min string) bool {
}
currVersion, err := strconv.ParseInt(curr, 10, 64)
if err != nil {
logrus.Errorf("datastore: failed to parse current resource version %v: %v", curr, err)
logrus.WithError(err).Errorf("datastore: failed to parse current resource version %v", curr)
return false
}
minVersion, err := strconv.ParseInt(min, 10, 64)
if err != nil {
logrus.Errorf("datastore: failed to parse minimal resource version %v: %v", min, err)
logrus.WithError(err).Errorf("datastore: failed to parse minimal resource version %v", min)
return false
}
return currVersion >= minVersion
Expand Down

0 comments on commit 9fa7892

Please sign in to comment.