代码拉取完成,页面将自动刷新
package generator
import (
"bytes"
"fmt"
"strings"
"text/template"
loggingconfig "github.com/rancher/rancher/pkg/controllers/user/logging/config"
"github.com/rancher/rancher/pkg/controllers/user/logging/utils"
"github.com/rancher/rancher/pkg/project"
mgmtv3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/pkg/errors"
k8scorev1 "k8s.io/api/core/v1"
)
func generateConfig(templateM, tempalteName string, conf map[string]interface{}) ([]byte, error) {
tp, err := template.New(tempalteName).Parse(templateM)
if err != nil {
return nil, err
}
buf := &bytes.Buffer{}
if err = tp.Execute(buf, conf); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func GenerateClusterConfig(logging mgmtv3.ClusterLoggingSpec, excludeNamespaces, certDir string) ([]byte, error) {
wl, err := utils.NewWrapClusterLogging(logging, excludeNamespaces)
if err != nil {
return nil, errors.Wrap(err, "to wraper cluster logging failed")
}
if wl == nil {
return []byte{}, nil
}
conf := map[string]interface{}{
"clusterTarget": wl,
"clusterName": logging.ClusterName,
"certDir": certDir,
}
buf, err := generateConfig(ClusterTemplate, loggingconfig.ClusterLevel, conf)
if err != nil {
return nil, errors.Wrap(err, "generate cluster config file failed")
}
return buf, nil
}
func GenerateProjectConfig(projectLoggings []*mgmtv3.ProjectLogging, namespaces []*k8scorev1.Namespace, systemProjectID, certDir string) ([]byte, error) {
var wl []utils.ProjectLoggingTemplateWrap
for _, v := range projectLoggings {
var grepNamespace []string
for _, v2 := range namespaces {
if nsProjectName, ok := v2.Annotations[project.ProjectIDAnn]; ok && nsProjectName == v.Spec.ProjectName {
namespacePattern := loggingconfig.GetNamespacePattern(v2.Name)
grepNamespace = append(grepNamespace, namespacePattern)
}
}
if len(grepNamespace) == 0 {
continue
}
formatgrepNamespace := fmt.Sprintf("(%s)", strings.Join(grepNamespace, "|"))
isSystemProject := v.Spec.ProjectName == systemProjectID
wpl, err := utils.NewWrapProjectLogging(v.Spec, formatgrepNamespace, isSystemProject)
if err != nil {
return nil, err
}
if wpl == nil {
continue
}
wl = append(wl, *wpl)
}
conf := map[string]interface{}{
"projectTargets": wl,
"certDir": certDir,
}
buf, err := generateConfig(ProjectTemplate, loggingconfig.ProjectLevel, conf)
if err != nil {
return nil, errors.Wrap(err, "generate project config file failed")
}
return buf, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。