代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。