Skip to content

Commit

Permalink
Move mpi-operator v2 to the top of the repository
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
Co-authored-by: Aldo Culquicondor <1299064+alculquicondor@users.noreply.github.com>
  • Loading branch information
tenzen-y and alculquicondor committed Jan 11, 2023
1 parent 52f0b81 commit e229bd8
Show file tree
Hide file tree
Showing 54 changed files with 24 additions and 42 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ jobs:
with:
version: v1.50.1
args: --timeout=5m
# To avoid the following errors, we comment out.
# Error: options working-directory and only-new-issues aren't compatible, Error: options working-directory and only-new-issues aren't compatible
# TODO: Once we move the v2 directory to the top of the repository, we need to uncomment the following.
# only-new-issues: true
working-directory: v2
only-new-issues: true
14 changes: 2 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,15 @@ git clone https://github.com/${GITHUB_USER}/mpi-operator.git

We use Go v1.15+ for development and use [Go Modules](https://blog.golang.org/using-go-modules) to download and install the dependencies.

## Controller versions

The main module `github.com/kubeflow/mpi-operator` contains the code of the legacy
controller `v1`.

The newest iteration of the controller is in the module `github.com/kubeflow/mpi-operator/v2`.

## Run tests

### Unit and integration tests

You can execute all the unit and integration tests via `make test`.

If you only which to run the tests for the v2 controller, you can run `make test_v2`.

You can find the unit tests in the same folders as the functional code.

You can find the integration tests in a separate directory, `v2/test/integration`.
You can find the integration tests in a separate directory, `test/integration`.
Integration tests make use of a real kube-apiserver to test the interaction of
the controller with a real Kubernetes API. In these tests, other components
are not running, including `kubelet` or `kube-controller-manager`.
Expand Down Expand Up @@ -84,8 +75,7 @@ make images dev_manifest
kubectl apply -k manifests/overlays/dev
```

The image comes bundled with all the controller versions. For example, you can
find the v1 controller binary at `/opt/mpi-operator.v1`.
The controller handles MPIJobs with API version v2beta1 or newer.

If you need to use a different registry, or a different tag, you can do:

Expand Down
26 changes: 10 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ RELEASE_VERSION?=v0.3.0
CONTROLLER_VERSION?=v2
BASE_IMAGE_SSH_PORT?=2222
IMG_BUILDER=docker
LD_FLAGS=" \
-X '${REPO_PATH}/pkg/version.GitSHA=${GitSHA}' \
-X '${REPO_PATH}/pkg/version.Built=${Date}' \
-X '${REPO_PATH}/pkg/version.Version=${RELEASE_VERSION}'"
LD_FLAGS_V2=" \
-X '${REPO_PATH}/v2/pkg/version.GitSHA=${GitSHA}' \
-X '${REPO_PATH}/v2/pkg/version.Built=${Date}' \
Expand All @@ -31,37 +27,35 @@ all: ${BIN_DIR} fmt tidy lint test mpi-operator.v2

.PHONY: mpi-operator.v2
mpi-operator.v2:
cd v2 && \
go build -ldflags ${LD_FLAGS_V2} -o ../${BIN_DIR}/mpi-operator.v2 ./cmd/mpi-operator/
go build -ldflags ${LD_FLAGS_V2} -o ${BIN_DIR}/mpi-operator.v2 ./cmd/mpi-operator/

${BIN_DIR}:
mkdir -p ${BIN_DIR}

.PHONY: fmt
fmt:
cd v2 && go fmt ./...
go fmt ./...

.PHONY: test
test: export KUBEBUILDER_ASSETS = ${KUBEBUILDER_ASSETS_PATH}
test: bin/kubebuilder
cd v2 && go test -covermode atomic -coverprofile=profile.cov ./...
go test -covermode atomic -coverprofile=profile.cov ./...

# Only works with CONTROLLER_VERSION=v2
.PHONY: test_e2e
test_e2e: export TEST_MPI_OPERATOR_IMAGE = ${IMAGE_NAME}:${RELEASE_VERSION}
test_e2e: bin/kubectl kind images test_images dev_manifest
cd v2 && go test -tags e2e ./test/e2e/...
go test -tags e2e ./test/e2e/...

.PHONY: dev_manifest
dev_manifest:
# Use `~` instead of `/` because image name might contain `/`.
sed -e "s~%IMAGE_NAME%~${IMAGE_NAME}~g" -e "s~%IMAGE_TAG%~${RELEASE_VERSION}~g" manifests/overlays/dev/kustomization.yaml.template > manifests/overlays/dev/kustomization.yaml

.PHONY: generate_v2
generate_v2:
cd v2 && \
.PHONY: generate
generate:
go generate ./pkg/... ./cmd/... && \
openapi-gen --input-dirs github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2,k8s.io/api/core/v1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/version,github.com/kubeflow/common/pkg/apis/common/v1 --output-package github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2 --go-header-file ../hack/boilerplate/boilerplate.go.txt
openapi-gen --input-dirs github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2beta1,k8s.io/api/core/v1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/version,github.com/kubeflow/common/pkg/apis/common/v1 --output-package github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1 --go-header-file hack/boilerplate/boilerplate.go.txt

.PHONY: clean
clean:
Expand All @@ -84,7 +78,7 @@ test_images:

.PHONY: tidy
tidy:
cd v2 && go mod tidy -compat 1.17
go mod tidy -compat 1.17

GOLANGCI_LINT = ./bin/golangci-lint
bin/golangci-lint:
Expand All @@ -106,15 +100,15 @@ bin/kubectl:

.PHONY: lint
lint: bin/golangci-lint ## Run golangci-lint linter
cd v2 && ../$(GOLANGCI_LINT) run --new-from-rev=origin/master
$(GOLANGCI_LINT) run --new-from-rev=origin/master

.PHONY: kind
kind:
go install sigs.k8s.io/kind@${KIND_VERSION}

# Generate CRD
crd: controller-gen
cd v2 && $(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=crd
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=crd

# Download controller-gen locally if necessary
CONTROLLER_GEN = $(PROJECT_DIR)/bin/controller-gen
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ import (
mpijobclientset "github.com/kubeflow/mpi-operator/v2/pkg/client/clientset/versioned"
informers "github.com/kubeflow/mpi-operator/v2/pkg/client/informers/externalversions"
controllersv1 "github.com/kubeflow/mpi-operator/v2/pkg/controller"
version "github.com/kubeflow/mpi-operator/v2/pkg/version"
"github.com/kubeflow/mpi-operator/v2/pkg/version"
)

const (
apiVersion = "v1"
apiVersion = "v2"
RecommendedKubeConfigPathEnv = "KUBECONFIG"
controllerName = "mpi-operator"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions hack/python-sdk/gen-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ set -o pipefail
SWAGGER_JAR_URL="https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.1.0/openapi-generator-cli-5.1.0.jar"
SWAGGER_CODEGEN_JAR="hack/python-sdk/openapi-generator-cli.jar"
SWAGGER_CODEGEN_CONF="hack/python-sdk/swagger_config.json"
SWAGGER_V2_CODEGEN_FILE="v2/pkg/apis/kubeflow/v2beta1/swagger.json"
SWAGGER_V2_CODEGEN_FILE="pkg/apis/kubeflow/v2beta1/swagger.json"
SDK_OUTPUT_PATH="sdk/python"

if [ -z "${GOPATH:-}" ]; then
export GOPATH=$(go env GOPATH)
fi

# Backup existing v2 openapi_generated.go
mv v2/pkg/apis/kubeflow/v2beta1/openapi_generated.go v2/pkg/apis/kubeflow/v2beta1/openapi_generated.go.backup
mv pkg/apis/kubeflow/v2beta1/openapi_generated.go pkg/apis/kubeflow/v2beta1/openapi_generated.go.backup

echo "Generating V2 OpenAPI specification ..."
openapi-gen --input-dirs github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2beta1,github.com/kubeflow/common/pkg/apis/common/v1 --output-package github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2beta1 --go-header-file hack/boilerplate/boilerplate.go.txt
openapi-gen --input-dirs github.com/kubeflow/mpi-operator/v2/pkg/apis/kubeflow/v2beta1,k8s.io/api/core/v1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/version,github.com/kubeflow/common/pkg/apis/common/v1 --output-package github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1 --go-header-file hack/boilerplate/boilerplate.go.txt

echo "Generating V2 swagger file ..."
go run hack/python-sdk/main.go v2beta1 > ${SWAGGER_V2_CODEGEN_FILE}
Expand All @@ -46,6 +46,6 @@ echo "Generating V2 Python SDK for Kubeflow MPI-Operator ..."
java -jar ${SWAGGER_CODEGEN_JAR} generate -i ${SWAGGER_V2_CODEGEN_FILE} -g python-legacy -o ${SDK_OUTPUT_PATH}/v2beta1 -c ${SWAGGER_CODEGEN_CONF}

# Rollback the current V2 openapi_generated.go
mv v2/pkg/apis/kubeflow/v2beta1/openapi_generated.go.backup v2/pkg/apis/kubeflow/v2beta1/openapi_generated.go
mv pkg/apis/kubeflow/v2beta1/openapi_generated.go.backup pkg/apis/kubeflow/v2beta1/openapi_generated.go

echo "Kubeflow MPI-Operator Python SDK is generated successfully to folder ${SDK_OUTPUT_PATH}/."
Binary file added hack/python-sdk/openapi-generator-cli.jar
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

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

File renamed without changes.
File renamed without changes.
File renamed without changes.

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

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
defaultKindImage = "kindest/node:v1.21.2"
openMPIImage = "mpioperator/mpi-pi:openmpi"
intelMPIImage = "mpioperator/mpi-pi:intel"
rootPath = "../../.."
rootPath = "../.."
kubectlPath = rootPath + "/bin/kubectl"
operatorManifestsPath = rootPath + "/manifests/overlays/dev"

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (

func TestMain(m *testing.M) {
env := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "manifests", "base")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "manifests", "base")},
}
var err error
restConfig, err = env.Start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func startController(ctx context.Context, kClient kubernetes.Interface, mpiClien
go kubeInformerFactory.Start(ctx.Done())
go mpiInformerFactory.Start(ctx.Done())

go func () {
go func() {
if err := ctrl.Run(1, ctx.Done()); err != nil {
panic(err)
}
Expand Down

0 comments on commit e229bd8

Please sign in to comment.