Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
Signed-off-by: Malay Kumar Parida <[email protected]>
  • Loading branch information
malayparida2000 committed Sep 6, 2023
1 parent 20cc6c5 commit 1837cfb
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 282 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tags
# End of https://www.gitignore.io/api/go,vim,visualstudiocode
_output
_cache
bin

catalog/ocs-bundle.yaml
catalog/noobaa-bundle.yaml
Expand Down
60 changes: 21 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Export GO111MODULE=on to enable project to be built from within GOPATH/src
export GO111MODULE=on
# Enable GOPROXY. This speeds up a lot of vendoring operations.
export GOPROXY=https://proxy.golang.org
# Export GOROOT. Required for OPERATOR_SDK to work correctly for generate commands.
export GOROOT=$(shell go env GOROOT)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
LOCALBIN=$(shell pwd)/bin

KUSTOMIZE_VERSION=v4.5.2
KUSTOMIZE_VERSION=v4.5.5
KUSTOMIZE=$(LOCALBIN)/kustomize
CONTROLLER_GEN_VERSION=v0.9.2
CONTROLLER_GEN=$(LOCALBIN)/controller-gen


.PHONY: \
Expand Down Expand Up @@ -91,10 +82,6 @@ operator-bundle: gen-latest-csv
@echo "Building ocs operator bundle"
hack/build-operator-bundle.sh

operator-index:
@echo "Building ocs index image in sqlite db based format"
hack/build-operator-index.sh

operator-catalog:
@echo "Building ocs catalog image in file based catalog format"
hack/build-operator-catalog.sh
Expand Down Expand Up @@ -127,10 +114,6 @@ golangci-lint:
@echo "Running golangci-lint run"
hack/golangci_lint.sh

lint: ## Run golangci-lint inside a container
source hack/common.sh; source hack/docker-common.sh; \
$${IMAGE_BUILD_CMD} run --rm -v $${PROJECT_DIR}:/app:Z -w /app $${GO_LINT_IMG} golangci-lint run ./...

# ignoring the functest dir since it requires an active cluster
# use 'make functest' to run just the functional tests
unit-test:
Expand Down Expand Up @@ -169,30 +152,29 @@ run: manifests generate

# find or download controller-gen if necessary
controller-gen:
ifneq ($(CONTROLLER_GEN_VERSION), $(shell $(GOBIN)/controller-gen --version | awk '{print $$2}'))
@{ \
echo "Installing controller-gen@$(CONTROLLER_GEN_VERSION)" ;\
set -e ;\
go install -mod=readonly sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) ;\
echo "Installed controller-gen@$(CONTROLLER_GEN_VERSION)" ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
ifeq ($(wildcard ${CONTROLLER_GEN}),)
@echo "Installing controller-gen@${CONTROLLER_GEN_VERSION} at ${CONTROLLER_GEN}"
@GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
else ifneq ($(shell ${CONTROLLER_GEN} --version | awk '{print $$2}'), $(CONTROLLER_GEN_VERSION))
@echo "Installing newer controller-gen@${CONTROLLER_GEN_VERSION} at ${CONTROLLER_GEN}"
@GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
else
CONTROLLER_GEN=$(shell which $(GOBIN)/controller-gen)
@echo "Using existing controller-gen@${CONTROLLER_GEN_VERSION} at ${CONTROLLER_GEN}"
endif

# find or download kustomize if necessary
kustomize:
ifeq (, $(shell which $(GOBIN)/kustomize))
@{ \
echo "Installing kustomize/v4@${KUSTOMIZE_VERSION}" ;\
set -e ;\
go install -mod=readonly sigs.k8s.io/kustomize/kustomize/v4@${KUSTOMIZE_VERSION} ;\
echo "Installed kustomize/v4@${KUSTOMIZE_VERSION}" ;\
}
export KUSTOMIZE=$(GOBIN)/kustomize
ifeq ($(wildcard ${KUSTOMIZE}),)
@echo "Installing kustomize@${KUSTOMIZE_VERSION} at ${KUSTOMIZE}"
@curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
else ifneq ($(shell ${KUSTOMIZE} version | awk -F'[ /]' '/Version/{print $$2}'), $(KUSTOMIZE_VERSION))
@echo "Installing newer kustomize@${KUSTOMIZE_VERSION} at ${KUSTOMIZE}"
@rm -f ${KUSTOMIZE}
@curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
else
export KUSTOMIZE=$(shell which $(GOBIN)/kustomize)
@echo "Using existing kustomize@${KUSTOMIZE_VERSION} at ${KUSTOMIZE}"
endif
export KUSTOMIZE

