Skip to content
This repository was archived by the owner on Oct 3, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,49 @@ clean: $(CLEAN_TARGETS)
## Build the operator
build: prebuild-check deps
@echo "building $(BINARY_SERVER_BIN)..."
operator-sdk generate k8s
go build -v -o $(BINARY_SERVER_BIN) cmd/manager/main.go

# -------------------------------------------------------------------
# deploy
# -------------------------------------------------------------------

APP_NAMESPACE ?= myproject
.PHONY: local
## Run Operator locally
local: deploy-rbac build deploy-crd
@-oc new-project $(APP_NAMESPACE)
operator-sdk up local --namespace=$(APP_NAMESPACE)

.PHONY: deploy-rbac
## Setup service account and deploy RBAC
deploy-rbac:
@-oc login -u system:admin
@-oc create -f deploy/service_account.yaml
@-oc create -f deploy/role.yaml
@-oc create -f deploy/role_binding.yaml

.PHONY: deploy-crd
## Deploy CRD
deploy-crd:
@-oc apply -f deploy/crds/devopsconsole_v1alpha1_component_crd.yaml
@-oc apply -f deploy/crds/devopsconsole_v1alpha1_envdeployment_crd.yaml

.PHONY: deploy-operator
## Deploy Operator
deploy-operator: deploy-crd
oc create -f deploy/operator.yaml

.PHONY: deploy-clean
## Deploy a CR as test
deploy-clean:
@-oc delete imagestream.image.openshift.io/myapp-runtime
@-oc delete imagestream.image.openshift.io/myapp-output
@-oc delete buildconfig.build.openshift.io/myapp-bc
@-oc delete deploymentconfig.apps.openshift.io/myapp
@-oc delete component.devopsconsole.openshift.io/myapp

.PHONY: deploy-test
## Deploy a CR as test
deploy-test:
oc create -f examples/devopsconsole_v1alpha1_component_cr.yaml
103 changes: 69 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,80 @@
## Quick Start
# DevOpsConsole

