Skip to content

Commit 6545a72

Browse files
Fiona-WatersRaghul-M
authored andcommitted
Added unit tests for support package
1 parent 32729c5 commit 6545a72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3765
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Verify Generated Files and Import Organization
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
paths:
7+
- '**.go'
8+
- '**go.mod'
9+
- '**go.sum'
10+
tags-ignore:
11+
- 'v*'
12+
pull_request:
13+
paths:
14+
- '**.go'
15+
- '**go.mod'
16+
- '**go.sum'
17+
jobs:
18+
verify-imports:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set Go
23+
uses: actions/setup-go@v3
24+
with:
25+
go-version: v1.19
26+
- name: Verify that imports are organized
27+
run: make verify-imports
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Verify Unit tests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'support/**'
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
<<<<<<< HEAD
15+
16+
=======
17+
>>>>>>> 156eb48 (Fixed Changes in Comments and added Ingress_test)
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: v1.19
24+
25+
<<<<<<< HEAD
26+
27+
=======
28+
>>>>>>> 156eb48 (Fixed Changes in Comments and added Ingress_test)
29+
30+
- name: Run unit tests
31+
run: go test ./support/. -v
32+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.dll
88
*.so
99
*.dylib
10+
bin
1011

1112
# Test binary, built with `go test -c`
1213
*.test

Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# CODEFLARE_SDK_VERSION defines the default version of the CodeFlare SDK
2+
CODEFLARE_SDK_VERSION ?= 0.9.0
3+
4+
# RAY_VERSION defines the default version of Ray (used for testing)
5+
RAY_VERSION ?= 2.5.0
6+
7+
# RAY_IMAGE defines the default container image for Ray (used for testing)
8+
RAY_IMAGE ?= rayproject/ray:$(RAY_VERSION)
9+
10+
##@ Development
11+
12+
DEFAULTS_TEST_FILE := support/defaults.go
13+
14+
.PHONY: defaults
15+
defaults:
16+
$(info Regenerating $(DEFAULTS_TEST_FILE))
17+
@echo "package support" > $(DEFAULTS_TEST_FILE)
18+
@echo "" >> $(DEFAULTS_TEST_FILE)
19+
@echo "// ***********************" >> $(DEFAULTS_TEST_FILE)
20+
@echo "// DO NOT EDIT THIS FILE" >> $(DEFAULTS_TEST_FILE)
21+
@echo "// ***********************" >> $(DEFAULTS_TEST_FILE)
22+
@echo "" >> $(DEFAULTS_TEST_FILE)
23+
@echo "const (" >> $(DEFAULTS_TEST_FILE)
24+
@echo " CodeFlareSDKVersion = \"$(CODEFLARE_SDK_VERSION)\"" >> $(DEFAULTS_TEST_FILE)
25+
@echo " RayVersion = \"$(RAY_VERSION)\"" >> $(DEFAULTS_TEST_FILE)
26+
@echo " RayImage = \"$(RAY_IMAGE)\"" >> $(DEFAULTS_TEST_FILE)
27+
@echo "" >> $(DEFAULTS_TEST_FILE)
28+
@echo ")" >> $(DEFAULTS_TEST_FILE)
29+
@echo "" >> $(DEFAULTS_TEST_FILE)
30+
31+
gofmt -w $(DEFAULTS_TEST_FILE)
32+
33+
## Location to install dependencies to
34+
LOCALBIN ?= $(shell pwd)/bin
35+
$(LOCALBIN):
36+
mkdir -p $(LOCALBIN)
37+
38+
OPENSHIFT-GOIMPORTS ?= $(LOCALBIN)/openshift-goimports
39+
40+
.PHONY: openshift-goimports
41+
openshift-goimports: $(OPENSHIFT-GOIMPORTS) ## Download openshift-goimports locally if necessary.
42+
$(OPENSHIFT-GOIMPORTS): $(LOCALBIN)
43+
test -s $(LOCALBIN)/openshift-goimports || GOBIN=$(LOCALBIN) go install github.com/openshift-eng/openshift-goimports@latest
44+
45+
.PHONY: imports
46+
imports: openshift-goimports ## Organize imports in go files using openshift-goimports. Example: make imports
47+
$(OPENSHIFT-GOIMPORTS)
48+
49+
.PHONY: verify-imports
50+
verify-imports: openshift-goimports ## Run import verifications.
51+
./hack/verify-imports.sh $(OPENSHIFT-GOIMPORTS)