install-noobaa: operator-sdk
@echo "Installing noobaa operator"
Expand Down
13 changes: 5 additions & 8 deletions hack/build-functest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ set -e

source hack/common.sh

suite="${GINKGO_TEST_SUITE:-ocs}"
GOBIN="${GOBIN:-$GOPATH/bin}"
GINKGO=$GOBIN/ginkgo
mkdir -p "${LOCALBIN}"

if ! [ -x "$GINKGO" ]; then
echo "Installing GINKGO"
go install -v github.com/onsi/ginkgo/v2/ginkgo@latest
echo "Installing GINKGO binary at $GINKGO"
GOBIN=${LOCALBIN} go install -v github.com/onsi/ginkgo/v2/ginkgo
else
echo "GINKO binary found at $GINKGO"
fi

"${GINKGO}" build --ldflags "${LDFLAGS}" "functests/${suite}/"
"${GINKGO}" build --ldflags "${LDFLAGS}" "functests/${GINKGO_TEST_SUITE}/"

mkdir -p $OUTDIR_BIN
mv "functests/${suite}/${suite}.test" "${OUTDIR_BIN}/${suite}_tests"
mv "functests/${GINKGO_TEST_SUITE}/${GINKGO_TEST_SUITE}.test" "${LOCALBIN}/${GINKGO_TEST_SUITE}_tests"
2 changes: 1 addition & 1 deletion hack/build-metrics-exporter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
source hack/common.sh
source hack/docker-common.sh

${IMAGE_BUILD_CMD} build --build-arg="LDFLAGS=${LDFLAGS}" --no-cache -f metrics/Dockerfile -t "${METRICS_EXPORTER_FULL_IMAGE_NAME}" .
${IMAGE_BUILD_CMD} build --build-arg="LDFLAGS=${LDFLAGS}" --platform="${GOOS}"/"${GOARCH}" --no-cache -f metrics/Dockerfile -t "${METRICS_EXPORTER_FULL_IMAGE_NAME}" .
2 changes: 1 addition & 1 deletion hack/build-operator-bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set -e
source hack/common.sh
source hack/docker-common.sh

${IMAGE_BUILD_CMD} build --no-cache -t "$BUNDLE_FULL_IMAGE_NAME" -f Dockerfile.bundle .
${IMAGE_BUILD_CMD} build --platform="${GOOS}"/"${GOARCH}" --no-cache -t "$BUNDLE_FULL_IMAGE_NAME" -f Dockerfile.bundle .
echo
echo "Run '${IMAGE_BUILD_CMD} push ${BUNDLE_FULL_IMAGE_NAME}' to push operator bundle to image registry."
2 changes: 1 addition & 1 deletion hack/build-operator-catalog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ ${OPM} validate catalog
${OPM} generate dockerfile catalog

mv catalog.Dockerfile Dockerfile.catalog
${IMAGE_BUILD_CMD} build --no-cache -t "${FILE_BASED_CATALOG_FULL_IMAGE_NAME}" -f Dockerfile.catalog .
${IMAGE_BUILD_CMD} build --platform="${GOOS}"/"${GOARCH}" --no-cache -t "${FILE_BASED_CATALOG_FULL_IMAGE_NAME}" -f Dockerfile.catalog .

echo "Run '${IMAGE_BUILD_CMD} push ${FILE_BASED_CATALOG_FULL_IMAGE_NAME}' to push operator catalog image to image registry."
2 changes: 1 addition & 1 deletion hack/build-operator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
source hack/common.sh
source hack/docker-common.sh

${IMAGE_BUILD_CMD} build --build-arg="LDFLAGS=${LDFLAGS}" --no-cache -t "${OPERATOR_FULL_IMAGE_NAME}" .
${IMAGE_BUILD_CMD} build --build-arg="LDFLAGS=${LDFLAGS}" --platform="${GOOS}"/"${GOARCH}" --no-cache -t "${OPERATOR_FULL_IMAGE_NAME}" .
4 changes: 2 additions & 2 deletions hack/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -e

source hack/common.sh

rm -rf ${OUTDIR}
echo "cleaned $OUTDIR"
rm -rf "${LOCALBIN}"
echo "cleaned $LOCALBIN"
3 changes: 0 additions & 3 deletions hack/cluster-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,3 @@ for i in "${managed_namespaces[@]}"; do
done
fi
done

# clean old
rm -rf $OUTDIR_CLUSTER_DEPLOY_MANIFESTS
1 change: 1 addition & 0 deletions hack/cluster-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set +e

