Skip to content

Commit

Permalink
CLI + noobaa v5
Browse files Browse the repository at this point in the history
  • Loading branch information
guymguym committed Jul 25, 2019
1 parent 0cf953c commit d6e5063
Show file tree
Hide file tree
Showing 68 changed files with 4,322 additions and 1,237 deletions.
8 changes: 4 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# we only want to take build/ into the image
# so we ignore everything else here
cmd/
deploy/
pkg/
*
!build

# make sure we ignore vendor explicitly
vendor/
version/
33 changes: 15 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
language: go
sudo: required
dist: xenial

sevices:
- docker
go:
- 1.12.5

stages:
- name: build
- name: deploy
- 1.12.7

env:
global:
Expand All @@ -17,21 +14,21 @@ env:
- MINIKUBE_HOME=$HOME
- CHANGE_MINIKUBE_NONE_USER=true
- KUBECONFIG=$HOME/.kube/config
- GO111MODULE=on
- CGO_ENABLED=0

stages:
- name: build

jobs:
include:
- stage: build
name: "Build and unit test"
script:
- make all
- make test

- stage: build
name: "Run smoke tests"
name: "Build and Test"
install:
- make install-sdk
- "./.travis/deploy_minikube.sh"
- bash .travis/install-operator-sdk.sh
- bash .travis/install-python.sh
- bash .travis/install-minikube.sh
script:
- make test-e2e
env:
- TEST_GROUP=smoke
- make build
- make test
- make test-integ
4 changes: 2 additions & 2 deletions .travis/deploy_minikube.sh → .travis/install-minikube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ set -x
# socat is needed for port forwarding
sudo apt-get update && sudo apt-get install socat

export MINIKUBE_VERSION=v1.0.0
export KUBERNETES_VERSION=v1.14.0
export MINIKUBE_VERSION=v1.2.0
export KUBERNETES_VERSION=v1.15.0

sudo mount --make-rshared /
sudo mount --make-rshared /proc
Expand Down
7 changes: 7 additions & 0 deletions .travis/install-operator-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SDK_VERSION="v0.9.0"
SDK_RELEASE="https://github.com/operator-framework/operator-sdk/releases/download/${SDK_VERSION}/operator-sdk-${SDK_VERSION}-x86_64-linux-gnu"

echo "install-sdk - installing version ${SDK_VERSION}"
curl "${SDK_RELEASE}" -Lo $GOPATH/bin/operator-sdk
chmod +x $GOPATH/bin/operator-sdk
$GOPATH/bin/operator-sdk version
4 changes: 4 additions & 0 deletions .travis/install-python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sudo apt-get update
sudo apt-get install python3-venv
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
190 changes: 118 additions & 72 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,97 +1,143 @@
VERSION ?= 0.1.0
# Required build-tools:
# - go
# - git
# - python3
# - minikube
# - operator-sdk

VERSION ?= $(shell go run cmd/version/main.go)
IMAGE ?= noobaa/noobaa-operator:$(VERSION)
REPO ?= github.com/noobaa/noobaa-operator

GO_FLAGS ?= CGO_ENABLED=0 GO111MODULE=on
GO_LINUX_FLAGS ?= GOOS=linux GOARCH=amd64
GO ?= CGO_ENABLED=0 GO111MODULE=on go
GO_LINUX ?= GOOS=linux GOARCH=amd64 $(GO)
GO_LIST ?= ./cmd/... ./pkg/... ./test/... ./version/...
GOHOSTOS ?= $(shell go env GOHOSTOS)

OUTPUT = build/_output
BIN = $(OUTPUT)/bin
BUNDLE = $(OUTPUT)/bundle
VENV = $(OUTPUT)/venv
OUTPUT ?= build/_output
BIN ?= $(OUTPUT)/bin
OLM ?= $(OUTPUT)/olm
VENV ?= $(OUTPUT)/venv
BUNDLE ?= $(OUTPUT)/bundle

# Default tasks:

all: build
@echo "@@@ All Done."
.PHONY: all

# Developer tasks:
#------------#
#- Building -#
#------------#