Install the operator-sdk CLI:
This repository was initially bootstrapped using [CoreOS operator](https://github.com/operator-framework/operator-sdk).

```sh
$ mkdir -p $GOPATH/src/github.com/operator-framework
$ cd $GOPATH/src/github.com/operator-framework
$ git clone https://github.com/operator-framework/operator-sdk
$ cd operator-sdk
$ git checkout master
$ make dep
$ make install
```
## Build

Add a new API for the custom resource AppService
### Pre-requisites
- [operator-sdk v0.5.0](https://github.com/operator-framework/operator-sdk#quick-start)
- [dep][dep_tool] version v0.5.0+.
- [git][git_tool]
- [go][go_tool] version v1.10+.
- [docker][docker_tool] version 17.03+.
- [kubectl][kubectl_tool] version v1.11.0+ or [oc] version 3.11
- Access to a kubernetes v.1.11.0+ cluster or openshift cluster version 3.11

```sh
$ operator-sdk add api --api-version=devopsconsole.openshift.io/v1alpha1 --kind=AppService
### Build
```

Add a new controller that watches for AppService

```sh
$ operator-sdk add controller --api-version=devopsconsole.openshift.io/v1alpha1 --kind=AppService
make build
```
## Deployment

Apply the app-operator CRD.

```sh
$ kubectl apply -f deploy/crds/app_v1alpha1_appservice_crd.yaml
### Set up Minishift (one-off)
* create a new profile to test the operator
```
minishift profile set devopsconsole
```
* enable the admin-user add-on
```
minishift addon enable admin-user
```
* optionally, configure the VM
```
minishift config set cpus 4
minishift config set memory 8GB
minishift config set vm-driver virtualbox
```
* start the instance
```
minishift start
```
> NOTE: this setup should be deprecated in favor of [OCP4 install]().

Set the OPERATOR_NAME variable
### Deploy the operator

```sh
$ export OPERATOR_NAME=app-operator
In dev mode, simply run your operator locally:
```
make local
```

Run the operator from outside the Minishift environment.

```sh
$ operator-sdk up local --namespace myproject
### Deploy the CR for testing
* Make sure minishift is running and use myproject
```
oc project myproject
```
* Clean previously created resources
```
make deploy-clean
```
* Deploy CR
```
make deploy-test
```
* See the newly created resources
```
oc get is,bc,svc,component.devopsconsole,build
NAME DOCKER REPO TAGS UPDATED
imagestream.image.openshift.io/myapp-output 172.30.1.1:5000/myproject/myapp-output
imagestream.image.openshift.io/myapp-runtime 172.30.1.1:5000/myproject/myapp-runtime latest 46 seconds ago

Your operator is now watching for the existence of an object that matches: GroupVersionKind(app.example.com/v1alpha1, Kind=App)
NAME TYPE FROM LATEST
buildconfig.build.openshift.io/myapp-bc Source Git@master 1

Apply the provided CR.yaml to your cluster. This should trigger the default logic specified in the handler.
NAME AGE
component.devopsconsole.openshift.io/myapp 48s

```sh
$ kubectl create -f deploy/examples/app_v1alpha1_appservice_cr.yaml
NAME TYPE FROM STATUS STARTED DURATION
build.build.openshift.io/myapp-bc-1 Source Git@85ac14e Running 45 seconds ago
```

## Directory layout
Expand All @@ -63,3 +90,11 @@ Please consult [the documentation](https://github.com/operator-framework/operato
| deploy | Contains various YAML manifests for registering CRDs, setting up [RBAC](https://kubernetes.io/docs/reference/access-authn-authz/rbac/), and deploying the operator as a Deployment.|
| Gopkg.toml Gopkg.lock | The [dep](https://github.com/golang/dep) manifests that describe the external dependencies of this operator.|
| vendor | The golang [Vendor](https://golang.org/cmd/go/#hdr-Vendor_Directories) folder that contains the local copies of the external dependencies that satisfy the imports of this project. [dep](https://github.com/golang/dep) manages the vendor directly.|



[dep_tool]:https://golang.github.io/dep/docs/installation.html
[git_tool]:https://git-scm.com/downloads
[go_tool]:https://golang.org/dl/
[docker_tool]:https://docs.docker.com/install/
[kubectl_tool]:https://kubernetes.io/docs/tasks/tools/install-kubectl/
15 changes: 15 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"os"
"runtime"

appsv1 "github.com/openshift/api/apps/v1"
buildv1 "github.com/openshift/api/build/v1"
imagev1 "github.com/openshift/api/image/v1"
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/leader"
"github.com/operator-framework/operator-sdk/pkg/ready"
Expand Down Expand Up @@ -87,6 +90,18 @@ func main() {
log.Error(err, "")
os.Exit(1)
}
if err := imagev1.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
os.Exit(1)
}
if err := buildv1.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
os.Exit(1)
}
if err := appsv1.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
os.Exit(1)
}

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
Expand Down
44 changes: 44 additions & 0 deletions deploy/crds/devopsconsole_v1alpha1_component_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
name: components.devopsconsole.openshift.io
spec:
group: devopsconsole.openshift.io
names:
kind: Component
listKind: ComponentList
plural: components
singular: component
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
properties:
buildType:
type: string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we would have a limited number of buildTypes, I think we should add the enum here. See https://github.com/operator-framework/operator-lifecycle-manager/blob/master/deploy/upstream/quickstart/olm.yaml#L1011 for an example.

What do you think @corinnekrych

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5046adb
for now only added nodejs, more will be added as we progress

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

description: The type of the image that is required to build your component.
enum:
- nodejs
codebase:
type: string
required:
- buildType
- codebase
type: object
status:
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
7 changes: 7 additions & 0 deletions deploy/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@ rules:
- devopsconsole.openshift.io
resources:
- '*'
- components
verbs:
- '*'
- apiGroups:
- components.devopsconsole.openshift.io
resources:
- '*'
verbs:
- '*'
7 changes: 7 additions & 0 deletions examples/devopsconsole_v1alpha1_component_cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: devopsconsole.openshift.io/v1alpha1
kind: Component
metadata:
name: myapp
spec:
buildType: "nodejs"
codebase: "https://github.com/nodeshift-starters/nodejs-rest-http-crud"
10 changes: 10 additions & 0 deletions pkg/apis/addtoscheme_components_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package apis

import (
"github.com/redhat-developer/devopsconsole-operator/pkg/apis/devopsconsole/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
}
2 changes: 1 addition & 1 deletion pkg/apis/addtoscheme_devopsconsole_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package apis

import (
"github.com/redhat-developer/devopsconsole-operator/pkg/apis/devopsconsole-operator/v1alpha1"
"github.com/redhat-developer/devopsconsole-operator/pkg/apis/devopsconsole/v1alpha1"
)

func init() {
Expand Down
Loading