$CLUSTER_DEPLOY --ocs-catalog-image="${CATALOG_FULL_IMAGE_NAME}" --ocs-subscription-channel="${OCS_SUBSCRIPTION_CHANNEL}" --install-namespace="${INSTALL_NAMESPACE}"

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
hack/dump-debug-info.sh
echo "ERROR: cluster-deploy failed."
Expand Down
47 changes: 25 additions & 22 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,20 @@
# shellcheck disable=SC2034
# disable unused variable warnings

GO111MODULE="on"
GOPROXY="https://proxy.golang.org"
GOROOT="${GOROOT:-go env GOROOT}"
GOOS="${GOOS:-linux}"
GOARCH="${GOARCH:-amd64}"

GO_LINT_IMG_LOCATION="${GO_LINT_IMG_LOCATION:-golangci/golangci-lint}"
GO_LINT_IMG_TAG="${GO_LINT_IMG_TAG:-v1.49.0}"
GO_LINT_IMG="${GO_LINT_IMG:-${GO_LINT_IMG_LOCATION}:${GO_LINT_IMG_TAG}}"
GOHOSTOS="$(go env GOHOSTOS)"
GOHOSTARCH="$(go env GOHOSTARCH)"

# Current DEV version of the CSV
DEFAULT_CSV_VERSION="4.14.0"
CSV_VERSION="${CSV_VERSION:-${DEFAULT_CSV_VERSION}}"
VERSION="${VERSION:-${CSV_VERSION}}"
LDFLAGS="-X github.com/red-hat-storage/ocs-operator/v4/version.Version=${CSV_VERSION}"

OUTDIR="build/_output"
OUTDIR_BIN="build/_output/bin"
LOCALBIN="$(pwd)/bin"
OUTDIR_TEMPLATES="deploy/csv-templates"
OUTDIR_CRDS="$OUTDIR_TEMPLATES/crds"
OUTDIR_TOOLS="$OUTDIR/tools"
OUTDIR_CLUSTER_DEPLOY_MANIFESTS="$OUTDIR/cluster-deploy-manifests"

DEPLOY_YAML_PATH="deploy/deploy-with-olm.yaml"
PROMETHEUS_RULES_PATH="metrics/deploy"
Expand Down Expand Up @@ -82,23 +74,34 @@ OCS_OPERATOR_INSTALL="${OCS_OPERATOR_INSTALL:-false}"
OCS_CLUSTER_UNINSTALL="${OCS_CLUSTER_UNINSTALL:-false}"
OCS_SUBSCRIPTION_CHANNEL=${OCS_SUBSCRIPTION_CHANNEL:-alpha}
INSTALL_NAMESPACE="${INSTALL_NAMESPACE:-openshift-storage}"
OCS_ALLOW_UNSUPPORTED_CEPH_VERSION="${OCS_ALLOW_UNSUPPORTED_CEPH_VERSION:-allowed}"

UPGRADE_FROM_OCS_REGISTRY_IMAGE="${UPGRADE_FROM_OCS_REGISTRY_IMAGE:-quay.io/ocs-dev/ocs-registry:4.2.0}"
UPGRADE_FROM_OCS_SUBSCRIPTION_CHANNEL="${UPGRADE_FROM_OCS_SUBSCRIPTION_CHANNEL:-$OCS_SUBSCRIPTION_CHANNEL}"

OCS_MUST_GATHER_DIR="${OCS_MUST_GATHER_DIR:-ocs-must-gather}"
OCP_MUST_GATHER_DIR="${OCP_MUST_GATHER_DIR:-ocp-must-gather}"

OS_TYPE=$(uname)

# Protobuf
PROTOC_VERSION="3.14.0"
PROTOC_VERSION="3.20.0"
PROTOC_GEN_GO_VERSION="1.26.0"
PROTOC_GEN_GO_GRPC_VERSION="1.1.0"
OUTDIR_GRPC="build/_output/grpc"
OUTDIR_PROTO_DIST="build/_output/grpc/dist"
OUTDIR_PROTO_GOOGLE="build/_output/grpc/google/protobuf"

GRPC_BIN="${LOCALBIN}/grpc"
PROTOC="${GRPC_BIN}/protoc"
PROTO_GOOGLE="${GRPC_BIN}/google/protobuf"
PROTOC_GEN_GO="${GRPC_BIN}/protoc-gen-go"
PROTOC_GEN_GO_GRPC="${GRPC_BIN}/protoc-gen-go-grpc"

# gRPC services
declare -a SERVICES=("provider")
SERVICES=("provider")

OPERATOR_SDK_VERSION="v1.25.4"
OPERATOR_SDK="${LOCALBIN}/operator-sdk-${OPERATOR_SDK_VERSION}"

