Skip to content

Commit 2bd1b13

Browse files
authored
[defaulting] clean up unused image methods (#1839)
* [defaulting] use jmx images for agent and cluster checks runner * clean up jmx methods instead
1 parent 89046e8 commit 2bd1b13

File tree

6 files changed

+4
-77
lines changed

6 files changed

+4
-77
lines changed

internal/controller/datadogagent/component/agent/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func getDefaultServiceAccountName(dda metav1.Object) string {
101101
}
102102

103103
func agentImage() string {
104-
return fmt.Sprintf("%s/%s:%s", defaulting.DefaultImageRegistry, defaulting.DefaultAgentImageName, defaulting.AgentLatestVersion)
104+
return defaulting.GetLatestAgentImage()
105105
}
106106

107107
func otelAgentImage() string {

internal/controller/datadogagent/component/clusteragent/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func defaultPodSpec(dda metav1.Object, volumes []corev1.Volume, volumeMounts []c
115115
Containers: []corev1.Container{
116116
{
117117
Name: string(apicommon.ClusterAgentContainerName),
118-
Image: fmt.Sprintf("%s/%s:%s", defaulting.DefaultImageRegistry, defaulting.DefaultClusterAgentImageName, defaulting.ClusterAgentLatestVersion),
118+
Image: defaulting.GetLatestClusterAgentImage(),
119119
Ports: []corev1.ContainerPort{
120120
{
121121
ContainerPort: 5005,

internal/controller/datadogagent/component/clusterchecksrunner/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func getDefaultServiceAccountName(dda metav1.Object) string {
141141
}
142142

143143
func clusterChecksRunnerImage() string {
144-
return fmt.Sprintf("%s/%s:%s", defaulting.DefaultImageRegistry, defaulting.DefaultAgentImageName, defaulting.AgentLatestVersion)
144+
return defaulting.GetLatestAgentImage()
145145
}
146146

147147
func defaultPodSpec(dda metav1.Object, volumes []corev1.Volume, volumeMounts []corev1.VolumeMount, envVars []corev1.EnvVar) corev1.PodSpec {

pkg/constants/utils_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ func Test_GetImage(t *testing.T) {
6060
registry: &emptyRegistry,
6161
want: "gcr.io/datadoghq/agent:latest",
6262
},
63-
{
64-
name: "add jmx",
65-
imageSpec: &v2alpha1.AgentImageConfig{
66-
Name: "agent",
67-
Tag: defaulting.AgentLatestVersion,
68-
JMXEnabled: true,
69-
},
70-
registry: nil,
71-
want: defaulting.GetLatestAgentImageJMX(),
72-
},
7363
{
7464
name: "cluster-agent",
7565
imageSpec: &v2alpha1.AgentImageConfig{

pkg/defaulting/images.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434
DefaultEuropeImageRegistry string = "eu.gcr.io/datadoghq"
3535
DefaultAsiaImageRegistry string = "asia.gcr.io/datadoghq"
3636
DefaultGovImageRegistry string = "public.ecr.aws/datadog"
37-
// JMXTagSuffix prefix tag for agent JMX images
37+
// JMXTagSuffix suffix tag for agent JMX images
3838
JMXTagSuffix = "-jmx"
3939
// Default Image names
4040
DefaultAgentImageName string = "agent"
@@ -84,18 +84,6 @@ func GetLatestAgentImage(opts ...ImageOptions) string {
8484
return image.String()
8585
}
8686

87-
// GetLatestAgentImageJMX return the latest JMX stable agent release version
88-
func GetLatestAgentImageJMX(opts ...ImageOptions) string {
89-
image := &Image{
90-
registry: DefaultImageRegistry,
91-
imageName: DefaultAgentImageName,
92-
tag: AgentLatestVersion,
93-
}
94-
processOptions(image, opts...)
95-
image.tag = fmt.Sprintf("%s%s", image.tag, JMXTagSuffix)
96-
return image.String()
97-
}
98-
9987
// GetLatestClusterAgentImage return the latest stable agent release version
10088
func GetLatestClusterAgentImage(opts ...ImageOptions) string {
10189
image := &Image{
@@ -128,13 +116,6 @@ func WithImageName(name string) ImageOptions {
128116
}
129117
}
130118

131-
// WithJMX ImageOptions to specify if the JMX prefix should be added
132-
func WithJMX(jmx bool) ImageOptions {
133-
return func(image *Image) {
134-
image.isJMX = jmx
135-
}
136-
}
137-
138119
func processOptions(image *Image, opts ...ImageOptions) {
139120
for _, option := range opts {
140121
option(image)

pkg/defaulting/images_test.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ func TestGetLatestAgentImage(t *testing.T) {
4646
},
4747
want: "gcr.io/datadoghq/foo:latest",
4848
},
49-
{
50-
name: "with jmx",
51-
opts: []ImageOptions{
52-
WithImageName("foo"),
53-
WithTag("latest"),
54-
WithJMX(true),
55-
},
56-
want: "gcr.io/datadoghq/foo:latest-jmx",
57-
},
5849
}
5950
for _, tt := range tests {
6051
t.Run(tt.name, func(t *testing.T) {
@@ -65,41 +56,6 @@ func TestGetLatestAgentImage(t *testing.T) {
6556
}
6657
}
6758

68-
func TestGetLatestAgentImageJMX(t *testing.T) {
69-
tests := []struct {
70-
name string
71-
opts []ImageOptions
72-
want string
73-
}{
74-
{
75-
name: "default registry",
76-
want: fmt.Sprintf("gcr.io/datadoghq/agent:%s-jmx", AgentLatestVersion),
77-
},
78-
79-
{
80-
name: "docker.io",
81-
opts: []ImageOptions{
82-
WithRegistry(DockerHubContainerRegistry),
83-
},
84-
want: fmt.Sprintf("docker.io/datadog/agent:%s-jmx", AgentLatestVersion),
85-
},
86-
{
87-
name: "with tag",
88-
opts: []ImageOptions{
89-
WithTag("latest"),
90-
},
91-
want: "gcr.io/datadoghq/agent:latest-jmx",
92-
},
93-
}
94-
for _, tt := range tests {
95-
t.Run(tt.name, func(t *testing.T) {
96-
if got := GetLatestAgentImageJMX(tt.opts...); got != tt.want {
97-
t.Errorf("GetLatestAgentImageJMX() = %v, want %v", got, tt.want)
98-
}
99-
})
100-
}
101-
}
102-
10359
func TestGetLatestClusterAgentImage(t *testing.T) {
10460
tests := []struct {
10561
name string

0 commit comments

Comments
 (0)