| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package k8s_state |
| 4 | |
| 5 | import "maps" |
| 6 | |
| 7 | func (c *Collector) runUpdateState(in <-chan resource) { |
| 8 | for { |
| 9 | select { |
| 10 | case <-c.ctx.Done(): |
| 11 | return |
| 12 | case res := <-in: |
| 13 | c.state.Lock() |
| 14 | switch res.kind() { |
| 15 | case kubeResourceNode: |
| 16 | c.updateNodeState(res) |
| 17 | case kubeResourcePod: |
| 18 | c.updatePodState(res) |
| 19 | case kubeResourceDeployment: |
| 20 | c.updateDeploymentState(res) |
| 21 | case kubeResourceCronJob: |
| 22 | c.updateCronJobState(res) |
| 23 | case kubeResourceJob: |
| 24 | c.updateJobState(res) |
| 25 | } |
| 26 | c.state.Unlock() |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func copyLabels(dst, src map[string]string) { |
| 32 | maps.Copy(dst, src) |
| 33 | } |
| 34 | |
| 35 | //go:fix inline |
| 36 | func ptr[T any](v T) *T { |
| 37 | return new(v) |
| 38 | } |