Skip to content

Commit afeefb0

Browse files
committed
Use AnyConfig for Scrape Configs in v1beta1.TargetAllocator
1 parent f8e9096 commit afeefb0

File tree

4 files changed

+10
-54
lines changed

4 files changed

+10
-54
lines changed

apis/v1beta1/targetallocator_types.go

+1-43
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package v1beta1
1818

1919
import (
20-
"encoding/json"
21-
2220
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2321
)
2422

@@ -44,7 +42,7 @@ type TargetAllocatorSpec struct {
4442
// For the exact format, see https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config.
4543
// +optional
4644
// +listType=atomic
47-
ScrapeConfigs []ScrapeConfig `json:"scrapeConfigs,omitempty"`
45+
ScrapeConfigs []AnyConfig `json:"scrapeConfigs,omitempty"`
4846
// PrometheusCR defines the configuration for the retrieval of PrometheusOperator CRDs ( servicemonitor.monitoring.coreos.com/v1 and podmonitor.monitoring.coreos.com/v1 ).
4947
// +optional
5048
PrometheusCR TargetAllocatorPrometheusCR `json:"prometheusCR,omitempty"`
@@ -85,46 +83,6 @@ type TargetAllocatorStatus struct {
8583
Image string `json:"image,omitempty"`
8684
}
8785

88-
// ScrapeConfig is a Prometheus scrape config definition.
89-
type ScrapeConfig map[string]interface{}
90-
91-
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
92-
func (in *ScrapeConfig) DeepCopyInto(out *ScrapeConfig) {
93-
*out = make(map[string]interface{}, len(*in))
94-
for key, val := range *in {
95-
(*out)[key] = val
96-
}
97-
}
98-
99-
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScrapeConfig.
100-
func (in *ScrapeConfig) DeepCopy() *ScrapeConfig {
101-
if in == nil {
102-
return nil
103-
}
104-
out := new(ScrapeConfig)
105-
in.DeepCopyInto(out)
106-
return out
107-
}
108-
109-
var _ json.Marshaler = &ScrapeConfig{}
110-
var _ json.Unmarshaler = &ScrapeConfig{}
111-
112-
// UnmarshalJSON implements an alternative parser for this field.
113-
func (c *ScrapeConfig) UnmarshalJSON(b []byte) error {
114-
if err := json.Unmarshal(b, c); err != nil {
115-
return err
116-
}
117-
return nil
118-
}
119-
120-
// MarshalJSON specifies how to convert this object into JSON.
121-
func (c *ScrapeConfig) MarshalJSON() ([]byte, error) {
122-
if c == nil {
123-
return []byte("{}"), nil
124-
}
125-
return json.Marshal(c)
126-
}
127-
12886
//+kubebuilder:object:root=true
12987
//+kubebuilder:subresource:status
13088

apis/v1beta1/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/manifests/collector/targetallocator.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TargetAllocator(params manifests.Params) (*v1beta1.TargetAllocator, error)
7575
}, nil
7676
}
7777

78-
func getScrapeConfigs(otelcolConfig string) ([]v1beta1.ScrapeConfig, error) {
78+
func getScrapeConfigs(otelcolConfig string) ([]v1beta1.AnyConfig, error) {
7979
// Collector supports environment variable substitution, but the TA does not.
8080
// TA Scrape Configs should have a single "$", as it does not support env var substitution
8181
prometheusReceiverConfig, err := adapters.UnescapeDollarSignsInPromConfig(otelcolConfig)
@@ -88,10 +88,10 @@ func getScrapeConfigs(otelcolConfig string) ([]v1beta1.ScrapeConfig, error) {
8888
return nil, err
8989
}
9090

91-
v1beta1scrapeConfigs := make([]v1beta1.ScrapeConfig, len(scrapeConfigs))
91+
v1beta1scrapeConfigs := make([]v1beta1.AnyConfig, len(scrapeConfigs))
9292

9393
for i, config := range scrapeConfigs {
94-
v1beta1scrapeConfigs[i] = config
94+
v1beta1scrapeConfigs[i] = v1beta1.AnyConfig{Object: config}
9595
}
9696

9797
return v1beta1scrapeConfigs, nil

internal/manifests/collector/targetallocator_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestTargetAllocator(t *testing.T) {
8484
CollectorSelector: metav1.LabelSelector{
8585
MatchLabels: manifestutils.SelectorLabels(objectMetadata, ComponentOpenTelemetryCollector),
8686
},
87-
ScrapeConfigs: []v1beta1.ScrapeConfig{},
87+
ScrapeConfigs: []v1beta1.AnyConfig{},
8888
},
8989
},
9090
},
@@ -107,7 +107,7 @@ func TestGetScrapeConfigs(t *testing.T) {
107107
testCases := []struct {
108108
name string
109109
input v1beta1.Config
110-
want []v1beta1.ScrapeConfig
110+
want []v1beta1.AnyConfig
111111
wantErr error
112112
}{
113113
{
@@ -123,7 +123,7 @@ func TestGetScrapeConfigs(t *testing.T) {
123123
},
124124
},
125125
},
126-
want: []v1beta1.ScrapeConfig{},
126+
want: []v1beta1.AnyConfig{},
127127
},
128128
{
129129
name: "no scrape configs key",
@@ -155,10 +155,8 @@ func TestGetScrapeConfigs(t *testing.T) {
155155
},
156156
},
157157
},
158-
want: []v1beta1.ScrapeConfig{
159-
{
160-
"job": "somejob",
161-
},
158+
want: []v1beta1.AnyConfig{
159+
{Object: map[string]interface{}{"job": "somejob"}},
162160
},
163161
},
164162
}

0 commit comments

Comments
 (0)