Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chechiachang/cattle-operator
https://github.com/chechiachang/cattle-operator
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/chechiachang/cattle-operator
- Owner: chechiachang
- Created: 2019-05-25T06:44:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-25T08:35:29.000Z (over 5 years ago)
- Last Synced: 2023-03-03T12:56:00.894Z (over 1 year ago)
- Language: Go
- Size: 5.22 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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/chechiachangexport 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.gotype 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.yamlapiVersion: 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.gomake 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
```