Skip to content

Added unit tests and E2E tests #418

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Unit Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.24.x]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Download dependencies
run: go mod download

- name: Run tests
run: |
go test ./... -v -coverprofile=coverage.out
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ CMDS=cosi-driver-nutanix
REGISTRY_NAME=ghcr.io/nutanix-cloud-native/cosi-driver-nutanix
IMAGE_TAG=latest

LOCAL_IMAGE_NAME=cosi-driver-nutanix
LOCAL_IMAGE_TAG=debug

all: build

.PHONY: build-% build container-% container clean
Expand Down Expand Up @@ -54,7 +51,6 @@ docker-push:
clean:
-rm -rf bin

# Creates an image of the driver in local environment
local-%: build-%
docker build -t $(LOCAL_IMAGE_NAME):$(LOCAL_IMAGE_TAG) -f package/docker/Dockerfile --label revision=$(REV) .
local: $(CMDS:%=local-%)
.PHONY: e2e-tests
e2e-tests:
ginkgo -v --tags e2e_test ./tests/...
49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ $ cd cosi-driver-nutanix
- `ENDPOINT` : Nutanix Object Store Endpoint
- `ACCESS_KEY` : Nutanix Object Store Access Key
- `SECRET_KEY` : Nutanix Object Store Secret Key
- `PC_SECRET` : Prism Central Credentials in the form 'prism-ip:prism-port:username:password'
- `PC_ENDPOINT` : Prism Central endpoint'
- `PC_SECRET` : Prism Central Credentials in the form 'username:password'
- `S3_INSECURE` : Controls whether certificate chain will be validated for S3 endpoint (Default: "false")
- `PC_INSECURE` : Controls whether certificate chain will be validated for Prism Central (Default: "false")
- `ACCOUNT_NAME` (Optional) : DisplayName identifier prefix for Nutanix Object Store (Default_Prefix: ntnx-cosi-iam-user)
Expand Down Expand Up @@ -168,9 +169,11 @@ Update the `objectstorage-provisioner` secret that is used by the running provis
ACCESS_KEY: ""
# Admin IAM Secret key to be used for Nutanix Objects
SECRET_KEY: ""
# PC Credentials in format <prism-ip>:<prism-port>:<user>:<password>.
# eg. "<ip>:<port>:user:password"
PC_SECRET: ""
# Prism Central endpoint, eg. "https://10.51.149.82:9440"
PC_ENDPOINT: "<ENDPOINT>"
# PC Credentials in format <user>:<password>.
# eg. "user:password"
PC_SECRET: "<USER>:<PASSWORD>"
# Controls whether certificate chain will be validated for S3 endpoint
# If INSECURE is set to true, an insecure connection will be made with
# the S3 endpoint (Certs will not be used)
Expand Down Expand Up @@ -221,3 +224,41 @@ $ make REGISTRY_NAME=SampleRegistryUsername/cosi-driver-nutanix IMAGE_TAG=latest
```

Your custom image `SampleRegistry/cosi-driver-nutanix:latest` is now ready to be used.

## Running Tests
### Unit Tests
Execute the following to run unit tests:
```sh
go test ./...
```
To generate the coverage report and an HTML page to view the report:
```sh
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
```
Open the HTML file in any web vrowser to view the coverage of each file.

### E2E Tests
Execute the following to run E2E tests:
```sh
sh scripts/setup_test_env.sh [flags]
```
```
Options:
-o, --oss_endpoint ENDPOINT Nutanix Object Store instance endpoint, eg. "http://10.51.142.82:80".
-i, --pc_endpoint ENDPOINT Prism Central endpoint, eg. "https://10.51.142.82:9440".
-u, --pc_user USERNAME Prism Central username. [default = admin]
-p, --pc_pass PASSWORD Prism Central password.
-a, --access_key KEY Admin IAM Access key to be used for Nutanix Objects.
-s, --secret_key KEY Admin IAM Secret key to be used for Nutanix Objects.
-n, --namespace NAMESAPCE Cluster namespace for the COSI deployment [default = cosi]
```
You can also run the E2E tests on Triton in a local environment if a real cluster is not available.
To run on Triton, you need the image [http://uranus.corp.nutanix.com/~ankush.patanwal/objects-triton.tar.gz] and k8s cluster running locally (eg. `minikube`) then execute the script with flag `-t` or `--use_triton`.
```sh
sh scripts/setup_test_env.sh -t
```
NOTE: You will need to load the Triton image to the local cluster. In `minikube` this can be done using:
```sh
minikube image load objects-triton:debug
```
3 changes: 1 addition & 2 deletions charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ The following table lists the configurable parameters of the cosi-driver-nutanix
| `secret.endpoint` | Nutanix Object Store instance endpoint | Yes | `""` |
| `secret.access_key` | Admin IAM Access key to be used for Nutanix Objects | Yes | `""` |
| `secret.secret_key` | Admin IAM Secret key to be used for Nutanix Objects | Yes | `""` |
| `secret.pc_ip` | PC ip | Yes | `""` |
| `secret.pc_port` | PC port | Yes | `""` |
| `secret.pc_endpoint` | PC endpoint | Yes | `""` |
| `secret.pc_username` | PC username | Yes | `""` |
| `secret.pc_password` | PC password | Yes | `""` |
| `secret.account_name` | Account Name is a displayName identifier Prefix for Nutanix | No | `"ntnx-cosi-iam-user"` |
Expand Down
1 change: 0 additions & 1 deletion charts/templates/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
name: objectstorage-provisioner
namespace: {{ .Release.Namespace }}
spec:
minReadySeconds: 30
progressDeadlineSeconds: 600
replicas: {{ .Values.replicas }}
revisionHistoryLimit: 3
Expand Down
3 changes: 2 additions & 1 deletion charts/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ stringData:
ACCESS_KEY: {{ required "access_key is required." .Values.secret.access_key | quote }}
ACCOUNT_NAME: {{ .Values.secret.account_name | quote }}
ENDPOINT: {{ required "endpoint is required." .Values.secret.endpoint | quote }}
PC_SECRET: "{{ required "pc_ip is required." .Values.secret.pc_ip }}:{{ required "pc_port is required." .Values.secret.pc_port }}:{{ required "pc_username is required." .Values.secret.pc_username }}:{{ required "pc_password is required." .Values.secret.pc_password }}"
PC_ENDPOINT: "{{ required "pc_endpoint is required." .Values.secret.pc_endpoint }}"
PC_SECRET: "{{ required "pc_username is required." .Values.secret.pc_username }}:{{ required "pc_password is required." .Values.secret.pc_password }}"
SECRET_KEY: {{ required "secret_key is required." .Values.secret.secret_key | quote }}
S3_INSECURE: {{ .Values.tls.s3.insecure | default "false" | quote }}
PC_INSECURE: {{ .Values.tls.pc.insecure | default "false" | quote }}
Expand Down
4 changes: 2 additions & 2 deletions charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ secret:
access_key: ""
# Admin IAM Secret key to be used for Nutanix Objects.
secret_key: ""
# Prism Central endpoint, eg. "https://10.51.149.82:9440"
pc_endpoint: ""
# PC Credentials.
pc_ip: ""
pc_port: "9440"
pc_username: "admin"
pc_password: ""
# Account Name is a displayName identifier Prefix for Nutanix.
Expand Down
16 changes: 14 additions & 2 deletions cmd/cosi-driver-nutanix/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,17 @@ func init() {
SecretKey,
"Admin IAM Secret key to be used for Nutanix Objects")

stringFlag(&PCEndpoint,
"pc_endpoint",
"t",
PCEndpoint,
"Prism Central Endpoint, eg: https://10.56.192.122:9440")

stringFlag(&PCSecret,
"pc_secret",
"k",
PCSecret,
"Prism Central Credentials in the format <prism-ip>:<prism-port>:<pc_user>:<pc_password>")
"Prism Central Credentials in the format <pc_user>:<pc_password>")

stringFlag(&AccountName,
"account_name",
Expand Down Expand Up @@ -144,13 +150,19 @@ func init() {
}

func run(ctx context.Context) error {
PCEndpoint, PCUsername, PCPassword, err := ntnxIam.GetCredsFromPCSecret(PCSecret)
PCUsername, PCPassword, err := ntnxIam.GetCredsFromPCSecret(PCSecret)
if err != nil {
errMsg := fmt.Errorf("failed to extract PC credential information from secret: %w", err)
klog.Error(errMsg)
return err
}

err = ntnxIam.ValidateEndpoint(PCEndpoint)
if err != nil {
klog.Error(fmt.Errorf("failed to validate PC endpoint: %w", err))
return err
}

identityServer, bucketProvisioner, err := driver.NewDriver(ctx,
provisionerName,
Endpoint,
Expand Down
58 changes: 49 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,81 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.69.4
k8s.io/apimachinery v0.32.0
k8s.io/api v0.32.3
k8s.io/apimachinery v0.32.3
k8s.io/klog/v2 v2.130.1
sigs.k8s.io/container-object-storage-interface-provisioner-sidecar v0.1.1-0.20230130215648-c0cf9951ffc6
sigs.k8s.io/container-object-storage-interface-spec v0.1.1-0.20221006174327-ec782953b8ac

)

require (
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/time v0.7.0 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/onsi/ginkgo/v2 v2.23.4
github.com/onsi/gomega v1.37.0
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/tools v0.31.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/protobuf v1.35.1 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/client-go v0.32.3
sigs.k8s.io/container-object-storage-interface-api v0.1.0
sigs.k8s.io/controller-runtime v0.20.4 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
)
Loading
Loading