OPM_VERSION="v1.28.0"
OPM="${LOCALBIN}/opm-${OPM_VERSION}"

GOLANGCI_LINT_VERSION="v1.51.1"
GOLANGCI_LINT="${LOCALBIN}/golangci-lint"

SHELLCHECK="${LOCALBIN}/shellcheck"
SHELLCHECK_VERSION="v0.9.0"

GINKGO="${LOCALBIN}/ginkgo"
15 changes: 7 additions & 8 deletions hack/ensure-operator-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
set -e

source hack/common.sh
source hack/operator-sdk-common.sh

OPERATOR_SDK_DL_URL="https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk_${GOHOSTOS}_${GOHOSTARCH}"

mkdir -p "${LOCALBIN}"

if [ ! -x "${OPERATOR_SDK}" ]; then
echo "Downloading operator-sdk: ${OPERATOR_SDK_DL_URL_FULL} --> ${OPERATOR_SDK}"
mkdir -p "${OUTDIR_TOOLS}"
curl -JL "${OPERATOR_SDK_DL_URL_FULL}" -o "${OPERATOR_SDK}"
echo "Installing operator-sdk CLI at ${OPERATOR_SDK}"
curl -JL "${OPERATOR_SDK_DL_URL}" -o "${OPERATOR_SDK}"
chmod +x "${OPERATOR_SDK}"
else
echo "Using operator-sdk cached at ${OPERATOR_SDK}"
echo "Using operator-sdk CLI present at ${OPERATOR_SDK}"
fi

# Ensure operator-sdk can run properly on local machine
"${OPERATOR_SDK}" version > /dev/null 2>&1 || echo "Bad operator-sdk binary: ${OPERATOR_SDK}"
44 changes: 7 additions & 37 deletions hack/ensure-opm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,13 @@ set -e

source hack/common.sh

OPM_VERSION="v1.28.0"
case "$(uname -m)" in
x86_64)
OPM_ARCH="amd64"
;;
aarch64)
OPM_ARCH="arm64"
;;
*)
OPM_ARCH="$(uname -m)"
;;
esac
OPM_OS=$(echo -n "${OS_TYPE}" | awk '{print tolower($0)}')
OPM_PLATFORM="${OPM_OS}-${OPM_ARCH}-opm"
OPM_URL="https://github.com/operator-framework/operator-registry/releases/download/${OPM_VERSION}/${OPM_PLATFORM}"
OPM_BIN="opm-${OPM_VERSION}"
OPM="${OUTDIR_TOOLS}/${OPM_BIN}"
OPERATOR_REGISTRY_TMPDIR="${OUTDIR_TOOLS}/operator-registry"
OPM_DL_URL="https://github.com/operator-framework/operator-registry/releases/download/${OPM_VERSION}/${GOHOSTOS}-${GOHOSTARCH}-opm"
mkdir -p "${LOCALBIN}"

if [ -x "${OPM}" ]; then
# Case 1: already has opm binray
echo "Using opm cached at ${OPM}"
elif [ "${OPM_ARCH}" != "amd64" ]; then
# Case 2: image does not exist, need to build from source
echo "Building opm from source under ${OPERATOR_REGISTRY_TMPDIR} for ${OPM_OS}-${OPM_ARCH}"
mkdir -p "${OPERATOR_REGISTRY_TMPDIR}"
pushd "${OPERATOR_REGISTRY_TMPDIR}"
git clone https://github.com/operator-framework/operator-registry .
git checkout "${OPM_VERSION}"
make
popd
cp "${OPERATOR_REGISTRY_TMPDIR}/bin/opm" "${OPM}"
rm -rf "${OPERATOR_REGISTRY_TMPDIR}"
else
# Case 3: use public image
echo "Downloading opm ${OPM_VERSION} for ${OS_TYPE}"
mkdir -p "${OUTDIR_TOOLS}"
curl -JL "${OPM_URL}" -o "${OPM}"
if [ ! -x "${OPM}" ]; then
echo "Installing opm CLI at ${OPM}"
curl -JL "${OPM_DL_URL}" -o "${OPM}"
chmod +x "${OPM}"
else
echo "Using opm CLI present at ${OPM}"
fi
1 change: 1 addition & 0 deletions hack/functest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ source hack/common.sh
--ocs-operator-install="${OCS_OPERATOR_INSTALL}" \
--ocs-cluster-uninstall="${OCS_CLUSTER_UNINSTALL}" "$@"

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "ERROR: Functest failed."
exit 1
Expand Down
Loading

0 comments on commit 1837cfb

Please sign in to comment.