forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processor/k8sattributes] Fixes running with role/rolebinding (open-t…
…elemetry#31673) **Description:** This PR allows running the k8sattributes processor with a k8s role/rolebinding. This can be useful for k8s users w/o access to create clusterroles and want to enrich pods' telemetry within the scope of a namespace only. The PR also adds more comprehensive e2e tests including tests for different RBAC use cases to ensure any changes going forward do not introduce RBAC incompatibility. **Link to tracking Issue:** open-telemetry#14742 **Testing:** Added e2e tests **Documentation:** <Describe the documentation added.> Updated README
- Loading branch information
1 parent
ea573b2
commit 86856f2
Showing
43 changed files
with
1,259 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: bug_fix | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: processor/k8sattributes | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Allows k8sattributes processor to work with k8s role/rolebindings when filter::namespace is set. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [14742] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package k8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest" | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"k8s.io/client-go/discovery" | ||
memory "k8s.io/client-go/discovery/cached" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/restmapper" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
type K8sClient struct { | ||
DynamicClient *dynamic.DynamicClient | ||
DiscoveryClient *discovery.DiscoveryClient | ||
Mapper *restmapper.DeferredDiscoveryRESTMapper | ||
} | ||
|
||
func NewK8sClient(kubeconfigPath string) (*K8sClient, error) { | ||
|
||
if kubeconfigPath == "" { | ||
return nil, errors.New("Please provide file path to load kubeconfig") | ||
} | ||
restConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to load kubeconfig from %s: %w", kubeconfigPath, err) | ||
} | ||
|
||
dynamicClient, err := dynamic.NewForConfig(restConfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating dynamic client: %w", err) | ||
} | ||
|
||
discoveryClient, err := discovery.NewDiscoveryClientForConfig(restConfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating discovery client: %w", err) | ||
} | ||
|
||
mapper := restmapper.NewDeferredDiscoveryRESTMapper(memory.NewMemCacheClient(discoveryClient)) | ||
return &K8sClient{ | ||
DynamicClient: dynamicClient, DiscoveryClient: discoveryClient, Mapper: mapper}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.