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 resource not found error #2281

Merged
merged 1 commit into from
Nov 6, 2023
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
8 changes: 4 additions & 4 deletions datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ func NewDataStore(namespace string, lhClient lhclientset.Interface, kubeClient c
cacheSyncs = append(cacheSyncs, csiDriverInformer.Informer().HasSynced)
storageclassInformer := informerFactories.KubeInformerFactory.Storage().V1().StorageClasses()
cacheSyncs = append(cacheSyncs, storageclassInformer.Informer().HasSynced)
priorityClassInformer := informerFactories.KubeInformerFactory.Scheduling().V1().PriorityClasses()
cacheSyncs = append(cacheSyncs, priorityClassInformer.Informer().HasSynced)

// Filtered kube Informers by longhorn-system namespace
cronJobInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Batch().V1().CronJobs()
Expand All @@ -191,8 +193,6 @@ func NewDataStore(namespace string, lhClient lhclientset.Interface, kubeClient c
cacheSyncs = append(cacheSyncs, configMapInformer.Informer().HasSynced)
secretInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Core().V1().Secrets()
cacheSyncs = append(cacheSyncs, secretInformer.Informer().HasSynced)
priorityClassInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Scheduling().V1().PriorityClasses()
cacheSyncs = append(cacheSyncs, priorityClassInformer.Informer().HasSynced)
serviceInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Core().V1().Services()
cacheSyncs = append(cacheSyncs, serviceInformer.Informer().HasSynced)
podDisruptionBudgetInformer := informerFactories.KubeNamespaceFilteredInformerFactory.Policy().V1().PodDisruptionBudgets()
Expand Down Expand Up @@ -266,15 +266,15 @@ func NewDataStore(namespace string, lhClient lhclientset.Interface, kubeClient c
CSIDriverInformer: csiDriverInformer.Informer(),
storageclassLister: storageclassInformer.Lister(),
StorageClassInformer: storageclassInformer.Informer(),
priorityClassLister: priorityClassInformer.Lister(),
PriorityClassInformer: priorityClassInformer.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(),
Expand Down
31 changes: 24 additions & 7 deletions datastore/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,19 @@ func (s *DataStore) UpdateConfigMap(configMap *corev1.ConfigMap) (*corev1.Config
// This function returns direct reference to the internal cache object and should not be mutated.
// Consider using this function when you can guarantee read only access and don't want the overhead of deep copies
func (s *DataStore) GetConfigMapRO(namespace, name string) (*corev1.ConfigMap, error) {
return s.configMapLister.ConfigMaps(namespace).Get(name)
if namespace == s.namespace {
return s.configMapLister.ConfigMaps(namespace).Get(name)
}
return s.kubeClient.CoreV1().ConfigMaps(namespace).Get(context.Background(), name, metav1.GetOptions{})
}

// GetConfigMap return a new ConfigMap object for the given namespace and name
func (s *DataStore) GetConfigMap(namespace, name string) (*corev1.ConfigMap, error) {
resultRO, err := s.configMapLister.ConfigMaps(namespace).Get(name)
func (s *DataStore) GetConfigMap(namespace, name string) (resultRO *corev1.ConfigMap, err error) {
if namespace == s.namespace {
resultRO, err = s.configMapLister.ConfigMaps(namespace).Get(name)
} else {
resultRO, err = s.kubeClient.CoreV1().ConfigMaps(namespace).Get(context.Background(), name, metav1.GetOptions{})
}
if err != nil {
return nil, err
}
Expand All @@ -656,12 +663,19 @@ func (s *DataStore) DeleteConfigMap(namespace, name string) error {
// This function returns direct reference to the internal cache object and should not be mutated.
// Consider using this function when you can guarantee read only access and don't want the overhead of deep copies
func (s *DataStore) GetSecretRO(namespace, name string) (*corev1.Secret, error) {
return s.secretLister.Secrets(namespace).Get(name)
if namespace == s.namespace {
return s.secretLister.Secrets(namespace).Get(name)
}
return s.kubeClient.CoreV1().Secrets(namespace).Get(context.Background(), name, metav1.GetOptions{})
}

// GetSecret return a new Secret object with the given namespace and name
func (s *DataStore) GetSecret(namespace, name string) (*corev1.Secret, error) {
resultRO, err := s.secretLister.Secrets(namespace).Get(name)
func (s *DataStore) GetSecret(namespace, name string) (resultRO *corev1.Secret, err error) {
if namespace == s.namespace {
resultRO, err = s.secretLister.Secrets(namespace).Get(name)
} else {
resultRO, err = s.kubeClient.CoreV1().Secrets(namespace).Get(context.Background(), name, metav1.GetOptions{})
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -702,7 +716,10 @@ func (s *DataStore) CreateService(ns string, service *corev1.Service) (*corev1.S

// GetService gets the Service for the given name and namespace
func (s *DataStore) GetService(namespace, name string) (*corev1.Service, error) {
return s.serviceLister.Services(namespace).Get(name)
if namespace == s.namespace {
return s.serviceLister.Services(namespace).Get(name)
}
return s.kubeClient.CoreV1().Services(namespace).Get(context.Background(), name, metav1.GetOptions{})
}

// DeleteService deletes the Service for the given name and namespace
Expand Down