OWNERS

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
approvers:
2+
- anishasthana
3+
- astefanutti
4+
- sutaakar
5+
reviewers:
6+
- anishasthana
7+
- astefanutti
8+
- dimakis
9+
- Fiona-Waters
10+
- sutaakar

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
# codeflare-common
22
Common packages for use with CodeFlare Distributed Workload stack.
3+
4+
## GitHub actions collection
5+
Folder github-actions contains collection of GitHub composite actions which can be reused in other repositories.
6+
This approach is used to keep all the usable actions on one place, unlike from default usage when every action is located in dedicated repository.
7+
8+
Usage:
9+
- Clone CodeFlare common repository
10+
- Refer to the action file using `uses` step parameter pointing to the local folder path with action.yml
11+
12+
### KinD GitHub action
13+
GitHub action which spins up KinD cluster with Ingress and local registry available in the cluster.
14+
15+
Action creates environment variables:
16+
- `TEMP_DIR` - helper env variable, pointing to local temporary directory
17+
- `REGISTRY_ADDRESS` - hostname of the locally available insecure registry
18+
- `KIND_CONFIG_FILE` - helper env variable, pointing to the KinD config file
19+
- `CLUSTER_TYPE` - type of cluster, hardcoded to `KIND`
20+
- `CLUSTER_HOSTNAME` - hostname of the KinD cluster
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "Export all KinD pod logs"
2+
description: "Step to export all KinD pod logs"
3+
4+
inputs:
5+
output-directory:
6+
description: "Directory to export log files to"
7+
required: true
8+
cluster-name:
9+
description: "Name of the KinD cluster"
10+
required: false
11+
default: cluster
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Export all KinD pod logs
17+
run: |
18+
echo "Export all KinD pod logs to ${{ inputs.output-directory }}"
19+
kind export logs ${{ inputs.output-directory }} --name ${{ inputs.cluster-name }}
20+
shell: bash

github-actions/kind/action.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: "Set up KinD"
2+
description: "Step to start and configure KinD cluster"
3+
4+
inputs:
5+
node-hostname:
6+
description: "Hostname of the main kind node"
7+
required: false
8+
default: kind
9+
cluster-name:
10+
description: "Name of the KinD cluster"
11+
required: false
12+
default: cluster
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Init directories
18+
shell: bash
19+
run: |
20+
TEMP_DIR="$(pwd)/tmp"
21+
mkdir -p "${TEMP_DIR}"
22+
echo "TEMP_DIR=${TEMP_DIR}" >> $GITHUB_ENV
23+
24+
mkdir -p "$(pwd)/bin"
25+
echo "$(pwd)/bin" >> $GITHUB_PATH
26+
27+
- name: Container image registry
28+
shell: bash
29+
run: |
30+
podman run -d -p 5000:5000 --name registry registry:2.8.1
31+
32+
export REGISTRY_ADDRESS=$(hostname -i):5000
33+
echo "REGISTRY_ADDRESS=${REGISTRY_ADDRESS}" >> $GITHUB_ENV
34+
echo "Container image registry started at ${REGISTRY_ADDRESS}"
35+
36+
KIND_CONFIG_FILE=${{ env.TEMP_DIR }}/kind.yaml
37+
echo "KIND_CONFIG_FILE=${KIND_CONFIG_FILE}" >> $GITHUB_ENV
38+
envsubst < ${GITHUB_ACTION_PATH}/resouces/kind.yaml > ${KIND_CONFIG_FILE}
39+
40+
sudo --preserve-env=REGISTRY_ADDRESS sh -c 'cat > /etc/containers/registries.conf.d/local.conf <<EOF
41+
[[registry]]
42+
prefix = "$REGISTRY_ADDRESS"
43+
insecure = true
44+
location = "$REGISTRY_ADDRESS"
45+
EOF'
46+
47+
- name: Setup KinD cluster
48+
uses: helm/kind-action@v1.8.0
49+
with:
50+
cluster_name: ${{ inputs.cluster-name }}
51+
version: v0.17.0
52+
config: ${{ env.KIND_CONFIG_FILE }}
53+
54+
- name: Print cluster info
55+
shell: bash
56+
run: |
57+
echo "KinD cluster:"
58+
kubectl cluster-info
59+
kubectl describe nodes
60+
61+
- name: Install Ingress controller
62+
shell: bash
63+
run: |
64+
VERSION=controller-v1.6.4
65+
echo "Deploying Ingress controller into KinD cluster"
66+
curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/"${VERSION}"/deploy/static/provider/kind/deploy.yaml | sed "s/--publish-status-address=localhost/--report-node-internal-ip-address\\n - --status-update-interval=10/g" | kubectl apply -f -
67+
kubectl annotate ingressclass nginx "ingressclass.kubernetes.io/is-default-class=true"
68+
kubectl -n ingress-nginx wait --timeout=300s --for=condition=Available deployments --all
69+
70+
- name: Add ${{ inputs.node-hostname }} host to machine hosts
71+
shell: bash
72+
run: echo "127.0.0.1 ${{ inputs.node-hostname }}" | sudo tee -a /etc/hosts
73+
74+
- name: Set env variables for tests to properly leverage KinD cluster
75+
shell: bash
76+
run: |
77+
echo "CLUSTER_TYPE=KIND" >> $GITHUB_ENV
78+
echo "CLUSTER_HOSTNAME=${{ inputs.node-hostname }}" >> $GITHUB_ENV
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ---------------------------------------------------------------------------
2+
# Copyright 2023.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ---------------------------------------------------------------------------
16+
17+
kind: Cluster
18+
apiVersion: kind.x-k8s.io/v1alpha4
19+
nodes:
20+
- role: control-plane
21+
image: kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1
22+
kubeadmConfigPatches:
23+
- |
24+
kind: InitConfiguration
25+
nodeRegistration:
26+
kubeletExtraArgs:
27+
node-labels: "ingress-ready=true"
28+
containerdConfigPatches:
29+
- |-
30+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."${REGISTRY_ADDRESS}"]
31+
endpoint = ["http://${REGISTRY_ADDRESS}"]

