Skip to content

Commit

Permalink
Use agent keyword instead of otelCol. Add statefulset rbac permission…
Browse files Browse the repository at this point in the history
…s. Fix config issue by using json instead of yaml
  • Loading branch information
lisguo committed Jan 19, 2024
1 parent 2d757b3 commit f98b527
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ARG AGENT_VERSION
ARG AUTO_INSTRUMENTATION_JAVA_VERSION

# Build
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION}" -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.agent=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION}" -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
6 changes: 1 addition & 5 deletions controllers/amazoncloudwatchagent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (

"github.com/go-logr/logr"
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
policyV1 "k8s.io/api/policy/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -123,9 +121,7 @@ func (r *AmazonCloudWatchAgentReconciler) SetupWithManager(mgr ctrl.Manager) err
Owns(&corev1.Service{}).
Owns(&appsv1.Deployment{}).
Owns(&appsv1.DaemonSet{}).
Owns(&appsv1.StatefulSet{}).
Owns(&autoscalingv2.HorizontalPodAutoscaler{}).
Owns(&policyV1.PodDisruptionBudget{})
Owns(&appsv1.StatefulSet{})

return builder.Complete(r)
}
3 changes: 3 additions & 0 deletions helm/templates/operator-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ rules:
- apiGroups: [ "apps" ]
resources: [ "deployments" ]
verbs: [ "create","delete","get","list","patch","update","watch" ]
- apiGroups: [ "apps" ]
resources: [ "statefulsets" ]
verbs: [ "create","delete","get","list","patch","update","watch" ]
- apiGroups: [ "apps" ]
resources: [ "replicasets" ]
verbs: [ "get","list","watch" ]
Expand Down
1 change: 1 addition & 0 deletions internal/manifests/collector/adapters/config_from.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package adapters
import (
"encoding/json"
"errors"

"gopkg.in/yaml.v2"
)

Expand Down
7 changes: 4 additions & 3 deletions internal/manifests/collector/config_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
package collector

import (
"encoding/json"

_ "github.com/prometheus/prometheus/discovery/install" // Package install has the side-effect of registering all builtin.
"gopkg.in/yaml.v2"

"github.com/aws/amazon-cloudwatch-agent-operator/apis/v1alpha1"
"github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/collector/adapters"
)

func ReplaceConfig(instance v1alpha1.AmazonCloudWatchAgent) (string, error) {
config, err := adapters.ConfigFromString(instance.Spec.Config)
config, err := adapters.ConfigFromJSONString(instance.Spec.Config)
if err != nil {
return "", err
}

out, err := yaml.Marshal(config)
out, err := json.Marshal(config)
if err != nil {
return "", err
}
Expand Down
8 changes: 6 additions & 2 deletions internal/manifests/collector/container_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package collector

import (
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)

func TestStatsDGetContainerPorts(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/manifests/collector/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
)

const (
defaultCollectorImage = "default-collector"
defaultCollectorImage = "default-collector"
)

func deploymentParams() manifests.Params {
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func main() {
metricsAddr string
probeAddr string
pprofAddr string
collectorImage string
agentImage string
autoInstrumentationJava string
webhookPort int
tlsOpt tlsConfig
Expand All @@ -95,7 +95,7 @@ func main() {
pflag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
pflag.StringVar(&probeAddr, "health-probe-addr", ":8081", "The address the probe endpoint binds to.")
pflag.StringVar(&pprofAddr, "pprof-addr", "", "The address to expose the pprof server. Default is empty string which disables the pprof server.")
stringFlagOrEnv(&collectorImage, "collector-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("%s:%s", cloudwatchAgentImageRepository, v.AmazonCloudWatchAgent), "The default CloudWatch Agent image. This image is used when no image is specified in the CustomResource.")
stringFlagOrEnv(&agentImage, "agent-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("%s:%s", cloudwatchAgentImageRepository, v.AmazonCloudWatchAgent), "The default CloudWatch Agent image. This image is used when no image is specified in the CustomResource.")
stringFlagOrEnv(&autoInstrumentationJava, "auto-instrumentation-java-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_JAVA", fmt.Sprintf("%s:%s", autoInstrumentationJavaImageRepository, v.AutoInstrumentationJava), "The default OpenTelemetry Java instrumentation image. This image is used when no image is specified in the CustomResource.")
pflag.Parse()

Expand All @@ -107,7 +107,7 @@ func main() {

logger.Info("Starting the Amazon CloudWatch Agent Operator",
"amazon-cloudwatch-agent-operator", v.Operator,
"cloudwatch-agent", collectorImage,
"cloudwatch-agent", agentImage,
"auto-instrumentation-java", autoInstrumentationJava,
"build-date", v.BuildDate,
"go-version", v.Go,
Expand All @@ -118,7 +118,7 @@ func main() {
cfg := config.New(
config.WithLogger(ctrl.Log.WithName("config")),
config.WithVersion(v),
config.WithCollectorImage(collectorImage),
config.WithCollectorImage(agentImage),
config.WithAutoInstrumentationJavaImage(autoInstrumentationJava),
)

Expand Down

0 comments on commit f98b527

Please sign in to comment.