37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
logging.go 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
Aiwantaozi 提交于 2018-04-26 12:06 . fix logging issue
package utils
import (
"github.com/rancher/types/apis/core/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
loggingconfig "github.com/rancher/rancher/pkg/controllers/user/logging/config"
)
func IsAllLoggingDisable(clusterLoggingLister v3.ClusterLoggingLister, projectLoggingLister v3.ProjectLoggingLister, currentCL *v3.ClusterLogging, currentPL *v3.ProjectLogging) (bool, error) {
clusterLoggings, err := clusterLoggingLister.List("", labels.NewSelector())
if err != nil {
return false, err
}
projectLoggings, err := projectLoggingLister.List("", labels.NewSelector())
if err != nil {
return false, err
}
if len(clusterLoggings) == 0 && len(projectLoggings) == 0 {
return true, nil
}
for _, v := range clusterLoggings {
if currentCL != nil && v.Name == currentCL.Name {
v = currentCL
}
logging, _, err := GetWrapConfig(v.Spec.ElasticsearchConfig, v.Spec.SplunkConfig, v.Spec.SyslogConfig, v.Spec.KafkaConfig, v.Spec.EmbeddedConfig)
if err != nil {
return false, err
}
if logging.CurrentTarget != "" {
return false, nil
}
}
for _, v := range projectLoggings {
if currentPL != nil && v.Name == currentPL.Name {
v = currentPL
}
logging, _, err := GetWrapConfig(v.Spec.ElasticsearchConfig, v.Spec.SplunkConfig, v.Spec.SyslogConfig, v.Spec.KafkaConfig, nil)
if err != nil {
return false, err
}
if logging.CurrentTarget != "" {
return false, nil
}
}
return true, nil
}
func CleanResource(ns v1.NamespaceInterface, cl v3.ClusterLoggingLister, pl v3.ProjectLoggingLister, currentCL *v3.ClusterLogging, currentPL *v3.ProjectLogging) (bool, error) {
allDisabled, err := IsAllLoggingDisable(cl, pl, currentCL, currentPL)
if err != nil {
return allDisabled, err
}
var zero int64
foreground := metav1.DeletePropagationForeground
if allDisabled {
if err = ns.Delete(loggingconfig.LoggingNamespace, &metav1.DeleteOptions{GracePeriodSeconds: &zero, PropagationPolicy: &foreground}); err != nil && !apierrors.IsNotFound(err) {
return allDisabled, err
}
}
return allDisabled, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.5-rc6

搜索帮助

0d507c66 1850385 C8b1a773 1850385