Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests for /apis, /internal, /pkg #63

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ignore the integration-tests as part of make test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could add an integration-test build tag to the integration tests, so they're skipped normally.

//go:build integration-test


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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure-generate-is-noop doesn't exist in the Makefile, we don't use it

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this

// +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