configs.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package external
  2. // Config stores the configuration for external labels.
  3. // Currently, only NodeLabelConfig is supported, and ConfigMaps
  4. // are the only supported source of external node labels.
  5. type Config struct {
  6. nodeLabelConfig *NodeLabelConfig
  7. }
  8. func NewConfig(nodeCfg *NodeLabelConfig) *Config {
  9. return &Config{
  10. nodeLabelConfig: nodeCfg,
  11. }
  12. }
  13. // NodeLabelConfig returns the node label configuration.
  14. // It returns nil if node label configuration is not provided.
  15. func (c *Config) NodeLabelConfig() *NodeLabelConfig {
  16. if c == nil {
  17. return nil
  18. }
  19. return c.nodeLabelConfig
  20. }
  21. // HasNodeLabelConfig reports whether node labels are configured.
  22. func (c *Config) HasNodeLabelConfig() bool {
  23. return c != nil && c.nodeLabelConfig != nil
  24. }
  25. // NodeLabelConfig identifies a ConfigMap to watch and describes how to extract
  26. // labels from its data. ConfigMapName is required; all other fields are optional.
  27. // Set Key and Route only when labels are embedded inside a YAML document
  28. // stored as a block-scalar value; leave both empty for a flat key/value ConfigMap.
  29. type NodeLabelConfig struct {
  30. // configMapName is the name of the ConfigMap to watch.
  31. configMapName string
  32. // namespace is the namespace of the ConfigMap. Defaults to the agent's own namespace when empty.
  33. namespace string
  34. // key is the ConfigMap data key that holds the YAML document (block-scalar ConfigMaps only).
  35. key string
  36. // route is the dot-separated path to the labels map within the parsed YAML document.
  37. route string
  38. }
  39. func NewNodeLabelConfig(
  40. configMapName string,
  41. namespace string,
  42. key string,
  43. route string,
  44. ) *NodeLabelConfig {
  45. return &NodeLabelConfig{
  46. configMapName: configMapName,
  47. namespace: namespace,
  48. key: key,
  49. route: route,
  50. }
  51. }
  52. func (nlc *NodeLabelConfig) ConfigMapName() string {
  53. return nlc.configMapName
  54. }
  55. func (nlc *NodeLabelConfig) Namespace() string {
  56. return nlc.namespace
  57. }
  58. func (nlc *NodeLabelConfig) Key() string {
  59. return nlc.key
  60. }
  61. func (nlc *NodeLabelConfig) Route() string {
  62. return nlc.route
  63. }