Skip to content

Commit

Permalink
Fix unit tests for /apis, /internal, /pkg (#63)
Browse files Browse the repository at this point in the history
* Fix unit tests for /apis and /pkg/instrumentation. Remove TargetAllocator artifacts. Run go mod tidy

* Fix manifest

* Fix api group in kubebuilder

* Use version 0.0.0 for unit tests
  • Loading branch information
lisguo authored Jan 24, 2024
1 parent a02591d commit fe144bb
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 2,803 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.12.0
ALL_SRC := $(shell find . -name '*.go' -type f | sort)
CW_AGENT_OPERATOR_IMPORT_PATH = "github.com/aws/amazon-cloudwatch-agent-operator"

GOTEST_OPTS := $(shell go list ./... | grep -v integration-tests)

ifndef ignore-not-found
ignore-not-found = false
endif
Expand Down Expand Up @@ -82,10 +84,10 @@ ci: test
# Run tests
# setup-envtest uses KUBEBUILDER_ASSETS which points to a directory with binaries (api-server, etcd and kubectl)
.PHONY: test
test: generate fmt vet ensure-generate-is-noop envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS} ./...
cd cmd/otel-allocator && KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS} ./...
cd cmd/operator-opamp-bridge && KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS} ./...
test: generate fmt vet envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS}
cd cmd/otel-allocator && KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS}
cd cmd/operator-opamp-bridge && KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test ${GOTEST_OPTS}

# Build manager binary
.PHONY: manager
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha1/amazoncloudwatchagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ type AmazonCloudWatchAgentSpec struct {
// UpgradeStrategy represents how the operator will handle upgrades to the CR when a newer version of the operator is deployed
// +optional
UpgradeStrategy UpgradeStrategy `json:"upgradeStrategy"`

// ImagePullPolicy indicates the pull policy to be used for retrieving the container image (Always, Never, IfNotPresent)
// +optional
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions apis/v1alpha1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ var (
_ admission.CustomDefaulter = &CollectorWebhook{}
)

// +kubebuilder:webhook:path=/mutate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=true,failurePolicy=fail,groups=cloudwatch.aws.amazon.co,resources=amazoncloudwatchagents,verbs=create;update,versions=v1alpha1,name=mamazoncloudwatchagent.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:verbs=create;update,path=/validate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=false,failurePolicy=fail,groups=cloudwatch.aws.amazon.co,resources=amazoncloudwatchagents,versions=v1alpha1,name=vamazoncloudwatchagentcreateupdate.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:verbs=delete,path=/validate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=false,failurePolicy=ignore,groups=cloudwatch.aws.amazon.co,resources=amazoncloudwatchagents,versions=v1alpha1,name=vamazoncloudwatchagentdelete.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:path=/mutate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=true,failurePolicy=fail,groups=cloudwatch.aws.amazon.com,resources=amazoncloudwatchagents,verbs=create;update,versions=v1alpha1,name=mamazoncloudwatchagent.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:verbs=create;update,path=/validate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=false,failurePolicy=fail,groups=cloudwatch.aws.amazon.com,resources=amazoncloudwatchagents,versions=v1alpha1,name=vamazoncloudwatchagentcreateupdate.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:verbs=delete,path=/validate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=false,failurePolicy=ignore,groups=cloudwatch.aws.amazon.com,resources=amazoncloudwatchagents,versions=v1alpha1,name=vamazoncloudwatchagentdelete.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:object:generate=false

type CollectorWebhook struct {
Expand Down
29 changes: 0 additions & 29 deletions apis/v1alpha1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
scheme: testScheme,
cfg: config.New(
config.WithCollectorImage("collector:v0.0.0"),
config.WithTargetAllocatorImage("ta:v0.0.0"),
),
}
ctx := context.Background()
Expand Down Expand Up @@ -314,9 +313,6 @@ func TestOTELColValidatingWebhook(t *testing.T) {
Replicas: &three,
MaxReplicas: &five,
UpgradeStrategy: "adhoc",
TargetAllocator: OpenTelemetryTargetAllocator{
Enabled: true,
},
Config: `receivers:
examplereceiver:
endpoint: "0.0.0.0:12345"
Expand Down Expand Up @@ -377,30 +373,6 @@ func TestOTELColValidatingWebhook(t *testing.T) {
},
expectedErr: "does not support the attribute 'tolerations'",
},
{
name: "invalid mode with target allocator",
otelcol: AmazonCloudWatchAgent{
Spec: AmazonCloudWatchAgentSpec{
Mode: ModeDeployment,
TargetAllocator: OpenTelemetryTargetAllocator{
Enabled: true,
},
},
},
expectedErr: "does not support the target allocation deployment",
},
{
name: "invalid target allocator config",
otelcol: AmazonCloudWatchAgent{
Spec: AmazonCloudWatchAgentSpec{
Mode: ModeStatefulSet,
TargetAllocator: OpenTelemetryTargetAllocator{
Enabled: true,
},
},
},
expectedErr: "the OpenTelemetry Spec Prometheus configuration is incorrect",
},
{
name: "invalid port name",
otelcol: AmazonCloudWatchAgent{
Expand Down Expand Up @@ -783,7 +755,6 @@ func TestOTELColValidatingWebhook(t *testing.T) {
scheme: testScheme,
cfg: config.New(
config.WithCollectorImage("collector:v0.0.0"),
config.WithTargetAllocatorImage("ta:v0.0.0"),
),
}
ctx := context.Background()
Expand Down
1 change: 0 additions & 1 deletion apis/v1alpha2/amazoncloudwatchagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ type AmazonCloudWatchAgentSpec struct {
// UpgradeStrategy represents how the operator will handle upgrades to the CR when a newer version of the operator is deployed
// +optional
UpgradeStrategy v1alpha1.UpgradeStrategy `json:"upgradeStrategy"`

// ImagePullPolicy indicates the pull policy to be used for retrieving the container image (Always, Never, IfNotPresent)
// +optional
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
Expand Down
Loading

0 comments on commit fe144bb

Please sign in to comment.