Skip to content

Commit

Permalink
Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Oct 7, 2024
1 parent fca4974 commit b78ec48
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
45 changes: 24 additions & 21 deletions libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,25 @@ func (p *pod) GenerateHints(event bus.Event) bus.Event {
var kubeMeta, container mapstr.M

annotations := make(mapstr.M, 0)
rawMeta, ok := event["kubernetes"]
if ok {
kubeMeta = rawMeta.(mapstr.M)
// The builder base config can configure any of the field values of kubernetes if need be.
e["kubernetes"] = kubeMeta
if rawAnn, ok := kubeMeta["annotations"]; ok {
anns, _ := rawAnn.(mapstr.M)
if len(anns) != 0 {
annotations = anns.Clone()
rawMeta, found := event["kubernetes"]
if found {
kubeMeta, ok := rawMeta.(mapstr.M)
if ok {
// The builder base config can configure any of the field values of kubernetes if need be.
e["kubernetes"] = kubeMeta
if rawAnn, ok := kubeMeta["annotations"]; ok {
anns, _ := rawAnn.(mapstr.M)
if len(anns) != 0 {
annotations = anns.Clone()
}
}
}

// Look at all the namespace level default annotations and do a merge with priority going to the pod annotations.
if rawNsAnn, ok := kubeMeta["namespace_annotations"]; ok {
namespaceAnnotations, _ := rawNsAnn.(mapstr.M)
if len(namespaceAnnotations) != 0 {
annotations.DeepUpdateNoOverwrite(namespaceAnnotations)
// Look at all the namespace level default annotations and do a merge with priority going to the pod annotations.
if rawNsAnn, ok := kubeMeta["namespace_annotations"]; ok {
namespaceAnnotations, _ := rawNsAnn.(mapstr.M)
if len(namespaceAnnotations) != 0 {
annotations.DeepUpdateNoOverwrite(namespaceAnnotations)
}
}
}
}
Expand All @@ -269,12 +271,13 @@ func (p *pod) GenerateHints(event bus.Event) bus.Event {
e["ports"] = ports
}

if rawCont, ok := kubeMeta["container"]; ok {
container = rawCont.(mapstr.M)
// This would end up adding a runtime entry into the event. This would make sure
// that there is not an attempt to spin up a docker input for a rkt container and when a
// rkt input exists it would be natively supported.
e["container"] = container
if rawCont, found := kubeMeta["container"]; found {
if container, ok := rawCont.(mapstr.M); ok {
// This would end up adding a runtime entry into the event. This would make sure
// that there is not an attempt to spin up a docker input for a rkt container and when a
// rkt input exists it would be natively supported.
e["container"] = container
}
}

cname := utils.GetContainerName(container)
Expand Down
6 changes: 3 additions & 3 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ func (k *kubernetesAnnotator) init(config kubeAnnotatorConfig, cfg *config.C) {

watcher.AddEventHandler(kubernetes.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
pod := obj.(*kubernetes.Pod)
pod, _ := obj.(*kubernetes.Pod)
k.addPod(pod)
},
UpdateFunc: func(obj interface{}) {
pod := obj.(*kubernetes.Pod)
pod, _ := obj.(*kubernetes.Pod)
k.updatePod(pod)
},
DeleteFunc: func(obj interface{}) {
pod := obj.(*kubernetes.Pod)
pod, _ := obj.(*kubernetes.Pod)
k.removePod(pod)
},
})
Expand Down
8 changes: 4 additions & 4 deletions metricbeat/module/kubernetes/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ func getExtraWatchers(resourceName string, addResourceMetadata *metadata.AddReso
// in order to be able to retrieve 2nd layer Owner metadata like in case of:
// Deployment -> Replicaset -> Pod
// CronJob -> job -> Pod
if addResourceMetadata != nil && addResourceMetadata.Deployment {
if addResourceMetadata.Deployment {
extra = append(extra, ReplicaSetResource)
}
if addResourceMetadata != nil && addResourceMetadata.CronJob {
if addResourceMetadata.CronJob {
extra = append(extra, JobResource)
}
return extra
Expand Down Expand Up @@ -618,8 +618,8 @@ func NewResourceMetadataEnricher(
return &nilEnricher{}
}

var specificMetaGen metadata.MetaGen //nolint:typecheck // older versions of typecheck complain about this
var generalMetaGen *metadata.Resource //nolint:typecheck // older versions of typecheck complain about this
var specificMetaGen metadata.MetaGen

Check failure on line 621 in metricbeat/module/kubernetes/util/kubernetes.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

specificMetaGen declared and not used (typecheck)
var generalMetaGen *metadata.Resource

Check failure on line 622 in metricbeat/module/kubernetes/util/kubernetes.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

generalMetaGen declared and not used (typecheck)
// We initialise the use_kubeadm variable based on modules KubeAdm base configuration
err = config.AddResourceMetadata.Namespace.SetBool("use_kubeadm", -1, commonMetaConfig.KubeAdm)
if err != nil {
Expand Down

0 comments on commit b78ec48

Please sign in to comment.