Skip to content

Commit

Permalink
pr review
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Nov 26, 2024
1 parent f72e1bf commit 5a5fb6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions internal/metadataproviders/kubeadm/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ type Provider interface {
ClusterName(ctx context.Context) (string, error)
}

type LocalCache struct {
ClusterName string
}

type kubeadmProvider struct {
kubeadmClient kubernetes.Interface
configMapName string
configMapNamespace string
cache LocalCache
}

func NewProvider(configMapName string, configMapNamespace string, apiConf k8sconfig.APIConfig) (Provider, error) {
Expand All @@ -37,10 +42,15 @@ func NewProvider(configMapName string, configMapNamespace string, apiConf k8scon
}

func (k *kubeadmProvider) ClusterName(ctx context.Context) (string, error) {
if k.cache.ClusterName != "" {
return k.cache.ClusterName, nil
}
configmap, err := k.kubeadmClient.CoreV1().ConfigMaps(k.configMapNamespace).Get(ctx, k.configMapName, metav1.GetOptions{})
if err != nil {
return "", fmt.Errorf("failed to fetch ConfigMap with name %s and namespace %s from K8s API: %w", k.configMapName, k.configMapNamespace, err)
}

k.cache.ClusterName = configmap.Data["clusterName"]

return configmap.Data["clusterName"], nil
}
5 changes: 3 additions & 2 deletions processor/resourcedetectionprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,14 @@ Queries the K8S API server to retrieve the following resource attributes:

The following permissions are required:
```yaml
kind: ClusterRole
kind: Role
metadata:
name: otel-collector
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "list"]
resourceNames: ["kubeadm-config"]
verbs: ["get"]
```

| Name | Type | Required | Default | Docs |
Expand Down

0 comments on commit 5a5fb6a

Please sign in to comment.