Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chechiachang/cattle-operator


https://github.com/chechiachang/cattle-operator

Last synced: 23 days ago
JSON representation

Awesome Lists containing this project

README

        

cattle-operator
===

Cattle-operator is an example operator generated by operator-sdk.

---

# Install operator-sdk Cli

https://github.com/operator-framework/operator-sdk/blob/master/doc/user/install-operator-sdk.md

```
$ go version
go version go1.12.4 linux/amd64

$ operator-sdk version
operator-sdk version: v0.8.0, commit: 78c472461e75e6c64589cfadf577a2004b8a26b3
```

---

# Get Started

https://github.com/operator-framework/getting-started

New operator
```
cd ${GOPATH}/src/github.com/chechiachang

export GO111MODULE=on
OPERATOR=cattle-operator
operator-sdk new ${OPERATOR}

$ tree -L 2
.
├── cattle-operator
│   ├── build
│   ├── cmd
│   ├── deploy
│   ├── go.mod
│   ├── go.sum
│   ├── pkg
│   ├── tools.go
│   ├── vendor
│   └── version
└── README.md
```

Add api and controller
```
API_VERSION=cattle.chechiachang.com/v1alpha1
CRD=Cattle
operator-sdk add api --api-version=${API_VERSION} --kind=${CRD}
operator-sdk add controller --api-version=${API_VERSION} --kind=${CRD}
```

# Update CRD definition

Add Spec to Cattle
```
vim pkg/apis/cattle/v1alpha1/cattle_types.go

type CattleSpec struct {
Name string `json:"name"`
Size int32 `json:"size"`
BeefParts []string `json:"beefParts"`
}

make generate
```

Add angus-cattle resource
```
cp deploy/crds/cattle_v1apha1_cattle_cr.yaml deploy/crds/angus_cattle_cr.yaml
vim deploy/crds/angus_cattle_cr.yaml

apiVersion: cattle.chechiachang.com/v1alpha1
kind: Cattle
metadata:
name: angus-cattle
spec:
# Add fields here
name: angus
beatParts:
- chuck
- rib
- plate
size: 3
```

# Update controller reconcile logic

```
vim pkg/controller/cattle/cattle_controller.go

make generate
```

---

# Test

Test on a local cluster
```
make local
```

# Build Image

```
make build push
```

# Deploy to kubernetes

Update image tag
```
make tag
```

(Grant extra privilege for serviceaccount rulebinding)

```
kubectl apply -f deploy/crds/cattle_v1alpha1_cattle_crd.yaml
kubectl apply -f deploy
```

# Apply angus-cattle CR

```
kubectl apply -f deploy/crds/angus_cattle_cr.yaml
```