lint:
@echo Linting...
go get -u golang.org/x/lint/golint
golint -set_exit_status=1 $(shell go list ./cmd/... ./pkg/...)
.PHONY: lint
all: local build
@echo "all - done."
.PHONY: all

build: cli image
@echo "@@@ Build Done."
build: image olm
@echo "build - done."
.PHONY: build

cli: vendor
${GO_FLAGS} go generate cmd/cli/cli.go
${GO_FLAGS} go build -mod=vendor -o $(BIN)/kubectl-noobaa $(REPO)/cmd/cli
.PHONY: cli

dev: operator
WATCH_NAMESPACE=noobaa OPERATOR_NAME=noobaa-operator $(BIN)/noobaa-operator-local
.PHONY: dev

operator: vendor
go build -mod=vendor -o $(BIN)/noobaa-operator-local $(REPO)/cmd/manager
.PHONY: operator
image: gen
operator-sdk build $(IMAGE)
.PHONY: image

gen: vendor
operator-sdk generate k8s
operator-sdk generate openapi
gen: vendor $(BUNDLE)/deploy.go
.PHONY: gen

$(BUNDLE)/deploy.go: pkg/bundle/bundle.go $(shell find deploy/ -type f)
mkdir -p $(BUNDLE)
$(GO) run pkg/bundle/bundle.go deploy/ $(BUNDLE)/deploy.go

vendor:
${GO_FLAGS} go mod vendor
$(GO) mod vendor
.PHONY: vendor

