代码拉取完成,页面将自动刷新
package kontainerdriver
import (
"fmt"
errorsutil "github.com/pkg/errors"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/tools/cache"
)
type store struct {
types.Store
KontainerDriverLister v3.KontainerDriverLister
ClusterIndexer cache.Indexer
}
func NewStore(management *config.ScaledContext, s types.Store) types.Store {
clusterInformer := management.Management.Clusters("").Controller().Informer()
// use an indexer instead of expensive k8s api calls
clusterInformer.AddIndexers(map[string]cache.IndexFunc{
clusterByKontainerDriverKey: clusterByKontainerDriver,
})
kd := management.Management.KontainerDrivers("").Controller().Lister()
storeObj := store{
Store: s,
KontainerDriverLister: kd,
ClusterIndexer: clusterInformer.GetIndexer(),
}
return &storeObj
}
// Delete removes the KontainerDriver if it is not in use by a cluster
func (s *store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
//need to get the full driver since just the id is not enough see if a cluster uses it
driver, err := s.KontainerDriverLister.Get("", id)
if err != nil {
if !errors.IsNotFound(err) {
return nil, errorsutil.WithMessage(err, fmt.Sprintf("error getting kontainer driver %s", id))
}
//if driver is not found, don't return error
return nil, nil
}
clustersWithKontainerDriver, err := s.ClusterIndexer.ByIndex(clusterByKontainerDriverKey, driver.Status.DisplayName)
if err != nil {
return nil, errorsutil.WithMessage(err, fmt.Sprintf("error determing if kontainer driver [%s] was in use", driver.Status.DisplayName))
}
if len(clustersWithKontainerDriver) != 0 {
return nil, httperror.NewAPIError(httperror.MethodNotAllowed, "cluster Driver is in use by one or more clusters, delete clusters before deleting this driver")
}
return s.Store.Delete(apiContext, schema, id)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。