Skip to content

Commit

Permalink
Issue 97: Update operator SDK dependency to 0.2.0 (full refactor) (#98)
Browse files Browse the repository at this point in the history
* Updates the operator SDK dependency from 0.0.5 to 0.2.0.
Applied the official migration guide step by step to migrate
the existing operator project to be compliant with the latest SDK.

* Sets up the operator testing framework as explained in the
official documentation. There's no test case implementation
yet, but the framework is ready to accept test cases.

* Creates new test-e2e make command that runs the end-to-end
tests

* Updates Travis configuration to set up and deploy MiniKube as
the testing Kubernetes backend.


Signed-off-by: Adrian Moreno <[email protected]>
  • Loading branch information
adrianmo authored and fpj committed Dec 5, 2018
1 parent 947bb96 commit c7a776c
Show file tree
Hide file tree
Showing 42 changed files with 1,011 additions and 709 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,8 @@ tags
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode,intellij

bin/

# Ignore YAML files in the project root directory
/*.yaml

deploy/test
31 changes: 27 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
language: go
go_import_path: github.com/pravega/pravega-operator
sudo: required

go:
- '1.10'

sudo: required
- '1.11'

env:
global:
secure: "X4zdixrmuh/D4WwJ6btu0fJROq7fTPO5n4/jeyoxTQvrpwikycwf3ZpXS94u43rHx1ovc8vweVIc4Kur7MFAJDmFpPz5adjD7cCjqaRHo+Sw4a/gdNKizFEmZEBFlelynJ+cYekfF3rIFRws+u/8yWUQnSPl4495Qq1NKjrDTqoB6ZrQDxYdIPPpLAit+Aj9a2zQ4xPHyOv02SmfgL22wQhOx8SF78VNmqVah6klC8j3tAemHJQSBmUQ2fPVBpqAy3YsI7mpF9aSdBOzr7Dk1/cajOx4M5WrAxDPZ7+fSKD97SjICKqtM6MuX63O6Tg86zzdoEdvTWvwBwjWpbI3iCytJOCD8vT1QBPd9bLwZI7K5dElrW990HGrBBS4GmKTFykEE6PCNvxDHu1pG4N0vmLhZ3Hh4evZxA8xSnHRyYTLOaDkSe/vurlmsRJiW0GOEa6Fyz+xrD5y4l5MDkPVvaEPzWFZQf8v+l3OvvDvmHmqup4ADXE/XBYbVraTn8wPcQnvk5ueCvJWBOd/E4keGFsGbqDxQpvQRG/8aHWv32lj2HHK6/qbihXvTfJfRbrWli2BV0LMBL/OBIiuL1JeXycYZG3AtbnwgJVXPzs8kpwrmxkRYvbb3Kc9HXu9x+ajeWDYb978Rq6/0DfXhKFIiLrgUOxR2SK6eHDTcfUY+us="
- KUBERNETES_CONFIG_FILE=$HOME/.kube/config
- CHANGE_MINIKUBE_NONE_USER=true
- secure: "X4zdixrmuh/D4WwJ6btu0fJROq7fTPO5n4/jeyoxTQvrpwikycwf3ZpXS94u43rHx1ovc8vweVIc4Kur7MFAJDmFpPz5adjD7cCjqaRHo+Sw4a/gdNKizFEmZEBFlelynJ+cYekfF3rIFRws+u/8yWUQnSPl4495Qq1NKjrDTqoB6ZrQDxYdIPPpLAit+Aj9a2zQ4xPHyOv02SmfgL22wQhOx8SF78VNmqVah6klC8j3tAemHJQSBmUQ2fPVBpqAy3YsI7mpF9aSdBOzr7Dk1/cajOx4M5WrAxDPZ7+fSKD97SjICKqtM6MuX63O6Tg86zzdoEdvTWvwBwjWpbI3iCytJOCD8vT1QBPd9bLwZI7K5dElrW990HGrBBS4GmKTFykEE6PCNvxDHu1pG4N0vmLhZ3Hh4evZxA8xSnHRyYTLOaDkSe/vurlmsRJiW0GOEa6Fyz+xrD5y4l5MDkPVvaEPzWFZQf8v+l3OvvDvmHmqup4ADXE/XBYbVraTn8wPcQnvk5ueCvJWBOd/E4keGFsGbqDxQpvQRG/8aHWv32lj2HHK6/qbihXvTfJfRbrWli2BV0LMBL/OBIiuL1JeXycYZG3AtbnwgJVXPzs8kpwrmxkRYvbb3Kc9HXu9x+ajeWDYb978Rq6/0DfXhKFIiLrgUOxR2SK6eHDTcfUY+us="
matrix:
- KUBERNETES_VERSION=v1.9.4

services:
- docker

install:
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$KUBERNETES_VERSION/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.28.2/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- curl -Lo dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && chmod +x dep && sudo mv dep /usr/local/bin/
- curl -Lo operator-sdk https://github.com/operator-framework/operator-sdk/releases/download/v0.2.0/operator-sdk-v0.2.0-x86_64-linux-gnu && chmod +x operator-sdk && sudo mv operator-sdk /usr/local/bin/

before_script:
# Make root mounted as rshared to fix kube-dns issues
- sudo mount --make-rshared /
# Start MiniKube
- sudo minikube start --vm-driver=none --bootstrapper=localkube --kubernetes-version=$KUBERNETES_VERSION --extra-config=apiserver.Authorization.Mode=RBAC
# Fix the kubectl context, as it's often stale
- minikube update-context
# Wait for Kubernetes to be up and ready
- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done
# Show cluster information
- kubectl cluster-info

script:
- make dep
- make check
- make test
- make build
Expand Down
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#
# Copyright (c) 2017 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
FROM golang:1.10.1-alpine3.7 as go-builder

ARG PROJECT_NAME=pravega-operator
ARG REPO_PATH=github.com/pravega/$PROJECT_NAME
ARG BUILD_PATH=${REPO_PATH}/cmd/${PROJECT_NAME}
ARG REPO_PATH=github.com/pravega/${PROJECT_NAME}
ARG BUILD_PATH=${REPO_PATH}/cmd/manager

# Build version and commit SHA should be passed in when performing docker build
ARG VERSION=0.0.0-localdev
Expand Down
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,31 @@ GIT_SHA=$(shell git rev-parse --short HEAD)
GOOS=linux
GOARCH=amd64

.PHONY: all build check clean test
.PHONY: all dep build check clean test

all: check build
all: check test build

build: test build-go build-image
dep:
dep ensure -v

build: build-go build-image

build-go:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags "-X github.com/$(REPO)/pkg/version.Version=$(VERSION) -X github.com/$(REPO)/pkg/version.GitSHA=$(GIT_SHA)" \
-o bin/$(PROJECT_NAME) cmd/$(PROJECT_NAME)/main.go
-o bin/$(PROJECT_NAME) cmd/manager/main.go

build-image:
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_SHA=$(GIT_SHA) -t $(REPO):$(VERSION) .
docker tag $(REPO):$(VERSION) $(REPO):latest

test:
go test $$(go list ./... | grep -v /vendor/)
test: test-unit test-e2e

test-unit:
go test $$(go list ./... | grep -v /vendor/ | grep -v /test/e2e )

test-e2e:
operator-sdk test local ./test/e2e --go-test-flags -v

login:
@docker login -u "$(DOCKER_USER)" -p "$(DOCKER_PASS)"
Expand Down
62 changes: 47 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The project is currently alpha. While no breaking API changes are currently plan
* [Uninstall the Operator](#uninstall-the-operator)
* [Configuration](#configuration)
* [Use non-default service accounts](#use-non-default-service-accounts)
* [Installing on a Custom Namespace with RBAC enabled](#installing-on-a-custom-namespace-with-rbac-enabled)
* [Tier 2: Google Filestore Storage](#use-google-filestore-storage-as-tier-2)
* [Tune Pravega Configurations](#tune-pravega-configuration)
* [Development](#development)
Expand Down Expand Up @@ -49,22 +50,10 @@ The Pravega operator manages Pravega clusters deployed to Kubernetes and automat

> Note: If you are running on Google Kubernetes Engine (GKE), please [check this first](#installation-on-google-kubernetes-engine).
Register the `PravegaCluster` custom resource definition (CRD).
Run the following command to install the `PravegaCluster` custom resource definition (CRD), create the `pravega-operator` service account, roles, bindings, and the deploy the operator.

```
$ kubectl create -f deploy/crd.yaml
```

Create the operator role and role binding.

```
$ kubectl create -f deploy/rbac.yaml
```

Deploy the Pravega operator.

```
$ kubectl create -f deploy/operator.yaml
$ kubectl create -f deploy
```

Verify that the Pravega operator is running.
Expand All @@ -73,7 +62,6 @@ Verify that the Pravega operator is running.
$ kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
pravega-operator 1 1 1 1 17s
zookeeper-operator 1 1 1 1 12m
```

### Deploy a sample Pravega cluster
Expand Down Expand Up @@ -287,6 +275,50 @@ spec:
...
```
### Installing on a Custom Namespace with RBAC enabled
Create the namespace.
```
$ kubectl create namespace pravega-io
```
Update the namespace configured in the `deploy/role_binding.yaml` file.
```
$ sed -i -e 's/namespace: default/namespace: pravega-io/g' deploy/role_binding.yaml
```
Apply the changes.
```
$ kubectl -n pravega-io apply -f deploy
```
Note that the Pravega operator only monitors the `PravegaCluster` resources which are created in the same namespace, `pravega-io` in this example. Therefore, before creating a `PravegaCluster` resource, make sure an operator exists in that namespace.
```
$ kubectl -n pravega-io create -f example/cr.yaml
```
```
$ kubectl -n pravega-io get pravegaclusters
NAME AGE
pravega 28m
```
```
$ kubectl -n pravega-io get pods -l pravega_cluster=pravega
NAME READY STATUS RESTARTS AGE
pravega-bookie-0 1/1 Running 0 29m
pravega-bookie-1 1/1 Running 0 29m
pravega-bookie-2 1/1 Running 0 29m
pravega-pravega-controller-6c54fdcdf5-947nw 1/1 Running 0 29m
pravega-pravega-segmentstore-0 1/1 Running 0 29m
pravega-pravega-segmentstore-1 1/1 Running 0 29m
pravega-pravega-segmentstore-2 1/1 Running 0 29m
```
### Use Google Filestore Storage as Tier 2
1. [Create a Google Filestore](https://console.cloud.google.com/filestore/instances).
Expand Down
14 changes: 14 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Copyright (c) 2017 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
FROM alpine:3.6

USER nobody

ADD build/_output/bin/pravega-operator /usr/local/bin/pravega-operator
90 changes: 90 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright (c) 2018 Dell Inc., or its subsidiaries. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/

package main

import (
"flag"
"os"
"runtime"

"github.com/pravega/pravega-operator/pkg/apis"
"github.com/pravega/pravega-operator/pkg/controller"
"github.com/pravega/pravega-operator/pkg/version"

"github.com/operator-framework/operator-sdk/pkg/k8sutil"
sdkVersion "github.com/operator-framework/operator-sdk/version"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

log "github.com/sirupsen/logrus"
)

var (
versionFlag bool
)

func init() {
flag.BoolVar(&versionFlag, "version", false, "Show version and quit")
flag.Parse()
}

func printVersion() {
log.Printf("pravega-operator Version: %v", version.Version)
log.Printf("Git SHA: %s", version.GitSHA)
log.Printf("Go Version: %s", runtime.Version())
log.Printf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
log.Printf("operator-sdk Version: %v", sdkVersion.Version)
}

func main() {
printVersion()
flag.Parse()

if versionFlag {
os.Exit(0)
}

namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
log.Fatalf("failed to get watch namespace: %v", err)
}

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
log.Fatal(err)
}

// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
if err != nil {
log.Fatal(err)
}

log.Print("Registering Components")

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
}

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Fatal(err)
}

log.Print("Starting the Cmd")

// Start the Cmd
log.Fatal(mgr.Start(signals.SetupSignalHandler()))
}
67 changes: 0 additions & 67 deletions cmd/pravega-operator/main.go

This file was deleted.

3 changes: 0 additions & 3 deletions config/config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ spec:
plural: pravegaclusters
singular: pravegacluster
scope: Namespaced
version: v1alpha1
version: v1alpha1
Loading

0 comments on commit c7a776c

Please sign in to comment.