Skip to content

Commit

Permalink
Merge pull request #4237 from zhzhuang-zju/configmap
Browse files Browse the repository at this point in the history
Restrict “configmap/extension-apiserver-authentication” object from being distributed to member clusters
  • Loading branch information
karmada-bot authored Nov 15, 2023
2 parents 3dac48b + 3de4fe1 commit 5e27024
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,15 @@ func (d *ResourceDetector) Reconcile(key util.QueueKey) error {
return d.propagateResource(object, clusterWideKey)
}

// EventFilter tells if an object should be take care of.
// EventFilter tells if an object should be taken care of.
//
// All objects under Kubernetes reserved namespace should be ignored:
// - kube-*
// All objects under Karmada reserved namespace should be ignored:
// - karmada-system
// - karmada-cluster
// - karmada-es-*
//
// If '--skipped-propagating-namespaces' is specified, all APIs in the skipped-propagating-namespaces will be ignored.
// If '--skipped-propagating-namespaces'(defaults to kube-.*) is specified,
// all resources in the skipped-propagating-namespaces will be ignored.
func (d *ResourceDetector) EventFilter(obj interface{}) bool {
key, err := ClusterWideKeyFunc(obj)
if err != nil {
Expand Down Expand Up @@ -279,6 +278,14 @@ func (d *ResourceDetector) EventFilter(obj interface{}) bool {
}
}

// Prevent configmap/extension-apiserver-authentication from propagating as it is generated
// and managed by kube-apiserver.
// Refer to https://github.com/karmada-io/karmada/issues/4228 for more details.
if clusterWideKey.Namespace == "kube-system" && clusterWideKey.Kind == "ConfigMap" &&
clusterWideKey.Name == "extension-apiserver-authentication" {
return false
}

return true
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/detector/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,20 @@ func BenchmarkEventFilterMultiSkipNameSpaces(b *testing.B) {
})
}
}

func BenchmarkEventFilterExtensionApiserverAuthentication(b *testing.B) {
dt := &ResourceDetector{}
dt.SkippedPropagatingNamespaces = append(dt.SkippedPropagatingNamespaces, regexp.MustCompile("^kube-.*$"))
for i := 0; i < b.N; i++ {
dt.EventFilter(&unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "extension-apiserver-authentication",
"namespace": "kube-system",
},
},
})
}
}

0 comments on commit 5e27024

Please sign in to comment.