Skip to content

Commit

Permalink
fixing operator suite test (#65)
Browse files Browse the repository at this point in the history
* fixing operator suite test

* added test in makefile

* added test as a step in github workflows

* added test as a step in github workflows

* added test at the end of lint

* Running tests in all folder

* removing race

* added verbose output for go test

* running raw go test

* wip

* wip

* wip

* test

* wip

* test

* checking

* test

* test

* use json.RawMessage for trigger metadata

* use testEnv config for manager

* move controller setup to BeforeSuite

* resolve comments and cleanup

---------

Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com>
Co-authored-by: Maanas M Singh <59373661+Maanas-23@users.noreply.github.com>
Co-authored-by: Maanas M Singh <maanasmsingh@gmail.com>
  • Loading branch information
4 people authored Feb 20, 2025
1 parent 14c76c5 commit 8dbe398
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 101 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/lint-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,41 @@ jobs:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install dependencies
run: go mod tidy
working-directory: ${{ matrix.modules }}
- name: golangci-lint ${{ matrix.modules }}
uses: golangci/golangci-lint-action@v6
with:
working-directory: ${{ matrix.modules }}
args: -v --timeout 5m
version: v1.63.4
version: v1.63.4
test:
needs: detect-modules
runs-on: ubuntu-latest
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install dependencies
run: go mod tidy
working-directory: ${{ matrix.modules }}
- name: test ${{ matrix.modules }}
run: cd ${{ matrix.modules }} && make test
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ deploy: ## Deploy the operator and resolver
undeploy: ## Undeploy the operator and resolver
kubectl delete -f ./install.yaml

.PHONY: test
test: test-operator test-resolver test-pkg ## Run all tests

.PHONY: test-operator
test-operator: ## Run operator tests
cd operator && make test

.PHONY: test-resolver
test-resolver: ## Run resolver tests
cd resolver && make test

.PHONY: test-pkg
test-pkg: ## Run pkg tests
cd pkg && make test

7 changes: 6 additions & 1 deletion charts/elasti/templates/elastiservice-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ spec:
items:
properties:
metadata:
x-kubernetes-preserve-unknown-fields: true
description: |-
RawMessage is a raw encoded JSON value.
It implements [Marshaler] and [Unmarshaler] and can
be used to delay JSON decoding or precompute a JSON encoding.
format: byte
type: string
type:
type: string
required:
Expand Down
13 changes: 1 addition & 12 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
Expand All @@ -61,7 +50,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v $$(go list ./... | grep -v /e2e) -coverprofile cover.out

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
Expand Down
8 changes: 4 additions & 4 deletions operator/api/v1alpha1/elastiservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1alpha1

import (
"encoding/json"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -76,10 +78,8 @@ type ElastiServiceList struct {
}

type ScaleTrigger struct {
Type string `json:"type"`
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Metadata any `json:"metadata,omitempty"`
Type string `json:"type"`
Metadata json.RawMessage `json:"metadata,omitempty"`
}

type AutoscalerSpec struct {
Expand Down
54 changes: 53 additions & 1 deletion operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ spec:
items:
properties:
metadata:
x-kubernetes-preserve-unknown-fields: true
description: |-
RawMessage is a raw encoded JSON value.
It implements [Marshaler] and [Unmarshaler] and can
be used to delay JSON decoding or precompute a JSON encoding.
format: byte
type: string
type:
type: string
required:
Expand Down
15 changes: 15 additions & 0 deletions operator/hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
Loading

0 comments on commit 8dbe398

Please sign in to comment.