go.mod

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module github.com/project-codeflare/codeflare-common
2+
3+
go 1.19
4+
5+
require (
6+
github.com/onsi/gomega v1.27.10
7+
github.com/openshift-online/ocm-sdk-go v0.1.368
8+
github.com/openshift/api v0.0.0-20230213134911-7ba313770556
9+
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c
10+
github.com/project-codeflare/multi-cluster-app-dispatcher v1.37.0
11+
github.com/ray-project/kuberay/ray-operator v0.0.0-20231016183545-097828931d15
12+
k8s.io/api v0.26.3
13+
k8s.io/apimachinery v0.26.3
14+
k8s.io/client-go v0.26.3
15+
sigs.k8s.io/controller-runtime v0.14.6
16+
)
17+
18+
require (
19+
github.com/aymerick/douceur v0.2.0 // indirect
20+
github.com/beorn7/perks v1.0.1 // indirect
21+
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
22+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
23+
github.com/davecgh/go-spew v1.1.1 // indirect
24+
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
25+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
26+
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
27+
github.com/go-logr/logr v1.2.4 // indirect
28+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
29+
github.com/go-openapi/jsonreference v0.20.1 // indirect
30+
github.com/go-openapi/swag v0.22.3 // indirect
31+
github.com/gogo/protobuf v1.3.2 // indirect
32+
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
33+
github.com/golang/glog v1.0.0 // indirect
34+
github.com/golang/protobuf v1.5.3 // indirect
35+
github.com/google/gnostic v0.6.9 // indirect
36+
github.com/google/go-cmp v0.5.9 // indirect
37+
github.com/google/gofuzz v1.2.0 // indirect
38+
github.com/google/uuid v1.3.0 // indirect
39+
github.com/gorilla/css v1.0.0 // indirect
40+
github.com/imdario/mergo v0.3.12 // indirect
41+
github.com/josharian/intern v1.0.0 // indirect
42+
github.com/json-iterator/go v1.1.12 // indirect
43+
github.com/mailru/easyjson v0.7.7 // indirect
44+
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
45+
github.com/microcosm-cc/bluemonday v1.0.18 // indirect
46+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
47+
github.com/modern-go/reflect2 v1.0.2 // indirect
48+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
49+
github.com/pkg/errors v0.9.1 // indirect
50+
github.com/prometheus/client_golang v1.14.0 // indirect
51+
github.com/prometheus/client_model v0.3.0 // indirect
52+
github.com/prometheus/common v0.37.0 // indirect
53+
github.com/prometheus/procfs v0.8.0 // indirect
54+
github.com/spf13/pflag v1.0.5 // indirect
55+
github.com/stretchr/testify v1.8.4 // indirect
56+
golang.org/x/net v0.12.0 // indirect
57+
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
58+
golang.org/x/sys v0.10.0 // indirect
59+
golang.org/x/term v0.10.0 // indirect
60+
golang.org/x/text v0.11.0 // indirect
61+
golang.org/x/time v0.3.0 // indirect
62+
google.golang.org/appengine v1.6.7 // indirect
63+
google.golang.org/protobuf v1.28.1 // indirect
64+
gopkg.in/inf.v0 v0.9.1 // indirect
65+
gopkg.in/yaml.v2 v2.4.0 // indirect
66+
gopkg.in/yaml.v3 v3.0.1 // indirect
67+
k8s.io/klog/v2 v2.90.1 // indirect
68+
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d // indirect
69+
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
70+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
71+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
72+
sigs.k8s.io/yaml v1.3.0 // indirect
73+
)

0 commit comments

Comments
 (0)