image:
${GO_FLAGS} ${GO_LINUX_FLAGS} go build -mod=vendor -o $(BIN)/noobaa-operator $(REPO)/cmd/manager
docker build -f build/Dockerfile -t $(IMAGE) .
.PHONY: image
olm:
rm -rf $(OLM)
mkdir -p $(OLM)
cp deploy/olm-catalog/package/* $(OLM)/
cp deploy/crds/*crd.yaml $(OLM)/
python3 -m venv $(VENV)
( \
. $(VENV)/bin/activate && \
pip3 install --upgrade pip && \
pip3 install operator-courier && \
operator-courier verify --ui_validate_io $(OLM) \
)
@echo "olm - ready at $(OLM)"
.PHONY: olm


#-----------#
#- Testing -#
#-----------#

test: lint unittest
@echo "test - done."
.PHONY: test

bundle:
mkdir -p $(BUNDLE)
cp deploy/olm-catalog/noobaa-operator/*.yaml $(BUNDLE)/
cp deploy/olm-catalog/noobaa-operator/$(VERSION)/*.yaml $(BUNDLE)/
cp deploy/crds/*crd.yaml $(BUNDLE)/
( python3 -m venv $(VENV) && . $(VENV)/bin/activate && pip install operator-courier >/dev/null )
( . $(VENV)/bin/activate && operator-courier verify --ui_validate_io $(BUNDLE) )
.PHONY: bundle

push:
@echo TODO: To which tag do we want to push here?
test-integ: scorecard test-e2e
@echo "test-integ - done."
.PHONY: test-integ

lint: gen
go get -u golang.org/x/lint/golint
golint -set_exit_status=0 ./cmd/... ./pkg/... ./test/... ./version/...
.PHONY: lint

unittest: gen
go test ./cmd/... ./pkg/... ./version/...
.PHONY: unittest

test-e2e: gen
# TODO fix test-e2e !
# operator-sdk test local ./test/e2e \
# --global-manifest deploy/cluster_role_binding.yaml \
# --debug \
# --go-test-flags "-v -parallel=1"
.PHONY: test-e2e

scorecard: gen
kubectl create ns test-noobaa-operator-scorecard
operator-sdk scorecard \
--cr-manifest deploy/crds/noobaa_v1alpha1_noobaa_cr.yaml \
--cr-manifest deploy/crds/noobaa_v1alpha1_backingstore_cr.yaml \
--cr-manifest deploy/crds/noobaa_v1alpha1_bucketclass_cr.yaml \
--csv-path deploy/olm-catalog/package/noobaa-operator.v$(VERSION).clusterserviceversion.yaml \
--namespace test-noobaa-operator-scorecard
.PHONY: scorecard


#-------------#
#- Releasing -#
#-------------#

push-image:
@echo "push-image - It is too risky to push like this, because it easily overrides.
@echo version from version/version.go? master? git describe?
# docker push $(IMAGE)
.PHONY: push
.PHONY: push-image

test: vendor
go test ./cli/... ./pkg/...
.PHONY: test

test-e2e: vendor
operator-sdk test local ./test/e2e \
--global-manifest deploy/cluster_role_binding.yaml \
--debug \
--go-test-flags "-v -parallel=1"
.PHONY: test
#--------------#
#- Developing -#
#--------------#

clean:
rm $(BIN)/*
rm -rf vendor/
.PHONY: clean
local: gen
operator-sdk up local &>/dev/null
.PHONY: local

run: gen
operator-sdk up local --operator-flags "operator run"
.PHONY: run

# Deps
gen-api: gen
operator-sdk generate k8s
operator-sdk generate openapi
.PHONY: gen-api

install-sdk:
@echo Installing SDK ${SDK_VERSION}
curl https://github.com/operator-framework/operator-sdk/releases/download/${SDK_VERSION}/operator-sdk-${SDK_VERSION}-x86_64-linux-gnu -sLo ${GOPATH}/bin/operator-sdk
chmod +x ${GOPATH}/bin/operator-sdk
.PHONY: install-sdk
ensure-gen-api-is-noop: gen-api
git diff -s --exit-code pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go || (echo "Build failed: API has been changed but the deep copy functions aren't up to date. Run 'make gen-api' and update your PR." && exit 1)
git diff -s --exit-code pkg/apis/noobaa/v1alpha1/zz_generated.openapi.go || (echo "Build failed: API has been changed but the deep copy functions aren't up to date. Run 'make gen-api' and update your PR." && exit 1)
.PHONY: ensure-gen-api-is-noop

#TODO scorecard
clean:
rm -rf $(OUTPUT)
rm -rf vendor/
.PHONY: clean
1 change: 1 addition & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo = github.com/noobaa/noobaa-operator
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# noobaa-operator
# NooBaa Operator

NooBaa is an object data service for hybrid and multi cloud environments. NooBaa runs on kubernetes, provides an S3 object store service (and Lambda with bucket triggers) to clients both inside and outside the cluster, and uses storage resources from within or outside the cluster, with flexible placement policies to automate data use cases.

[About NooBaa](doc/about-noobaa.md)

# Using the operator as CLI

- Download the compiled operator binary from the [releases page](/releases)
- Run: `noobaa --help` for CLI usage
- Install the operator and noobaa with: `noobaa install`

# Operator Design

CRDs
- [NooBaa](doc/noobaa-crd.md) - The basic CRD to deploy a NooBaa system.
- [BackingStore](doc/backing-store-crd.md) - Connection to cloud or local storage to use in policies.
- [BucketClass](doc/bucket-class-crd.md) - Policies applied to a class of buckets.

Applications
- [S3 Account](doc/s3-account.md) - Method to obtain S3 account credentials for native S3 applications.
- [OBC Provisioner](doc/obc-provisioner.md) - Method to claim a new/existing bucket.

# Developing

- Fork and clone the repo: `git clone https://github.com/<username>/noobaa-operator`
- Use minikube: `minikube start`
- Source the devenv into your shell: `. devenv.sh`
- Build the project: `make`
- Test with the alias `nb` that runs the local operator from `build/_output/bin` (alias created by devenv)
- `nb install`
- ...
5 changes: 3 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ ENV OPERATOR=/usr/local/bin/noobaa-operator \
# install operator binary
COPY build/_output/bin/noobaa-operator ${OPERATOR}

# copy scripts
COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup
USER ${USER_UID}

ENTRYPOINT ["/usr/local/bin/entrypoint"]

USER ${USER_UID}
CMD ["operator", "run"]
1 change: 0 additions & 1 deletion cmd/cli/bundle/.gitignore

This file was deleted.

Loading

0 comments on commit d6e5063

Please sign in to comment.