Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Add load filtering to clusterLogConfig and exclude namespaces #643

Merged
merged 6 commits into from
Nov 9, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
)

const (
SelectorTypePod = "pod"
SelectorTypeNode = "node"
SelectorTypeCluster = "cluster"
SelectorTypeVm = "vm"
SelectorTypeAll = "all"
SelectorTypePod = "pod"
SelectorTypeNode = "node"
SelectorTypeCluster = "cluster"
SelectorTypeVm = "vm"
SelectorTypeWorkload = "workload"
SelectorTypeAll = "all"
)

// +genclient
Expand All @@ -48,10 +49,12 @@ type Spec struct {
}

type Selector struct {
Cluster string `json:"cluster,omitempty"`
Type string `json:"type,omitempty"`
PodSelector `json:",inline"`
NodeSelector `json:",inline"`
Cluster string `json:"cluster,omitempty"`
Type string `json:"type,omitempty"`
PodSelector `json:",inline"`
NodeSelector `json:",inline"`
NamespaceSelector `json:",inline"`
WorkloadSelector []WorkloadSelector `json:"workloadSelector,omitempty"`
}

type PodSelector struct {
Expand All @@ -62,6 +65,18 @@ type NodeSelector struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

type NamespaceSelector struct {
NamespaceSelector []string `json:"namespaceSelector,omitempty"`
ExcludeNamespaceSelector []string `json:"excludeNamespaceSelector,omitempty"`
}

type WorkloadSelector struct {
Type []string `json:"type,omitempty"`
NameSelector []string `json:"nameSelector,omitempty"`
NamespaceSelector []string `json:"namespaceSelector,omitempty"`
ExcludeNamespaceSelector []string `json:"excludeNamespaceSelector,omitempty"`
}

type Pipeline struct {
Name string `json:"name,omitempty"`
Sources string `json:"sources,omitempty"`
Expand Down Expand Up @@ -91,7 +106,7 @@ func (in *ClusterLogConfig) Validate() error {
}

tp := in.Spec.Selector.Type
if tp != SelectorTypePod && tp != SelectorTypeNode && tp != SelectorTypeCluster && tp != SelectorTypeVm {
if tp != SelectorTypePod && tp != SelectorTypeNode && tp != SelectorTypeCluster && tp != SelectorTypeVm && tp != SelectorTypeWorkload {
return errors.New("spec.selector.type is invalidate")
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/discovery/kubernetes/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (c *Controller) handleLogConfigSelectorHasChange(new *logconfigv1beta1.LogC

lgcKey := helper.MetaNamespaceKey(old.Namespace, old.Name)
switch new.Spec.Selector.Type {
case logconfigv1beta1.SelectorTypePod:
case logconfigv1beta1.SelectorTypePod, logconfigv1beta1.SelectorTypeWorkload:
if !helper.MatchStringMap(new.Spec.Selector.LabelSelector,
old.Spec.Selector.LabelSelector) {
err = c.handleAllTypesDelete(lgcKey, logconfigv1beta1.SelectorTypePod)
Expand Down
4 changes: 2 additions & 2 deletions pkg/discovery/kubernetes/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (c *Controller) handleAllTypesAddOrUpdate(lgc *logconfigv1beta1.LogConfig)

lgc = lgc.DeepCopy()
switch lgc.Spec.Selector.Type {
case logconfigv1beta1.SelectorTypePod:
case logconfigv1beta1.SelectorTypePod, logconfigv1beta1.SelectorTypeWorkload:
return c.handleLogConfigTypePodAddOrUpdate(lgc)

case logconfigv1beta1.SelectorTypeNode:
Expand Down Expand Up @@ -311,7 +311,7 @@ func (c *Controller) reconcileLogConfigDelete(key string, selectorType string) e

func (c *Controller) handleAllTypesDelete(key string, selectorType string) error {
switch selectorType {
case logconfigv1beta1.SelectorTypePod:
case logconfigv1beta1.SelectorTypePod, logconfigv1beta1.SelectorTypeWorkload:
if ok := c.typePodIndex.DeletePipeConfigsByLogConfigKey(key); !ok {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/discovery/kubernetes/controller/selectpodhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type fmtKey struct {

func (c *Controller) handleLogConfigTypePodAddOrUpdate(lgc *logconfigv1beta1.LogConfig) (err error, podsName []string) {
// find pods related in the node
podList, err := helper.GetLogConfigRelatedPod(lgc, c.podsLister)
podList, err := helper.GetLogConfigRelatedPod(lgc, c.podsLister, c.kubeClientset)
if err != nil {
return err, nil
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func (c *Controller) handlePodAddOrUpdate(pod *corev1.Pod) error {

func (c *Controller) handlePodAddOrUpdateOfLogConfig(pod *corev1.Pod) {
// label selected logConfigs
lgcList, err := helper.GetPodRelatedLogConfigs(pod, c.logConfigLister)
lgcList, err := helper.GetPodRelatedLogConfigs(pod, c.logConfigLister, c.kubeClientset)
if err != nil || len(lgcList) == 0 {
return
}
Expand All @@ -207,7 +207,7 @@ func (c *Controller) handlePodAddOrUpdateOfLogConfig(pod *corev1.Pod) {

func (c *Controller) handlePodAddOrUpdateOfClusterLogConfig(pod *corev1.Pod) {
// label selected clusterLogConfigs
clgcList, err := helper.GetPodRelatedClusterLogConfigs(pod, c.clusterLogConfigLister)
clgcList, err := helper.GetPodRelatedClusterLogConfigs(pod, c.clusterLogConfigLister, c.kubeClientset)
if err != nil || len(clgcList) == 0 {
return
}
Expand Down
Loading
Loading