mirror of
https://github.com/rancher/rke.git
synced 2025-09-08 02:20:13 +00:00
add the parsing for eventRateLimit
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
@@ -37,6 +38,7 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/client-go/transport"
|
||||
eventratelimitapi "k8s.io/kubernetes/plugin/pkg/admission/eventratelimit/apis/eventratelimit"
|
||||
)
|
||||
|
||||
type Cluster struct {
|
||||
@@ -374,11 +376,11 @@ func parseAuditLogConfig(clusterFile string, rkeConfig *v3.RancherKubernetesEngi
|
||||
if services["kube-api"] == nil {
|
||||
return nil
|
||||
}
|
||||
kubeapi := services["kube-api"].(map[string]interface{})
|
||||
if kubeapi["audit_log"] == nil {
|
||||
kubeAPI := services["kube-api"].(map[string]interface{})
|
||||
if kubeAPI["audit_log"] == nil {
|
||||
return nil
|
||||
}
|
||||
auditlog := kubeapi["audit_log"].(map[string]interface{})
|
||||
auditlog := kubeAPI["audit_log"].(map[string]interface{})
|
||||
if auditlog["configuration"] == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -405,6 +407,39 @@ func parseAuditLogConfig(clusterFile string, rkeConfig *v3.RancherKubernetesEngi
|
||||
return err
|
||||
}
|
||||
|
||||
func parseEventRateLimit(clusterFile string, rkeConfig *v3.RancherKubernetesEngineConfig) error {
|
||||
if rkeConfig.Services.KubeAPI.EventRateLimit == nil || !rkeConfig.Services.KubeAPI.EventRateLimit.Enabled {
|
||||
return nil
|
||||
}
|
||||
logrus.Debugf("event rate limit is found in cluster.yml")
|
||||
var r map[string]interface{}
|
||||
err := ghodssyaml.Unmarshal([]byte(clusterFile), &r)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error unmarshalling: %v", err)
|
||||
}
|
||||
if r["services"] == nil {
|
||||
return nil
|
||||
}
|
||||
cfg, found, err := unstructured.NestedMap(r, "services", "kube-api", "event_rate_limit", "configuration")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
cfgBytes, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error marshalling eventRateLimit: %v", err)
|
||||
}
|
||||
output := eventratelimitapi.Configuration{}
|
||||
err = json.Unmarshal(cfgBytes, &output)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error decoding eventRateLimit: %v", err)
|
||||
}
|
||||
rkeConfig.Services.KubeAPI.EventRateLimit.Configuration = &output
|
||||
return err
|
||||
}
|
||||
|
||||
func parseAdmissionConfig(clusterFile string, rkeConfig *v3.RancherKubernetesEngineConfig) error {
|
||||
if rkeConfig.Services.KubeAPI.AdmissionConfiguration == nil {
|
||||
return nil
|
||||
@@ -685,6 +720,9 @@ func ParseConfig(clusterFile string) (*v3.RancherKubernetesEngineConfig, error)
|
||||
if err := parseAuditLogConfig(clusterFile, &rkeConfig); err != nil {
|
||||
return &rkeConfig, fmt.Errorf("error parsing audit log config: %v", err)
|
||||
}
|
||||
if err := parseEventRateLimit(clusterFile, &rkeConfig); err != nil {
|
||||
return &rkeConfig, fmt.Errorf("error parsing event rate limit config: %v", err)
|
||||
}
|
||||
if err := parseIngressConfig(clusterFile, &rkeConfig); err != nil {
|
||||
return &rkeConfig, fmt.Errorf("error parsing ingress config: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user